



from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import (
							    TFConvBertForMaskedLM,
							    TFConvBertForMultipleChoice,
							    TFConvBertForQuestionAnswering,
							    TFConvBertForSequenceClassification,
							    TFConvBertForTokenClassification,
							    TFConvBertModel,
							)



class  lowerCamelCase__    :




		'''simple docstring'''



		def __init__(self	,__lowerCamelCase	,__lowerCamelCase=13	,__lowerCamelCase=7	,__lowerCamelCase=True	,__lowerCamelCase=True	,__lowerCamelCase=True	,__lowerCamelCase=True	,__lowerCamelCase=99	,__lowerCamelCase=32	,__lowerCamelCase=2	,__lowerCamelCase=4	,__lowerCamelCase=37	,__lowerCamelCase="gelu"	,__lowerCamelCase=0.1	,__lowerCamelCase=0.1	,__lowerCamelCase=5_12	,__lowerCamelCase=16	,__lowerCamelCase=2	,__lowerCamelCase=0.02	,__lowerCamelCase=3	,__lowerCamelCase=4	,__lowerCamelCase=None	,)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  parent
						lowerCAmelCase__  :       Any				=  13
						lowerCAmelCase__  :       Union[str, Any]				=  7
						lowerCAmelCase__  :       str				=  True
						lowerCAmelCase__  :       List[Any]				=  True
						lowerCAmelCase__  :       Optional[Any]				=  True
						lowerCAmelCase__  :       Any				=  True
						lowerCAmelCase__  :       str				=  99
						lowerCAmelCase__  :       Any				=  3_84
						lowerCAmelCase__  :       Union[str, Any]				=  2
						lowerCAmelCase__  :       Optional[int]				=  4
						lowerCAmelCase__  :       int				=  37
						lowerCAmelCase__  :       str				=  '''gelu'''
						lowerCAmelCase__  :       str				=  0.1
						lowerCAmelCase__  :       Union[str, Any]				=  0.1
						lowerCAmelCase__  :       Tuple				=  5_12
						lowerCAmelCase__  :       int				=  16
						lowerCAmelCase__  :       Tuple				=  2
						lowerCAmelCase__  :       Optional[int]				=  0.02
						lowerCAmelCase__  :       Any				=  3
						lowerCAmelCase__  :       Any				=  4
						lowerCAmelCase__  :       List[Any]				=  1_28
						lowerCAmelCase__  :       Any				=  2
						lowerCAmelCase__  :       Union[str, Any]				=  9
						lowerCAmelCase__  :       List[Any]				=  1
						lowerCAmelCase__  :       List[str]				=  None



		def 	lowerCAmelCase__   (self				)  ->    int:

						"""simple docstring"""






						lowerCAmelCase__  :       Any				=  ids_tensor([self.batch_size, self.seq_length]	,self.vocab_size				)

						lowerCAmelCase__  :       List[str]				=  None
						if self.use_input_mask:
										lowerCAmelCase__  :       Optional[int]				=  random_attention_mask([self.batch_size, self.seq_length]				)

						lowerCAmelCase__  :       Optional[Any]				=  None
						if self.use_token_type_ids:
										lowerCAmelCase__  :       str				=  ids_tensor([self.batch_size, self.seq_length]	,self.type_vocab_size				)

						lowerCAmelCase__  :       Tuple				=  None
						lowerCAmelCase__  :       List[str]				=  None
						lowerCAmelCase__  :       str				=  None
						if self.use_labels:
										lowerCAmelCase__  :       Optional[int]				=  ids_tensor([self.batch_size]	,self.type_sequence_label_size				)
										lowerCAmelCase__  :       str				=  ids_tensor([self.batch_size, self.seq_length]	,self.num_labels				)
										lowerCAmelCase__  :       Dict				=  ids_tensor([self.batch_size]	,self.num_choices				)

						lowerCAmelCase__  :       int				=  ConvBertConfig(
						    vocab_size=self.vocab_size	,hidden_size=self.hidden_size	,num_hidden_layers=self.num_hidden_layers	,num_attention_heads=self.num_attention_heads	,intermediate_size=self.intermediate_size	,hidden_act=self.hidden_act	,hidden_dropout_prob=self.hidden_dropout_prob	,attention_probs_dropout_prob=self.attention_probs_dropout_prob	,max_position_embeddings=self.max_position_embeddings	,type_vocab_size=self.type_vocab_size	,initializer_range=self.initializer_range	,return_dict=__lowerCamelCase	,)

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  TFConvBertModel(config=__lowerCamelCase				)
						lowerCAmelCase__  :       List[str]				=  {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

						lowerCAmelCase__  :       int				=  [input_ids, input_mask]
						lowerCAmelCase__  :       int				=  model(__lowerCamelCase				)

						lowerCAmelCase__  :       Optional[Any]				=  model(__lowerCamelCase				)

						self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.hidden_size)				)



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

						"""simple docstring"""






						lowerCAmelCase__  :       Any				=  TFConvBertForMaskedLM(config=__lowerCamelCase				)
						lowerCAmelCase__  :       int				=  {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						lowerCAmelCase__  :       Union[str, Any]				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.vocab_size)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  self.num_labels
						lowerCAmelCase__  :       List[str]				=  TFConvBertForSequenceClassification(config=__lowerCamelCase				)
						lowerCAmelCase__  :       Union[str, Any]				=  {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						lowerCAmelCase__  :       int				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Tuple				=  self.num_choices
						lowerCAmelCase__  :       Optional[int]				=  TFConvBertForMultipleChoice(config=__lowerCamelCase				)
						lowerCAmelCase__  :       Optional[int]				=  tf.tile(tf.expand_dims(__lowerCamelCase	,1				)	,(1, self.num_choices, 1)				)
						lowerCAmelCase__  :       Tuple				=  tf.tile(tf.expand_dims(__lowerCamelCase	,1				)	,(1, self.num_choices, 1)				)
						lowerCAmelCase__  :       Tuple				=  tf.tile(tf.expand_dims(__lowerCamelCase	,1				)	,(1, self.num_choices, 1)				)
						lowerCAmelCase__  :       Optional[int]				=  {
						    '''input_ids''': multiple_choice_inputs_ids,
						    '''attention_mask''': multiple_choice_input_mask,
						    '''token_type_ids''': multiple_choice_token_type_ids,
						}
						lowerCAmelCase__  :       Any				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_choices)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__  :       Tuple				=  self.num_labels
						lowerCAmelCase__  :       Optional[Any]				=  TFConvBertForTokenClassification(config=__lowerCamelCase				)
						lowerCAmelCase__  :       Union[str, Any]				=  {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						lowerCAmelCase__  :       Dict				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.num_labels)				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    List[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  TFConvBertForQuestionAnswering(config=__lowerCamelCase				)
						lowerCAmelCase__  :       str				=  {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						lowerCAmelCase__  :       Optional[int]				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.start_logits.shape	,(self.batch_size, self.seq_length)				)
						self.parent.assertEqual(result.end_logits.shape	,(self.batch_size, self.seq_length)				)



		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  self.prepare_config_and_inputs()
						(
						    (
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	(
						    lowerCAmelCase__
						)		,	
						)  :       Optional[int]				=  config_and_inputs
						lowerCAmelCase__  :       List[Any]				=  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
						return config, inputs_dict



@require_tf
class  lowerCamelCase__    (							lowerCamelCase__   ,       lowerCamelCase__   ,       unittest.TestCase):




		'''simple docstring'''



		snake_case_			=(
		    (
		        TFConvBertModel,
		        TFConvBertForMaskedLM,
		        TFConvBertForQuestionAnswering,
		        TFConvBertForSequenceClassification,
		        TFConvBertForTokenClassification,
		        TFConvBertForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		snake_case_			=(
		    {
		        """feature-extraction""": TFConvBertModel,
		        """fill-mask""": TFConvBertForMaskedLM,
		        """question-answering""": TFConvBertForQuestionAnswering,
		        """text-classification""": TFConvBertForSequenceClassification,
		        """token-classification""": TFConvBertForTokenClassification,
		        """zero-shot""": TFConvBertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		snake_case_			=False
		snake_case_			=False
		snake_case_			=False



		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  TFConvBertModelTester(self				)
						lowerCAmelCase__  :       int				=  ConfigTester(self	,config_class=__lowerCamelCase	,hidden_size=37				)



		def 	lowerCAmelCase__   (self				)  ->    List[Any]:

						"""simple docstring"""






						self.config_tester.run_common_tests()



		def 	lowerCAmelCase__   (self				)  ->    Dict:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Dict:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase				)



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

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase				)



		@slow
		def 	lowerCAmelCase__   (self				)  ->    Tuple:

						"""simple docstring"""






						lowerCAmelCase__		,	lowerCAmelCase__  :       Optional[Any]				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       int				=  True
						lowerCAmelCase__  :       int				=  True

						if hasattr(__lowerCamelCase	,'''use_cache'''				):
										lowerCAmelCase__  :       List[Any]				=  True

						lowerCAmelCase__  :       str				=  getattr(self.model_tester	,'''encoder_seq_length'''	,self.model_tester.seq_length				)
						lowerCAmelCase__  :       Union[str, Any]				=  getattr(self.model_tester	,'''key_length'''	,__lowerCamelCase				)

						for model_class in self.all_model_classes:
										lowerCAmelCase__  :       int				=  self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)
										lowerCAmelCase__  :       Any				=  model_class(__lowerCamelCase				)
										lowerCAmelCase__  :       Optional[Any]				=  len(model(__lowerCamelCase				)				)

										with tempfile.TemporaryDirectory() as tmpdirname:
														model.save_pretrained(__lowerCamelCase	,saved_model=__lowerCamelCase				)
														lowerCAmelCase__  :       Optional[Any]				=  os.path.join(__lowerCamelCase	,'''saved_model'''	,'''1'''				)
														lowerCAmelCase__  :       Union[str, Any]				=  tf.keras.models.load_model(__lowerCamelCase				)
														lowerCAmelCase__  :       Any				=  model(__lowerCamelCase				)

														if self.is_encoder_decoder:
																		lowerCAmelCase__  :       Any				=  outputs['''encoder_hidden_states''']
																		lowerCAmelCase__  :       Tuple				=  outputs['''encoder_attentions''']
														else:
																		lowerCAmelCase__  :       Union[str, Any]				=  outputs['''hidden_states''']
																		lowerCAmelCase__  :       Dict				=  outputs['''attentions''']

														self.assertEqual(len(__lowerCamelCase				)	,__lowerCamelCase				)

														lowerCAmelCase__  :       Dict				=  getattr(
														    self.model_tester	,'''expected_num_hidden_layers'''	,self.model_tester.num_hidden_layers + 1				)

														self.assertEqual(len(__lowerCamelCase				)	,__lowerCamelCase				)
														self.assertListEqual(
														    list(output_hidden_states[0].shape[-2:]				)	,[self.model_tester.seq_length, self.model_tester.hidden_size]	,)

														self.assertEqual(len(__lowerCamelCase				)	,self.model_tester.num_hidden_layers				)
														self.assertListEqual(
														    list(output_attentions[0].shape[-3:]				)	,[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]	,)



		@slow
		def 	lowerCAmelCase__   (self				)  ->    List[str]:

						"""simple docstring"""






						lowerCAmelCase__  :       Tuple				=  TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''				)
						self.assertIsNotNone(__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__		,	lowerCAmelCase__  :       Dict				=  self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__  :       List[str]				=  True
						lowerCAmelCase__  :       Optional[Any]				=  getattr(self.model_tester	,'''decoder_seq_length'''	,self.model_tester.seq_length				)
						lowerCAmelCase__  :       Any				=  getattr(self.model_tester	,'''encoder_seq_length'''	,self.model_tester.seq_length				)
						lowerCAmelCase__  :       Optional[Any]				=  getattr(self.model_tester	,'''key_length'''	,__lowerCamelCase				)
						lowerCAmelCase__  :       Union[str, Any]				=  getattr(self.model_tester	,'''key_length'''	,__lowerCamelCase				)

						def check_decoder_attentions_output(__lowerCamelCase				):
										lowerCAmelCase__  :       List[str]				=  len(__lowerCamelCase				)
										self.assertEqual(out_len % 2	,0				)
										lowerCAmelCase__  :       Optional[int]				=  outputs.decoder_attentions
										self.assertEqual(len(__lowerCamelCase				)	,self.model_tester.num_hidden_layers				)
										self.assertListEqual(
										    list(decoder_attentions[0].shape[-3:]				)	,[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]	,)

						def check_encoder_attentions_output(__lowerCamelCase				):
										lowerCAmelCase__  :       List[Any]				=  [
										    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
										]
										self.assertEqual(len(__lowerCamelCase				)	,self.model_tester.num_hidden_layers				)
										self.assertListEqual(
										    list(attentions[0].shape[-3:]				)	,[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]	,)

						for model_class in self.all_model_classes:
										lowerCAmelCase__  :       Any				=  True
										lowerCAmelCase__  :       Any				=  False
										lowerCAmelCase__  :       Optional[int]				=  model_class(__lowerCamelCase				)
										lowerCAmelCase__  :       List[str]				=  model(self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)				)
										lowerCAmelCase__  :       Dict				=  len(__lowerCamelCase				)
										self.assertEqual(config.output_hidden_states	,__lowerCamelCase				)
										check_encoder_attentions_output(__lowerCamelCase				)

										if self.is_encoder_decoder:
														lowerCAmelCase__  :       Union[str, Any]				=  model_class(__lowerCamelCase				)
														lowerCAmelCase__  :       Union[str, Any]				=  model(self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)				)
														self.assertEqual(config.output_hidden_states	,__lowerCamelCase				)
														check_decoder_attentions_output(__lowerCamelCase				)

										# Check that output attentions can also be changed via the config
										del inputs_dict["output_attentions"]
										lowerCAmelCase__  :       Optional[Any]				=  True
										lowerCAmelCase__  :       Any				=  model_class(__lowerCamelCase				)
										lowerCAmelCase__  :       Optional[int]				=  model(self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)				)
										self.assertEqual(config.output_hidden_states	,__lowerCamelCase				)
										check_encoder_attentions_output(__lowerCamelCase				)

										# Check attention is always last and order is fine
										lowerCAmelCase__  :       Union[str, Any]				=  True
										lowerCAmelCase__  :       List[Any]				=  True
										lowerCAmelCase__  :       Dict				=  model_class(__lowerCamelCase				)
										lowerCAmelCase__  :       Optional[Any]				=  model(self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)				)

										self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)	,len(__lowerCamelCase				)				)
										self.assertEqual(model.config.output_hidden_states	,__lowerCamelCase				)
										check_encoder_attentions_output(__lowerCamelCase				)



@require_tf
class  lowerCamelCase__    (							unittest.TestCase):




		'''simple docstring'''



		@slow
		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Tuple				=  TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''				)
						lowerCAmelCase__  :       Union[str, Any]				=  tf.constant([[0, 1, 2, 3, 4, 5]]				)
						lowerCAmelCase__  :       Dict				=  model(__lowerCamelCase				)[0]

						lowerCAmelCase__  :       int				=  [1, 6, 7_68]
						self.assertEqual(output.shape	,__lowerCamelCase				)

						lowerCAmelCase__  :       Union[str, Any]				=  tf.constant(
						    [
						        [
						            [-0.0347_5493, -0.468_6034, -0.3063_8832],
						            [0.2263_7248, -0.2698_8646, -0.742_3424],
						            [0.1032_4868, -0.4501_3508, -0.5828_0784],
						        ]
						    ]				)
						tf.debugging.assert_near(output[:, :3, :3]	,__lowerCamelCase	,atol=1e-4				)






from scipy.stats import pearsonr, spearmanr
from sklearn.metrics import fa_score, matthews_corrcoef

import datasets


__snake_case       :	str            ='\\n@inproceedings{wang2019glue,\n  title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},\n  author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},\n  note={In the Proceedings of ICLR.},\n  year={2019}\n}\n'

__snake_case       :	Tuple            ='\\nGLUE, the General Language Understanding Evaluation benchmark\n(https://gluebenchmark.com/) is a collection of resources for training,\nevaluating, and analyzing natural language understanding systems.\n'

__snake_case       :	int            ='\nCompute GLUE evaluation metric associated to each GLUE dataset.\nArgs:\n    predictions: list of predictions to score.\n        Each translation should be tokenized into a list of tokens.\n    references: list of lists of references for each translation.\n        Each reference should be tokenized into a list of tokens.\nReturns: depending on the GLUE subset, one or several of:\n    "accuracy": Accuracy\n    "f1": F1 score\n    "pearson": Pearson Correlation\n    "spearmanr": Spearman Correlation\n    "matthews_correlation": Matthew Correlation\nExamples:\n\n    >>> glue_metric = datasets.load_metric(\'glue\', \'sst2\')  # \'sst2\' or any of ["mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0}\n\n    >>> glue_metric = datasets.load_metric(\'glue\', \'mrpc\')  # \'mrpc\' or \'qqp\'\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0, \'f1\': 1.0}\n\n    >>> glue_metric = datasets.load_metric(\'glue\', \'stsb\')\n    >>> references = [0., 1., 2., 3., 4., 5.]\n    >>> predictions = [0., 1., 2., 3., 4., 5.]\n    >>> results = glue_metric.compute(predictions=predictions, references=references)\n    >>> print({"pearson": round(results["pearson"], 2), "spearmanr": round(results["spearmanr"], 2)})\n    {\'pearson\': 1.0, \'spearmanr\': 1.0}\n\n    >>> glue_metric = datasets.load_metric(\'glue\', \'cola\')\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'matthews_correlation\': 1.0}\n'






def 			lowerCAmelCase__	(					lowerCamelCase_	:	List[str] ,lowerCamelCase_	:	Dict):





				'''simple docstring'''

				return float((preds == labels).mean())






def 			lowerCAmelCase__	(					lowerCamelCase_	:	List[Any] ,lowerCamelCase_	:	Optional[int]):





				'''simple docstring'''

				lowerCAmelCase__  :       int				=  simple_accuracy(lowerCamelCase_ ,lowerCamelCase_)
				lowerCAmelCase__  :       Any				=  float(fa_score(y_true=lowerCamelCase_ ,y_pred=lowerCamelCase_))
				return {
				    "accuracy": acc,
				    "f1": fa,
				}






def 			lowerCAmelCase__	(					lowerCamelCase_	:	List[Any] ,lowerCamelCase_	:	Optional[Any]):





				'''simple docstring'''

				lowerCAmelCase__  :       Union[str, Any]				=  float(pearsonr(lowerCamelCase_ ,lowerCamelCase_)[0])
				lowerCAmelCase__  :       int				=  float(spearmanr(lowerCamelCase_ ,lowerCamelCase_)[0])
				return {
				    "pearson": pearson_corr,
				    "spearmanr": spearman_corr,
				}



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




		'''simple docstring'''



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

						"""simple docstring"""






						if self.config_name not in [
						    "sst2",
						    "mnli",
						    "mnli_mismatched",
						    "mnli_matched",
						    "cola",
						    "stsb",
						    "mrpc",
						    "qqp",
						    "qnli",
						    "rte",
						    "wnli",
						    "hans",
						]:
										raise KeyError(
										    '''You should supply a configuration name selected in '''
										    '''["sst2", "mnli", "mnli_mismatched", "mnli_matched", '''
										    '''"cola", "stsb", "mrpc", "qqp", "qnli", "rte", "wnli", "hans"]'''				)
						return datasets.MetricInfo(
						    description=_DESCRIPTION	,citation=_CITATION	,inputs_description=_KWARGS_DESCRIPTION	,features=datasets.Features(
						        {
						            '''predictions''': datasets.Value('''int64''' if self.config_name != '''stsb''' else '''float32'''				),
						            '''references''': datasets.Value('''int64''' if self.config_name != '''stsb''' else '''float32'''				),
						        }				)	,codebase_urls=[]	,reference_urls=[]	,format='''numpy'''	,)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase				)  ->    Tuple:

						"""simple docstring"""






						if self.config_name == "cola":
										return {"matthews_correlation": matthews_corrcoef(__lowerCamelCase	,__lowerCamelCase				)}
						elif self.config_name == "stsb":
										return pearson_and_spearman(__lowerCamelCase	,__lowerCamelCase				)
						elif self.config_name in ["mrpc", "qqp"]:
										return acc_and_fa(__lowerCamelCase	,__lowerCamelCase				)
						elif self.config_name in ["sst2", "mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]:
										return {"accuracy": simple_accuracy(__lowerCamelCase	,__lowerCamelCase				)}
						else:
										raise KeyError(
										    '''You should supply a configuration name selected in '''
										    '''["sst2", "mnli", "mnli_mismatched", "mnli_matched", '''
										    '''"cola", "stsb", "mrpc", "qqp", "qnli", "rte", "wnli", "hans"]'''				)

