


"""simple docstring"""







import functools
import operator

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


__lowercase          = logging.get_logger(__name__)

__lowercase          = {
    """facebook/hubert-base-ls960""": """https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json""",
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}






class 		_A    (    __A    ):







    """simple docstring"""




    UpperCAmelCase			:				Optional[Any]      =			"""hubert"""






    def __init__(   self							:       Tuple							,					__UpperCAmelCase							:       int=32							,					__UpperCAmelCase							:       Union[str, Any]=768							,					__UpperCAmelCase							:       int=12							,					__UpperCAmelCase							:       List[str]=12							,					__UpperCAmelCase							:       Optional[Any]=3072							,					__UpperCAmelCase							:       Dict="gelu"							,					__UpperCAmelCase							:       Any=0.1							,					__UpperCAmelCase							:       Tuple=0.1							,					__UpperCAmelCase							:       List[Any]=0.1							,					__UpperCAmelCase							:       Tuple=True							,					__UpperCAmelCase							:       List[Any]=0.0							,					__UpperCAmelCase							:       List[Any]=0.1							,					__UpperCAmelCase							:       List[str]=0.1							,					__UpperCAmelCase							:       str=0.02							,					__UpperCAmelCase							:       Any=1e-5							,					__UpperCAmelCase							:       Dict="group"							,					__UpperCAmelCase							:       Optional[int]="gelu"							,					__UpperCAmelCase							:       Optional[int]=(512, 512, 512, 512, 512, 512, 512)							,					__UpperCAmelCase							:       int=(5, 2, 2, 2, 2, 2, 2)							,					__UpperCAmelCase							:       Dict=(10, 3, 3, 3, 3, 2, 2)							,					__UpperCAmelCase							:       Union[str, Any]=False							,					__UpperCAmelCase							:       str=128							,					__UpperCAmelCase							:       Dict=16							,					__UpperCAmelCase							:       Optional[Any]=False							,					__UpperCAmelCase							:       int=True							,					__UpperCAmelCase							:       Tuple=0.05							,					__UpperCAmelCase							:       Tuple=10							,					__UpperCAmelCase							:       Union[str, Any]=2							,					__UpperCAmelCase							:       Union[str, Any]=0.0							,					__UpperCAmelCase							:       str=10							,					__UpperCAmelCase							:       Optional[Any]=0							,					__UpperCAmelCase							:       Tuple="sum"							,					__UpperCAmelCase							:       List[str]=False							,					__UpperCAmelCase							:       str=False							,					__UpperCAmelCase							:       Any=256							,					__UpperCAmelCase							:       str=0							,					__UpperCAmelCase							:       Optional[int]=1							,					__UpperCAmelCase							:       int=2							,					**__UpperCAmelCase							:       int							,					):
      super().__init__(**UpperCamelCase__							,					pad_token_id=UpperCamelCase__							,					bos_token_id=UpperCamelCase__							,					eos_token_id=UpperCamelCase__)
      a		:						int 				=     hidden_size
      a		:						List[str] 				=     feat_extract_norm
      a		:						Union[str, Any] 				=     feat_extract_activation
      a		:						Union[str, Any] 				=     list(UpperCamelCase__)
      a		:						Tuple 				=     list(UpperCamelCase__)
      a		:						Optional[Any] 				=     list(UpperCamelCase__)
      a		:						str 				=     conv_bias
      a		:						int 				=     num_conv_pos_embeddings
      a		:						int 				=     num_conv_pos_embedding_groups
      a		:						int 				=     len(self.conv_dim)
      a		:						Optional[Any] 				=     num_hidden_layers
      a		:						List[str] 				=     intermediate_size
      a		:						Optional[Any] 				=     hidden_act
      a		:						Dict 				=     num_attention_heads
      a		:						List[str] 				=     hidden_dropout
      a		:						List[str] 				=     attention_dropout
      a		:						Any 				=     activation_dropout
      a		:						Optional[Any] 				=     feat_proj_layer_norm
      a		:						Union[str, Any] 				=     feat_proj_dropout
      a		:						Any 				=     final_dropout
      a		:						Tuple 				=     layerdrop
      a		:						Union[str, Any] 				=     layer_norm_eps
      a		:						Dict 				=     initializer_range
      a		:						str 				=     vocab_size
      a		:						Optional[int] 				=     do_stable_layer_norm
      a		:						int 				=     use_weighted_layer_sum
      a		:						List[Any] 				=     classifier_proj_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)`, but is `len(config.conv_dim) ="
            f''' {len(self.conv_dim)}`, `len(config.conv_stride) = {len(self.conv_stride)}`,'''
            f''' `len(config.conv_kernel) = {len(self.conv_kernel)}`.''')

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

      # ctc loss
      a		:						Optional[int] 				=     ctc_loss_reduction
      a		:						int 				=     ctc_zero_infinity






    @property
    def       __snake_case				(   self							:       Tuple):
      return functools.reduce(operator.mul							,					self.conv_stride							,					1)














import json
import os
import unittest

from transformers import HerbertTokenizer, HerbertTokenizerFast
from transformers.models.herbert.tokenization_herbert import VOCAB_FILES_NAMES
from transformers.testing_utils import get_tests_dir, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class 				__a				(	__A			,						unittest.TestCase    ):





		'''simple docstring'''



		UpperCAmelCase__   :					Optional[Any]					     =    HerbertTokenizer
		UpperCAmelCase__   :					List[Any]					     =    HerbertTokenizerFast
		UpperCAmelCase__   :					Optional[Any]					     =    True


		def 	__snake_case      (    self							):
						super().setUp()

						# Use a simpler test file without japanese/chinese characters
						with open(F'''{get_tests_dir()}/fixtures/sample_text_no_unicode.txt'''			,     encoding='utf-8'							) as f_data:
										SCREAMING_SNAKE_CASE_ :						Dict    				= f_data.read().replace('\n\n'			,     '\n'							).strip()

						SCREAMING_SNAKE_CASE_ :						str    				= [
						    '<s>',
						    '</s>',
						    '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>',
						    ',</w>',
						    '<unk>',
						]
						SCREAMING_SNAKE_CASE_ :						str    				= dict(zip(UpperCamelCase__			,     range(len(UpperCamelCase__							)							)							)							)
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= ['l o 123', 'lo w 1456', 'e r</w> 1789', '']

						SCREAMING_SNAKE_CASE_ :						int    				= os.path.join(self.tmpdirname			,     VOCAB_FILES_NAMES['vocab_file']							)
						SCREAMING_SNAKE_CASE_ :						int    				= 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 	__snake_case      (    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= 'lower newer'
						SCREAMING_SNAKE_CASE_ :						int    				= 'lower newer'
						return input_text, output_text


		def 	__snake_case      (    self							):
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= self.tokenizer_class(vocab_file=self.vocab_file			,     merges_file=self.merges_file							)

						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= 'lower'
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= ['low', 'er</w>']
						SCREAMING_SNAKE_CASE_ :						int    				= tokenizer.tokenize(UpperCamelCase__							)
						self.assertListEqual(UpperCamelCase__			,     UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= tokens + ['<unk>']
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= [16, 17, 23]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__							)			,     UpperCamelCase__							)


		def 	__snake_case      (    self							):
						if not self.test_rust_tokenizer:
										return

						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= self.get_tokenizer()
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= self.get_rust_tokenizer()

						SCREAMING_SNAKE_CASE_ :						List[str]    				= 'lower,newer'

						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= tokenizer.tokenize(UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						Tuple    				= rust_tokenizer.tokenize(UpperCamelCase__							)
						self.assertListEqual(UpperCamelCase__			,     UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= tokenizer.encode(UpperCamelCase__			,     add_special_tokens=UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						Any    				= rust_tokenizer.encode(UpperCamelCase__			,     add_special_tokens=UpperCamelCase__							)
						self.assertListEqual(UpperCamelCase__			,     UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= self.get_rust_tokenizer()
						SCREAMING_SNAKE_CASE_ :						Dict    				= tokenizer.encode(UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= rust_tokenizer.encode(UpperCamelCase__							)
						self.assertListEqual(UpperCamelCase__			,     UpperCamelCase__							)






		@slow
		def 	__snake_case      (    self							):
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= self.tokenizer_class.from_pretrained('allegro/herbert-base-cased'							)

						SCREAMING_SNAKE_CASE_ :						List[str]    				= tokenizer.encode('konstruowanie sekwencji'			,     add_special_tokens=UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= tokenizer.encode('konstruowanie wielu sekwencji'			,     add_special_tokens=UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Any    				= tokenizer.build_inputs_with_special_tokens(UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						Dict    				= tokenizer.build_inputs_with_special_tokens(UpperCamelCase__			,     UpperCamelCase__							)

						assert encoded_sentence == [0] + text + [2]
						assert encoded_pair == [0] + text + [2] + text_a + [2]