mbrs.decoders.mbr module

mbrs.decoders.mbr module#

class mbrs.decoders.mbr.DecoderMBR(cfg: ~mbrs.decoders.base.DecoderBase.Config, metric: ~mbrs.metrics.base.MetricBase, selector: ~mbrs.selectors.base.Selector = <mbrs.selectors.nbest.SelectorNbest object>)[source]#

Bases: DecoderReferenceBased

Naive MBR decoder class.

  • Time complexity: O(N^2)

  • Space complexity: O(N^2)

References

S. Kumar and W. Byrne, 2004, “Minimum Bayes-Risk Decoding for Statistical Machine Translation”. https://aclanthology.org/N04-1022

B. Eikema and W. Aziz, 2020, “Is MAP Decoding All You Need? The Inadequacy of the Mode in Neural Machine Translation”. https://aclanthology.org/2020.coling-main.398

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:
  • hypotheses (list[str]) – Hypotheses.

  • references (list[str]) – References.

  • source (str, optional) – A source.

  • nbest (int) – Return the n-best hypotheses.

  • reference_lprobs (Tensor, optional) – Log-probabilities for each reference sample. The shape must be (len(references),). See https://arxiv.org/abs/2311.05263.

Returns:

The n-best hypotheses.

Return type:

DecoderMBR.Output