



"""simple docstring"""






from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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.models.distilbert.modeling_tf_distilbert import (
	    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFDistilBertForMaskedLM,
	    TFDistilBertForMultipleChoice,
	    TFDistilBertForQuestionAnswering,
	    TFDistilBertForSequenceClassification,
	    TFDistilBertForTokenClassification,
	    TFDistilBertModel,
	)



class 			A__   :




	'''simple docstring'''





	def __init__(     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       parent
				__lowerCAmelCase      :  int												=       13
				__lowerCAmelCase      :  int												=       7
				__lowerCAmelCase      :  Tuple												=       True
				__lowerCAmelCase      :  Dict												=       True
				__lowerCAmelCase      :  Union[str, Any]												=       False
				__lowerCAmelCase      :  int												=       True
				__lowerCAmelCase      :  Union[str, Any]												=       99
				__lowerCAmelCase      :  List[Any]												=       32
				__lowerCAmelCase      :  str												=       2
				__lowerCAmelCase      :  Dict												=       4
				__lowerCAmelCase      :  List[Any]												=       37
				__lowerCAmelCase      :  Tuple												=       'gelu'
				__lowerCAmelCase      :  Optional[int]												=       0.1
				__lowerCAmelCase      :  Tuple												=       0.1
				__lowerCAmelCase      :  List[Any]												=       512
				__lowerCAmelCase      :  Union[str, Any]												=       16
				__lowerCAmelCase      :  List[str]												=       2
				__lowerCAmelCase      :  Tuple												=       0.02
				__lowerCAmelCase      :  Optional[Any]												=       3
				__lowerCAmelCase      :  Optional[int]												=       4
				__lowerCAmelCase      :  Tuple												=       None

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

				"""simple docstring"""

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

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

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

				__lowerCAmelCase      :  Union[str, Any]												=       DistilBertConfig(
				    vocab_size=self.vocab_size       ,			dim=self.hidden_size       ,			n_layers=self.num_hidden_layers       ,			n_heads=self.num_attention_heads       ,			hidden_dim=self.intermediate_size       ,			hidden_act=self.hidden_act       ,			dropout=self.hidden_dropout_prob       ,			attention_dropout=self.attention_probs_dropout_prob       ,			max_position_embeddings=self.max_position_embeddings       ,			initializer_range=self.initializer_range       ,			)

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[Any])				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       TFDistilBertModel(config=_UpperCAmelCase)
				__lowerCAmelCase      :  Dict												=       {'input_ids': input_ids, 'attention_mask': input_mask}

				__lowerCAmelCase      :  Optional[int]												=       model(_UpperCAmelCase)

				__lowerCAmelCase      :  Optional[int]												=       [input_ids, input_mask]

				__lowerCAmelCase      :  Optional[int]												=       model(_UpperCAmelCase)

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		str       ,			_SCREAMING_SNAKE_CASE:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		int)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       TFDistilBertForMaskedLM(config=_UpperCAmelCase)
				__lowerCAmelCase      :  Dict												=       {'input_ids': input_ids, 'attention_mask': input_mask}
				__lowerCAmelCase      :  Any												=       model(_UpperCAmelCase)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.seq_length, self.vocab_size))

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		str       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		str)				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       TFDistilBertForQuestionAnswering(config=_UpperCAmelCase)
				__lowerCAmelCase      :  Tuple												=       {
				    'input_ids': input_ids,
				    'attention_mask': input_mask,
				}
				__lowerCAmelCase      :  Tuple												=       model(_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 							_SCREAMING_SNAKE_CASE   (     self:		Any       ,			_SCREAMING_SNAKE_CASE:		str       ,			_SCREAMING_SNAKE_CASE:		Any       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		str)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       self.num_labels
				__lowerCAmelCase      :  List[Any]												=       TFDistilBertForSequenceClassification(_UpperCAmelCase)
				__lowerCAmelCase      :  Dict												=       {'input_ids': input_ids, 'attention_mask': input_mask}
				__lowerCAmelCase      :  int												=       model(_UpperCAmelCase)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.num_labels))

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		str       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		Tuple)				->       Any:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       self.num_choices
				__lowerCAmelCase      :  Optional[Any]												=       TFDistilBertForMultipleChoice(_UpperCAmelCase)
				__lowerCAmelCase      :  List[Any]												=       tf.tile(tf.expand_dims(_UpperCAmelCase       ,			1)       ,			(1, self.num_choices, 1))
				__lowerCAmelCase      :  Union[str, Any]												=       tf.tile(tf.expand_dims(_UpperCAmelCase       ,			1)       ,			(1, self.num_choices, 1))
				__lowerCAmelCase      :  Optional[Any]												=       {
				    'input_ids': multiple_choice_inputs_ids,
				    'attention_mask': multiple_choice_input_mask,
				}
				__lowerCAmelCase      :  Tuple												=       model(_UpperCAmelCase)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.num_choices))

	def 							_SCREAMING_SNAKE_CASE   (     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		int)				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       self.num_labels
				__lowerCAmelCase      :  Optional[Any]												=       TFDistilBertForTokenClassification(_UpperCAmelCase)
				__lowerCAmelCase      :  str												=       {'input_ids': input_ids, 'attention_mask': input_mask}
				__lowerCAmelCase      :  Union[str, Any]												=       model(_UpperCAmelCase)
				self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.seq_length, self.num_labels))







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

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       self.prepare_config_and_inputs()
				(__lowerCAmelCase)      :  Union[str, Any]												=       config_and_inputs
				__lowerCAmelCase      :  Dict												=       {'input_ids': input_ids, 'attention_mask': input_mask}
				return config, inputs_dict






@require_tf
class 			A__   (  a__  ,		a__  ,		unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	(
	    (
	        TFDistilBertModel,
	        TFDistilBertForMaskedLM,
	        TFDistilBertForQuestionAnswering,
	        TFDistilBertForSequenceClassification,
	        TFDistilBertForTokenClassification,
	        TFDistilBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else None
	)
	SCREAMING_SNAKE_CASE          =	(
	    {
	        'feature-extraction': TFDistilBertModel,
	        'fill-mask': TFDistilBertForMaskedLM,
	        'question-answering': TFDistilBertForQuestionAnswering,
	        'text-classification': TFDistilBertForSequenceClassification,
	        'token-classification': TFDistilBertForTokenClassification,
	        'zero-shot': TFDistilBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	SCREAMING_SNAKE_CASE          =	False
	SCREAMING_SNAKE_CASE          =	False

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       TFDistilBertModelTester(self)
				__lowerCAmelCase      :  List[Any]												=       ConfigTester(self       ,			config_class=_UpperCAmelCase       ,			dim=37)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Any:

				"""simple docstring"""

				self.config_tester.run_common_tests()

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

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_model(*_UpperCAmelCase)

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

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_masked_lm(*_UpperCAmelCase)

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_question_answering(*_UpperCAmelCase)

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

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_sequence_classification(*_UpperCAmelCase)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       List[str]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_multiple_choice(*_UpperCAmelCase)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_distilbert_for_token_classification(*_UpperCAmelCase)







	@slow
	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       Dict:

				"""simple docstring"""

				for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]):
							__lowerCAmelCase      :  Tuple												=       TFDistilBertModel.from_pretrained(_UpperCAmelCase)
							self.assertIsNotNone(_UpperCAmelCase)






@require_tf
class 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	@slow
	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       TFDistilBertModel.from_pretrained("distilbert-base-uncased")
				__lowerCAmelCase      :  Union[str, Any]												=       tf.constant([[0, 1, 2, 3, 4, 5]])
				__lowerCAmelCase      :  Optional[Any]												=       model(_UpperCAmelCase)[0]

				__lowerCAmelCase      :  int												=       [1, 6, 768]
				self.assertEqual(output.shape       ,			_UpperCAmelCase)

				__lowerCAmelCase      :  List[str]												=       tf.constant(
				    [
				        [
				            [0.1926_1885, -0.1373_2955, 0.411_9799],
				            [0.2215_0156, -0.0742_2661, 0.3903_7204],
				            [0.2275_6018, -0.089_6414, 0.370_1467],
				        ]
				    ])
				tf.debugging.assert_near(output[:, :3, :3]       ,			_UpperCAmelCase       ,			atol=1e-4)






'''simple docstring'''




import random






def        _lowerCAmelCase			(  __snake_case  : int ,							__snake_case  : float ,							__snake_case  : bool = False			)     ->     dict:
     __A						: dict      =       {i: [] for i in range(__snake_case			)}

     # if probability is greater or equal than 1, then generate a complete graph
     if probability >= 1:
          return complete_graph(__snake_case			)
     # if probability is lower or equal than 0, then return a graph without edges
     if probability <= 0:
          return graph

     # for each couple of nodes, add an edge from u to v
     # if the number randomly generated is greater than probability probability
     for i in range(__snake_case			):
          for j in range(i + 1 ,							__snake_case			):
               if random.random() < probability:
                    graph[i].append(__snake_case			)
                    if not directed:
                         # if the graph is undirected, add an edge in from j to i, either
                         graph[j].append(__snake_case			)
     return graph






def        _lowerCAmelCase			(  __snake_case  : int			)     ->     dict:
     return {
         i: [j for j in range(__snake_case			) if i != j] for i in range(__snake_case			)
     }


if __name__ == "__main__":
  import doctest

  doctest.testmod()