mbrs.decoders.centroid_mbr module#

class mbrs.decoders.centroid_mbr.DecoderCentroidMBR(cfg: ~mbrs.decoders.centroid_mbr.DecoderCentroidMBR.Config, metric: ~mbrs.metrics.base.MetricAggregatableCache, selector: ~mbrs.selectors.base.Selector = <mbrs.selectors.nbest.SelectorNbest object>)[source]#

Bases: DecoderMBR

Centroid-Based MBR decoder class.

  • Time complexity: O(Nk)

  • Space complexity: O(Nk)

where k << N.

References

H. Deguchi et al., 2024. “Centroid-Based Efficient Minimum Bayes Risk Decoding”. https://aclanthology.org/2024.findings-acl.654

class Config(kmeans: ~mbrs.modules.kmeans.Kmeans.Config = <factory>, count_weight: bool = False)[source]#

Bases: Config

Configuration for the decoder.

  • kmeans (Kmeans.Config): Configuration for k-means.

  • count_weight: (bool) Weight the scores with counts.

count_weight: bool = False#
kmeans: Config#
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:

DecoderCentroidMBR.Output

metric: Metric#