





'''simple docstring'''







import os
from typing import List, Union

import tensorflow as tf
from tensorflow_text import BertTokenizer as BertTokenizerLayer
from tensorflow_text import FastBertTokenizer, ShrinkLongestTrimmer, case_fold_utfa, combine_segments, pad_model_inputs

from .tokenization_bert import BertTokenizer


class        __a   (tf.keras.layers.Layer  ):

							def __init__(				self				:  Tuple							,  __magic_name__				:  List							,  __magic_name__				:  bool							,  __magic_name__				:  int = None							,  __magic_name__				:  int = None							,  __magic_name__				:  int = None							,  __magic_name__				:  str = "longest"							,  __magic_name__				:  bool = True							,  __magic_name__				:  int = 5_12							,  __magic_name__				:  int = None							,  __magic_name__				:  bool = True							,  __magic_name__				:  bool = True							,  __magic_name__				:  bool = True							,  **__magic_name__				:  Optional[Any]							,  )       ->							Optional[int]:







													"""simple docstring"""
													super().__init__()
													if use_fast_bert_tokenizer:
																			UpperCAmelCase_      :   Optional[Any]      =	FastBertTokenizer(
																			    __magic_name__							,  token_out_type=tf.intaa							,  lower_case_nfd_strip_accents=__magic_name__							,  **__magic_name__ )
													else:
																			UpperCAmelCase_      :   List[Any]      =	tf.lookup.StaticVocabularyTable(
																			    tf.lookup.KeyValueTensorInitializer(
																			        keys=__magic_name__							,  key_dtype=tf.string							,  values=tf.range(tf.size(__magic_name__							,  out_type=tf.intaa )							,  dtype=tf.intaa )							,  value_dtype=tf.intaa							,  )							,  num_oov_buckets=1							,  )
																			UpperCAmelCase_      :   Any      =	BertTokenizerLayer(
																			    __magic_name__							,  token_out_type=tf.intaa							,  lower_case=__magic_name__							,  **__magic_name__ )

													UpperCAmelCase_      :   Optional[int]      =	vocab_list
													UpperCAmelCase_      :   str      =	do_lower_case
													UpperCAmelCase_      :   Optional[Any]      =	cls_token_id or vocab_list.index('''[CLS]''' )
													UpperCAmelCase_      :   Tuple      =	sep_token_id or vocab_list.index('''[SEP]''' )
													UpperCAmelCase_      :   str      =	pad_token_id or vocab_list.index('''[PAD]''' )
													UpperCAmelCase_      :   Tuple      =	ShrinkLongestTrimmer(max_length - 3							,  axis=1 )  # Allow room for special tokens
													UpperCAmelCase_      :   str      =	max_length
													UpperCAmelCase_      :   Optional[Any]      =	padding
													UpperCAmelCase_      :   Union[str, Any]      =	truncation
													UpperCAmelCase_      :   str      =	pad_to_multiple_of
													UpperCAmelCase_      :   Dict      =	return_token_type_ids
													UpperCAmelCase_      :   Union[str, Any]      =	return_attention_mask

							@classmethod
							def      UpperCAmelCase__						(				cls				:  Optional[Any]							,  __magic_name__				:  "PreTrainedTokenizerBase"							,  **__magic_name__				:  str )       ->							Union[str, Any]:  # noqa: F821







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	kwargs.pop('''do_lower_case'''							,  __magic_name__ )
													UpperCAmelCase_      :   Union[str, Any]      =	tokenizer.do_lower_case if do_lower_case is None else do_lower_case
													UpperCAmelCase_      :   int      =	kwargs.pop('''cls_token_id'''							,  __magic_name__ )
													UpperCAmelCase_      :   List[Any]      =	tokenizer.cls_token_id if cls_token_id is None else cls_token_id
													UpperCAmelCase_      :   Union[str, Any]      =	kwargs.pop('''sep_token_id'''							,  __magic_name__ )
													UpperCAmelCase_      :   List[Any]      =	tokenizer.sep_token_id if sep_token_id is None else sep_token_id
													UpperCAmelCase_      :   int      =	kwargs.pop('''pad_token_id'''							,  __magic_name__ )
													UpperCAmelCase_      :   List[Any]      =	tokenizer.pad_token_id if pad_token_id is None else pad_token_id

													UpperCAmelCase_      :   Tuple      =	tokenizer.get_vocab()
													UpperCAmelCase_      :   List[str]      =	sorted([(wordpiece, idx) for wordpiece, idx in vocab.items()]							,  key=lambda __magic_name__ : x[1] )
													UpperCAmelCase_      :   int      =	[entry[0] for entry in vocab]
													return cls(
													    vocab_list=__magic_name__							,  do_lower_case=__magic_name__							,  cls_token_id=__magic_name__							,  sep_token_id=__magic_name__							,  pad_token_id=__magic_name__							,  **__magic_name__							,  )

							@classmethod
							def      UpperCAmelCase__						(				cls				:  Optional[Any]							,  __magic_name__				:  Union[str, os.PathLike]							,  *__magic_name__				:  Dict							,  **__magic_name__				:  List[Any] )       ->							Tuple:







													"""simple docstring"""
													try:
																			UpperCAmelCase_      :   List[Any]      =	BertTokenizer.from_pretrained(__magic_name__							,  *__magic_name__							,  **__magic_name__ )
													except:  # noqa: E722
																			from .tokenization_bert_fast import BertTokenizerFast

																			UpperCAmelCase_      :   int      =	BertTokenizerFast.from_pretrained(__magic_name__							,  *__magic_name__							,  **__magic_name__ )
													return cls.from_tokenizer(__magic_name__							,  **__magic_name__ )

							def      UpperCAmelCase__						(				self				:  Union[str, Any]							,  __magic_name__				:  int )       ->							List[str]:







													"""simple docstring"""
													if self.do_lower_case:
																			UpperCAmelCase_      :   int      =	case_fold_utfa(__magic_name__ )
													UpperCAmelCase_      :   List[Any]      =	self.tf_tokenizer.tokenize(__magic_name__ )
													return tokens.merge_dims(1							,  -1 )

							def      UpperCAmelCase__						(				self				:  Union[str, Any]							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[str]=None							,  __magic_name__				:  List[Any]=None							,  __magic_name__				:  Optional[int]=None							,  __magic_name__				:  Union[str, Any]=None							,  __magic_name__				:  int=None							,  __magic_name__				:  Optional[int]=None							,  __magic_name__				:  Optional[Any]=None							,  )       ->							Dict:







													"""simple docstring"""
													if padding is None:
																			UpperCAmelCase_      :   Optional[int]      =	self.padding
													if padding not in ("longest", "max_length"):
																			raise ValueError('''Padding must be either \'longest\' or \'max_length\'!''' )
													if max_length is not None and text_pair is not None:
																			# Because we have to instantiate a Trimmer to do it properly
																			raise ValueError('''max_length cannot be overridden at call time when truncating paired texts!''' )
													if max_length is None:
																			UpperCAmelCase_      :   Any      =	self.max_length
													if truncation is None:
																			UpperCAmelCase_      :   Dict      =	self.truncation
													if pad_to_multiple_of is None:
																			UpperCAmelCase_      :   Optional[int]      =	self.pad_to_multiple_of
													if return_token_type_ids is None:
																			UpperCAmelCase_      :   Optional[int]      =	self.return_token_type_ids
													if return_attention_mask is None:
																			UpperCAmelCase_      :   List[str]      =	self.return_attention_mask
													if not isinstance(__magic_name__							,  tf.Tensor ):
																			UpperCAmelCase_      :   Tuple      =	tf.convert_to_tensor(__magic_name__ )
													if text_pair is not None and not isinstance(__magic_name__							,  tf.Tensor ):
																			UpperCAmelCase_      :   Optional[Any]      =	tf.convert_to_tensor(__magic_name__ )
													if text_pair is not None:
																			if text.shape.rank > 1:
																									raise ValueError('''text argument should not be multidimensional when a text pair is supplied!''' )
																			if text_pair.shape.rank > 1:
																									raise ValueError('''text_pair should not be multidimensional!''' )
													if text.shape.rank == 2:
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   List[str]      =	text[:, 0], text[:, 1]
													UpperCAmelCase_      :   Union[str, Any]      =	self.unpaired_tokenize(__magic_name__ )
													if text_pair is None:  # Unpaired text
																			if truncation:
																									UpperCAmelCase_      :   List[str]      =	text[:, : max_length - 2]  # Allow room for special tokens
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   Optional[Any]      =	combine_segments(
																			    (text,)							,  start_of_sequence_id=self.cls_token_id							,  end_of_segment_id=self.sep_token_id )
													else:  # Paired text
																			UpperCAmelCase_      :   Any      =	self.unpaired_tokenize(__magic_name__ )
																			if truncation:
																									UpperCAmelCase_    ,							UpperCAmelCase_      :   Union[str, Any]      =	self.paired_trimmer.trim([text, text_pair] )
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   Tuple      =	combine_segments(
																			    (text, text_pair)							,  start_of_sequence_id=self.cls_token_id							,  end_of_segment_id=self.sep_token_id )
													if padding == "longest":
																			UpperCAmelCase_      :   Dict      =	input_ids.bounding_shape(axis=1 )
																			if pad_to_multiple_of is not None:
																									# No ceiling division in tensorflow, so we negate floordiv instead
																									UpperCAmelCase_      :   Dict      =	pad_to_multiple_of * (-tf.math.floordiv(-pad_length							,  __magic_name__ ))
													else:
																			UpperCAmelCase_      :   Optional[Any]      =	max_length

													UpperCAmelCase_    ,							UpperCAmelCase_      :   Dict      =	pad_model_inputs(__magic_name__							,  max_seq_length=__magic_name__							,  pad_value=self.pad_token_id )
													UpperCAmelCase_      :   int      =	{'''input_ids''': input_ids}
													if return_attention_mask:
																			UpperCAmelCase_      :   Dict      =	attention_mask
													if return_token_type_ids:
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   Tuple      =	pad_model_inputs(
																			    __magic_name__							,  max_seq_length=__magic_name__							,  pad_value=self.pad_token_id )
																			UpperCAmelCase_      :   Optional[int]      =	token_type_ids
													return output



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







													"""simple docstring"""
													return {
													    "vocab_list": self.vocab_list,
													    "do_lower_case": self.do_lower_case,
													    "cls_token_id": self.cls_token_id,
													    "sep_token_id": self.sep_token_id,
													    "pad_token_id": self.pad_token_id,
													}






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_  							=			logging.get_logger(__name__)

lowercase_  							=			{
    "google/mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/config.json"
}







class      SCREAMING_SNAKE_CASE__					(  __UpperCamelCase    ):
       A							:	List[Any]          =	MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP
       A							:	int          =	"mobilebert"

       def __init__(							self					:     Any			,			_lowerCAmelCase					:     Union[str, Any]=3_05_22			,			_lowerCAmelCase					:     Tuple=5_12			,			_lowerCAmelCase					:     Dict=24			,			_lowerCAmelCase					:     int=4			,			_lowerCAmelCase					:     Optional[Any]=5_12			,			_lowerCAmelCase					:     Union[str, Any]="relu"			,			_lowerCAmelCase					:     List[str]=0.0			,			_lowerCAmelCase					:     str=0.1			,			_lowerCAmelCase					:     Tuple=5_12			,			_lowerCAmelCase					:     Optional[Any]=2			,			_lowerCAmelCase					:     Optional[int]=0.02			,			_lowerCAmelCase					:     List[str]=1e-12			,			_lowerCAmelCase					:     int=0			,			_lowerCAmelCase					:     Union[str, Any]=1_28			,			_lowerCAmelCase					:     Optional[Any]=True			,			_lowerCAmelCase					:     Dict=True			,			_lowerCAmelCase					:     Any=1_28			,			_lowerCAmelCase					:     Optional[int]=False			,			_lowerCAmelCase					:     str=True			,			_lowerCAmelCase					:     Tuple=4			,			_lowerCAmelCase					:     List[str]="no_norm"			,			_lowerCAmelCase					:     Union[str, Any]=True			,			_lowerCAmelCase					:     Optional[int]=None			,			**_lowerCAmelCase					:     int			,			):
           super().__init__(pad_token_id=_lowerCAmelCase			,			**_lowerCAmelCase			)

           __snake_case       :				Any 			=    vocab_size
           __snake_case       :				Tuple 			=    hidden_size
           __snake_case       :				int 			=    num_hidden_layers
           __snake_case       :				Dict 			=    num_attention_heads
           __snake_case       :				List[Any] 			=    hidden_act
           __snake_case       :				List[Any] 			=    intermediate_size
           __snake_case       :				Union[str, Any] 			=    hidden_dropout_prob
           __snake_case       :				Any 			=    attention_probs_dropout_prob
           __snake_case       :				Any 			=    max_position_embeddings
           __snake_case       :				List[Any] 			=    type_vocab_size
           __snake_case       :				List[Any] 			=    initializer_range
           __snake_case       :				Dict 			=    layer_norm_eps
           __snake_case       :				Any 			=    embedding_size
           __snake_case       :				List[str] 			=    trigram_input
           __snake_case       :				Union[str, Any] 			=    use_bottleneck
           __snake_case       :				List[Any] 			=    intra_bottleneck_size
           __snake_case       :				Tuple 			=    use_bottleneck_attention
           __snake_case       :				Optional[Any] 			=    key_query_shared_bottleneck
           __snake_case       :				Tuple 			=    num_feedforward_networks
           __snake_case       :				int 			=    normalization_type
           __snake_case       :				List[Any] 			=    classifier_activation

           if self.use_bottleneck:
               __snake_case       :				List[str] 			=    intra_bottleneck_size
           else:
               __snake_case       :				int 			=    hidden_size

           __snake_case       :				Optional[Any] 			=    classifier_dropout







class      SCREAMING_SNAKE_CASE__					(  __UpperCamelCase    ):

       @property
       def 			snake_case__    (							self					:     Optional[Any]			):
           if self.task == "multiple-choice":
               __snake_case       :				Any 			=    {0: """batch""", 1: """choice""", 2: """sequence"""}
           else:
               __snake_case       :				Optional[Any] 			=    {0: """batch""", 1: """sequence"""}
           return OrderedDict(
               [
                   ("""input_ids""", dynamic_axis),
                   ("""attention_mask""", dynamic_axis),
                   ("""token_type_ids""", dynamic_axis),
               ]			)



