code: 
  
  
  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 						snake_case			(       tf.keras.layers.Layer	):
  			'''simple docstring'''
  
  			def __init__(	self     :     Any							,							lowerCAmelCase_     :     List							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     int = None							,							lowerCAmelCase_     :     int = None							,							lowerCAmelCase_     :     int = None							,							lowerCAmelCase_     :     str = "longest"							,							lowerCAmelCase_     :     bool = True							,							lowerCAmelCase_     :     int = 512							,							lowerCAmelCase_     :     int = None							,							lowerCAmelCase_     :     bool = True							,							lowerCAmelCase_     :     bool = True							,							lowerCAmelCase_     :     bool = True							,							**lowerCAmelCase_     :     Optional[Any]							,							)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								super().__init__()
  								if use_fast_bert_tokenizer:
  													SCREAMING_SNAKE_CASE_	      =       FastBertTokenizer(
  													    lowerCAmelCase_							,							token_out_type=tf.intaa							,							lower_case_nfd_strip_accents=lowerCAmelCase_							,							**lowerCAmelCase_					)
  								else:
  													SCREAMING_SNAKE_CASE_	      =       tf.lookup.StaticVocabularyTable(
  													    tf.lookup.KeyValueTensorInitializer(
  													        keys=lowerCAmelCase_							,							key_dtype=tf.string							,							values=tf.range(tf.size(lowerCAmelCase_							,							out_type=tf.intaa					)							,							dtype=tf.intaa					)							,							value_dtype=tf.intaa							,							)							,							num_oov_buckets=1							,							)
  													SCREAMING_SNAKE_CASE_	      =       BertTokenizerLayer(
  													    lowerCAmelCase_							,							token_out_type=tf.intaa							,							lower_case=lowerCAmelCase_							,							**lowerCAmelCase_					)
  
  								SCREAMING_SNAKE_CASE_	      =       vocab_list
  								SCREAMING_SNAKE_CASE_	      =       do_lower_case
  								SCREAMING_SNAKE_CASE_	      =       cls_token_id or vocab_list.index('''[CLS]'''					)
  								SCREAMING_SNAKE_CASE_	      =       sep_token_id or vocab_list.index('''[SEP]'''					)
  								SCREAMING_SNAKE_CASE_	      =       pad_token_id or vocab_list.index('''[PAD]'''					)
  								SCREAMING_SNAKE_CASE_	      =       ShrinkLongestTrimmer(max_length - 3							,							axis=1					)  # Allow room for special tokens
  								SCREAMING_SNAKE_CASE_	      =       max_length
  								SCREAMING_SNAKE_CASE_	      =       padding
  								SCREAMING_SNAKE_CASE_	      =       truncation
  								SCREAMING_SNAKE_CASE_	      =       pad_to_multiple_of
  								SCREAMING_SNAKE_CASE_	      =       return_token_type_ids
  								SCREAMING_SNAKE_CASE_	      =       return_attention_mask
  
  			@classmethod
  			def _lowercase (	cls     :     Dict							,							lowerCAmelCase_     :     "PreTrainedTokenizerBase"							,							**lowerCAmelCase_     :     List[Any]					)					->					Tuple:  # noqa: F821
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       kwargs.pop('''do_lower_case'''							,							lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.do_lower_case if do_lower_case is None else do_lower_case
  								SCREAMING_SNAKE_CASE_	      =       kwargs.pop('''cls_token_id'''							,							lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.cls_token_id if cls_token_id is None else cls_token_id
  								SCREAMING_SNAKE_CASE_	      =       kwargs.pop('''sep_token_id'''							,							lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.sep_token_id if sep_token_id is None else sep_token_id
  								SCREAMING_SNAKE_CASE_	      =       kwargs.pop('''pad_token_id'''							,							lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.pad_token_id if pad_token_id is None else pad_token_id
  
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.get_vocab()
  								SCREAMING_SNAKE_CASE_	      =       sorted([(wordpiece, idx) for wordpiece, idx in vocab.items()]							,							key=lambda lowerCAmelCase_					: x[1]					)
  								SCREAMING_SNAKE_CASE_	      =       [entry[0] for entry in vocab]
  								return cls(
  								    vocab_list=lowerCAmelCase_							,							do_lower_case=lowerCAmelCase_							,							cls_token_id=lowerCAmelCase_							,							sep_token_id=lowerCAmelCase_							,							pad_token_id=lowerCAmelCase_							,							**lowerCAmelCase_							,							)
  
  			@classmethod
  			def _lowercase (	cls     :     Optional[int]							,							lowerCAmelCase_     :     Union[str, os.PathLike]							,							*lowerCAmelCase_     :     Tuple							,							**lowerCAmelCase_     :     Any					)					->					Optional[int]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								try:
  													SCREAMING_SNAKE_CASE_	      =       BertTokenizer.from_pretrained(lowerCAmelCase_							,							*lowerCAmelCase_							,							**lowerCAmelCase_					)
  								except:  # noqa: E722
  													from .tokenization_bert_fast import BertTokenizerFast
  
  													SCREAMING_SNAKE_CASE_	      =       BertTokenizerFast.from_pretrained(lowerCAmelCase_							,							*lowerCAmelCase_							,							**lowerCAmelCase_					)
  								return cls.from_tokenizer(lowerCAmelCase_							,							**lowerCAmelCase_					)
  
  			def _lowercase (	self     :     Union[str, Any]							,							lowerCAmelCase_     :     Optional[Any]					)					->					Dict:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								if self.do_lower_case:
  													SCREAMING_SNAKE_CASE_	      =       case_fold_utfa(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       self.tf_tokenizer.tokenize(lowerCAmelCase_					)
  								return tokens.merge_dims(1							,							-1					)
  
  			def _lowercase (	self     :     str							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     Tuple=None							,							lowerCAmelCase_     :     str=None							,							lowerCAmelCase_     :     int=None							,							lowerCAmelCase_     :     List[Any]=None							,							lowerCAmelCase_     :     str=None							,							lowerCAmelCase_     :     List[str]=None							,							lowerCAmelCase_     :     Dict=None							,							)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								if padding is None:
  													SCREAMING_SNAKE_CASE_	      =       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:
  													SCREAMING_SNAKE_CASE_	      =       self.max_length
  								if truncation is None:
  													SCREAMING_SNAKE_CASE_	      =       self.truncation
  								if pad_to_multiple_of is None:
  													SCREAMING_SNAKE_CASE_	      =       self.pad_to_multiple_of
  								if return_token_type_ids is None:
  													SCREAMING_SNAKE_CASE_	      =       self.return_token_type_ids
  								if return_attention_mask is None:
  													SCREAMING_SNAKE_CASE_	      =       self.return_attention_mask
  								if not isinstance(lowerCAmelCase_							,							tf.Tensor					):
  													SCREAMING_SNAKE_CASE_	      =       tf.convert_to_tensor(lowerCAmelCase_					)
  								if text_pair is not None and not isinstance(lowerCAmelCase_							,							tf.Tensor					):
  													SCREAMING_SNAKE_CASE_	      =       tf.convert_to_tensor(lowerCAmelCase_					)
  								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:
  													SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       text[:, 0], text[:, 1]
  								SCREAMING_SNAKE_CASE_	      =       self.unpaired_tokenize(lowerCAmelCase_					)
  								if text_pair is None:  # Unpaired text
  													if truncation:
  																		SCREAMING_SNAKE_CASE_	      =       text[:, : max_length - 2]  # Allow room for special tokens
  													SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       combine_segments(
  													    (text,)							,							start_of_sequence_id=self.cls_token_id							,							end_of_segment_id=self.sep_token_id					)
  								else:  # Paired text
  													SCREAMING_SNAKE_CASE_	      =       self.unpaired_tokenize(lowerCAmelCase_					)
  													if truncation:
  																		SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       self.paired_trimmer.trim([text, text_pair]					)
  													SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       combine_segments(
  													    (text, text_pair)							,							start_of_sequence_id=self.cls_token_id							,							end_of_segment_id=self.sep_token_id					)
  								if padding == "longest":
  													SCREAMING_SNAKE_CASE_	      =       input_ids.bounding_shape(axis=1					)
  													if pad_to_multiple_of is not None:
  																		# No ceiling division in tensorflow, so we negate floordiv instead
  																		SCREAMING_SNAKE_CASE_	      =       pad_to_multiple_of * (-tf.math.floordiv(-pad_length							,							lowerCAmelCase_					))
  								else:
  													SCREAMING_SNAKE_CASE_	      =       max_length
  
  								SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       pad_model_inputs(lowerCAmelCase_							,							max_seq_length=lowerCAmelCase_							,							pad_value=self.pad_token_id					)
  								SCREAMING_SNAKE_CASE_	      =       {'''input_ids''': input_ids}
  								if return_attention_mask:
  													SCREAMING_SNAKE_CASE_	      =       attention_mask
  								if return_token_type_ids:
  													SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       pad_model_inputs(
  													    lowerCAmelCase_							,							max_seq_length=lowerCAmelCase_							,							pad_value=self.pad_token_id					)
  													SCREAMING_SNAKE_CASE_	      =       token_type_ids
  								return output
  
  
  
  
  			def _lowercase (	self     :     Dict					)					->					int:
  
  
  
  
  								"""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,
  								}
  
  
  
style_context: 
  
  
  def 							UpperCAmelCase				(     UpperCAmelCase      )->		bool:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					if not isinstance(UpperCAmelCase				,UpperCAmelCase      ):
  										SCREAMING_SNAKE_CASE_	      =       f'''Input value of [number={number}] must be an integer'''
  										raise TypeError(UpperCAmelCase      )
  					if number < 0 or number % 2 == 1:
  										return False
  					SCREAMING_SNAKE_CASE_	      =       int(number**0.5      )
  					return number == number_sqrt * (number_sqrt + 1)
  
  
  if __name__ == "__main__":
  		import doctest
  
  		doctest.testmod()
  
  
  