





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


__UpperCAmelCase       :   Optional[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 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    List[str]:
  warnings.warn(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)
  requires_backends(SCREAMING_SNAKE_CASE__					,					"""sklearn""")
  return (preds == labels).mean()







def 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    Optional[Any]:
  warnings.warn(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)
  requires_backends(SCREAMING_SNAKE_CASE__					,					"""sklearn""")
  __snake_case:						Union[str, Any]   =						simple_accuracy(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)
  __snake_case:						List[str]   =						fa_score(y_true=SCREAMING_SNAKE_CASE__					,					y_pred=SCREAMING_SNAKE_CASE__)
  return {
      "acc": acc,
      "f1": fa,
      "acc_and_f1": (acc + fa) / 2,
  }







def 			A__							(    SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)   ->    str:
  warnings.warn(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)
  requires_backends(SCREAMING_SNAKE_CASE__					,					"""sklearn""")
  __snake_case:						Union[str, Any]   =						pearsonr(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)[0]
  __snake_case:						Tuple   =						spearmanr(SCREAMING_SNAKE_CASE__					,					SCREAMING_SNAKE_CASE__)[0]
  return {
      "pearson": pearson_corr,
      "spearmanr": spearman_corr,
      "corr": (pearson_corr + spearman_corr) / 2,
  }







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







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













import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin







class     __snake_case       (							unittest.TestCase   ,			__lowerCamelCase			):





       '''simple docstring'''







       def 							UpperCAmelCase__ (  self :    Union[str, Any]		):
         __snake_case:						Optional[int]   =						load_tool("""text-classification"""		)
         self.tool.setup()
         __snake_case:						Dict   =						load_tool("""text-classification"""							,				remote=A		)




       def 							UpperCAmelCase__ (  self :    Optional[int]		):
         __snake_case:						List[str]   =						self.tool("""That's quite cool"""							,				["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)




       def 							UpperCAmelCase__ (  self :    Dict		):
         __snake_case:						List[str]   =						self.remote_tool("""That's quite cool"""							,				["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)




       def 							UpperCAmelCase__ (  self :    Optional[Any]		):
         __snake_case:						Optional[Any]   =						self.tool(text="""That's quite cool"""							,				labels=["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)






       def 							UpperCAmelCase__ (  self :    Tuple		):
         __snake_case:						int   =						self.remote_tool(text="""That's quite cool"""							,				labels=["""positive""", """negative"""]		)
         self.assertEqual(A							,				"""positive"""		)






