






'''simple docstring'''




from scipy.stats import pearsonr, spearmanr
from sklearn.metrics import fa_score, matthews_corrcoef

import datasets


__lowerCamelCase   :					Optional[Any]   							=					'''\
@inproceedings{wang2019glue,
  title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},
  author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},
  note={In the Proceedings of ICLR.},
  year={2019}
}
'''

__lowerCamelCase   :					str   							=					'''\
GLUE, the General Language Understanding Evaluation benchmark
(https://gluebenchmark.com/) is a collection of resources for training,
evaluating, and analyzing natural language understanding systems.
'''

__lowerCamelCase   :					Dict   							=					'''
Compute GLUE evaluation metric associated to each GLUE dataset.
Args:
    predictions: list of predictions to score.
        Each translation should be tokenized into a list of tokens.
    references: list of lists of references for each translation.
        Each reference should be tokenized into a list of tokens.
Returns: depending on the GLUE subset, one or several of:
    "accuracy": Accuracy
    "f1": F1 score
    "pearson": Pearson Correlation
    "spearmanr": Spearman Correlation
    "matthews_correlation": Matthew Correlation
Examples:

    >>> glue_metric = datasets.load_metric(\'glue\', \'sst2\')  # \'sst2\' or any of ["mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0}

    >>> glue_metric = datasets.load_metric(\'glue\', \'mrpc\')  # \'mrpc\' or \'qqp\'
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0, \'f1\': 1.0}

    >>> glue_metric = datasets.load_metric(\'glue\', \'stsb\')
    >>> references = [0., 1., 2., 3., 4., 5.]
    >>> predictions = [0., 1., 2., 3., 4., 5.]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print({"pearson": round(results["pearson"], 2), "spearmanr": round(results["spearmanr"], 2)})
    {\'pearson\': 1.0, \'spearmanr\': 1.0}

    >>> glue_metric = datasets.load_metric(\'glue\', \'cola\')
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'matthews_correlation\': 1.0}
'''

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



			"""simple docstring"""



			return float((preds == labels).mean()						)

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    str:



			"""simple docstring"""



			snake_case_				:					Dict   =       simple_accuracy(__magic_name__     ,__magic_name__						)
			snake_case_				:					Union[str, Any]   =       float(fa_score(y_true=__magic_name__     ,y_pred=__magic_name__						)						)
			return {
			    "accuracy": acc,
			    "f1": fa,
			}

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    Optional[int]:



			"""simple docstring"""



			snake_case_				:					List[str]   =       float(pearsonr(__magic_name__     ,__magic_name__						)[0]						)
			snake_case_				:					Tuple   =       float(spearmanr(__magic_name__     ,__magic_name__						)[0]						)
			return {
			    "pearson": pearson_corr,
			    "spearmanr": spearman_corr,
			}







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,					_KWARGS_DESCRIPTION							)
class    A_	(datasets.Metric							):
							"""simple docstring"""




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


										'''simple docstring'''




										if self.config_name not in [
										    "sst2",
										    "mnli",
										    "mnli_mismatched",
										    "mnli_matched",
										    "cola",
										    "stsb",
										    "mrpc",
										    "qqp",
										    "qnli",
										    "rte",
										    "wnli",
										    "hans",
										]:
													raise KeyError(
													    "You should supply a configuration name selected in "
													    "[\"sst2\", \"mnli\", \"mnli_mismatched\", \"mnli_matched\", "
													    "\"cola\", \"stsb\", \"mrpc\", \"qqp\", \"qnli\", \"rte\", \"wnli\", \"hans\"]"				)
										return datasets.MetricInfo(
										    description=_DESCRIPTION       ,							citation=_CITATION       ,							inputs_description=_KWARGS_DESCRIPTION       ,							features=datasets.Features(
										        {
										            "predictions": datasets.Value("int64" if self.config_name != "stsb" else "float32"				),
										            "references": datasets.Value("int64" if self.config_name != "stsb" else "float32"				),
										        }				)       ,							codebase_urls=[]       ,							reference_urls=[]       ,							format="numpy"       ,							)






							def 							_A	(		self			:Optional[Any]       ,							lowerCAmelCase__			:Optional[int]       ,							lowerCAmelCase__			:List[Any]				)				->  Dict:


										'''simple docstring'''




										if self.config_name == "cola":
													return {"matthews_correlation": matthews_corrcoef(lowerCAmelCase__       ,							lowerCAmelCase__				)}
										elif self.config_name == "stsb":
													return pearson_and_spearman(lowerCAmelCase__       ,							lowerCAmelCase__				)
										elif self.config_name in ["mrpc", "qqp"]:
													return acc_and_fa(lowerCAmelCase__       ,							lowerCAmelCase__				)
										elif self.config_name in ["sst2", "mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]:
													return {"accuracy": simple_accuracy(lowerCAmelCase__       ,							lowerCAmelCase__				)}
										else:
													raise KeyError(
													    "You should supply a configuration name selected in "
													    "[\"sst2\", \"mnli\", \"mnli_mismatched\", \"mnli_matched\", "
													    "\"cola\", \"stsb\", \"mrpc\", \"qqp\", \"qnli\", \"rte\", \"wnli\", \"hans\"]"				)












'''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()




