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



  """simple docstring"""







  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_=512   ,    snake_case_=16   ,    snake_case_=2   ,    snake_case_=0.0_2   ,    snake_case_=3   ,    snake_case_=4   ,    snake_case_=None   ,    snake_case_=0   ,    ):

    '''simple docstring'''







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







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					int		= ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size					)

    __UpperCAmelCase:					Tuple		= None
    if self.use_input_mask:
      # follow test_modeling_tf_ctrl.py
      __UpperCAmelCase:					Optional[int]		= random_attention_mask([self.batch_size, self.seq_length]					)

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

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

    __UpperCAmelCase:					str		= 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=snake_case_   ,    initializer_range=self.initializer_range   ,    )
    __UpperCAmelCase:					List[str]		= 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    lowercase_  (							self   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= TFDPRContextEncoder(config=snake_case_					)
    __UpperCAmelCase:					Optional[int]		= model(snake_case_   ,    attention_mask=snake_case_   ,    token_type_ids=snake_case_					)
    __UpperCAmelCase:					List[str]		= model(snake_case_   ,    token_type_ids=snake_case_					)
    __UpperCAmelCase:					List[Any]		= model(snake_case_					)
    self.parent.assertEqual(result.pooler_output.shape   ,    (self.batch_size, self.projection_dim or self.hidden_size)					)







  def    lowercase_  (							self   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= TFDPRQuestionEncoder(config=snake_case_					)
    __UpperCAmelCase:					Dict		= model(snake_case_   ,    attention_mask=snake_case_   ,    token_type_ids=snake_case_					)
    __UpperCAmelCase:					Optional[Any]		= model(snake_case_   ,    token_type_ids=snake_case_					)
    __UpperCAmelCase:					int		= model(snake_case_					)
    self.parent.assertEqual(result.pooler_output.shape   ,    (self.batch_size, self.projection_dim or self.hidden_size)					)







  def    lowercase_  (							self   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_   ,    snake_case_					):

    '''simple docstring'''







    __UpperCAmelCase:					Tuple		= TFDPRReader(config=snake_case_					)
    __UpperCAmelCase:					Union[str, Any]		= model(snake_case_   ,    attention_mask=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)					)
    self.parent.assertEqual(result.relevance_logits.shape   ,    (self.batch_size,)					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Tuple		= self.prepare_config_and_inputs()
    (
        __UpperCAmelCase 
    ):					List[Any]		= config_and_inputs
    __UpperCAmelCase:					Optional[int]		= {"""input_ids""": input_ids}
    return config, inputs_dict




@require_tf
class    a (       __lowerCAmelCase						,  __lowerCAmelCase						,  unittest.TestCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					(
      (
          TFDPRContextEncoder,
          TFDPRQuestionEncoder,
          TFDPRReader,
      )
      if is_tf_available()
      else ()
  )
  __lowerCAmelCase				      =					{"""feature-extraction""": TFDPRQuestionEncoder} if is_tf_available() else {}

  __lowerCAmelCase				      =					False
  __lowerCAmelCase				      =					False
  __lowerCAmelCase				      =					False
  __lowerCAmelCase				      =					False
  __lowerCAmelCase				      =					False







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= TFDPRModelTester(self					)
    __UpperCAmelCase:					Dict		= ConfigTester(self   ,    config_class=snake_case_   ,    hidden_size=37					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    self.config_tester.run_common_tests()







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_dpr_context_encoder(*snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_dpr_question_encoder(*snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







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







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __UpperCAmelCase:					str		= TFDPRContextEncoder.from_pretrained(snake_case_					)
      self.assertIsNotNone(snake_case_					)

    for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __UpperCAmelCase:					Union[str, Any]		= TFDPRContextEncoder.from_pretrained(snake_case_					)
      self.assertIsNotNone(snake_case_					)

    for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __UpperCAmelCase:					Dict		= TFDPRQuestionEncoder.from_pretrained(snake_case_					)
      self.assertIsNotNone(snake_case_					)

    for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __UpperCAmelCase:					Any		= TFDPRReader.from_pretrained(snake_case_					)
      self.assertIsNotNone(snake_case_					)




@require_tf
class    a (       unittest.TestCase				):



  """simple docstring"""







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= TFDPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""					)

    __UpperCAmelCase:					str		= tf.constant(
        [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]]					)  # [CLS] hello, is my dog cute? [SEP]
    __UpperCAmelCase:					Dict		= model(snake_case_					)[0]  # embedding shape = (1, 768)
    # compare the actual values for a slice.
    __UpperCAmelCase:					Optional[Any]		= tf.constant(
        [
            [
                0.0_3_2_3_6_2_5_3,
                0.1_2_7_5_3_3_3_5,
                0.1_6_8_1_8_5_0_9,
                0.0_0_2_7_9_7_8_6,
                0.3_8_9_6_9_3_3,
                0.2_4_2_6_4_9_4_5,
                0.2_1_7_8_9_7_1,
                -0.0_2_3_3_5_2_2_7,
                -0.0_8_4_8_1_9_5_9,
                -0.1_4_3_2_4_1_1_7,
            ]
        ]					)
    self.assertTrue(numpy.allclose(output[:, :10].numpy()   ,    expected_slice.numpy()   ,    atol=1e-4					)					)
'''simple docstring'''






def  UpperCamelCase__					(					_lowercase    :				int     )							->	int:

  if not isinstance(_lowercase   ,    _lowercase     ):
    __UpperCAmelCase:					List[str]		= F'''Input value of [number={number}] must be an integer'''
    raise TypeError(_lowercase     )

  if number < 1:
    __UpperCAmelCase:					Dict		= F'''Input value of [number={number}] must be > 0'''
    raise ValueError(_lowercase     )

  __UpperCAmelCase:					int		= 1

  for i in range(1   ,    _lowercase     ):
    current_number *= 4 * i - 2
    current_number //= i + 1

  return current_number


if __name__ == "__main__":
    import doctest

    doctest.testmod()