



'''simple docstring'''

import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


a							   =				{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

a							   =				{
    'vocab_file': {
        'unc-nlp/lxmert-base-uncased': 'https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt',
    },
    'tokenizer_file': {
        'unc-nlp/lxmert-base-uncased': (
            'https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json'
        ),
    },
}

a							   =				{
    'unc-nlp/lxmert-base-uncased': 512,
}

a							   =				{
    'unc-nlp/lxmert-base-uncased': {'do_lower_case': True},
}






class 						a_		(     snake_case    ):
							UpperCAmelCase			:		Optional[Any]        =				VOCAB_FILES_NAMES
							UpperCAmelCase			:		List[str]        =				PRETRAINED_VOCAB_FILES_MAP
							UpperCAmelCase			:		Optional[int]        =				PRETRAINED_INIT_CONFIGURATION
							UpperCAmelCase			:		str        =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							UpperCAmelCase			:		Dict        =				LxmertTokenizer


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

										snake_case:    Optional[Any]      							=json.loads(self.backend_tokenizer.normalizer.__getstate__()			)
										if (
										    normalizer_state.get('lowercase'      ,						a_			) != do_lower_case
										    or normalizer_state.get('strip_accents'      ,						a_			) != strip_accents
										    or normalizer_state.get('handle_chinese_chars'      ,						a_			) != tokenize_chinese_chars
										):
													snake_case:    List[str]      							=getattr(a_      ,						normalizer_state.pop('type'			)			)
													snake_case:    Any      							=do_lower_case
													snake_case:    List[str]      							=strip_accents
													snake_case:    Dict      							=tokenize_chinese_chars
													snake_case:    List[str]      							=normalizer_class(**a_			)

										snake_case:    Optional[int]      							=do_lower_case


							def    UpperCamelCase     (				self   :						Union[str, Any]      ,						a_   :						str      ,						a_   :						List[str]=None			)			->					Any:
										snake_case:    Union[str, Any]      							=[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   :						int      ,						a_   :						List[int]      ,						a_   :						Optional[List[int]] = None			)			->					List[int]:
										snake_case:    List[Any]      							=[self.sep_token_id]
										snake_case:    Optional[Any]      							=[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   :						Any      ,						a_   :						str      ,						a_   :						Optional[str] = None			)			->					Tuple[str]:
										snake_case:    Optional[Any]      							=self._tokenizer.model.save(a_      ,						name=a_			)
										return tuple(a_			)









'''simple docstring'''

import math

import tensorflow as tf
from packaging import version







def a_     (    __UpperCAmelCase					)				->					Optional[Any]:





			"""simple docstring"""







			snake_case:    str      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    int      							=0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0					)				,							x.dtype					)					))

			return x * cdf







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			snake_case:    Optional[int]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Tuple      							=tf.cast(math.pi				,							x.dtype					)
			snake_case:    Dict      							=tf.cast(0.04_4715				,							x.dtype					)
			snake_case:    List[str]      							=0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi					) * (x + coeff * tf.pow(__UpperCAmelCase				,							3					))					))

			return x * cdf







def a_     (    __UpperCAmelCase					)				->					Tuple:





			"""simple docstring"""







			snake_case:    Optional[int]      							=tf.convert_to_tensor(__UpperCAmelCase					)

			return x * tf.tanh(tf.math.softplus(__UpperCAmelCase					)					)







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			snake_case:    List[str]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Dict      							=tf.cast(0.04_4715				,							x.dtype					)
			snake_case:    List[str]      							=tf.cast(0.79_7884_5608				,							x.dtype					)

			return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)					))







def a_     (    __UpperCAmelCase					)				->					Optional[Any]:





			"""simple docstring"""







			snake_case:    Union[str, Any]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Tuple      							=tf.cast(1.702				,							x.dtype					)
			return x * tf.math.sigmoid(coeff * x					)







def a_     (    __UpperCAmelCase					)				->					int:





			"""simple docstring"""







			return tf.clip_by_value(_gelu(__UpperCAmelCase					)				,							-10				,							10					)







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase=-1					)				->					List[str]:





			"""simple docstring"""







			snake_case							,  snake_case:    int      							=tf.split(__UpperCAmelCase				,							2				,							axis=__UpperCAmelCase					)
			return a * tf.math.sigmoid(__UpperCAmelCase					)


if version.parse(tf.version.VERSION) >= version.parse('2.4'):







	def a_     (    __UpperCAmelCase					)				->					int:





				"""simple docstring"""







				return tf.keras.activations.gelu(__UpperCAmelCase				,							approximate=__UpperCAmelCase					)

	a							   =				tf.keras.activations.gelu







	a							   =				approximate_gelu_wrap
else:
	a							   =				_gelu
	a							   =				_gelu_new


a							   =				{
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			if activation_string in ACTaFN:
						return ACTaFN[activation_string]
			else:
						raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()					)}'''					)




