

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


a		=logging.getLogger()






@unittest.skip('''Temporarily disable the doc tests.'''				)
@require_torch
@require_tf
@slow
class        A_		(       unittest.TestCase				):
							def     lowerCAmelCase     (		self		:			str   ,SCREAMING_SNAKE_CASE__		:			Path   ,SCREAMING_SNAKE_CASE__		:			Union[str, None] = None   ,SCREAMING_SNAKE_CASE__		:			Union[List[str], None] = None   ,SCREAMING_SNAKE_CASE__		:			Union[str, List[str], None] = None   ,SCREAMING_SNAKE_CASE__		:			bool = True   ,):
								__lowerCamelCase				:				List[Any]					       = [file for file in os.listdir(SCREAMING_SNAKE_CASE__) if os.path.isfile(os.path.join(SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__))]

								if identifier is not None:
									__lowerCamelCase				:				Optional[Any]					       = [file for file in files if identifier in file]

								if n_identifier is not None:
									if isinstance(SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__):
										for n_ in n_identifier:
											__lowerCamelCase				:				int					       = [file for file in files if n_ not in file]
									else:
										__lowerCamelCase				:				List[str]					       = [file for file in files if n_identifier not in file]

								__lowerCamelCase				:				Any					       = ignore_files or []
								ignore_files.append('__init__.py')
								__lowerCamelCase				:				Dict					       = [file for file in files if file not in ignore_files]

								for file in files:
									# Open all files
									print('Testing'   ,SCREAMING_SNAKE_CASE__)

									if only_modules:
										__lowerCamelCase				:				List[Any]					       = file.split('.')[0]
										try:
											__lowerCamelCase				:				Optional[Any]					       = getattr(SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__)
											__lowerCamelCase				:				List[Any]					       = doctest.DocTestSuite(SCREAMING_SNAKE_CASE__)
											__lowerCamelCase				:				List[str]					       = unittest.TextTestRunner().run(SCREAMING_SNAKE_CASE__)
											self.assertIs(len(result.failures)   ,0)
										except AttributeError:
											logger.info(F"{module_identifier} is not a module.")
									else:
										__lowerCamelCase				:				Union[str, Any]					       = doctest.testfile(str('..' / directory / file)   ,optionflags=doctest.ELLIPSIS)
										self.assertIs(result.failed   ,0)
							def     lowerCAmelCase     (		self		:			Optional[Any]):
								__lowerCamelCase				:				List[Any]					       = Path('src/transformers')
								__lowerCamelCase				:				List[Any]					       = 'modeling'
								__lowerCamelCase				:				int					       = [
								    'modeling_ctrl.py',
								    'modeling_tf_ctrl.py',
								]
								self.analyze_directory(SCREAMING_SNAKE_CASE__   ,identifier=SCREAMING_SNAKE_CASE__   ,ignore_files=SCREAMING_SNAKE_CASE__)
							def     lowerCAmelCase     (		self		:			List[str]):
								__lowerCamelCase				:				int					       = Path('src/transformers')
								__lowerCamelCase				:				Any					       = 'tokenization'
								self.analyze_directory(SCREAMING_SNAKE_CASE__   ,identifier=SCREAMING_SNAKE_CASE__)
							def     lowerCAmelCase     (		self		:			Optional[Any]):
								__lowerCamelCase				:				List[Any]					       = Path('src/transformers')
								__lowerCamelCase				:				Tuple					       = 'configuration'
								self.analyze_directory(SCREAMING_SNAKE_CASE__   ,identifier=SCREAMING_SNAKE_CASE__)
							def     lowerCAmelCase     (		self		:			List[str]):
								__lowerCamelCase				:				Any					       = Path('src/transformers')
								__lowerCamelCase				:				Optional[int]					       = ['configuration', 'modeling', 'tokenization']
								self.analyze_directory(SCREAMING_SNAKE_CASE__   ,n_identifier=SCREAMING_SNAKE_CASE__)


							def     lowerCAmelCase     (		self		:			Dict):
								__lowerCamelCase				:				List[str]					       = Path('docs/source')
								__lowerCamelCase				:				int					       = ['favicon.ico']
								self.analyze_directory(SCREAMING_SNAKE_CASE__   ,ignore_files=SCREAMING_SNAKE_CASE__   ,only_modules=SCREAMING_SNAKE_CASE__)








"""simple docstring"""







import warnings

from ...utils import is_sklearn_available, requires_backends


if is_sklearn_available():
		from scipy.stats import pearsonr, spearmanr
		from sklearn.metrics import fa_score, matthews_corrcoef


a__				:							Any						=     (
    '''This metric will be removed from the library soon, metrics should be handled with the 🤗 Evaluate '''
    '''library. You can have a look at this example script for pointers: '''
    '''https://github.com/huggingface/transformers/blob/main/examples/pytorch/text-classification/run_glue.py'''
)




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					warnings.warn(lowerCAmelCase_  ,						lowerCAmelCase_   )
					requires_backends(lowerCAmelCase_  ,						"sklearn"   )
					return (preds == labels).mean()




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					warnings.warn(lowerCAmelCase_  ,						lowerCAmelCase_   )
					requires_backends(lowerCAmelCase_  ,						"sklearn"   )
					__SCREAMING_SNAKE_CASE						   =				simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )
					__SCREAMING_SNAKE_CASE						   =				fa_score(y_true=lowerCAmelCase_  ,						y_pred=lowerCAmelCase_   )
					return {
					    "acc": acc,
					    "f1": fa,
					    "acc_and_f1": (acc + fa) / 2,
					}




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					warnings.warn(lowerCAmelCase_  ,						lowerCAmelCase_   )
					requires_backends(lowerCAmelCase_  ,						"sklearn"   )
					__SCREAMING_SNAKE_CASE						   =				pearsonr(lowerCAmelCase_  ,						lowerCAmelCase_   )[0]
					__SCREAMING_SNAKE_CASE						   =				spearmanr(lowerCAmelCase_  ,						lowerCAmelCase_   )[0]
					return {
					    "pearson": pearson_corr,
					    "spearmanr": spearman_corr,
					    "corr": (pearson_corr + spearman_corr) / 2,
					}




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					warnings.warn(lowerCAmelCase_  ,						lowerCAmelCase_   )
					requires_backends(lowerCAmelCase_  ,						"sklearn"   )
					assert len(lowerCAmelCase_   ) == len(lowerCAmelCase_   ), f"""Predictions and labels have mismatched lengths {len(lowerCAmelCase_   )} and {len(lowerCAmelCase_   )}"""
					if task_name == "cola":
										return {"mcc": matthews_corrcoef(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "sst-2":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "mrpc":
										return acc_and_fa(lowerCAmelCase_  ,						lowerCAmelCase_   )
					elif task_name == "sts-b":
										return pearson_and_spearman(lowerCAmelCase_  ,						lowerCAmelCase_   )
					elif task_name == "qqp":
										return acc_and_fa(lowerCAmelCase_  ,						lowerCAmelCase_   )
					elif task_name == "mnli":
										return {"mnli/acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "mnli-mm":
										return {"mnli-mm/acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "qnli":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "rte":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "wnli":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					elif task_name == "hans":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					else:
										raise KeyError(lowerCAmelCase_   )




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					warnings.warn(lowerCAmelCase_  ,						lowerCAmelCase_   )
					requires_backends(lowerCAmelCase_  ,						"sklearn"   )
					if len(lowerCAmelCase_   ) != len(lowerCAmelCase_   ):
										raise ValueError(f"""Predictions and labels have mismatched lengths {len(lowerCAmelCase_   )} and {len(lowerCAmelCase_   )}"""   )
					if task_name == "xnli":
										return {"acc": simple_accuracy(lowerCAmelCase_  ,						lowerCAmelCase_   )}
					else:
										raise KeyError(lowerCAmelCase_   )
