





"""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						: Tuple     	=			(
    '''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       _SCREAMING_SNAKE_CASE		(	_lowercase						:    List[str]    ,       _lowercase						:    List[str]					) ->Dict:






	'''simple docstring'''






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






def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    Tuple    ,       _lowercase						:    Union[str, Any]					) ->Optional[int]:






	'''simple docstring'''






	warnings.warn(_lowercase    ,       _lowercase					)
	requires_backends(_lowercase    ,       "sklearn"					)
	a      :		Dict	=				simple_accuracy(_lowercase    ,       _lowercase					)
	a      :		Optional[int]	=				fa_score(y_true=_lowercase    ,       y_pred=_lowercase					)
	return {
	    "acc": acc,
	    "f1": fa,
	    "acc_and_f1": (acc + fa) / 2,
	}






def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    str    ,       _lowercase						:    Tuple					) ->str:






	'''simple docstring'''






	warnings.warn(_lowercase    ,       _lowercase					)
	requires_backends(_lowercase    ,       "sklearn"					)
	a      :		Union[str, Any]	=				pearsonr(_lowercase    ,       _lowercase					)[0]
	a      :		List[Any]	=				spearmanr(_lowercase    ,       _lowercase					)[0]
	return {
	    "pearson": pearson_corr,
	    "spearmanr": spearman_corr,
	    "corr": (pearson_corr + spearman_corr) / 2,
	}






def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    Optional[Any]    ,       _lowercase						:    str    ,       _lowercase						:    Optional[int]					) ->str:






	'''simple docstring'''






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







def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    Optional[Any]    ,       _lowercase						:    Tuple    ,       _lowercase						:    Tuple					) ->Optional[int]:






	'''simple docstring'''






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






import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

snake_case							:       List[str]     			=      '''python tqdm regex requests packaging filelock numpy tokenizers'''.split()
if sys.version_info < (3, 7):
						pkgs_to_check_at_runtime.append('''dataclasses''')
if sys.version_info < (3, 8):
						pkgs_to_check_at_runtime.append('''importlib_metadata''')

for pkg in pkgs_to_check_at_runtime:
						if pkg in deps:
												if pkg == "tokenizers":
																		# must be loaded here, or else tqdm check may fail
																		from .utils import is_tokenizers_available

																		if not is_tokenizers_available():
																								continue  # not required, check version only if installed

												require_version_core(deps[pkg])
						else:
												raise ValueError(f"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")






def 							__lowercase   ( __lowerCAmelCase							:				Optional[Any]					,    __lowerCAmelCase							:				Tuple=None   ):
							require_version(deps[pkg]					,    __lowerCAmelCase   )




