





'''simple docstring'''






import comet  # From: unbabel-comet
import torch

import datasets


__UpperCamelCase					    =	datasets.logging.get_logger(__name__)

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

__UpperCamelCase					    =	"\\nCrosslingual 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).\nWith 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.\n\nSee the [README.md] file at https://unbabel.github.io/COMET/html/models.html for more information.\n"

__UpperCamelCase					    =	"\nCOMET score.\n\nArgs:\n\n`sources` (list of str): Source sentences\n`predictions` (list of str): candidate translations\n`references` (list of str): reference translations\n`cuda` (bool): If set to True, runs COMET using GPU\n`show_progress` (bool): Shows progress\n`model`: COMET model to be used. Will default to `wmt-large-da-estimator-1719` if None.\n\nReturns:\n    `samples`: List of dictionaries with `src`, `mt`, `ref` and `score`.\n    `scores`: List of scores.\n\nExamples:\n\n    >>> comet_metric = datasets.load_metric('comet')\n    >>> # comet_metric = load_metric('comet', 'wmt20-comet-da')  # you can also choose which model to use\n    >>> source = [\"Dem Feuer konnte Einhalt geboten werden\", \"Schulen und Kindergärten wurden eröffnet.\"]\n    >>> hypothesis = [\"The fire could be stopped\", \"Schools and kindergartens were open\"]\n    >>> reference = [\"They were able to control the fire.\", \"Schools and kindergartens opened\"]\n    >>> results = comet_metric.compute(predictions=hypothesis, references=reference, sources=source)\n    >>> print([round(v, 2) for v in results[\"scores\"]])\n    [0.19, 0.92]\n"




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

		def 	lowercase__     (   self					:   str			)					->    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 	lowercase__     (   self					:   int  ,      __magic_name__					:   Any			)					->    Any:


					"""simple docstring"""

					if self.config_name == "default":
								__snake_case					:      Tuple							      =     comet.load_from_checkpoint(comet.download_model("""wmt20-comet-da"""			)			)
					else:
								__snake_case					:      Any							      =     comet.load_from_checkpoint(comet.download_model(self.config_name			)			)

		def 	lowercase__     (   self					:   Union[str, Any]  ,      __magic_name__					:   Dict  ,      __magic_name__					:   List[str]  ,      __magic_name__					:   Any  ,      __magic_name__					:   int=None  ,      __magic_name__					:   str=False			)					->    List[str]:


					"""simple docstring"""

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









'''simple docstring'''






import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


__UpperCamelCase					    =	logging.getLogger()




@unittest.skip('''Temporarily disable the doc tests.'''		)
@require_torch
@require_tf
@slow
class  _A (					unittest.TestCase		):

		def 	lowercase__     (   self					:   Optional[int]  ,      __magic_name__					:   Path  ,      __magic_name__					:   Union[str, None] = None  ,      __magic_name__					:   Union[List[str], None] = None  ,      __magic_name__					:   Union[str, List[str], None] = None  ,      __magic_name__					:   bool = True  ,      )					->    Optional[int]:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     [file for file in os.listdir(__magic_name__			) if os.path.isfile(os.path.join(__magic_name__  ,      __magic_name__			)			)]

					if identifier is not None:
								__snake_case					:      List[Any]							      =     [file for file in files if identifier in file]

					if n_identifier is not None:
								if isinstance(__magic_name__  ,      __magic_name__			):
											for n_ in n_identifier:
														__snake_case					:      Optional[int]							      =     [file for file in files if n_ not in file]
								else:
											__snake_case					:      Tuple							      =     [file for file in files if n_identifier not in file]

					__snake_case					:      Dict							      =     ignore_files or []
					ignore_files.append("""__init__.py"""			)
					__snake_case					:      List[str]							      =     [file for file in files if file not in ignore_files]

					for file in files:
								# Open all files
								print("""Testing"""  ,      __magic_name__			)

								if only_modules:
											__snake_case					:      List[Any]							      =     file.split("""."""			)[0]
											try:
														__snake_case					:      List[Any]							      =     getattr(__magic_name__  ,      __magic_name__			)
														__snake_case					:      Union[str, Any]							      =     doctest.DocTestSuite(__magic_name__			)
														__snake_case					:      Dict							      =     unittest.TextTestRunner().run(__magic_name__			)
														self.assertIs(len(result.failures			)  ,      0			)
											except AttributeError:
														logger.info(f'''{module_identifier} is not a module.'''			)
								else:
											__snake_case					:      Tuple							      =     doctest.testfile(str("""..""" / directory / file			)  ,      optionflags=doctest.ELLIPSIS			)
											self.assertIs(result.failed  ,      0			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    Any:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     Path("""src/transformers"""			)
					__snake_case					:      List[Any]							      =     """modeling"""
					__snake_case					:      Union[str, Any]							      =     [
					    """modeling_ctrl.py""",
					    """modeling_tf_ctrl.py""",
					]
					self.analyze_directory(__magic_name__  ,      identifier=__magic_name__  ,      ignore_files=__magic_name__			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    int:


					"""simple docstring"""

					__snake_case					:      Union[str, Any]							      =     Path("""src/transformers"""			)
					__snake_case					:      Any							      =     """tokenization"""
					self.analyze_directory(__magic_name__  ,      identifier=__magic_name__			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    int:


					"""simple docstring"""

					__snake_case					:      List[Any]							      =     Path("""src/transformers"""			)
					__snake_case					:      List[str]							      =     """configuration"""
					self.analyze_directory(__magic_name__  ,      identifier=__magic_name__			)

		def 	lowercase__     (   self					:   Dict			)					->    Dict:


					"""simple docstring"""

					__snake_case					:      Tuple							      =     Path("""src/transformers"""			)
					__snake_case					:      int							      =     ["""configuration""", """modeling""", """tokenization"""]
					self.analyze_directory(__magic_name__  ,      n_identifier=__magic_name__			)

		def 	lowercase__     (   self					:   Optional[int]			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      int							      =     Path("""docs/source"""			)
					__snake_case					:      Optional[int]							      =     ["""favicon.ico"""]
					self.analyze_directory(__magic_name__  ,      ignore_files=__magic_name__  ,      only_modules=__magic_name__			)


