mbrs.decoders.base module#
- class mbrs.decoders.base.DecoderBase(cfg: ~mbrs.decoders.base.DecoderBase.Config, metric: ~mbrs.metrics.base.MetricBase, selector: ~mbrs.selectors.base.Selector = <mbrs.selectors.nbest.SelectorNbest object>)[source]#
Bases:
ABCDecoder base class.
- class Output(idx: list[int], sentence: list[str], score: list[float])[source]#
Bases:
objectidx (list[int]): Index numbers of the n-best hypotheses.
sentence (list[str]): Sentences of the n-best hypotheses.
score (list[float]): Scores of the n-best hypotheses.
- argbest(x: Tensor) Tensor[source]#
Return the index of the best element.
- Parameters:
x (Tensor) – Input 1-D array.
- Returns:
A scalar tensor of the best index.
- Return type:
Tensor
- select(hypotheses: list[str], expected_scores: Tensor, nbest: int = 1, source: str | None = None, **kwargs) Output[source]#
Select the final output list.
- Parameters:
- Returns:
Outputs.
- Return type:
- topk(x: Tensor, k: int = 1) tuple[list[float], list[int]][source]#
Return the top-k best elements and corresponding indices.
- Parameters:
x (Tensor) – Input 1-D array.
k (int) – Return the top-k values and indices.
- Returns:
- tuple[list[float], list[int]]
list[float]: The top-k values.
list[int]: The top-k indices.
- class mbrs.decoders.base.DecoderReferenceBased(cfg: ~mbrs.decoders.base.DecoderBase.Config, metric: ~mbrs.metrics.base.MetricBase, selector: ~mbrs.selectors.base.Selector = <mbrs.selectors.nbest.SelectorNbest object>)[source]#
Bases:
DecoderBaseDecoder base class for strategies that use references like MBR decoding.
- abstract decode(hypotheses: list[str], references: list[str], source: str | None = None, nbest: int = 1, reference_lprobs: Tensor | None = None) Output[source]#
Select the n-best hypotheses based on the strategy.
- Parameters:
- Returns:
The n-best hypotheses.
- Return type:
Decoder.Output
- class mbrs.decoders.base.DecoderReferenceless(cfg: ~mbrs.decoders.base.DecoderBase.Config, metric: ~mbrs.metrics.base.MetricBase, selector: ~mbrs.selectors.base.Selector = <mbrs.selectors.nbest.SelectorNbest object>)[source]#
Bases:
DecoderBaseDecoder base class for reference-free strategies.
- abstract decode(hypotheses: list[str], source: str, nbest: int = 1) Output[source]#
Select the n-best hypotheses based on the strategy.
- metric: MetricReferenceless#