

'''simple docstring'''
from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
					    TFDebertaVaForMaskedLM,
					    TFDebertaVaForQuestionAnswering,
					    TFDebertaVaForSequenceClassification,
					    TFDebertaVaForTokenClassification,
					    TFDebertaVaModel,
					)
class 					_snake_case		:






			def __init__(  self			,_snake_case			,_snake_case=13			,_snake_case=7			,_snake_case=True			,_snake_case=True			,_snake_case=True			,_snake_case=True			,_snake_case=99			,_snake_case=32			,_snake_case=2			,_snake_case=4			,_snake_case=37			,_snake_case="gelu"			,_snake_case=0.1			,_snake_case=0.1			,_snake_case=5_12			,_snake_case=16			,_snake_case=2			,_snake_case=0.02			,_snake_case=False			,_snake_case=True			,_snake_case="None"			,_snake_case=3			,_snake_case=4			,_snake_case=None			,):
				UpperCAmelCase_     :      Union[str, Any]						=  parent
				UpperCAmelCase_     :      Dict						=  batch_size
				UpperCAmelCase_     :      int						=  seq_length
				UpperCAmelCase_     :      Union[str, Any]						=  is_training
				UpperCAmelCase_     :      Union[str, Any]						=  use_input_mask
				UpperCAmelCase_     :      Optional[Any]						=  use_token_type_ids
				UpperCAmelCase_     :      Dict						=  use_labels
				UpperCAmelCase_     :      int						=  vocab_size
				UpperCAmelCase_     :      int						=  hidden_size
				UpperCAmelCase_     :      Optional[Any]						=  num_hidden_layers
				UpperCAmelCase_     :      Any						=  num_attention_heads
				UpperCAmelCase_     :      Tuple						=  intermediate_size
				UpperCAmelCase_     :      Tuple						=  hidden_act
				UpperCAmelCase_     :      Dict						=  hidden_dropout_prob
				UpperCAmelCase_     :      str						=  attention_probs_dropout_prob
				UpperCAmelCase_     :      int						=  max_position_embeddings
				UpperCAmelCase_     :      str						=  type_vocab_size
				UpperCAmelCase_     :      List[Any]						=  type_sequence_label_size
				UpperCAmelCase_     :      Any						=  initializer_range
				UpperCAmelCase_     :      Optional[Any]						=  num_labels
				UpperCAmelCase_     :      int						=  num_choices
				UpperCAmelCase_     :      str						=  relative_attention
				UpperCAmelCase_     :      List[str]						=  position_biased_input
				UpperCAmelCase_     :      List[str]						=  pos_att_type
				UpperCAmelCase_     :      Optional[int]						=  scope






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Union[str, Any]						=  ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size     )

				UpperCAmelCase_     :      Union[str, Any]						=  None
				if self.use_input_mask:
					UpperCAmelCase_     :      str						=  random_attention_mask([self.batch_size, self.seq_length]     )

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

				UpperCAmelCase_     :      Optional[Any]						=  None
				UpperCAmelCase_     :      Any						=  None
				UpperCAmelCase_     :      int						=  None
				if self.use_labels:
					UpperCAmelCase_     :      Optional[int]						=  ids_tensor([self.batch_size]			,self.type_sequence_label_size     )
					UpperCAmelCase_     :      Optional[int]						=  ids_tensor([self.batch_size, self.seq_length]			,self.num_labels     )

				UpperCAmelCase_     :      Optional[Any]						=  DebertaVaConfig(
				    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			,relative_attention=self.relative_attention			,position_biased_input=self.position_biased_input			,initializer_range=self.initializer_range			,return_dict=_snake_case			,)

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






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      List[str]						=  TFDebertaVaModel(config=_snake_case     )
				UpperCAmelCase_     :      Tuple						=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

				UpperCAmelCase_     :      Optional[Any]						=  [input_ids, input_mask]
				UpperCAmelCase_     :      Any						=  model(_snake_case     )

				UpperCAmelCase_     :      List[Any]						=  model(_snake_case     )

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






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Optional[int]						=  TFDebertaVaForMaskedLM(config=_snake_case     )
				UpperCAmelCase_     :      Union[str, Any]						=  {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}
				UpperCAmelCase_     :      List[str]						=  model(_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.seq_length, self.vocab_size)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      int						=  self.num_labels
				UpperCAmelCase_     :      Tuple						=  TFDebertaVaForSequenceClassification(config=_snake_case     )
				UpperCAmelCase_     :      Any						=  {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}

				UpperCAmelCase_     :      List[str]						=  model(_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.num_labels)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Dict						=  self.num_labels
				UpperCAmelCase_     :      Tuple						=  TFDebertaVaForTokenClassification(config=_snake_case     )
				UpperCAmelCase_     :      Optional[Any]						=  {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}
				UpperCAmelCase_     :      List[str]						=  model(_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.seq_length, self.num_labels)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      List[str]						=  TFDebertaVaForQuestionAnswering(config=_snake_case     )
				UpperCAmelCase_     :      Any						=  {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}

				UpperCAmelCase_     :      List[str]						=  model(_snake_case     )
				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 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[Any]						=  self.prepare_config_and_inputs()
				(
				    (
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					(
				    UpperCAmelCase_
				)					,					
				)     :      Optional[int]						=  config_and_inputs
				UpperCAmelCase_     :      Dict						=  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
				return config, inputs_dict




@require_tf
class 					_snake_case		(__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			unittest.TestCase):
			__A  :	List[str]        =(
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			__A  :	Optional[int]        =(
			    {
			        "feature-extraction": TFDebertaVaModel,
			        "fill-mask": TFDebertaVaForMaskedLM,
			        "question-answering": TFDebertaVaForQuestionAnswering,
			        "text-classification": TFDebertaVaForSequenceClassification,
			        "token-classification": TFDebertaVaForTokenClassification,
			        "zero-shot": TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			__A  :	Tuple        =False
			__A  :	List[Any]        =False






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Optional[int]						=  TFDebertaVaModelTester(self     )
				UpperCAmelCase_     :      Union[str, Any]						=  ConfigTester(self			,config_class=_snake_case			,hidden_size=37     )






			def 		UpperCamelCase__							(  self     ):
				self.config_tester.run_common_tests()






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[Any]						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      str						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Tuple						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*_snake_case     )






			@slow
			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"     )
				self.assertIsNotNone(_snake_case     )




@require_tf
class 					_snake_case		(unittest.TestCase):






			@unittest.skip(reason="Model not available yet"     )
			def 		UpperCamelCase__							(  self     ):
				pass






			@slow
			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[str]						=  TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"     )
				UpperCAmelCase_     :      int						=  tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]     )
				UpperCAmelCase_     :      List[Any]						=  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
				UpperCAmelCase_     :      Optional[Any]						=  model(_snake_case			,attention_mask=_snake_case     )[0]

				UpperCAmelCase_     :      List[str]						=  tf.constant(
				    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]     )
				tf.debugging.assert_near(output[:, 1:4, 1:4]			,_snake_case			,atol=1E-4     )









from sklearn.metrics import matthews_corrcoef

import datasets


a__   :					Any 						=      "\nCompute the Matthews correlation coefficient (MCC)\n\nThe Matthews correlation coefficient is used in machine learning as a\nmeasure of the quality of binary and multiclass classifications. It takes\ninto account true and false positives and negatives and is generally\nregarded as a balanced measure which can be used even if the classes are of\nvery different sizes. The MCC is in essence a correlation coefficient value\nbetween -1 and +1. A coefficient of +1 represents a perfect prediction, 0\nan average random prediction and -1 an inverse prediction.  The statistic\nis also known as the phi coefficient. [source: Wikipedia]\n"

a__   :					Any 						=      "\nArgs:\n    predictions (list of int): Predicted labels, as returned by a model.\n    references (list of int): Ground truth labels.\n    sample_weight (list of int, float, or bool): Sample weights. Defaults to `None`.\nReturns:\n    matthews_correlation (dict containing float): Matthews correlation.\nExamples:\n    Example 1, a basic example with only predictions and references as inputs:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3])\n        >>> print(round(results['matthews_correlation'], 2))\n        0.54\n\n    Example 2, the same example as above, but also including sample weights:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3],\n        ...                                     sample_weight=[0.5, 3, 1, 1, 1, 2])\n        >>> print(round(results['matthews_correlation'], 2))\n        0.1\n\n    Example 3, the same example as above, but with sample weights that cause a negative correlation:\n        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")\n        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],\n        ...                                     predictions=[1, 2, 2, 0, 3, 3],\n        ...                                     sample_weight=[0.5, 1, 0, 0, 0, 1])\n        >>> print(round(results['matthews_correlation'], 2))\n        -0.25\n"

a__   :					str 						=      "\\n@article{scikit-learn,\n  title={Scikit-learn: Machine Learning in {P}ython},\n  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n  journal={Journal of Machine Learning Research},\n  volume={12},\n  pages={2825--2830},\n  year={2011}\n}\n"



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

   '''simple docstring'''




   def       UpperCAmelCase		(    self	:      List[Any])						->					int:




         """simple docstring"""

         return datasets.MetricInfo(
             description=_DESCRIPTION      ,					citation=_CITATION      ,					inputs_description=_KWARGS_DESCRIPTION      ,					features=datasets.Features(
                 {
                     'predictions': datasets.Value('int32'),
                     'references': datasets.Value('int32'),
                 })      ,					reference_urls=[
                 'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html'
             ]      ,					)



   def       UpperCAmelCase		(    self	:      Dict      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Union[str, Any]=None)						->					Any:




         """simple docstring"""

         return {
             "matthews_correlation": float(matthews_corrcoef(lowerCAmelCase      ,					lowerCAmelCase      ,					sample_weight=lowerCAmelCase)),
         }
