


import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__UpperCAmelCase : str 			=				logging.get_logger(__name__)

__UpperCAmelCase : Dict 			=				{
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}



class    UpperCAmelCase_	(							_a):
       '''simple docstring'''
       __UpperCamelCase      :     Optional[int]							=					"sew-d"






       def __init__(     self ,					__SCREAMING_SNAKE_CASE=32 ,					__SCREAMING_SNAKE_CASE=768 ,					__SCREAMING_SNAKE_CASE=12 ,					__SCREAMING_SNAKE_CASE=12 ,					__SCREAMING_SNAKE_CASE=3_072 ,					__SCREAMING_SNAKE_CASE=2 ,					__SCREAMING_SNAKE_CASE=512 ,					__SCREAMING_SNAKE_CASE=256 ,					__SCREAMING_SNAKE_CASE=True ,					__SCREAMING_SNAKE_CASE=True ,					__SCREAMING_SNAKE_CASE=("p2c", "c2p") ,					__SCREAMING_SNAKE_CASE="layer_norm" ,					__SCREAMING_SNAKE_CASE="gelu_python" ,					__SCREAMING_SNAKE_CASE=0.1 ,					__SCREAMING_SNAKE_CASE=0.1 ,					__SCREAMING_SNAKE_CASE=0.1 ,					__SCREAMING_SNAKE_CASE=0.0 ,					__SCREAMING_SNAKE_CASE=0.1 ,					__SCREAMING_SNAKE_CASE=0.02 ,					__SCREAMING_SNAKE_CASE=1e-7 ,					__SCREAMING_SNAKE_CASE=1e-5 ,					__SCREAMING_SNAKE_CASE="group" ,					__SCREAMING_SNAKE_CASE="gelu" ,					__SCREAMING_SNAKE_CASE=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512) ,					__SCREAMING_SNAKE_CASE=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1) ,					__SCREAMING_SNAKE_CASE=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1) ,					__SCREAMING_SNAKE_CASE=False ,					__SCREAMING_SNAKE_CASE=128 ,					__SCREAMING_SNAKE_CASE=16 ,					__SCREAMING_SNAKE_CASE=True ,					__SCREAMING_SNAKE_CASE=0.05 ,					__SCREAMING_SNAKE_CASE=10 ,					__SCREAMING_SNAKE_CASE=2 ,					__SCREAMING_SNAKE_CASE=0.0 ,					__SCREAMING_SNAKE_CASE=10 ,					__SCREAMING_SNAKE_CASE=0 ,					__SCREAMING_SNAKE_CASE="mean" ,					__SCREAMING_SNAKE_CASE=False ,					__SCREAMING_SNAKE_CASE=False ,					__SCREAMING_SNAKE_CASE=256 ,					__SCREAMING_SNAKE_CASE=0 ,					__SCREAMING_SNAKE_CASE=1 ,					__SCREAMING_SNAKE_CASE=2 ,					**__SCREAMING_SNAKE_CASE ,					):




              """simple docstring"""




              super().__init__(**__a ,					pad_token_id=__a ,					bos_token_id=__a ,					eos_token_id=__a						)
              UpperCamelCase    :	List[Any]   	=		hidden_size
              UpperCamelCase    :	str   	=		feat_extract_norm
              UpperCamelCase    :	Tuple   	=		feat_extract_activation
              UpperCamelCase    :	List[Any]   	=		list(__a						)
              UpperCamelCase    :	Optional[int]   	=		list(__a						)
              UpperCamelCase    :	Any   	=		list(__a						)
              UpperCamelCase    :	Any   	=		conv_bias
              UpperCamelCase    :	Tuple   	=		num_conv_pos_embeddings
              UpperCamelCase    :	int   	=		num_conv_pos_embedding_groups
              UpperCamelCase    :	int   	=		len(self.conv_dim						)
              UpperCamelCase    :	int   	=		num_hidden_layers
              UpperCamelCase    :	Dict   	=		intermediate_size
              UpperCamelCase    :	Tuple   	=		squeeze_factor
              UpperCamelCase    :	Optional[Any]   	=		max_position_embeddings
              UpperCamelCase    :	Optional[Any]   	=		position_buckets
              UpperCamelCase    :	Dict   	=		share_att_key
              UpperCamelCase    :	Optional[Any]   	=		relative_attention
              UpperCamelCase    :	Union[str, Any]   	=		norm_rel_ebd
              UpperCamelCase    :	Optional[Any]   	=		list(__a						)
              UpperCamelCase    :	Tuple   	=		hidden_act
              UpperCamelCase    :	str   	=		num_attention_heads
              UpperCamelCase    :	Tuple   	=		hidden_dropout
              UpperCamelCase    :	str   	=		attention_dropout
              UpperCamelCase    :	Optional[Any]   	=		activation_dropout
              UpperCamelCase    :	Optional[Any]   	=		feat_proj_dropout
              UpperCamelCase    :	Optional[int]   	=		final_dropout
              UpperCamelCase    :	Dict   	=		layer_norm_eps
              UpperCamelCase    :	Any   	=		feature_layer_norm_eps
              UpperCamelCase    :	Tuple   	=		initializer_range
              UpperCamelCase    :	Dict   	=		vocab_size

              if (
                  (len(self.conv_stride						) != self.num_feat_extract_layers)
                  or (len(self.conv_kernel						) != self.num_feat_extract_layers)
                  or (len(self.conv_dim						) != self.num_feat_extract_layers)
              ):
                     raise ValueError(
                         '''Configuration for convolutional layers is incorrect.'''
                         '''It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,'''
                         f"""but is `len(config.conv_dim) = {len(self.conv_dim						)}`, `len(config.conv_stride)"""
                         f"""= {len(self.conv_stride						)}`, `len(config.conv_kernel) = {len(self.conv_kernel						)}`."""						)

              # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
              UpperCamelCase    :	int   	=		apply_spec_augment
              UpperCamelCase    :	Optional[Any]   	=		mask_time_prob
              UpperCamelCase    :	Optional[int]   	=		mask_time_length
              UpperCamelCase    :	Optional[int]   	=		mask_time_min_masks
              UpperCamelCase    :	Dict   	=		mask_feature_prob
              UpperCamelCase    :	str   	=		mask_feature_length
              UpperCamelCase    :	int   	=		mask_feature_min_masks

              # ctc loss
              UpperCamelCase    :	Any   	=		ctc_loss_reduction
              UpperCamelCase    :	Union[str, Any]   	=		ctc_zero_infinity

              # sequence classification
              UpperCamelCase    :	int   	=		use_weighted_layer_sum
              UpperCamelCase    :	Union[str, Any]   	=		classifier_proj_size






       @property
       def  _lowercase   (     self						):




              """simple docstring"""




              return functools.reduce(operator.mul ,					self.conv_stride ,					1						)





import json
import os
import unittest

from transformers import DebertaTokenizer, DebertaTokenizerFast
from transformers.models.deberta.tokenization_deberta import VOCAB_FILES_NAMES
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin



class    UpperCAmelCase_	(							_a,     unittest.TestCase):
       '''simple docstring'''
       __UpperCamelCase      :     str							=					DebertaTokenizer
       __UpperCamelCase      :     Optional[int]							=					True
       __UpperCamelCase      :     Optional[int]							=					DebertaTokenizerFast






       def  _lowercase   (     self						):




              """simple docstring"""




              super().setUp()

              # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
              UpperCamelCase    :	Optional[int]   	=		[
                  '''l''',
                  '''o''',
                  '''w''',
                  '''e''',
                  '''r''',
                  '''s''',
                  '''t''',
                  '''i''',
                  '''d''',
                  '''n''',
                  '''\u0120''',
                  '''\u0120l''',
                  '''\u0120n''',
                  '''\u0120lo''',
                  '''\u0120low''',
                  '''er''',
                  '''\u0120lowest''',
                  '''\u0120newer''',
                  '''\u0120wider''',
                  '''[UNK]''',
              ]
              UpperCamelCase    :	Tuple   	=		dict(zip(__SCREAMING_SNAKE_CASE ,					range(len(__SCREAMING_SNAKE_CASE						)						)						)						)
              UpperCamelCase    :	Any   	=		['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
              UpperCamelCase    :	List[Any]   	=		{'''unk_token''': '''[UNK]'''}

              UpperCamelCase    :	Union[str, Any]   	=		os.path.join(self.tmpdirname ,					VOCAB_FILES_NAMES['''vocab_file''']						)
              UpperCamelCase    :	Optional[int]   	=		os.path.join(self.tmpdirname ,					VOCAB_FILES_NAMES['''merges_file''']						)
              with open(self.vocab_file ,					'''w''' ,					encoding='''utf-8'''						) as fp:
                     fp.write(json.dumps(__SCREAMING_SNAKE_CASE						) + '''\n'''						)
              with open(self.merges_file ,					'''w''' ,					encoding='''utf-8'''						) as fp:
                     fp.write('''\n'''.join(__SCREAMING_SNAKE_CASE						)						)






       def  _lowercase   (     self ,					**__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              kwargs.update(self.special_tokens_map						)
              return self.tokenizer_class.from_pretrained(self.tmpdirname ,					**__SCREAMING_SNAKE_CASE						)






       def  _lowercase   (     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              UpperCamelCase    :	int   	=		'''lower newer'''
              UpperCamelCase    :	Union[str, Any]   	=		'''lower newer'''
              return input_text, output_text






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	List[str]   	=		self.get_tokenizer()
              UpperCamelCase    :	int   	=		'''lower newer'''
              UpperCamelCase    :	Union[str, Any]   	=		['''l''', '''o''', '''w''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
              UpperCamelCase    :	Tuple   	=		tokenizer.tokenize(__SCREAMING_SNAKE_CASE						)
              self.assertListEqual(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						)

              UpperCamelCase    :	List[Any]   	=		tokens + [tokenizer.unk_token]
              UpperCamelCase    :	Optional[int]   	=		[0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
              self.assertListEqual(tokenizer.convert_tokens_to_ids(__SCREAMING_SNAKE_CASE						) ,					__SCREAMING_SNAKE_CASE						)






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	int   	=		self.get_tokenizer()
              UpperCamelCase    :	Optional[Any]   	=		tokenizer('''Hello''' ,					'''World'''						)
              UpperCamelCase    :	List[str]   	=		[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
              self.assertListEqual(tokd['''token_type_ids'''] ,					__SCREAMING_SNAKE_CASE						)






       @slow
       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Union[str, Any]   	=		self.tokenizer_class.from_pretrained('''microsoft/deberta-base'''						)

              UpperCamelCase    :	Optional[Any]   	=		tokenizer.encode('''sequence builders''' ,					add_special_tokens=__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	int   	=		tokenizer.encode('''multi-sequence build''' ,					add_special_tokens=__SCREAMING_SNAKE_CASE						)

              UpperCamelCase    :	Dict   	=		tokenizer.encode(
                  '''sequence builders''' ,					add_special_tokens=__SCREAMING_SNAKE_CASE ,					add_prefix_space=__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Union[str, Any]   	=		tokenizer.encode(
                  '''sequence builders''' ,					'''multi-sequence build''' ,					add_special_tokens=__SCREAMING_SNAKE_CASE ,					add_prefix_space=__SCREAMING_SNAKE_CASE						)

              UpperCamelCase    :	List[str]   	=		tokenizer.build_inputs_with_special_tokens(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Union[str, Any]   	=		tokenizer.build_inputs_with_special_tokens(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						)

              assert encoded_sentence == encoded_text_from_decode
              assert encoded_pair == encoded_pair_from_decode






       @slow
       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Optional[Any]   	=		[self.tokenizer_class]
              if self.test_rust_tokenizer:
                     tokenizer_classes.append(self.rust_tokenizer_class						)

              for tokenizer_class in tokenizer_classes:
                     UpperCamelCase    :	Optional[int]   	=		tokenizer_class.from_pretrained('''microsoft/deberta-base'''						)

                     UpperCamelCase    :	str   	=		[
                         '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
                         '''ALBERT incorporates two parameter reduction techniques''',
                         '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
                         ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
                         ''' vocabulary embedding.''',
                     ]

                     UpperCamelCase    :	Union[str, Any]   	=		tokenizer(__SCREAMING_SNAKE_CASE ,					padding=__SCREAMING_SNAKE_CASE						)
                     UpperCamelCase    :	Union[str, Any]   	=		[tokenizer.decode(__SCREAMING_SNAKE_CASE ,					skip_special_tokens=__SCREAMING_SNAKE_CASE						) for seq in encoding['''input_ids''']]

                     # fmt: off
                     UpperCamelCase    :	int   	=		{
                         '''input_ids''': [
                             [1, 2_118, 11_126, 565, 35, 83, 25_191, 163, 18_854, 13, 12_156, 12, 16_101, 25_376, 13_807, 9, 22_205, 27_893, 1_635, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [1, 2_118, 11_126, 565, 24_536, 80, 43_797, 4_878, 7_373, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [1, 133, 78, 65, 16, 10, 3_724, 1_538, 33_183, 11_303, 43_797, 1_938, 4, 870, 24_165, 29_105, 5, 739, 32_644, 33_183, 11_303, 36_173, 88, 80, 650, 7_821, 45_940, 6, 52, 2_559, 5, 1_836, 9, 5, 7_397, 13_171, 31, 5, 1_836, 9, 32_644, 33_183, 11_303, 4, 2]
                         ],
                         '''token_type_ids''': [
                             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                         ],
                         '''attention_mask''': [
                             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
                         ]
                     }
                     # fmt: on

                     UpperCamelCase    :	List[str]   	=		[
                         '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
                         '''ALBERT incorporates two parameter reduction techniques''',
                         '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
                         ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
                         ''' vocabulary embedding.''',
                     ]

                     self.assertDictEqual(encoding.data ,					__SCREAMING_SNAKE_CASE						)

                     for expected, decoded in zip(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                            self.assertEqual(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						)

