"""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        __snake_case	:



      def __init__(						self   ,      lowercase   ,      )     ->      Optional[Any]:





        '''simple docstring'''





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



      def   lowerCamelCase_       (						self)     ->      int:





        '''simple docstring'''





        a__:					Dict      							=     ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size)

        a__:					Tuple      							=     None
        if self.use_input_mask:
          a__:					Union[str, Any]      							=     random_attention_mask([self.batch_size, self.seq_length])

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

        a__:					str      							=     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   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      List[Any]:





        '''simple docstring'''





        a__:					List[Any]      							=     TFDistilBertModel(config=lowercase)
        a__:					Optional[Any]      							=     {'input_ids': input_ids, 'attention_mask': input_mask}

        a__:					Tuple      							=     model(lowercase)

        a__:					Union[str, Any]      							=     [input_ids, input_mask]

        a__:					str      							=     model(lowercase)

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



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      Optional[Any]:





        '''simple docstring'''





        a__:					int      							=     TFDistilBertForMaskedLM(config=lowercase)
        a__:					Any      							=     {'input_ids': input_ids, 'attention_mask': input_mask}
        a__:					Union[str, Any]      							=     model(lowercase)
        self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.vocab_size))



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      str:





        '''simple docstring'''





        a__:					Tuple      							=     TFDistilBertForQuestionAnswering(config=lowercase)
        a__:					List[Any]      							=     {
            'input_ids': input_ids,
            'attention_mask': input_mask,
        }
        a__:					List[Any]      							=     model(lowercase)
        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   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      Dict:





        '''simple docstring'''





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



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      Union[str, Any]:





        '''simple docstring'''





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



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase   ,      lowercase)     ->      Union[str, Any]:





        '''simple docstring'''





        a__:					Dict      							=     self.num_labels
        a__:					Optional[Any]      							=     TFDistilBertForTokenClassification(lowercase)
        a__:					Dict      							=     {'input_ids': input_ids, 'attention_mask': input_mask}
        a__:					Tuple      							=     model(lowercase)
        self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.num_labels))



      def   lowerCamelCase_       (						self)     ->      Tuple:





        '''simple docstring'''





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







@require_tf
class        __snake_case	(					__lowerCAmelCase	,				__lowerCAmelCase	,				unittest.TestCase    ):
      a__				=		(
          (
              TFDistilBertModel,
              TFDistilBertForMaskedLM,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertForMultipleChoice,
          )
          if is_tf_available()
          else None
      )
      a__				=		(
          {
              """feature-extraction""": TFDistilBertModel,
              """fill-mask""": TFDistilBertForMaskedLM,
              """question-answering""": TFDistilBertForQuestionAnswering,
              """text-classification""": TFDistilBertForSequenceClassification,
              """token-classification""": TFDistilBertForTokenClassification,
              """zero-shot""": TFDistilBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      a__				=		False
      a__				=		False



      def   lowerCamelCase_       (						self)     ->      Any:





        '''simple docstring'''





        a__:					int      							=     TFDistilBertModelTester(self)
        a__:					Optional[Any]      							=     ConfigTester(self   ,      config_class=lowercase   ,      dim=37)



      def   lowerCamelCase_       (						self)     ->      Optional[int]:





        '''simple docstring'''





        self.config_tester.run_common_tests()



      def   lowerCamelCase_       (						self)     ->      str:





        '''simple docstring'''





        a__:					Optional[int]      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_model(*lowercase)



      def   lowerCamelCase_       (						self)     ->      Dict:





        '''simple docstring'''





        a__:					List[str]      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase)



      def   lowerCamelCase_       (						self)     ->      List[str]:





        '''simple docstring'''





        a__:					Tuple      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase)



      def   lowerCamelCase_       (						self)     ->      Any:





        '''simple docstring'''





        a__:					Dict      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase)



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





        '''simple docstring'''





        a__:					List[str]      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase)



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





        '''simple docstring'''





        a__:					Optional[int]      							=     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase)



      @slow
      def   lowerCamelCase_       (						self)     ->      List[str]:





        '''simple docstring'''





        for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]):
          a__:					str      							=     TFDistilBertModel.from_pretrained(lowercase)
          self.assertIsNotNone(lowercase)







@require_tf
class        __snake_case	(					unittest.TestCase    ):



      @slow
      def   lowerCamelCase_       (						self)     ->      Tuple:





        '''simple docstring'''





        a__:					List[Any]      							=     TFDistilBertModel.from_pretrained('distilbert-base-uncased')
        a__:					Any      							=     tf.constant([[0, 1, 2, 3, 4, 5]])
        a__:					str      							=     model(lowercase)[0]

        a__:					Tuple      							=     [1, 6, 7_68]
        self.assertEqual(output.shape   ,      lowercase)

        a__:					Tuple      							=     tf.constant(
            [
                [
                    [0.19261885, -0.13732955, 0.4119799],
                    [0.22150156, -0.07422661, 0.39037204],
                    [0.22756018, -0.0896414, 0.3701467],
                ]
            ])
        tf.debugging.assert_near(output[:, :3, :3]   ,      lowercase   ,      atol=1e-4)



"""simple docstring"""
def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  return credit_card_number.startswith(('34', '35', '37', '4', '5', '6')       )







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  a__:					Any      							=     credit_card_number
  a__:					Tuple      							=     0
  a__:					List[str]      							=     len(_SCREAMING_SNAKE_CASE       ) - 2
  for i in range(_SCREAMING_SNAKE_CASE		,					-1		,					-2       ):
    #  double the value of every second digit
    a__:					Tuple      							=     int(cc_number[i]       )
    digit *= 2
    # If doubling of a number results in a two digit number
    # i.e greater than 9(e.g., 6 × 2 = 12),
    # then add the digits of the product (e.g., 12: 1 + 2 = 3, 15: 1 + 5 = 6),
    # to get a single digit number.
    if digit > 9:
      digit %= 10
      digit += 1
    a__:					Optional[Any]      							=     cc_number[:i] + str(_SCREAMING_SNAKE_CASE       ) + cc_number[i + 1 :]
    total += digit

  # Sum up the remaining digits
  for i in range(len(_SCREAMING_SNAKE_CASE       ) - 1		,					-1		,					-2       ):
    total += int(cc_number[i]       )

  return total % 10 == 0







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:
  a__:					Optional[int]      							=     F'{credit_card_number} is an invalid credit card number because'
  if not credit_card_number.isdigit():
    print(F'{error_message} it has nonnumerical characters.'       )
    return False

  if not 13 <= len(_SCREAMING_SNAKE_CASE       ) <= 16:
    print(F'{error_message} of its length.'       )
    return False

  if not validate_initial_digits(_SCREAMING_SNAKE_CASE       ):
    print(F'{error_message} of its first two digits.'       )
    return False

  if not luhn_validation(_SCREAMING_SNAKE_CASE       ):
    print(F'{error_message} it fails the Luhn check.'       )
    return False

  print(F'{credit_card_number} is a valid credit card number.'       )
  return True


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 validate_credit_card_number('4111111111111111')
 validate_credit_card_number('32323')


