


"""simple docstring"""



import comet  # From: unbabel-comet
import torch

import datasets


__snake_case         =					datasets.logging.get_logger(__name__)

__snake_case         =					"""\
@inproceedings{rei-EtAl:2020:WMT,
   author    = {Rei, Ricardo  and  Stewart, Craig  and  Farinha, Ana C  and  Lavie, Alon},
   title     = {Unbabel's Participation in the WMT20 Metrics Shared Task},
   booktitle      = {Proceedings of the Fifth Conference on Machine Translation},
   month          = {November},
   year           = {2020},
   address        = {Online},
   publisher      = {Association for Computational Linguistics},
   pages     = {909--918},
}
@inproceedings{rei-etal-2020-comet,
   title = \"{COMET}: A Neural Framework for {MT} Evaluation\",
   author = \"Rei, Ricardo  and
      Stewart, Craig  and
      Farinha, Ana C  and
      Lavie, Alon\",
   booktitle = \"Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)\",
   month = nov,
   year = \"2020\",
   address = \"Online\",
   publisher = \"Association for Computational Linguistics\",
   url = \"https://www.aclweb.org/anthology/2020.emnlp-main.213\",
   pages = \"2685--2702\",
}
"""

__snake_case         =					"""\
Crosslingual Optimized Metric for Evaluation of Translation (COMET) is an open-source framework used to train Machine Translation metrics that achieve high levels of correlation with different types of human judgments (HTER, DA's or MQM).
With the release of the framework the authors also released fully trained models that were used to compete in the WMT20 Metrics Shared Task achieving SOTA in that years competition.

See the [README.md] file at https://unbabel.github.io/COMET/html/models.html for more information.
"""

__snake_case         =					"""
COMET score.

Args:

`sources` (list of str): Source sentences
`predictions` (list of str): candidate translations
`references` (list of str): reference translations
`cuda` (bool): If set to True, runs COMET using GPU
`show_progress` (bool): Shows progress
`model`: COMET model to be used. Will default to `wmt-large-da-estimator-1719` if None.

Returns:
    `samples`: List of dictionaries with `src`, `mt`, `ref` and `score`.
    `scores`: List of scores.

Examples:

    >>> comet_metric = datasets.load_metric('comet')
    >>> # comet_metric = load_metric('comet', 'wmt20-comet-da')  # you can also choose which model to use
    >>> source = [\"Dem Feuer konnte Einhalt geboten werden\", \"Schulen und Kindergärten wurden eröffnet.\"]
    >>> hypothesis = [\"The fire could be stopped\", \"Schools and kindergartens were open\"]
    >>> reference = [\"They were able to control the fire.\", \"Schools and kindergartens opened\"]
    >>> results = comet_metric.compute(predictions=hypothesis, references=reference, sources=source)
    >>> print([round(v, 2) for v in results[\"scores\"]])
    [0.19, 0.92]
"""







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION					,							_KWARGS_DESCRIPTION			)
class _lowerCAmelCase       (   datasets.Metric			):







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       return datasets.MetricInfo(
           description=_DESCRIPTION		,			citation=_CITATION		,			homepage="https://unbabel.github.io/COMET/html/index.html"		,			inputs_description=_KWARGS_DESCRIPTION		,			features=datasets.Features(
               {
                   "sources": datasets.Value("string"		,			id="sequence"		),
                   "predictions": datasets.Value("string"		,			id="sequence"		),
                   "references": datasets.Value("string"		,			id="sequence"		),
               }		)		,			codebase_urls=["https://github.com/Unbabel/COMET"]		,			reference_urls=[
               "https://github.com/Unbabel/COMET",
               "https://www.aclweb.org/anthology/2020.emnlp-main.213/",
               "http://www.statmt.org/wmt20/pdf/2020.wmt-1.101.pdf6",
           ]		,			)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		)			->	List[str]:

       '''simple docstring'''




       if self.config_name == "default":
           snake_case					:   Dict         =					comet.load_from_checkpoint(comet.download_model("wmt20-comet-da"		)		)
       else:
           snake_case					:   Optional[int]         =					comet.load_from_checkpoint(comet.download_model(self.config_name		)		)







   def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__=None		,			UpperCamelCase__=False		)			->	Dict:

       '''simple docstring'''




       if gpus is None:
           snake_case					:   Union[str, Any]         =					1 if torch.cuda.is_available() else 0
       snake_case					:   Dict         =					{"src": sources, "mt": predictions, "ref": references}
       snake_case					:   List[str]         =					[dict(zip(UpperCamelCase__		,			UpperCamelCase__		)		) for t in zip(*data.values()		)]
       snake_case      ,snake_case					:   int         =					self.scorer.predict(UpperCamelCase__		,			gpus=UpperCamelCase__		,			progress_bar=UpperCamelCase__		)
       return {"mean_score": mean_score, "scores": scores}









"""simple docstring"""



import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
  from transformers.models.roberta.modeling_flax_roberta import (
      FlaxRobertaForCausalLM,
      FlaxRobertaForMaskedLM,
      FlaxRobertaForMultipleChoice,
      FlaxRobertaForQuestionAnswering,
      FlaxRobertaForSequenceClassification,
      FlaxRobertaForTokenClassification,
      FlaxRobertaModel,
  )







class _lowerCAmelCase       (   unittest.TestCase			):







   def __init__(			self		,			UpperCamelCase__		,			UpperCamelCase__=13		,			UpperCamelCase__=7		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=True		,			UpperCamelCase__=99		,			UpperCamelCase__=32		,			UpperCamelCase__=5		,			UpperCamelCase__=4		,			UpperCamelCase__=37		,			UpperCamelCase__="gelu"		,			UpperCamelCase__=0.1		,			UpperCamelCase__=0.1		,			UpperCamelCase__=512		,			UpperCamelCase__=16		,			UpperCamelCase__=2		,			UpperCamelCase__=0.02		,			UpperCamelCase__=4		,			)			->	Dict:

       '''simple docstring'''




       snake_case					:   Any         =					parent
       snake_case					:   int         =					batch_size
       snake_case					:   Optional[Any]         =					seq_length
       snake_case					:   Dict         =					is_training
       snake_case					:   str         =					use_attention_mask
       snake_case					:   List[Any]         =					use_token_type_ids
       snake_case					:   Tuple         =					use_labels
       snake_case					:   str         =					vocab_size
       snake_case					:   Optional[Any]         =					hidden_size
       snake_case					:   Optional[Any]         =					num_hidden_layers
       snake_case					:   Dict         =					num_attention_heads
       snake_case					:   int         =					intermediate_size
       snake_case					:   Union[str, Any]         =					hidden_act
       snake_case					:   Optional[Any]         =					hidden_dropout_prob
       snake_case					:   int         =					attention_probs_dropout_prob
       snake_case					:   Optional[int]         =					max_position_embeddings
       snake_case					:   Dict         =					type_vocab_size
       snake_case					:   str         =					type_sequence_label_size
       snake_case					:   List[Any]         =					initializer_range
       snake_case					:   Dict         =					num_choices







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       snake_case					:   Optional[int]         =					ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size		)

       snake_case					:   Optional[int]         =					None
       if self.use_attention_mask:
           snake_case					:   Optional[Any]         =					random_attention_mask([self.batch_size, self.seq_length]		)

       snake_case					:   List[Any]         =					None
       if self.use_token_type_ids:
           snake_case					:   Dict         =					ids_tensor([self.batch_size, self.seq_length]		,			self.type_vocab_size		)

       snake_case					:   Union[str, Any]         =					RobertaConfig(
           vocab_size=self.vocab_size		,			hidden_size=self.hidden_size		,			num_hidden_layers=self.num_hidden_layers		,			num_attention_heads=self.num_attention_heads		,			intermediate_size=self.intermediate_size		,			hidden_act=self.hidden_act		,			hidden_dropout_prob=self.hidden_dropout_prob		,			attention_probs_dropout_prob=self.attention_probs_dropout_prob		,			max_position_embeddings=self.max_position_embeddings		,			type_vocab_size=self.type_vocab_size		,			is_decoder=UpperCamelCase__		,			initializer_range=self.initializer_range		,			)

       return config, input_ids, token_type_ids, attention_mask







   def 				lowerCamelCase	(			self		)			->	Tuple:

       '''simple docstring'''




       snake_case					:   List[str]         =					self.prepare_config_and_inputs()
       snake_case      ,snake_case      ,snake_case      ,snake_case					:   List[Any]         =					config_and_inputs
       snake_case					:   Tuple         =					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
       return config, inputs_dict







   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       snake_case					:   List[str]         =					self.prepare_config_and_inputs()
       snake_case      ,snake_case      ,snake_case      ,snake_case					:   List[Any]         =					config_and_inputs

       snake_case					:   int         =					True
       snake_case					:   Optional[int]         =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
       snake_case					:   Optional[Any]         =					ids_tensor([self.batch_size, self.seq_length]		,			vocab_size=2		)

       return (
           config,
           input_ids,
           token_type_ids,
           encoder_hidden_states,
           encoder_attention_mask,
       )







@require_flax
class _lowerCAmelCase       (   snake_case_					,							unittest.TestCase			):
   __UpperCAmelCase				: int													=						True

   __UpperCAmelCase				: Optional[Any]													=						(
       (
           FlaxRobertaModel,
           FlaxRobertaForCausalLM,
           FlaxRobertaForMaskedLM,
           FlaxRobertaForSequenceClassification,
           FlaxRobertaForTokenClassification,
           FlaxRobertaForMultipleChoice,
           FlaxRobertaForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )







   def 				lowerCamelCase	(			self		)			->	Dict:

       '''simple docstring'''




       snake_case					:   Dict         =					FlaxRobertaModelTester(self		)







   @slow
   def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

       '''simple docstring'''




       for model_class_name in self.all_model_classes:
           snake_case					:   Dict         =					model_class_name.from_pretrained("roberta-base"		,			from_pt=UpperCamelCase__		)
           snake_case					:   List[str]         =					model(np.ones((1, 1)		)		)
           self.assertIsNotNone(UpperCamelCase__		)





