
import warnings
from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_A     =  logging.get_logger(__name__)





class 			_lowerCAmelCase      (			__a ):
				_lowercase    	=['''input_ids''', '''attention_mask''']




				def __init__(      self       ,       _UpperCamelCase="</s>"       ,       _UpperCamelCase="<unk>"       ,       _UpperCamelCase="<pad>"       ,       _UpperCamelCase=125       ,       _UpperCamelCase=None       ,       **_UpperCamelCase       ,       )       ->   None:
							# Add extra_ids to the special token list
							if extra_ids > 0 and additional_special_tokens is None:
										lowerCAmelCase_      			=			[f"""<extra_id_{i}>""" for i in range(_UpperCamelCase  )]
							elif extra_ids > 0 and additional_special_tokens is not None:
										# Check that we have the right number of extra_id special tokens
										lowerCAmelCase_      			=			len(set(filter(lambda _UpperCamelCase  : bool("extra_id" in str(_UpperCamelCase  )  )       ,       _UpperCamelCase  )  )  )
										if extra_tokens != extra_ids:
													raise ValueError(
													    f"""Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are"""
													    " provided to ByT5Tokenizer. In this case the additional_special_tokens must include the"
													    " extra_ids tokens"  )

							lowerCAmelCase_      			=			AddedToken(_UpperCamelCase       ,       lstrip=_UpperCamelCase       ,       rstrip=_UpperCamelCase  ) if isinstance(_UpperCamelCase       ,       _UpperCamelCase  ) else pad_token
							lowerCAmelCase_      			=			AddedToken(_UpperCamelCase       ,       lstrip=_UpperCamelCase       ,       rstrip=_UpperCamelCase  ) if isinstance(_UpperCamelCase       ,       _UpperCamelCase  ) else eos_token
							lowerCAmelCase_      			=			AddedToken(_UpperCamelCase       ,       lstrip=_UpperCamelCase       ,       rstrip=_UpperCamelCase  ) if isinstance(_UpperCamelCase       ,       _UpperCamelCase  ) else unk_token

							super().__init__(
							    eos_token=_UpperCamelCase       ,       unk_token=_UpperCamelCase       ,       pad_token=_UpperCamelCase       ,       extra_ids=_UpperCamelCase       ,       additional_special_tokens=_UpperCamelCase       ,       **_UpperCamelCase       ,       )

							lowerCAmelCase_      			=			extra_ids

							lowerCAmelCase_      			=			2**8  # utf is 8 bits

							# define special tokens dict
							lowerCAmelCase_      			=			{
							    self.pad_token: 0,
							    self.eos_token: 1,
							    self.unk_token: 2,
							}
							lowerCAmelCase_      			=			len(self.special_tokens_encoder  )
							lowerCAmelCase_      			=			len(_UpperCamelCase  )
							for i, token in enumerate(_UpperCamelCase  ):
										lowerCAmelCase_      			=			self.vocab_size + i - n
							lowerCAmelCase_      			=			{v: k for k, v in self.special_tokens_encoder.items()}




				@property
				def   __a		(      self  )       ->   Optional[Any]:
							return self._utf_vocab_size + self._num_special_tokens + self._extra_ids




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase = None       ,       _UpperCamelCase = False  )       ->   List[int]:
							if already_has_special_tokens:
										return super().get_special_tokens_mask(
										    token_ids_a=_UpperCamelCase       ,       token_ids_a=_UpperCamelCase       ,       already_has_special_tokens=_UpperCamelCase  )

							# normal case: some special tokens
							if token_ids_a is None:
										return ([0] * len(_UpperCamelCase  )) + [1]
							return ([0] * len(_UpperCamelCase  )) + [1] + ([0] * len(_UpperCamelCase  )) + [1]




				def   __a		(      self       ,       _UpperCamelCase  )       ->   List[int]:
							if len(_UpperCamelCase  ) > 0 and token_ids[-1] == self.eos_token_id:
										warnings.warn(
										    f"""This sequence already has {self.eos_token}. In future versions this behavior may lead to duplicated"""
										    " eos tokens being added."  )
										return token_ids
							else:
										return token_ids + [self.eos_token_id]




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase = None  )       ->   List[int]:
							lowerCAmelCase_      			=			[self.eos_token_id]

							if token_ids_a is None:
										return len(token_ids_a + eos  ) * [0]
							return len(token_ids_a + eos + token_ids_a + eos  ) * [0]




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase = None  )       ->   List[int]:
							lowerCAmelCase_      			=			self._add_eos_if_not_present(_UpperCamelCase  )
							if token_ids_a is None:
										return token_ids_a
							else:
										lowerCAmelCase_      			=			self._add_eos_if_not_present(_UpperCamelCase  )
										return token_ids_a + token_ids_a




				def   __a		(      self       ,       _UpperCamelCase  )       ->   List[str]:
							lowerCAmelCase_      			=			[chr(_UpperCamelCase  ) for i in text.encode("utf-8"  )]
							return tokens




				def   __a		(      self       ,       _UpperCamelCase  )       ->   Dict:
							if token in self.special_tokens_encoder:
										lowerCAmelCase_      			=			self.special_tokens_encoder[token]
							elif token in self.added_tokens_encoder:
										lowerCAmelCase_      			=			self.added_tokens_encoder[token]
							elif len(_UpperCamelCase  ) != 1:
										lowerCAmelCase_      			=			self.unk_token_id
							else:
										lowerCAmelCase_      			=			ord(_UpperCamelCase  ) + self._num_special_tokens
							return token_id




				def   __a		(      self       ,       _UpperCamelCase  )       ->   str:
							if index in self.special_tokens_decoder:
										lowerCAmelCase_      			=			self.special_tokens_decoder[index]
							else:
										lowerCAmelCase_      			=			chr(index - self._num_special_tokens  )
							return token




				def   __a		(      self       ,       _UpperCamelCase  )       ->   str:
							lowerCAmelCase_      			=			B""
							for token in tokens:
										if token in self.special_tokens_decoder:
													lowerCAmelCase_      			=			self.special_tokens_decoder[token].encode("utf-8"  )
										elif token in self.added_tokens_decoder:
													lowerCAmelCase_      			=			self.special_tokens_decoder[token].encode("utf-8"  )
										elif token in self.special_tokens_encoder:
													lowerCAmelCase_      			=			token.encode("utf-8"  )
										elif token in self.added_tokens_encoder:
													lowerCAmelCase_      			=			token.encode("utf-8"  )
										else:
													lowerCAmelCase_      			=			bytes([ord(_UpperCamelCase  )]  )
										bstring += tok_string
							lowerCAmelCase_      			=			bstring.decode("utf-8"       ,       errors="ignore"  )
							return string




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase = None  )       ->   Tuple[str]:
							return ()





from collections import OrderedDict
from typing import Mapping

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


_A     =  logging.get_logger(__name__)

_A     =  {
    "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/config.json",
    "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/config.json",
    "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/config.json",
    "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/config.json",
    "bert-base-multilingual-uncased": "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/config.json",
    "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/config.json",
    "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/config.json",
    "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/config.json",
    "bert-large-uncased-whole-word-masking": (
        "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/config.json"
    ),
    "bert-large-cased-whole-word-masking": (
        "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/config.json"
    ),
    "bert-large-uncased-whole-word-masking-finetuned-squad": (
        "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json"
    ),
    "bert-large-cased-whole-word-masking-finetuned-squad": (
        "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/config.json"
    ),
    "bert-base-cased-finetuned-mrpc": "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/config.json",
    "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/config.json",
    "bert-base-german-dbmdz-uncased": "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/config.json",
    "cl-tohoku/bert-base-japanese": "https://huggingface.co/cl-tohoku/bert-base-japanese/resolve/main/config.json",
    "cl-tohoku/bert-base-japanese-whole-word-masking": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-whole-word-masking/resolve/main/config.json"
    ),
    "cl-tohoku/bert-base-japanese-char": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-char/resolve/main/config.json"
    ),
    "cl-tohoku/bert-base-japanese-char-whole-word-masking": (
        "https://huggingface.co/cl-tohoku/bert-base-japanese-char-whole-word-masking/resolve/main/config.json"
    ),
    "TurkuNLP/bert-base-finnish-cased-v1": (
        "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/config.json"
    ),
    "TurkuNLP/bert-base-finnish-uncased-v1": (
        "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/config.json"
    ),
    "wietsedv/bert-base-dutch-cased": "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/config.json",
    # See all BERT models at https://huggingface.co/models?filter=bert
}





class 			_lowerCAmelCase      (			__a ):
				_lowercase    	='''bert'''




				def __init__(      self       ,       _UpperCamelCase=30_522       ,       _UpperCamelCase=768       ,       _UpperCamelCase=12       ,       _UpperCamelCase=12       ,       _UpperCamelCase=3_072       ,       _UpperCamelCase="gelu"       ,       _UpperCamelCase=0.1       ,       _UpperCamelCase=0.1       ,       _UpperCamelCase=512       ,       _UpperCamelCase=2       ,       _UpperCamelCase=0.02       ,       _UpperCamelCase=1e-1_2       ,       _UpperCamelCase=0       ,       _UpperCamelCase="absolute"       ,       _UpperCamelCase=True       ,       _UpperCamelCase=None       ,       **_UpperCamelCase       ,       )       ->   str:
							super().__init__(pad_token_id=_UpperCamelCase       ,       **_UpperCamelCase  )

							lowerCAmelCase_      			=			vocab_size
							lowerCAmelCase_      			=			hidden_size
							lowerCAmelCase_      			=			num_hidden_layers
							lowerCAmelCase_      			=			num_attention_heads
							lowerCAmelCase_      			=			hidden_act
							lowerCAmelCase_      			=			intermediate_size
							lowerCAmelCase_      			=			hidden_dropout_prob
							lowerCAmelCase_      			=			attention_probs_dropout_prob
							lowerCAmelCase_      			=			max_position_embeddings
							lowerCAmelCase_      			=			type_vocab_size
							lowerCAmelCase_      			=			initializer_range
							lowerCAmelCase_      			=			layer_norm_eps
							lowerCAmelCase_      			=			position_embedding_type
							lowerCAmelCase_      			=			use_cache
							lowerCAmelCase_      			=			classifier_dropout





class 			_lowerCAmelCase      (			__a ):




				@property
				def   __a		(      self  )       ->   Mapping[str, Mapping[int, str]]:
							if self.task == "multiple-choice":
										lowerCAmelCase_      			=			{0: "batch", 1: "choice", 2: "sequence"}
							else:
										lowerCAmelCase_      			=			{0: "batch", 1: "sequence"}
							return OrderedDict(
							    [
							        ("input_ids", dynamic_axis),
							        ("attention_mask", dynamic_axis),
							        ("token_type_ids", dynamic_axis),
							    ]  )



