mbrs.metrics.xcomet module#
- class mbrs.metrics.xcomet.DeBERTaEncoder(pretrained_model: str, load_pretrained_weights: bool = True, local_files_only: bool = False)[source]#
Bases:
BERTEncoderDeBERTa encoder.
- Parameters:
- forward(input_ids: Tensor, attention_mask: Tensor | None = None, token_type_ids: Tensor | None = None, **kwargs) dict[str, Tensor][source]#
BERT model forward
- Parameters:
input_ids (torch.Tensor) – tokenized batch.
attention_mask (torch.Tensor) – batch attention mask.
token_type_ids (Optional[torch.tensor]) – batch attention mask. Defaults to None
- Returns:
- dictionary with ‘sentemb’, ‘wordemb’, ‘all_layers’
and ‘attention_mask’.
- Return type:
Dict[str, torch.Tensor]
- class mbrs.metrics.xcomet.MetricXCOMET(cfg: Config)[source]#
Bases:
MetricXCOMET metric class.
Both XCOMET (Guerreiro et al., 2024) and XCOMET-lite (Larionov et al., 2024) are supported.
- Supported models:
Unbabel/XCOMET-XL
Unbabel/XCOMET-XXL
myyycroft/XCOMET-lite
- class Config(model: str = 'Unbabel/XCOMET-XL', batch_size: int = 8, fp16: bool = False, bf16: bool = False, cpu: bool = False)[source]#
Bases:
ConfigXCOMET metric configuration.
model (str): Model name or path.
batch_size (int): Batch size.
fp16 (bool): Use float16 for the forward computation.
bf16 (bool): Use bfloat16 for the forward computation.
cpu (bool): Use CPU for the forward computation.
- corpus_score(hypotheses: list[str], references_lists: list[list[str]] | None = None, sources: list[str] | None = None) float[source]#
Calculate the corpus-level score.
- property device: device#
Returns the device of the model.
- pairwise_scores(hypotheses: list[str], references: list[str], source: str | None = None) Tensor[source]#
Calculate the pairwise scores.
- score(hypothesis: str, reference: str | None = None, source: str | None = None) float[source]#
Calculate the score of the given hypothesis.
- scorer: XCOMETMetric#