

from scipy.stats import pearsonr

import datasets


lowerCAmelCase							:  Dict            =						"""
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.
The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
"""


lowerCAmelCase							:  Tuple            =						"""
Args:
    predictions (`list` of `int`): Predicted class labels, as returned by a model.
    references (`list` of `int`): Ground truth labels.
    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.

Returns:
    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.
    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.

Examples:

    Example 1-A simple example using only predictions and references.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])
        >>> print(round(results['pearsonr'], 2))
        -0.74

    Example 2-The same as Example 1, but that also returns the `p-value`.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)
        >>> print(sorted(list(results.keys())))
        ['p-value', 'pearsonr']
        >>> print(round(results['pearsonr'], 2))
        -0.74
        >>> print(round(results['p-value'], 2))
        0.15
"""


lowerCAmelCase							:  Tuple            =						"""
@article{2020SciPy-NMeth,
author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
      Haberland, Matt and Reddy, Tyler and Cournapeau, David and
      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
      Kern, Robert and Larson, Eric and Carey, C J and
      Polat, Ilhan and Feng, Yu and Moore, Eric W. and
      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
      Harris, Charles R. and Archibald, Anne M. and
      Ribeiro, Antonio H. and Pedregosa, Fabian and
      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
      Computing in Python}},
journal = {Nature Methods},
year    = {2020},
volume  = {17},
pages   = {261--272},
adsurl  = {https://rdcu.be/b08Wh},
doi = {10.1038/s41592-019-0686-2},
}
"""



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




			"""simple docstring"""







			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple):
									return datasets.MetricInfo(
									    description=_DESCRIPTION       ,						citation=_CITATION       ,						inputs_description=_KWARGS_DESCRIPTION       ,						features=datasets.Features(
									        {
									            "predictions": datasets.Value("float"),
									            "references": datasets.Value("float"),
									        })       ,						reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html"]       ,						)




			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[Any]       ,						lowerCAmelCase__  :					Tuple       ,						lowerCAmelCase__  :					Tuple       ,						lowerCAmelCase__  :					Tuple=False):
									if return_pvalue:
															SCREAMING_SNAKE_CASE_:			Any  		=	pearsonr(lowerCAmelCase__       ,						lowerCAmelCase__)
															return {"pearsonr": results[0], "p-value": results[1]}
									else:
															return {"pearsonr": float(pearsonr(lowerCAmelCase__       ,						lowerCAmelCase__)[0])}









import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / """utils"""))

from test_module.custom_configuration import CustomConfig  # noqa E402


lowerCAmelCase							:  Union[str, Any]            =						get_tests_dir("""fixtures/dummy-config.json""")



class   __lowercase    (			unittest.TestCase     ):




			"""simple docstring"""







			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple):
									SCREAMING_SNAKE_CASE_:			Dict  		=	0



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Any):
									self.assertIsNotNone(transformers.models.auto.__spec__)
									self.assertIsNotNone(importlib.util.find_spec("transformers.models.auto"))



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	AutoConfig.from_pretrained("bert-base-uncased")
									self.assertIsInstance(lowerCAmelCase__       ,						lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					str):
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	AutoConfig.from_pretrained(lowerCAmelCase__)
									self.assertIsInstance(lowerCAmelCase__       ,						lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					int):
									SCREAMING_SNAKE_CASE_:			Tuple  		=	AutoConfig.from_pretrained(lowerCAmelCase__)
									self.assertIsInstance(lowerCAmelCase__       ,						lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Union[str, Any]):
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	AutoConfig.for_model("roberta")
									self.assertIsInstance(lowerCAmelCase__       ,						lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									with tempfile.TemporaryDirectory() as tmp_dir:
															# This model name contains bert and roberta, but roberta ends up being picked.
															SCREAMING_SNAKE_CASE_:			int  		=	os.path.join(lowerCAmelCase__       ,						"fake-roberta")
															os.makedirs(lowerCAmelCase__       ,						exist_ok=lowerCAmelCase__)
															with open(os.path.join(lowerCAmelCase__       ,						"config.json")       ,						"w") as f:
																					f.write(json.dumps({}))
															SCREAMING_SNAKE_CASE_:			Any  		=	AutoConfig.from_pretrained(lowerCAmelCase__)
															self.assertEqual(type(lowerCAmelCase__)       ,						lowerCAmelCase__)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[int]):
									try:
															AutoConfig.register("custom"       ,						lowerCAmelCase__)
															# Wrong model type will raise an error
															with self.assertRaises(lowerCAmelCase__):
																					AutoConfig.register("model"       ,						lowerCAmelCase__)
															# Trying to register something existing in the Transformers library will raise an error
															with self.assertRaises(lowerCAmelCase__):
																					AutoConfig.register("bert"       ,						lowerCAmelCase__)

															# Now that the config is registered, it can be used as any other config with the auto-API
															SCREAMING_SNAKE_CASE_:			List[Any]  		=	CustomConfig()
															with tempfile.TemporaryDirectory() as tmp_dir:
																					config.save_pretrained(lowerCAmelCase__)
																					SCREAMING_SNAKE_CASE_:			Tuple  		=	AutoConfig.from_pretrained(lowerCAmelCase__)
																					self.assertIsInstance(lowerCAmelCase__       ,						lowerCAmelCase__)

									finally:
															if "custom" in CONFIG_MAPPING._extra_content:
																					del CONFIG_MAPPING._extra_content["custom"]



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[str]):
									with self.assertRaisesRegex(
									    lowerCAmelCase__       ,						"bert-base is not a local folder and is not a valid model identifier"):
															SCREAMING_SNAKE_CASE_:			List[str]  		=	AutoConfig.from_pretrained("bert-base")



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									with self.assertRaisesRegex(
									    lowerCAmelCase__       ,						R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"):
															SCREAMING_SNAKE_CASE_:			str  		=	AutoConfig.from_pretrained(lowerCAmelCase__       ,						revision="aaaaaa")



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[int]):
									with self.assertRaisesRegex(
									    lowerCAmelCase__       ,						"hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."       ,						):
															SCREAMING_SNAKE_CASE_:			int  		=	AutoConfig.from_pretrained("hf-internal-testing/no-config-test-repo")



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[str]):
									# If remote code is not set, we will time out when asking whether to load the model.
									with self.assertRaises(lowerCAmelCase__):
															SCREAMING_SNAKE_CASE_:			str  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model")
									# If remote code is disabled, we can't load this config.
									with self.assertRaises(lowerCAmelCase__):
															SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       ,						trust_remote_code=lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_:			str  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       ,						trust_remote_code=lowerCAmelCase__)
									self.assertEqual(config.__class__.__name__       ,						"NewModelConfig")

									# Test config can be reloaded.
									with tempfile.TemporaryDirectory() as tmp_dir:
															config.save_pretrained(lowerCAmelCase__)
															SCREAMING_SNAKE_CASE_:			Any  		=	AutoConfig.from_pretrained(lowerCAmelCase__       ,						trust_remote_code=lowerCAmelCase__)
									self.assertEqual(reloaded_config.__class__.__name__       ,						"NewModelConfig")




			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):



									class   __lowercase    (			UpperCAmelCase_     ):




												"""simple docstring"""







												_UpperCAmelCase       :							int      							=					'''new-model'''

									try:
															AutoConfig.register("new-model"       ,						lowerCAmelCase__)
															# If remote code is not set, the default is to use local
															SCREAMING_SNAKE_CASE_:			int  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model")
															self.assertEqual(config.__class__.__name__       ,						"NewModelConfigLocal")

															# If remote code is disabled, we load the local one.
															SCREAMING_SNAKE_CASE_:			Optional[int]  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       ,						trust_remote_code=lowerCAmelCase__)
															self.assertEqual(config.__class__.__name__       ,						"NewModelConfigLocal")

															# If remote is enabled, we load from the Hub
															SCREAMING_SNAKE_CASE_:			int  		=	AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       ,						trust_remote_code=lowerCAmelCase__)
															self.assertEqual(config.__class__.__name__       ,						"NewModelConfig")

									finally:
															if "new-model" in CONFIG_MAPPING._extra_content:
																					del CONFIG_MAPPING._extra_content["new-model"]






