mbrs.metrics.bleu module#
- class mbrs.metrics.bleu.MetricBLEU(cfg: Config)[source]#
Bases:
MetricAggregatableBLEU metric class.
- class AggregatedReference(ngrams: Counter[tuple[str, ...]], length: float)[source]#
Bases:
objectAggregated reference representation.
ngrams (Counter[tuple[str, …]]): Bags of expected n-gram counts.
length (float): Expected length of references.
- class Config(lowercase: bool = False, force: bool = False, tokenize: str | None = None, smooth_method: str = 'exp', smooth_value: float | None = None, max_ngram_order: int = 4, effective_order: bool = True, trg_lang: str = '', num_workers: int = 8)[source]#
Bases:
ConfigBLEU metric configuration.
lowercase (bool): If True, lowercased BLEU is computed.
force (bool): Ignore data that looks already tokenized.
tokenize (str, optional): The tokenizer to use. If None, defaults to language-specific tokenizers with ‘13a’ as the fallback default.
smooth_method (str): The smoothing method to use (‘floor’, ‘add-k’, ‘exp’ or ‘none’).
smooth_value (float, optional): The smoothing value for floor and add-k methods. None falls back to default value.
max_ngram_order (int): If given, it overrides the maximum n-gram order (default: 4) when computing precisions.
effective_order (bool): If True, stop including n-gram orders for which precision is 0. This should be True, if sentence-level BLEU will be computed. (default: True)
trg_lang (str): An optional language code to raise potential tokenizer warnings.
num_workers (int): Number of workers for multiprocessing.
- corpus_score(hypotheses: list[str], references_lists: list[list[str]], sources: list[str] | None = None) float[source]#
Calculate the corpus-level score.
- 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
- pairwise_scores(hypotheses: list[str], references: list[str], *_, **__) Tensor[source]#
Calculate the pairwise scores.