mbrs.decoders.probabilistic_mbr module#

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

Bases: DecoderMBR

Probabilistic MBR decoder using alternating least squares (ALS) approximation.

References

F. Trabelsi et al., 2024, “Efficient Minimum Bayes Risk Decoding using Low-Rank Matrix Completion Algorithms”. https://arxiv.org/abs/2406.02832

class Config(reduction_factor: float = 8.0, regularization_weight: float = 0.1, rank: int = 8, niter: int = 10, seed: int = 0)[source]#

Bases: Config

Configuration for the decoder.

  • reduction_factor (float): Reduction factor. The computational budget will be reduced to 1 / reduction_factor.

  • regularization_weight (float): Weight of L2 regularization.

  • rank (int): Rank of the factarized matrices.

  • niter (int): The number of alternating steps performed.

  • seed (int): Random seed.

niter: int = 10#
rank: int = 8#
reduction_factor: float = 8.0#
regularization_weight: float = 0.1#
seed: int = 0#
cfg: Config#
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

metric: Metric#
pairwise_scores_probabilistic(hypotheses: list[str], references: list[str], source: str | None = None) Tensor[source]#

Compute approximated pairwise scores using the probabilistic MBR algorithm.

Parameters:
  • hypotheses (list[str]) – Hypotheses.

  • references (list[str]) – References.

  • source (str, optional) – A source.

Returns:

Approximated pairwise scores of shape (H, R).

Return type:

Tensor