






'''simple docstring'''




import comet  # From: unbabel-comet
import torch

import datasets


__lowerCamelCase   :					Optional[int]   							=					datasets.logging.get_logger(__name__)

__lowerCamelCase   :					Optional[Any]   							=					'''\
@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",
}
'''

__lowerCamelCase   :					List[Any]   							=					'''\
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.
'''

__lowerCamelCase   :					List[str]   							=					'''
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    A_	(datasets.Metric							):
							"""simple docstring"""




							def 							_A	(		self			:Any				)				->  List[Any]:


										'''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 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Union[str, Any]				)				->  int:


										'''simple docstring'''




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






							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:Optional[Any]       ,							lowerCAmelCase__			:Any       ,							lowerCAmelCase__			:Optional[int]=None       ,							lowerCAmelCase__			:Optional[int]=False				)				->  str:


										'''simple docstring'''




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












'''simple docstring'''




import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
__lowerCamelCase   :					Any   							=					'''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
__lowerCamelCase   :					List[str]   							=					direct_transformers_import(PATH_TO_TRANSFORMERS)

__lowerCamelCase   :					Optional[Any]   							=					transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__lowerCamelCase   :					Union[str, Any]   							=					re.compile(R'''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


__lowerCamelCase   :					Any   							=					{
    '''DecisionTransformerConfig''',
    '''EncoderDecoderConfig''',
    '''MusicgenConfig''',
    '''RagConfig''',
    '''SpeechEncoderDecoderConfig''',
    '''TimmBackboneConfig''',
    '''VisionEncoderDecoderConfig''',
    '''VisionTextDualEncoderConfig''',
    '''LlamaConfig''',
}

def 	__UpperCAmelCase       ( __magic_name__						)->    List[Any]:



			"""simple docstring"""



			snake_case_				:					Tuple   =       None

			# source code of `config_class`
			snake_case_				:					List[Any]   =       inspect.getsource(__magic_name__						)
			snake_case_				:					List[str]   =       _re_checkpoint.findall(__magic_name__						)

			# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
			# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
			for ckpt_name, ckpt_link in checkpoints:
						# allow the link to end with `/`
						if ckpt_link.endswith("/"						):
									snake_case_				:					Optional[Any]   =       ckpt_link[:-1]

						# verify the checkpoint name corresponds to the checkpoint link
						snake_case_				:					str   =       F'''https://huggingface.co/{ckpt_name}'''
						if ckpt_link == ckpt_link_from_name:
									snake_case_				:					Dict   =       ckpt_name
									break

			return checkpoint

def 	__UpperCAmelCase       ( )->    Dict:



			"""simple docstring"""



			snake_case_				:					Optional[int]   =       []

			for config_class in list(CONFIG_MAPPING.values()						):
						# Skip deprecated models
						if "models.deprecated" in config_class.__module__:
									continue
						snake_case_				:					str   =       get_checkpoint_from_config_class(__magic_name__						)

						snake_case_				:					Union[str, Any]   =       config_class.__name__
						if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
									configs_without_checkpoint.append(__magic_name__						)

			if len(__magic_name__						) > 0:
						snake_case_				:					Tuple   =       "\n".join(sorted(__magic_name__						)						)
						raise ValueError(F'''The following configurations don\'t contain any valid checkpoint:\n{message}'''						)


if __name__ == "__main__":
		check_config_docstrings_have_checkpoints()




