






"""simple docstring"""





import inspect
import json
import os
import tempfile
import unittest

from transformers.models.speech_to_text_a import SpeechaTextaTokenizer
from transformers.models.speech_to_text_a.tokenization_speech_to_text_a import VOCAB_FILES_NAMES

from ...test_tokenization_common import TokenizerTesterMixin
class  __lowerCamelCase     (	_a				,						unittest.TestCase	):
   a   :					Union[str, Any]			    =SpeechaTextaTokenizer
   a   :					Dict			    =False

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Optional[Any]:
       super().setUp()

       UpperCamelCase__								=     '<s> <pad> </s> <unk> here@@ a couple of@@ words for the he@@ re@@ vocab'.split(' '   )
       UpperCamelCase__								=     ['he re</w> 123', 'here a 1456']
       UpperCamelCase__								=     dict(zip(snake_case_			,					range(len(snake_case_   )   )   )   )

       UpperCamelCase__								=     {'pad_token': '<pad>', 'unk_token': '<unk>', 'bos_token': '<s>', 'eos_token': '</s>'}

       UpperCamelCase__								=     tempfile.mkdtemp()
       UpperCamelCase__								=     os.path.join(self.tmpdirname			,					VOCAB_FILES_NAMES['vocab_file']   )
       UpperCamelCase__								=     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(snake_case_   ) + '\n'   )

       with open(self.merges_file			,					'w'   ) as fp:
           fp.write('\n'.join(snake_case_   )   )

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							int:
       UpperCamelCase__								=     list(self.get_tokenizer().get_vocab().keys()   )

       self.assertEqual(vocab_keys[0]			,					'<s>'   )
       self.assertEqual(vocab_keys[1]			,					'<pad>'   )
       self.assertEqual(vocab_keys[-1]			,					'vocab'   )
       self.assertEqual(len(snake_case_   )			,					14   )

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Dict:
       self.assertEqual(self.get_tokenizer().vocab_size			,					14   )

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							str:
       UpperCamelCase__								=     SpeechaTextaTokenizer.from_pretrained(self.tmpdirname   )

       # make sure @@ is correctly concatenated
       UpperCamelCase__								=     [4, 6, 8, 7, 10]  # ["here@@", "couple", "words", "of@@", "the"]
       UpperCamelCase__								=     tokenizer.decode(snake_case_   )

       self.assertTrue(output_string == 'herecouple words ofthe'   )

   def     SCREAMING_SNAKE_CASE__			(       self   )		->							List[Any]:
       UpperCamelCase__								=     SpeechaTextaTokenizer.from_pretrained(self.tmpdirname   )

       with tempfile.TemporaryDirectory() as tmp_dirname:
           tokenizer.save_pretrained(snake_case_   )
           os.remove(os.path.join(snake_case_			,					'merges.txt'   )   )

           # load tokenizer without merges file should not throw an error
           UpperCamelCase__								=     SpeechaTextaTokenizer.from_pretrained(snake_case_   )

       with tempfile.TemporaryDirectory() as tmp_dirname:
           # save tokenizer and load again
           tokenizer.save_pretrained(snake_case_   )
           UpperCamelCase__								=     SpeechaTextaTokenizer.from_pretrained(snake_case_   )

       self.assertIsNotNone(snake_case_   )







   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Optional[int]:
       if not self.test_slow_tokenizer:
           return

       UpperCamelCase__								=     inspect.signature(self.tokenizer_class.__init__   )
       UpperCamelCase__								=     self.get_tokenizer()

       for parameter_name, parameter in signature.parameters.items():
           if parameter.default != inspect.Parameter.empty and parameter_name != "merges_file":
               self.assertIn(snake_case_			,					tokenizer.init_kwargs   )












"""simple docstring"""





import functools
import operator

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


A__       :			int=						logging.get_logger(__name__)

A__       :			Optional[int]=						{
    """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  __lowerCamelCase     (	_a	):
   a   :					Dict			    ="""hubert"""

   def __init__(       self			,					snake_case_=32			,					snake_case_=768			,					snake_case_=12			,					snake_case_=12			,					snake_case_=3072			,					snake_case_="gelu"			,					snake_case_=0.1			,					snake_case_=0.1			,					snake_case_=0.1			,					snake_case_=True			,					snake_case_=0.0			,					snake_case_=0.1			,					snake_case_=0.1			,					snake_case_=0.02			,					snake_case_=1E-5			,					snake_case_="group"			,					snake_case_="gelu"			,					snake_case_=(512, 512, 512, 512, 512, 512, 512)			,					snake_case_=(5, 2, 2, 2, 2, 2, 2)			,					snake_case_=(10, 3, 3, 3, 3, 2, 2)			,					snake_case_=False			,					snake_case_=128			,					snake_case_=16			,					snake_case_=False			,					snake_case_=True			,					snake_case_=0.05			,					snake_case_=10			,					snake_case_=2			,					snake_case_=0.0			,					snake_case_=10			,					snake_case_=0			,					snake_case_="sum"			,					snake_case_=False			,					snake_case_=False			,					snake_case_=256			,					snake_case_=0			,					snake_case_=1			,					snake_case_=2			,					**snake_case_			,					)		->							Any:
       super().__init__(**snake_case_			,					pad_token_id=snake_case_			,					bos_token_id=snake_case_			,					eos_token_id=snake_case_   )
       UpperCamelCase__								=     hidden_size
       UpperCamelCase__								=     feat_extract_norm
       UpperCamelCase__								=     feat_extract_activation
       UpperCamelCase__								=     list(snake_case_   )
       UpperCamelCase__								=     list(snake_case_   )
       UpperCamelCase__								=     list(snake_case_   )
       UpperCamelCase__								=     conv_bias
       UpperCamelCase__								=     num_conv_pos_embeddings
       UpperCamelCase__								=     num_conv_pos_embedding_groups
       UpperCamelCase__								=     len(self.conv_dim   )
       UpperCamelCase__								=     num_hidden_layers
       UpperCamelCase__								=     intermediate_size
       UpperCamelCase__								=     hidden_act
       UpperCamelCase__								=     num_attention_heads
       UpperCamelCase__								=     hidden_dropout
       UpperCamelCase__								=     attention_dropout
       UpperCamelCase__								=     activation_dropout
       UpperCamelCase__								=     feat_proj_layer_norm
       UpperCamelCase__								=     feat_proj_dropout
       UpperCamelCase__								=     final_dropout
       UpperCamelCase__								=     layerdrop
       UpperCamelCase__								=     layer_norm_eps
       UpperCamelCase__								=     initializer_range
       UpperCamelCase__								=     vocab_size
       UpperCamelCase__								=     do_stable_layer_norm
       UpperCamelCase__								=     use_weighted_layer_sum
       UpperCamelCase__								=     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
       UpperCamelCase__								=     apply_spec_augment
       UpperCamelCase__								=     mask_time_prob
       UpperCamelCase__								=     mask_time_length
       UpperCamelCase__								=     mask_time_min_masks
       UpperCamelCase__								=     mask_feature_prob
       UpperCamelCase__								=     mask_feature_length
       UpperCamelCase__								=     mask_feature_min_masks

       # ctc loss
       UpperCamelCase__								=     ctc_loss_reduction
       UpperCamelCase__								=     ctc_zero_infinity







   @property
   def     SCREAMING_SNAKE_CASE__			(       self   )		->							Dict:
       return functools.reduce(operator.mul			,					self.conv_stride			,					1   )




