


'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

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


__lowercase	:						List[str]       =	logging.get_logger(__name__)

__lowercase	:						Dict       =	{
    'distilbert-base-uncased': 'https://huggingface.co/distilbert-base-uncased/resolve/main/config.json',
    'distilbert-base-uncased-distilled-squad': (
        'https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json'
    ),
    'distilbert-base-cased': 'https://huggingface.co/distilbert-base-cased/resolve/main/config.json',
    'distilbert-base-cased-distilled-squad': (
        'https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json'
    ),
    'distilbert-base-german-cased': 'https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json',
    'distilbert-base-multilingual-cased': (
        'https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json'
    ),
    'distilbert-base-uncased-finetuned-sst-2-english': (
        'https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json'
    ),
}





class 							__UpperCamelCase				(		lowerCAmelCase_					):
	A_				=    "distilbert"
	A_				=    {
	    "hidden_size": "dim",
	    "num_attention_heads": "n_heads",
	    "num_hidden_layers": "n_layers",
	}




	def __init__(   self						,				__a=3_0522						,				__a=512						,				__a=False						,				__a=6						,				__a=12						,				__a=768						,				__a=4 * 768						,				__a=0.1						,				__a=0.1						,				__a="gelu"						,				__a=0.02						,				__a=0.1						,				__a=0.2						,				__a=0						,				**__a						,				):

						'''simple docstring'''





						__a			:       Any					    =  vocab_size
						__a			:       List[str]					    =  max_position_embeddings
						__a			:       Optional[Any]					    =  sinusoidal_pos_embds
						__a			:       int					    =  n_layers
						__a			:       Optional[Any]					    =  n_heads
						__a			:       Optional[int]					    =  dim
						__a			:       Optional[int]					    =  hidden_dim
						__a			:       Optional[Any]					    =  dropout
						__a			:       Tuple					    =  attention_dropout
						__a			:       Dict					    =  activation
						__a			:       List[str]					    =  initializer_range
						__a			:       Optional[Any]					    =  qa_dropout
						__a			:       Optional[int]					    =  seq_classif_dropout
						super().__init__(**__a						,				pad_token_id=__a							)





class 							__UpperCamelCase				(		lowerCAmelCase_					):




	@property
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						if self.task == "multiple-choice":
											__a			:       Dict					    =  {0: 'batch', 1: 'choice', 2: 'sequence'}
						else:
											__a			:       Optional[int]					    =  {0: 'batch', 1: 'sequence'}
						return OrderedDict(
						    [
						        ('input_ids', dynamic_axis),
						        ('attention_mask', dynamic_axis),
						    ]							)











"""simple docstring"""





import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing






class      a						(					__snake_case		):






    def __init__(       self     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							str = "▁"       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						__SCREAMING_SNAKE_CASE     :							Union[str, AddedToken] = "<unk>"       ,						__SCREAMING_SNAKE_CASE     :							Union[str, AddedToken] = "</s>"       ,						__SCREAMING_SNAKE_CASE     :							Union[str, AddedToken] = "<pad>"       ,						)     ->		Optional[int]:
      lowerCamelCase_         =						{
          'pad': {'id': 0, 'token': pad_token},
          'eos': {'id': 1, 'token': eos_token},
          'unk': {'id': 2, 'token': unk_token},
      }

      lowerCamelCase_         =						[None] * len(self.special_tokens					)
      for token_dict in self.special_tokens.values():
        lowerCamelCase_         =						token_dict['token']

      lowerCamelCase_         =						Tokenizer(Unigram()					)

      lowerCamelCase_         =						normalizers.Sequence(
          [
              normalizers.Nmt(),
              normalizers.NFKC(),
              normalizers.Replace(Regex(' {2,}'					)       ,						' '					),
              normalizers.Lowercase(),
          ]					)
      lowerCamelCase_         =						pre_tokenizers.Sequence(
          [
              pre_tokenizers.Metaspace(replacement=__SCREAMING_SNAKE_CASE       ,						add_prefix_space=__SCREAMING_SNAKE_CASE					),
              pre_tokenizers.Digits(individual_digits=__SCREAMING_SNAKE_CASE					),
              pre_tokenizers.Punctuation(),
          ]					)
      lowerCamelCase_         =						decoders.Metaspace(replacement=__SCREAMING_SNAKE_CASE       ,						add_prefix_space=__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_         =						TemplateProcessing(
          single=F'''$A {self.special_tokens["eos"]["token"]}'''       ,						special_tokens=[(self.special_tokens['eos']['token'], self.special_tokens['eos']['id'])]       ,						)

      lowerCamelCase_         =						{
          'model': 'SentencePieceUnigram',
          'replacement': replacement,
          'add_prefix_space': add_prefix_space,
      }

      super().__init__(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Union[str, List[str]]       ,						__SCREAMING_SNAKE_CASE     :							int = 8000       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						)     ->		Tuple:
      lowerCamelCase_         =						trainers.UnigramTrainer(
          vocab_size=__SCREAMING_SNAKE_CASE       ,						special_tokens=self.special_tokens_list       ,						show_progress=__SCREAMING_SNAKE_CASE       ,						)

      if isinstance(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					):
        lowerCamelCase_         =						[files]
      self._tokenizer.train(__SCREAMING_SNAKE_CASE       ,						trainer=__SCREAMING_SNAKE_CASE					)

      self.add_unk_id()






    def    UpperCamelCase       (       self     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Union[Iterator[str], Iterator[Iterator[str]]]       ,						__SCREAMING_SNAKE_CASE     :							int = 8000       ,						__SCREAMING_SNAKE_CASE     :							bool = True       ,						)     ->		str:
      lowerCamelCase_         =						trainers.UnigramTrainer(
          vocab_size=__SCREAMING_SNAKE_CASE       ,						special_tokens=self.special_tokens_list       ,						show_progress=__SCREAMING_SNAKE_CASE       ,						)

      self._tokenizer.train_from_iterator(__SCREAMING_SNAKE_CASE       ,						trainer=__SCREAMING_SNAKE_CASE					)

      self.add_unk_id()






    def    UpperCamelCase       (       self     :							List[Any]					)     ->		Dict:
      lowerCamelCase_         =						json.loads(self._tokenizer.to_str()					)

      lowerCamelCase_         =						self.special_tokens['unk']['id']

      lowerCamelCase_         =						Tokenizer.from_str(json.dumps(__SCREAMING_SNAKE_CASE					)					)




