





'''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 			lowerCamelCase					:


					def __init__(					self	:  str       ,     __snake_case	:  List[str]       ,     __snake_case	:  List[Any]=13       ,     __snake_case	:  Dict=7       ,     __snake_case	:  Tuple=True       ,     __snake_case	:  List[str]=True       ,     __snake_case	:  Optional[Any]=True       ,     __snake_case	:  int=True       ,     __snake_case	:  List[str]=99       ,     __snake_case	:  Union[str, Any]=32       ,     __snake_case	:  str=2       ,     __snake_case	:  Tuple=4       ,     __snake_case	:  Optional[Any]=37       ,     __snake_case	:  List[Any]="gelu"       ,     __snake_case	:  Optional[int]=0.1       ,     __snake_case	:  Tuple=0.1       ,     __snake_case	:  Dict=5_12       ,     __snake_case	:  Any=16       ,     __snake_case	:  Optional[Any]=2       ,     __snake_case	:  str=0.02       ,     __snake_case	:  Union[str, Any]=False       ,     __snake_case	:  List[Any]=True       ,     __snake_case	:  int="None"       ,     __snake_case	:  int=3       ,     __snake_case	:  Union[str, Any]=4       ,     __snake_case	:  Union[str, Any]=None       ,     ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		parent
											_snake_case:   Union[str, Any]  					=		batch_size
											_snake_case:   List[str]  					=		seq_length
											_snake_case:   List[Any]  					=		is_training
											_snake_case:   Dict  					=		use_input_mask
											_snake_case:   Dict  					=		use_token_type_ids
											_snake_case:   Optional[int]  					=		use_labels
											_snake_case:   Tuple  					=		vocab_size
											_snake_case:   str  					=		hidden_size
											_snake_case:   Any  					=		num_hidden_layers
											_snake_case:   List[Any]  					=		num_attention_heads
											_snake_case:   Union[str, Any]  					=		intermediate_size
											_snake_case:   str  					=		hidden_act
											_snake_case:   List[str]  					=		hidden_dropout_prob
											_snake_case:   Optional[int]  					=		attention_probs_dropout_prob
											_snake_case:   List[Any]  					=		max_position_embeddings
											_snake_case:   List[Any]  					=		type_vocab_size
											_snake_case:   List[Any]  					=		type_sequence_label_size
											_snake_case:   Tuple  					=		initializer_range
											_snake_case:   List[Any]  					=		num_labels
											_snake_case:   List[Any]  					=		num_choices
											_snake_case:   List[str]  					=		relative_attention
											_snake_case:   List[Any]  					=		position_biased_input
											_snake_case:   str  					=		pos_att_type
											_snake_case:   List[str]  					=		scope


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





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

											_snake_case:   Dict  					=		None
											if self.use_input_mask:
																	_snake_case:   List[str]  					=		random_attention_mask([self.batch_size, self.seq_length]       )

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

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

											_snake_case:   str  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  int       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Any       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		TFDebertaVaModel(config=snake_case_       )
											_snake_case:   Optional[int]  					=		{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

											_snake_case:   Dict  					=		[input_ids, input_mask]
											_snake_case:   int  					=		model(snake_case_       )

											_snake_case:   str  					=		model(snake_case_       )

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


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  Any       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		TFDebertaVaForMaskedLM(config=snake_case_       )
											_snake_case:   List[str]  					=		{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}
											_snake_case:   List[str]  					=		model(snake_case_       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Any       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.num_labels
											_snake_case:   str  					=		TFDebertaVaForSequenceClassification(config=snake_case_       )
											_snake_case:   List[Any]  					=		{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

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


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Any       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[Any]       ,     __snake_case	:  str       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		self.num_labels
											_snake_case:   Tuple  					=		TFDebertaVaForTokenClassification(config=snake_case_       )
											_snake_case:   Dict  					=		{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}
											_snake_case:   str  					=		model(snake_case_       )
											self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ,     __snake_case	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Dict       ,     __snake_case	:  Dict       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  int       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		TFDebertaVaForQuestionAnswering(config=snake_case_       )
											_snake_case:   Dict  					=		{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											_snake_case:   Union[str, Any]  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   str  					=		self.prepare_config_and_inputs()
											(
											    _snake_case					
											):   List[Any]  					=		config_and_inputs
											_snake_case:   List[Any]  					=		{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
											return config, inputs_dict







@require_tf
class 			lowerCamelCase					(						_snake_case     ,							_snake_case     ,							unittest.TestCase  ):
					_SCREAMING_SNAKE_CASE							   =    (
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					_SCREAMING_SNAKE_CASE							   =    (
					    {
					        """feature-extraction""": TFDebertaVaModel,
					        """fill-mask""": TFDebertaVaForMaskedLM,
					        """question-answering""": TFDebertaVaForQuestionAnswering,
					        """text-classification""": TFDebertaVaForSequenceClassification,
					        """token-classification""": TFDebertaVaForTokenClassification,
					        """zero-shot""": TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   Any  					=		TFDebertaVaModelTester(self       )
											_snake_case:   Dict  					=		ConfigTester(self       ,     config_class=snake_case_       ,     hidden_size=37       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											self.config_tester.run_common_tests()


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*snake_case_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   int  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*snake_case_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*snake_case_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*snake_case_       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*snake_case_       )




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
											self.assertIsNotNone(snake_case_       )







@require_tf
class 			lowerCamelCase					(						unittest.TestCase  ):


					@unittest.skip(reason='Model not available yet'       )
					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											pass




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
											_snake_case:   Optional[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]]       )
											_snake_case:   List[str]  					=		tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
											_snake_case:   str  					=		model(snake_case_       ,     attention_mask=snake_case_       )[0]

											_snake_case:   Optional[Any]  					=		tf.constant(
											    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]       )
											tf.debugging.assert_near(output[:, 1:4, 1:4]       ,     snake_case_       ,     atol=1e-4       )












'''simple docstring'''






from sklearn.metrics import matthews_corrcoef

import datasets


A   : Dict             =			'\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   : int             =			'\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   : Dict             =			'\\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 			lowerCamelCase					(						datasets.Metric  ):


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''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    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ,     __snake_case	:  int       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Union[str, Any]=None       ):





											'''simple docstring'''





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





