




'''simple docstring'''


from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 import (
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
           TFDebertaVaModel,
       )





class    __lowercase						:







   def __init__(	self      ,							UpperCamelCase      ,							UpperCamelCase=13      ,							UpperCamelCase=7      ,							UpperCamelCase=True      ,							UpperCamelCase=True      ,							UpperCamelCase=True      ,							UpperCamelCase=True      ,							UpperCamelCase=99      ,							UpperCamelCase=32      ,							UpperCamelCase=2      ,							UpperCamelCase=4      ,							UpperCamelCase=37      ,							UpperCamelCase="gelu"      ,							UpperCamelCase=0.1      ,							UpperCamelCase=0.1      ,							UpperCamelCase=512      ,							UpperCamelCase=16      ,							UpperCamelCase=2      ,							UpperCamelCase=0.02      ,							UpperCamelCase=False      ,							UpperCamelCase=True      ,							UpperCamelCase="None"      ,							UpperCamelCase=3      ,							UpperCamelCase=4      ,							UpperCamelCase=None      ,							)				->    Tuple:
     __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 		UpperCamelCase__			(	self      )				->    List[Any]:
     __a			=					ids_tensor([self.batch_size, self.seq_length]      ,							self.vocab_size      )

     __a			=					None
     if self.use_input_mask:
       __a			=					random_attention_mask([self.batch_size, self.seq_length]      )

     __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			=					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      ,							relative_attention=self.relative_attention      ,							position_biased_input=self.position_biased_input      ,							initializer_range=self.initializer_range      ,							return_dict=UpperCamelCase_      ,							)

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







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Dict:
     __a			=					TFDebertaVaModel(config=UpperCamelCase_      )
     __a			=					{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

     __a			=					[input_ids, input_mask]
     __a			=					model(UpperCamelCase_      )

     __a			=					model(UpperCamelCase_      )

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







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Any:
     __a			=					TFDebertaVaForMaskedLM(config=UpperCamelCase_      )
     __a			=					{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     __a			=					model(UpperCamelCase_      )
     self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.vocab_size)      )







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    List[Any]:
     __a			=					self.num_labels
     __a			=					TFDebertaVaForSequenceClassification(config=UpperCamelCase_      )
     __a			=					{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     __a			=					model(UpperCamelCase_      )
     self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_labels)      )







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    Tuple:
     __a			=					self.num_labels
     __a			=					TFDebertaVaForTokenClassification(config=UpperCamelCase_      )
     __a			=					{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     __a			=					model(UpperCamelCase_      )
     self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.num_labels)      )







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    List[str]:
     __a			=					TFDebertaVaForQuestionAnswering(config=UpperCamelCase_      )
     __a			=					{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     __a			=					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 		UpperCamelCase__			(	self      )				->    List[str]:
     __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_tf
class    __lowercase						(  __magic_name__       ,							__magic_name__       ,							unittest.TestCase ):
   _a							=      (
       (
           TFDebertaVaModel,
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   _a							=      (
       {
           "feature-extraction": TFDebertaVaModel,
           "fill-mask": TFDebertaVaForMaskedLM,
           "question-answering": TFDebertaVaForQuestionAnswering,
           "text-classification": TFDebertaVaForSequenceClassification,
           "token-classification": TFDebertaVaForTokenClassification,
           "zero-shot": TFDebertaVaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   _a							=      False
   _a							=      False







   def 		UpperCamelCase__			(	self      )				->    int:
     __a			=					TFDebertaVaModelTester(self      )
     __a			=					ConfigTester(self      ,							config_class=UpperCamelCase_      ,							hidden_size=37      )







   def 		UpperCamelCase__			(	self      )				->    Tuple:
     self.config_tester.run_common_tests()







   def 		UpperCamelCase__			(	self      )				->    Tuple:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*UpperCamelCase_      )







   def 		UpperCamelCase__			(	self      )				->    Optional[Any]:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase_      )







   def 		UpperCamelCase__			(	self      )				->    List[Any]:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*UpperCamelCase_      )







   def 		UpperCamelCase__			(	self      )				->    Dict:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase_      )







   def 		UpperCamelCase__			(	self      )				->    Union[str, Any]:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*UpperCamelCase_      )







   @slow
   def 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
     self.assertIsNotNone(UpperCamelCase_      )





@require_tf
class    __lowercase						(  unittest.TestCase ):







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







   @slow
   def 		UpperCamelCase__			(	self      )				->    Optional[int]:
     __a			=					TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
     __a			=					tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]      )
     __a			=					tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
     __a			=					model(UpperCamelCase_      ,							attention_mask=UpperCamelCase_      )[0]

     __a			=					tf.constant(
         [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]      )
     tf.debugging.assert_near(output[:, 1:4, 1:4]      ,							UpperCamelCase_      ,							atol=1e-4      )









'''simple docstring'''


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mobilebert import MobileBertTokenizer


UpperCAmelCase_ 		=      logging.get_logger(__name__)

UpperCAmelCase_ 		=      {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

UpperCAmelCase_ 		=      {
    "vocab_file": {"mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/vocab.txt"},
    "tokenizer_file": {
        "mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/tokenizer.json"
    },
}

UpperCAmelCase_ 		=      {"mobilebert-uncased": 5_12}


UpperCAmelCase_ 		=      {}





class    __lowercase						(  __magic_name__ ):
   _a							=      VOCAB_FILES_NAMES
   _a							=      PRETRAINED_VOCAB_FILES_MAP
   _a							=      PRETRAINED_INIT_CONFIGURATION
   _a							=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   _a							=      MobileBertTokenizer







   def __init__(	self      ,							UpperCamelCase=None      ,							UpperCamelCase=None      ,							UpperCamelCase=True      ,							UpperCamelCase="[UNK]"      ,							UpperCamelCase="[SEP]"      ,							UpperCamelCase="[PAD]"      ,							UpperCamelCase="[CLS]"      ,							UpperCamelCase="[MASK]"      ,							UpperCamelCase=True      ,							UpperCamelCase=None      ,							**UpperCamelCase      ,							)				->    List[Any]:
     super().__init__(
         UpperCamelCase      ,							tokenizer_file=UpperCamelCase      ,							do_lower_case=UpperCamelCase      ,							unk_token=UpperCamelCase      ,							sep_token=UpperCamelCase      ,							pad_token=UpperCamelCase      ,							cls_token=UpperCamelCase      ,							mask_token=UpperCamelCase      ,							tokenize_chinese_chars=UpperCamelCase      ,							strip_accents=UpperCamelCase      ,							**UpperCamelCase      ,							)

     __a			=					json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
     if (
         normalizer_state.get('lowercase'      ,							UpperCamelCase      ) != do_lower_case
         or normalizer_state.get('strip_accents'      ,							UpperCamelCase      ) != strip_accents
         or normalizer_state.get('handle_chinese_chars'      ,							UpperCamelCase      ) != tokenize_chinese_chars
     ):
       __a			=					getattr(UpperCamelCase      ,							normalizer_state.pop('type'      )      )
       __a			=					do_lower_case
       __a			=					strip_accents
       __a			=					tokenize_chinese_chars
       __a			=					normalizer_class(**UpperCamelCase      )

     __a			=					do_lower_case







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase=None      )				->    Tuple:
     __a			=					[self.cls_token_id] + token_ids_a + [self.sep_token_id]

     if token_ids_a:
       output += token_ids_a + [self.sep_token_id]

     return output







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase = None      )				->    List[int]:
     __a			=					[self.sep_token_id]
     __a			=					[self.cls_token_id]
     if token_ids_a is None:
       return len(cls + token_ids_a + sep      ) * [0]
     return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase = None      )				->    Tuple[str]:
     __a			=					self._tokenizer.model.save(UpperCamelCase      ,							name=UpperCamelCase      )
     return tuple(UpperCamelCase      )



