


'''simple docstring'''



import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs



class      a    (		_a	):


     """simple docstring"""






     def __init__(    self					:		List[str]							,			snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]=None							,			snake_case					:		Dict=True							,			snake_case					:		Any=None							,			**snake_case					:		Union[str, Any]      )						->							Optional[Any]:
          __UpperCAmelCase     :			Dict  							=      parent
          __UpperCAmelCase     :			List[str]  							=      config_class
          __UpperCAmelCase     :			Optional[Any]  							=      has_text_modality
          __UpperCAmelCase     :			Any  							=      kwargs
          __UpperCAmelCase     :			Tuple  							=      common_properties

     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							str:
          __UpperCAmelCase     :			Tuple  							=      self.config_class(**self.inputs_dict      )
          __UpperCAmelCase     :			Union[str, Any]  							=      (
              ['''hidden_size''', '''num_attention_heads''', '''num_hidden_layers''']
              if self.common_properties is None
              else self.common_properties
          )

          # Add common fields for text models
          if self.has_text_modality:
               common_properties.extend(['''vocab_size''']      )

          # Test that config has the common properties as getters
          for prop in common_properties:
               self.parent.assertTrue(hasattr(snake_case							,			snake_case      )							,			msg=f'`{prop}` does not exist'      )

          # Test that config has the common properties as setter
          for idx, name in enumerate(snake_case      ):
               try:
                    setattr(snake_case							,			snake_case							,			snake_case      )
                    self.parent.assertEqual(
                        getattr(snake_case							,			snake_case      )							,			snake_case							,			msg=f'`{name} value {idx} expected, but was {getattr(snake_case							,			snake_case      )}'      )
               except NotImplementedError:
                    # Some models might not be able to implement setters for common_properties
                    # In that case, a NotImplementedError is raised
                    pass

        # Test if config class can be called with Config(prop_name=..)
          for idx, name in enumerate(snake_case      ):
               try:
                    __UpperCAmelCase     :			int  							=      self.config_class(**{name: idx}      )
                    self.parent.assertEqual(
                        getattr(snake_case							,			snake_case      )							,			snake_case							,			msg=f'`{name} value {idx} expected, but was {getattr(snake_case							,			snake_case      )}'      )
               except NotImplementedError:
                    # Some models might not be able to implement setters for common_properties
                    # In that case, a NotImplementedError is raised
                    pass

     def 			lowerCamelCase__			(    self					:		int      )						->							Union[str, Any]:
          __UpperCAmelCase     :			str  							=      self.config_class(**self.inputs_dict      )
          __UpperCAmelCase     :			Optional[int]  							=      json.loads(config.to_json_string()      )
          for key, value in self.inputs_dict.items():
               self.parent.assertEqual(obj[key]							,			snake_case      )

     def 			lowerCamelCase__			(    self					:		Any      )						->							Dict:
          __UpperCAmelCase     :			Optional[int]  							=      self.config_class(**self.inputs_dict      )

          with tempfile.TemporaryDirectory() as tmpdirname:
               __UpperCAmelCase     :			List[Any]  							=      os.path.join(snake_case							,			'''config.json'''      )
               config_first.to_json_file(snake_case      )
               __UpperCAmelCase     :			Union[str, Any]  							=      self.config_class.from_json_file(snake_case      )

          self.parent.assertEqual(config_second.to_dict()							,			config_first.to_dict()      )

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Optional[Any]:
          __UpperCAmelCase     :			List[str]  							=      self.config_class(**self.inputs_dict      )

          with tempfile.TemporaryDirectory() as tmpdirname:
               config_first.save_pretrained(snake_case      )
               __UpperCAmelCase     :			str  							=      self.config_class.from_pretrained(snake_case      )

          self.parent.assertEqual(config_second.to_dict()							,			config_first.to_dict()      )

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Union[str, Any]:
          __UpperCAmelCase     :			List[str]  							=      self.config_class(**self.inputs_dict      )

          __UpperCAmelCase     :			int  							=      '''test'''
          with tempfile.TemporaryDirectory() as tmpdirname:
               __UpperCAmelCase     :			List[str]  							=      os.path.join(snake_case							,			snake_case      )
               config_first.save_pretrained(snake_case      )
               __UpperCAmelCase     :			int  							=      self.config_class.from_pretrained(snake_case							,			subfolder=snake_case      )

          self.parent.assertEqual(config_second.to_dict()							,			config_first.to_dict()      )

     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Tuple  							=      self.config_class(**self.inputs_dict							,			num_labels=5      )
          self.parent.assertEqual(len(config.idalabel      )							,			5      )
          self.parent.assertEqual(len(config.labelaid      )							,			5      )

          __UpperCAmelCase     :			int  							=      3
          self.parent.assertEqual(len(config.idalabel      )							,			3      )
          self.parent.assertEqual(len(config.labelaid      )							,			3      )

     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[int]:
          if self.config_class.is_composition:
               return
          __UpperCAmelCase     :			Optional[Any]  							=      self.config_class()
          self.parent.assertIsNotNone(snake_case      )

     def 			lowerCamelCase__			(    self					:		Dict      )						->							Optional[int]:
          __UpperCAmelCase     :			List[str]  							=      copy.deepcopy(snake_case      )
          __UpperCAmelCase     :			Tuple  							=      self.config_class(**snake_case      )
          __UpperCAmelCase     :			Any  							=      []
          for key, value in config_common_kwargs.items():
               if key == "torch_dtype":
                    if not is_torch_available():
                         continue
                    else:
                         import torch

                         if config.torch_dtype != torch.floataa:
                              wrong_values.append(('''torch_dtype''', config.torch_dtype, torch.floataa)      )
               elif getattr(snake_case							,			snake_case      ) != value:
                    wrong_values.append((key, getattr(snake_case							,			snake_case      ), value)      )

          if len(snake_case      ) > 0:
               __UpperCAmelCase     :			int  							=      '''\n'''.join([f'- {v[0]}: got {v[1]} instead of {v[2]}' for v in wrong_values]      )
               raise ValueError(f'The following keys were not properly set in the config:\n{errors}'      )






     def 			lowerCamelCase__			(    self					:		int      )						->							Optional[int]:
          self.create_and_test_config_common_properties()
          self.create_and_test_config_to_json_string()
          self.create_and_test_config_to_json_file()
          self.create_and_test_config_from_and_save_pretrained()
          self.create_and_test_config_from_and_save_pretrained_subfolder()
          self.create_and_test_config_with_num_labels()
          self.check_config_can_be_init_without_params()
          self.check_config_arguments_init()



'''simple docstring'''



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


__UpperCAmelCase      :Dict			    =       logging.get_logger(__name__)

__UpperCAmelCase      :str			    =       {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__UpperCAmelCase      :Optional[int]			    =       {
    "vocab_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/vocab.txt",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/vocab.txt",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"
        ),
        "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt",
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"
        ),
        "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt",
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"
        ),
        "bert-base-multilingual-cased": (
            "https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-cased": (
            "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"
        ),
    },
}

__UpperCAmelCase      :Union[str, Any]			    =       {
    "bert-base-uncased": 5_1_2,
    "bert-large-uncased": 5_1_2,
    "bert-base-cased": 5_1_2,
    "bert-large-cased": 5_1_2,
    "bert-base-multilingual-uncased": 5_1_2,
    "bert-base-multilingual-cased": 5_1_2,
    "bert-base-chinese": 5_1_2,
    "bert-base-german-cased": 5_1_2,
    "bert-large-uncased-whole-word-masking": 5_1_2,
    "bert-large-cased-whole-word-masking": 5_1_2,
    "bert-large-uncased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-large-cased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-base-cased-finetuned-mrpc": 5_1_2,
    "bert-base-german-dbmdz-cased": 5_1_2,
    "bert-base-german-dbmdz-uncased": 5_1_2,
    "TurkuNLP/bert-base-finnish-cased-v1": 5_1_2,
    "TurkuNLP/bert-base-finnish-uncased-v1": 5_1_2,
    "wietsedv/bert-base-dutch-cased": 5_1_2,
}

__UpperCAmelCase      :str			    =       {
    "bert-base-uncased": {"do_lower_case": True},
    "bert-large-uncased": {"do_lower_case": True},
    "bert-base-cased": {"do_lower_case": False},
    "bert-large-cased": {"do_lower_case": False},
    "bert-base-multilingual-uncased": {"do_lower_case": True},
    "bert-base-multilingual-cased": {"do_lower_case": False},
    "bert-base-chinese": {"do_lower_case": False},
    "bert-base-german-cased": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking-finetuned-squad": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking-finetuned-squad": {"do_lower_case": False},
    "bert-base-cased-finetuned-mrpc": {"do_lower_case": False},
    "bert-base-german-dbmdz-cased": {"do_lower_case": False},
    "bert-base-german-dbmdz-uncased": {"do_lower_case": True},
    "TurkuNLP/bert-base-finnish-cased-v1": {"do_lower_case": False},
    "TurkuNLP/bert-base-finnish-uncased-v1": {"do_lower_case": True},
    "wietsedv/bert-base-dutch-cased": {"do_lower_case": False},
}



class      a    (		_a	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE	:			List[Any]							       =       PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE	:			Tuple							       =       PRETRAINED_INIT_CONFIGURATION
     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE	:			Optional[Any]							       =       BertTokenizer

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

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

          __UpperCAmelCase     :			Optional[int]  							=      do_lower_case

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