


'''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_					:    str          =    (
    "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 	_A				(lowerCAmelCase__  :Dict				,						lowerCAmelCase__  :Any		)   ->  Optional[int]:




     '''simple docstring'''



     warnings.warn(lowerCAmelCase__				,						lowerCAmelCase__		)
     requires_backends(lowerCAmelCase__				,						'sklearn'		)
     return (preds == labels).mean()






def 	_A				(lowerCAmelCase__  :Dict				,						lowerCAmelCase__  :Any		)   ->  Union[str, Any]:




     '''simple docstring'''



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






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




     '''simple docstring'''



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






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




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




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





'''simple docstring'''






import pytest

from datasets.splits import SplitDict, SplitInfo
from datasets.utils.py_utils import asdict






@pytest.mark.parametrize(
    'split_dict'				,						[
        SplitDict(),
        SplitDict({'train': SplitInfo(name='train'				,						num_bytes=13_37				,						num_examples=42				,						dataset_name='my_dataset'		)}		),
        SplitDict({'train': SplitInfo(name='train'				,						num_bytes=13_37				,						num_examples=42		)}		),
        SplitDict({'train': SplitInfo()}		),
    ]				,						)
def 	_A				(lowerCAmelCase__  :SplitDict		)   ->  Any:




     '''simple docstring'''



     _a			      =							split_dict._to_yaml_list()
     assert len(lowerCAmelCase__		) == len(lowerCAmelCase__		)
     _a			      =							SplitDict._from_yaml_list(lowerCAmelCase__		)
     for split_name, split_info in split_dict.items():
          # dataset_name field is deprecated, and is therefore not part of the YAML dump
          _a			      =							None
          # the split name of split_dict takes over the name of the split info object
          _a			      =							split_name
     assert split_dict == reloaded






@pytest.mark.parametrize(
    'split_info'				,						[SplitInfo(), SplitInfo(dataset_name=lowerCAmelCase__		), SplitInfo(dataset_name='my_dataset'		)]		)
def 	_A				(lowerCAmelCase__  :Optional[Any]		)   ->  List[str]:




     '''simple docstring'''



     _a			      =							asdict(SplitDict({'train': split_info}		)		)
     assert "dataset_name" in split_dict_asdict["train"]
     assert split_dict_asdict["train"]["dataset_name"] == split_info.dataset_name

