mbrs.metrics.base module#
- class mbrs.metrics.base.Metric(cfg: Config)[source]#
Bases:
MetricBaseBase metric class.
- corpus_score(hypotheses: list[str], references_lists: list[list[str]], sources: list[str] | None = None) float[source]#
Calculate the corpus-level score.
- expected_scores(hypotheses: list[str], references: list[str], source: str | None = None, reference_lprobs: Tensor | None = None) Tensor[source]#
Calculate the expected scores for each hypothesis.
- Parameters:
- Returns:
The expected scores for each hypothesis.
- Return type:
Tensor
- pairwise_scores(hypotheses: list[str], references: list[str], source: str | None = None) Tensor[source]#
Calculate the pairwise scores.
- abstract score(hypothesis: str, reference: str, source: str | None = None) float[source]#
Calculate the score of the given hypothesis.
- class mbrs.metrics.base.MetricAggregatable(cfg: Config)[source]#
Bases:
MetricBase class for aggregatable metrics.
This class supports reference aggregation.
- abstract expected_scores_reference_aggregation(hypotheses: list[str], references: list[str], source: str | None = None, reference_lprobs: Tensor | None = None) Tensor[source]#
Calculate the expected scores for each hypothesis.
- Parameters:
- Returns:
The expected scores for each hypothesis.
- Return type:
Tensor
- class mbrs.metrics.base.MetricAggregatableCache(cfg: Config)[source]#
Bases:
MetricAggregatable,MetricCacheableBase class for metrics that can aggregate the cache.
This class supports to aggregate intermediate representations of sentences.
- class Cache[source]#
Bases:
CacheIntermediate representations of sentences.
- abstract aggregate(reference_lprobs: Tensor | None = None) Cache[source]#
Aggregate the cached representations.
- Parameters:
reference_lprobs (Tensor, optional) – Log-probabilities for each reference sample. The shape must be (len(references),). See https://arxiv.org/abs/2311.05263.
- Returns:
An aggregated representation.
- Return type:
- class mbrs.metrics.base.MetricBase(cfg: Config)[source]#
Bases:
ABCBase metric class.
- property device: device#
Returns the device of the metric object.
- class mbrs.metrics.base.MetricCacheable(cfg: Config)[source]#
Bases:
MetricBase class for cacheable metrics.
This class supports to cache intermediate representations of sentences.
- abstract encode(sentences: list[str]) Cache[source]#
Encode the given sentences into their intermediate representations.
- Parameters:
- Returns:
Intermediate representations.
- Return type:
- abstract out_proj(hypotheses_ir: Cache, references_ir: Cache, sources_ir: Cache | None = None) Tensor[source]#
Forward the output projection layer.
- pairwise_scores(hypotheses: list[str], references: list[str], source: str | None = None) Tensor[source]#
Calculate the pairwise scores.
- pairwise_scores_from_ir(hypotheses_ir: Cache, references_ir: Cache, source_ir: Cache | None = None) Tensor[source]#
Calculate the pairwise scores from the intermediate representations.
- score(hypothesis: str, reference: str, source: str | None = None) float[source]#
Calculate the score of the given hypothesis.
- scores(hypotheses: list[str], references: list[str], sources: list[str] | None = None) Tensor[source]#
Calculate the scores of the given hypotheses.
- class mbrs.metrics.base.MetricReferenceless(cfg: Config)[source]#
Bases:
MetricBaseBase class for reference-less metrics like quality estimation.
- corpus_score(hypotheses: list[str], sources: list[str]) float[source]#
Calculate the corpus-level score.