



import unittest

from transformers import DebertaVaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    DebertaVaForMaskedLM,
							    DebertaVaForMultipleChoice,
							    DebertaVaForQuestionAnswering,
							    DebertaVaForSequenceClassification,
							    DebertaVaForTokenClassification,
							    DebertaVaModel,
							)
							from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST


class      __lowerCAmelCase     (		__A      ):
					"""simple docstring"""






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






								"""simple docstring"""


								A__       =    parent
								A__       =    batch_size
								A__       =    seq_length
								A__       =    is_training
								A__       =    use_input_mask
								A__       =    use_token_type_ids
								A__       =    use_labels
								A__       =    vocab_size
								A__       =    hidden_size
								A__       =    num_hidden_layers
								A__       =    num_attention_heads
								A__       =    intermediate_size
								A__       =    hidden_act
								A__       =    hidden_dropout_prob
								A__       =    attention_probs_dropout_prob
								A__       =    max_position_embeddings
								A__       =    type_vocab_size
								A__       =    type_sequence_label_size
								A__       =    initializer_range
								A__       =    num_labels
								A__       =    num_choices
								A__       =    relative_attention
								A__       =    position_biased_input
								A__       =    pos_att_type
								A__       =    scope



					def     _a							(     self					:       List[Any]					):






								"""simple docstring"""


								A__       =    ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size					)

								A__       =    None
								if self.use_input_mask:
											A__       =    ids_tensor([self.batch_size, self.seq_length]				,					vocab_size=2					)

								A__       =    None
								if self.use_token_type_ids:
											A__       =    ids_tensor([self.batch_size, self.seq_length]				,					self.type_vocab_size					)

								A__       =    None
								A__       =    None
								A__       =    None
								if self.use_labels:
											A__       =    ids_tensor([self.batch_size]				,					self.type_sequence_label_size					)
											A__       =    ids_tensor([self.batch_size, self.seq_length]				,					self.num_labels					)
											A__       =    ids_tensor([self.batch_size]				,					self.num_choices					)

								A__       =    self.get_config()

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



					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								return 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				,					initializer_range=self.initializer_range				,					relative_attention=self.relative_attention				,					position_biased_input=self.position_biased_input				,					pos_att_type=self.pos_att_type				,					)



					def     _a							(     self					:       Optional[Any]				,					_snake_case					:       List[Any]					):






								"""simple docstring"""


								self.parent.assertListEqual(list(result.loss.size()					)				,					[]					)



					def     _a							(     self					:       Optional[Any]				,					_snake_case					:       List[str]				,					_snake_case					:       List[Any]				,					_snake_case					:       Dict				,					_snake_case					:       Tuple				,					_snake_case					:       Dict				,					_snake_case					:       Any				,					_snake_case					:       str					):






								"""simple docstring"""


								A__       =    DebertaVaModel(config=UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    model(UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__					)[0]
								A__       =    model(UpperCamelCase__				,					token_type_ids=UpperCamelCase__					)[0]
								A__       =    model(UpperCamelCase__					)[0]

								self.parent.assertListEqual(list(sequence_output.size()					)				,					[self.batch_size, self.seq_length, self.hidden_size]					)



					def     _a							(     self					:       str				,					_snake_case					:       int				,					_snake_case					:       Dict				,					_snake_case					:       List[str]				,					_snake_case					:       Dict				,					_snake_case					:       Optional[Any]				,					_snake_case					:       List[Any]				,					_snake_case					:       Optional[int]					):






								"""simple docstring"""


								A__       =    DebertaVaForMaskedLM(config=UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    model(UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__				,					labels=UpperCamelCase__					)

								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)					)



					def     _a							(     self					:       List[str]				,					_snake_case					:       List[Any]				,					_snake_case					:       List[str]				,					_snake_case					:       Union[str, Any]				,					_snake_case					:       Optional[int]				,					_snake_case					:       List[str]				,					_snake_case					:       Optional[Any]				,					_snake_case					:       Tuple					):






								"""simple docstring"""


								A__       =    self.num_labels
								A__       =    DebertaVaForSequenceClassification(UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    model(UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__				,					labels=UpperCamelCase__					)
								self.parent.assertListEqual(list(result.logits.size()					)				,					[self.batch_size, self.num_labels]					)
								self.check_loss_output(UpperCamelCase__					)



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






								"""simple docstring"""


								A__       =    self.num_labels
								A__       =    DebertaVaForTokenClassification(config=UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    model(UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__				,					labels=UpperCamelCase__					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.num_labels)					)



					def     _a							(     self					:       Optional[int]				,					_snake_case					:       Any				,					_snake_case					:       Optional[Any]				,					_snake_case					:       Optional[int]				,					_snake_case					:       Optional[int]				,					_snake_case					:       Tuple				,					_snake_case					:       Optional[Any]				,					_snake_case					:       Union[str, Any]					):






								"""simple docstring"""


								A__       =    DebertaVaForQuestionAnswering(config=UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    model(
								    UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__				,					start_positions=UpperCamelCase__				,					end_positions=UpperCamelCase__				,					)
								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     _a							(     self					:       Dict				,					_snake_case					:       Union[str, Any]				,					_snake_case					:       Tuple				,					_snake_case					:       List[Any]				,					_snake_case					:       Tuple				,					_snake_case					:       List[str]				,					_snake_case					:       List[Any]				,					_snake_case					:       Tuple					):






								"""simple docstring"""


								A__       =    DebertaVaForMultipleChoice(config=UpperCamelCase__					)
								model.to(UpperCamelCase__					)
								model.eval()
								A__       =    input_ids.unsqueeze(1					).expand(-1				,					self.num_choices				,					-1					).contiguous()
								A__       =    token_type_ids.unsqueeze(1					).expand(-1				,					self.num_choices				,					-1					).contiguous()
								A__       =    input_mask.unsqueeze(1					).expand(-1				,					self.num_choices				,					-1					).contiguous()
								A__       =    model(
								    UpperCamelCase__				,					attention_mask=UpperCamelCase__				,					token_type_ids=UpperCamelCase__				,					labels=UpperCamelCase__				,					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_choices)					)



					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    self.prepare_config_and_inputs()
								(
								    A__       
								)       =    config_and_inputs
								A__       =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
								return config, inputs_dict







@require_torch
class      __lowerCAmelCase     (		__A							,     __A							,     unittest.TestCase      ):
					"""simple docstring"""






					A__				:		Union[str, Any]			       =	(
					    (
					        DebertaVaModel,
					        DebertaVaForMaskedLM,
					        DebertaVaForSequenceClassification,
					        DebertaVaForTokenClassification,
					        DebertaVaForQuestionAnswering,
					        DebertaVaForMultipleChoice,
					    )
					    if is_torch_available()
					    else ()
					)
					A__				:		Tuple			       =	(
					    {
					        """feature-extraction""": DebertaVaModel,
					        """fill-mask""": DebertaVaForMaskedLM,
					        """question-answering""": DebertaVaForQuestionAnswering,
					        """text-classification""": DebertaVaForSequenceClassification,
					        """token-classification""": DebertaVaForTokenClassification,
					        """zero-shot""": DebertaVaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

					A__				:		Optional[int]			       =	True
					A__				:		int			       =	False
					A__				:		Union[str, Any]			       =	False
					A__				:		List[str]			       =	False
					A__				:		Optional[int]			       =	False



					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


								A__       =    DebertaVaModelTester(self					)
								A__       =    ConfigTester(self				,					config_class=UpperCamelCase__				,					hidden_size=37					)



					def     _a							(     self					:       int					):






								"""simple docstring"""


								self.config_tester.run_common_tests()



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*UpperCamelCase__					)



					def     _a							(     self					:       int					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*UpperCamelCase__					)



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*UpperCamelCase__					)



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






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*UpperCamelCase__					)



					def     _a							(     self					:       Any					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*UpperCamelCase__					)



					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_multiple_choice(*UpperCamelCase__					)



					@slow
					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


								for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											A__       =    DebertaVaModel.from_pretrained(UpperCamelCase__					)
											self.assertIsNotNone(UpperCamelCase__					)







@require_torch
@require_sentencepiece
@require_tokenizers
class      __lowerCAmelCase     (		unittest.TestCase      ):
					"""simple docstring"""






					@unittest.skip(reason='Model not available yet'					)
					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								pass



					@slow
					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


								A__       =    DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge'					)

								A__       =    torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]					)
								A__       =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
								with torch.no_grad():
											A__       =    model(UpperCamelCase__				,					attention_mask=UpperCamelCase__					)[0]
								# compare the actual values for a slice.
								A__       =    torch.tensor(
								    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]					)
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]				,					UpperCamelCase__				,					atol=1E-4					)				,					F'''{output[:, 1:4, 1:4]}'''					)









import math
import random


def A						(       __UpperCamelCase ,	__UpperCamelCase = False					)						->      float:
			if deriv:
						return value * (1 - value)
			return 1 / (1 + math.exp(-value					))


# Initial Value
SCREAMING_SNAKE_CASE__       =      0.02


def A						(       __UpperCamelCase ,	__UpperCamelCase					)						->      float:
			A__       =    float(2 * (random.randint(1 ,	100					)) - 1					)

			for _ in range(__UpperCamelCase					):
						# Forward propagation
						A__       =    sigmoid_function(INITIAL_VALUE * weight					)
						# How much did we miss?
						A__       =    (expected / 100) - layer_a
						# Error delta
						A__       =    layer_1_error * sigmoid_function(__UpperCamelCase ,	__UpperCamelCase					)
						# Update weight
						weight += INITIAL_VALUE * layer_1_delta

			return layer_a * 100


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							SCREAMING_SNAKE_CASE__       =      int(input('''Expected value: '''))
							SCREAMING_SNAKE_CASE__       =      int(input('''Number of propagations: '''))
							print(forward_propagation(expected, number_propagations))




