


from collections import OrderedDict
from typing import Mapping

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


A	:		List[Any]    =       logging.get_logger(__name__)

A	:		Tuple    =       {
    '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 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					A__      =			'''bert'''

					def __init__(self   :						Optional[int]				, _UpperCAmelCase   :						Optional[Any]=3_0522				, _UpperCAmelCase   :						Tuple=768				, _UpperCAmelCase   :						Optional[Any]=12				, _UpperCAmelCase   :						Optional[int]=12				, _UpperCAmelCase   :						Dict=3072				, _UpperCAmelCase   :						Dict="gelu"				, _UpperCAmelCase   :						List[str]=0.1				, _UpperCAmelCase   :						Optional[int]=0.1				, _UpperCAmelCase   :						List[str]=512				, _UpperCAmelCase   :						str=2				, _UpperCAmelCase   :						str=0.02				, _UpperCAmelCase   :						str=1E-1_2				, _UpperCAmelCase   :						List[str]=0				, _UpperCAmelCase   :						Union[str, Any]="absolute"				, _UpperCAmelCase   :						Dict=True				, _UpperCAmelCase   :						Dict=None				, **_UpperCAmelCase   :						List[Any]				, )						->       List[str]:




							"""simple docstring"""


							super().__init__(pad_token_id=_UpperCAmelCase				, **_UpperCAmelCase		)

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






class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					@property
					def   lowerCamelCase__					(self   :						Union[str, Any]		)						->       Mapping[str, Mapping[int, str]]:




							"""simple docstring"""


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





import json
import os
import unittest

from transformers import OpenAIGPTTokenizer, OpenAIGPTTokenizerFast
from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class 							A   (	UpperCAmelCase__			,  unittest.TestCase							):
					'''simple docstring'''






					A__      =			OpenAIGPTTokenizer
					A__      =			OpenAIGPTTokenizerFast
					A__      =			True
					A__      =			False

					def   lowerCamelCase__					(self   :						List[str]		)						->       int:




							"""simple docstring"""


							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							lowercase__					      =		[
							    """l""",
							    """o""",
							    """w""",
							    """e""",
							    """r""",
							    """s""",
							    """t""",
							    """i""",
							    """d""",
							    """n""",
							    """w</w>""",
							    """r</w>""",
							    """t</w>""",
							    """lo""",
							    """low""",
							    """er</w>""",
							    """low</w>""",
							    """lowest</w>""",
							    """newer</w>""",
							    """wider</w>""",
							    """<unk>""",
							]
							lowercase__					      =		dict(zip(_UpperCAmelCase				, range(len(_UpperCAmelCase		)		)		)		)
							lowercase__					      =		["""#version: 0.2""", """l o""", """lo w""", """e r</w>""", """"""]

							lowercase__					      =		os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES["""vocab_file"""]		)
							lowercase__					      =		os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES["""merges_file"""]		)
							with open(self.vocab_file				, """w"""		) as fp:
									fp.write(json.dumps(_UpperCAmelCase		)		)
							with open(self.merges_file				, """w"""		) as fp:
									fp.write("""\n""".join(_UpperCAmelCase		)		)

					def   lowerCamelCase__					(self   :						Dict				, _UpperCAmelCase   :						List[Any]		)						->       Any:




							"""simple docstring"""


							return "lower newer", "lower newer"

					def   lowerCamelCase__					(self   :						Dict		)						->       Tuple:




							"""simple docstring"""


							lowercase__					      =		OpenAIGPTTokenizer(self.vocab_file				, self.merges_file		)

							lowercase__					      =		"""lower"""
							lowercase__					      =		["""low""", """er</w>"""]
							lowercase__					      =		tokenizer.tokenize(_UpperCAmelCase		)
							self.assertListEqual(_UpperCAmelCase				, _UpperCAmelCase		)

							lowercase__					      =		tokens + ["""<unk>"""]
							lowercase__					      =		[14, 15, 20]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase		)				, _UpperCAmelCase		)

					def   lowerCamelCase__					(self   :						Optional[int]				, _UpperCAmelCase   :						Union[str, Any]=15		)						->       Optional[int]:




							"""simple docstring"""


							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
									with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''		):
											lowercase__					      =		self.rust_tokenizer_class.from_pretrained(_UpperCAmelCase				, **_UpperCAmelCase		)

											# Simple input
											lowercase__					      =		"""This is a simple input"""
											lowercase__					      =		["""This is a simple input 1""", """This is a simple input 2"""]
											lowercase__					      =		("""This is a simple input""", """This is a pair""")
											lowercase__					      =		[
											    ("""This is a simple input 1""", """This is a simple input 2"""),
											    ("""This is a simple pair 1""", """This is a simple pair 2"""),
											]

											# Simple input tests
											self.assertRaises(_UpperCAmelCase				, tokenizer_r.encode				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""		)

											# Simple input
											self.assertRaises(_UpperCAmelCase				, tokenizer_r.encode_plus				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""		)

											# Simple input
											self.assertRaises(
											    _UpperCAmelCase				, tokenizer_r.batch_encode_plus				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""				, )

											# Pair input
											self.assertRaises(_UpperCAmelCase				, tokenizer_r.encode				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""		)

											# Pair input
											self.assertRaises(_UpperCAmelCase				, tokenizer_r.encode_plus				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""		)

											# Pair input
											self.assertRaises(
											    _UpperCAmelCase				, tokenizer_r.batch_encode_plus				, _UpperCAmelCase				, max_length=_UpperCAmelCase				, padding="""max_length"""				, )


					def   lowerCamelCase__					(self   :						Tuple		)						->       Any:




							"""simple docstring"""


							pass






@require_ftfy
@require_spacy
@require_tokenizers
class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					pass

