
'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import 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 numpy
					import tensorflow as tf

					from transformers import (
					    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    BertConfig,
					    DPRConfig,
					    TFDPRContextEncoder,
					    TFDPRQuestionEncoder,
					    TFDPRReader,
					)


class 						__UpperCAmelCase      :


							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    ,   lowerCAmelCase_=0    ,   ):





								"""simple docstring"""






								_snake_case   						=		parent
								_snake_case   						=		batch_size
								_snake_case   						=		seq_length
								_snake_case   						=		is_training
								_snake_case   						=		use_input_mask
								_snake_case   						=		use_token_type_ids
								_snake_case   						=		use_labels
								_snake_case   						=		vocab_size
								_snake_case   						=		hidden_size
								_snake_case   						=		num_hidden_layers
								_snake_case   						=		num_attention_heads
								_snake_case   						=		intermediate_size
								_snake_case   						=		hidden_act
								_snake_case   						=		hidden_dropout_prob
								_snake_case   						=		attention_probs_dropout_prob
								_snake_case   						=		max_position_embeddings
								_snake_case   						=		type_vocab_size
								_snake_case   						=		type_sequence_label_size
								_snake_case   						=		initializer_range
								_snake_case   						=		num_labels
								_snake_case   						=		num_choices
								_snake_case   						=		scope
								_snake_case   						=		projection_dim


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






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

								_snake_case   						=		None
								if self.use_input_mask:
									# follow test_modeling_tf_ctrl.py
									_snake_case   						=		random_attention_mask([self.batch_size, self.seq_length]  )

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

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

								_snake_case   						=		BertConfig(
								    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    ,   is_decoder=lowerCAmelCase_    ,   initializer_range=self.initializer_range    ,   )
								_snake_case   						=		DPRConfig(projection_dim=self.projection_dim    ,   **config.to_dict()  )

								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_  ):





								"""simple docstring"""






								_snake_case   						=		TFDPRContextEncoder(config=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_    ,   attention_mask=lowerCAmelCase_    ,   token_type_ids=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_    ,   token_type_ids=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_  )
								self.parent.assertEqual(result.pooler_output.shape    ,   (self.batch_size, self.projection_dim or self.hidden_size)  )


							def  lowerCamelCase				(       self    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_  ):





								"""simple docstring"""






								_snake_case   						=		TFDPRQuestionEncoder(config=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_    ,   attention_mask=lowerCAmelCase_    ,   token_type_ids=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_    ,   token_type_ids=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_  )
								self.parent.assertEqual(result.pooler_output.shape    ,   (self.batch_size, self.projection_dim or self.hidden_size)  )


							def  lowerCamelCase				(       self    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_    ,   lowerCAmelCase_  ):





								"""simple docstring"""






								_snake_case   						=		TFDPRReader(config=lowerCAmelCase_  )
								_snake_case   						=		model(lowerCAmelCase_    ,   attention_mask=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)  )
								self.parent.assertEqual(result.relevance_logits.shape    ,   (self.batch_size,)  )




							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		self.prepare_config_and_inputs()
								(
								    (
								    _snake_case
								)						, (
								    _snake_case
								)						, (
								    _snake_case
								)						, (
								    _snake_case
								)						, (
								    _snake_case
								)						, (
								    _snake_case
								)						, (
								    _snake_case
								)						, 
								)   						=		config_and_inputs
								_snake_case   						=		{'input_ids': input_ids}
								return config, inputs_dict


@require_tf
class 						__UpperCAmelCase      (					_lowerCamelCase						,   _lowerCamelCase						,   unittest.TestCase						):
							__lowercase      		=       (
							    (
							        TFDPRContextEncoder,
							        TFDPRQuestionEncoder,
							        TFDPRReader,
							    )
							    if is_tf_available()
							    else ()
							)
							__lowercase      		=       {"""feature-extraction""": TFDPRQuestionEncoder} if is_tf_available() else {}

							__lowercase      		=       False
							__lowercase      		=       False
							__lowercase      		=       False
							__lowercase      		=       False
							__lowercase      		=       False


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		TFDPRModelTester(self  )
								_snake_case   						=		ConfigTester(self    ,   config_class=lowerCAmelCase_    ,   hidden_size=37  )


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								self.config_tester.run_common_tests()


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_context_encoder(*lowerCAmelCase_  )


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_question_encoder(*lowerCAmelCase_  )


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_dpr_reader(*lowerCAmelCase_  )




							@slow
							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case   						=		TFDPRContextEncoder.from_pretrained(lowerCAmelCase_  )
									self.assertIsNotNone(lowerCAmelCase_  )

								for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case   						=		TFDPRContextEncoder.from_pretrained(lowerCAmelCase_  )
									self.assertIsNotNone(lowerCAmelCase_  )

								for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case   						=		TFDPRQuestionEncoder.from_pretrained(lowerCAmelCase_  )
									self.assertIsNotNone(lowerCAmelCase_  )

								for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case   						=		TFDPRReader.from_pretrained(lowerCAmelCase_  )
									self.assertIsNotNone(lowerCAmelCase_  )


@require_tf
class 						__UpperCAmelCase      (					unittest.TestCase						):


							@slow
							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'  )

								_snake_case   						=		tf.constant(
								    [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]  )  # [CLS] hello, is my dog cute? [SEP]
								_snake_case   						=		model(lowerCAmelCase_  )[0]  # embedding shape = (1, 768)
								# compare the actual values for a slice.
								_snake_case   						=		tf.constant(
								    [
								        [
								            0.03236253,
								            0.12753335,
								            0.16818509,
								            0.00279786,
								            0.3896933,
								            0.24264945,
								            0.2178971,
								            -0.02335227,
								            -0.08481959,
								            -0.14324117,
								        ]
								    ]  )
								self.assertTrue(numpy.allclose(output[:, :10].numpy()    ,   expected_slice.numpy()    ,   atol=1E-4  )  )



'''simple docstring'''







def 				SCREAMING_SNAKE_CASE__	(   __A = 100	)       ->	int:
	_snake_case   						=		n * (n + 1) * (2 * n + 1) / 6
	_snake_case   						=		(n * (n + 1) / 2) ** 2
	return int(square_of_sum - sum_of_squares	)


if __name__ == "__main__":
					print(F'''{solution() = }''')

