

"""simple docstring"""




import functools
import operator

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


__UpperCAmelCase	=			logging.get_logger(__name__)

__UpperCAmelCase	=			{
    '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        __lowercase     (      __lowerCamelCase   ):
  snake_case_			    =    """hubert"""

  def __init__(					self						:     List[str]   ,A						:     str=32   ,A						:     Union[str, Any]=768   ,A						:     str=12   ,A						:     List[Any]=12   ,A						:     Dict=3_072   ,A						:     str="gelu"   ,A						:     Optional[int]=0.1   ,A						:     Optional[int]=0.1   ,A						:     str=0.1   ,A						:     List[Any]=True   ,A						:     Any=0.0   ,A						:     Any=0.1   ,A						:     str=0.1   ,A						:     List[str]=0.0_2   ,A						:     Dict=1e-5   ,A						:     Dict="group"   ,A						:     Optional[Any]="gelu"   ,A						:     Union[str, Any]=(512, 512, 512, 512, 512, 512, 512)   ,A						:     Dict=(5, 2, 2, 2, 2, 2, 2)   ,A						:     Any=(10, 3, 3, 3, 3, 2, 2)   ,A						:     List[Any]=False   ,A						:     Optional[int]=128   ,A						:     List[Any]=16   ,A						:     Optional[Any]=False   ,A						:     Optional[int]=True   ,A						:     List[str]=0.0_5   ,A						:     Union[str, Any]=10   ,A						:     int=2   ,A						:     str=0.0   ,A						:     List[str]=10   ,A						:     str=0   ,A						:     List[Any]="sum"   ,A						:     Any=False   ,A						:     Union[str, Any]=False   ,A						:     Tuple=256   ,A						:     str=0   ,A						:     List[Any]=1   ,A						:     Any=2   ,**A						:     Any   ,):






   '''simple docstring'''
   super().__init__(**A   ,pad_token_id=A   ,bos_token_id=A   ,eos_token_id=A      )
   UpperCAmelCase__   :					Union[str, Any]   				=   hidden_size
   UpperCAmelCase__   :					str   				=   feat_extract_norm
   UpperCAmelCase__   :					List[Any]   				=   feat_extract_activation
   UpperCAmelCase__   :					Any   				=   list(A      )
   UpperCAmelCase__   :					Dict   				=   list(A      )
   UpperCAmelCase__   :					str   				=   list(A      )
   UpperCAmelCase__   :					int   				=   conv_bias
   UpperCAmelCase__   :					Union[str, Any]   				=   num_conv_pos_embeddings
   UpperCAmelCase__   :					Dict   				=   num_conv_pos_embedding_groups
   UpperCAmelCase__   :					Union[str, Any]   				=   len(self.conv_dim      )
   UpperCAmelCase__   :					Union[str, Any]   				=   num_hidden_layers
   UpperCAmelCase__   :					List[Any]   				=   intermediate_size
   UpperCAmelCase__   :					Tuple   				=   hidden_act
   UpperCAmelCase__   :					List[str]   				=   num_attention_heads
   UpperCAmelCase__   :					Any   				=   hidden_dropout
   UpperCAmelCase__   :					Optional[int]   				=   attention_dropout
   UpperCAmelCase__   :					Union[str, Any]   				=   activation_dropout
   UpperCAmelCase__   :					List[Any]   				=   feat_proj_layer_norm
   UpperCAmelCase__   :					Union[str, Any]   				=   feat_proj_dropout
   UpperCAmelCase__   :					Dict   				=   final_dropout
   UpperCAmelCase__   :					Any   				=   layerdrop
   UpperCAmelCase__   :					List[Any]   				=   layer_norm_eps
   UpperCAmelCase__   :					Union[str, Any]   				=   initializer_range
   UpperCAmelCase__   :					Tuple   				=   vocab_size
   UpperCAmelCase__   :					List[str]   				=   do_stable_layer_norm
   UpperCAmelCase__   :					str   				=   use_weighted_layer_sum
   UpperCAmelCase__   :					int   				=   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__   :					List[str]   				=   apply_spec_augment
   UpperCAmelCase__   :					Union[str, Any]   				=   mask_time_prob
   UpperCAmelCase__   :					str   				=   mask_time_length
   UpperCAmelCase__   :					Union[str, Any]   				=   mask_time_min_masks
   UpperCAmelCase__   :					int   				=   mask_feature_prob
   UpperCAmelCase__   :					Union[str, Any]   				=   mask_feature_length
   UpperCAmelCase__   :					Tuple   				=   mask_feature_min_masks

   # ctc loss
   UpperCAmelCase__   :					str   				=   ctc_loss_reduction
   UpperCAmelCase__   :					List[str]   				=   ctc_zero_infinity




  @property
  def 				__lowercase    (					self						:     Dict      ):






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








"""simple docstring"""




import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_deberta import DebertaTokenizer


if TYPE_CHECKING:
      from transformers.pipelines.conversational import Conversation


__UpperCAmelCase	=			logging.get_logger(__name__)

__UpperCAmelCase	=			{'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

__UpperCAmelCase	=			{
    'vocab_file': {
        'microsoft/deberta-base': 'https://huggingface.co/microsoft/deberta-base/resolve/main/vocab.json',
        'microsoft/deberta-large': 'https://huggingface.co/microsoft/deberta-large/resolve/main/vocab.json',
        'microsoft/deberta-xlarge': 'https://huggingface.co/microsoft/deberta-xlarge/resolve/main/vocab.json',
        'microsoft/deberta-base-mnli': 'https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/vocab.json',
        'microsoft/deberta-large-mnli': 'https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/vocab.json',
        'microsoft/deberta-xlarge-mnli': (
            'https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/vocab.json'
        ),
    },
    'merges_file': {
        'microsoft/deberta-base': 'https://huggingface.co/microsoft/deberta-base/resolve/main/merges.txt',
        'microsoft/deberta-large': 'https://huggingface.co/microsoft/deberta-large/resolve/main/merges.txt',
        'microsoft/deberta-xlarge': 'https://huggingface.co/microsoft/deberta-xlarge/resolve/main/merges.txt',
        'microsoft/deberta-base-mnli': 'https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/merges.txt',
        'microsoft/deberta-large-mnli': 'https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/merges.txt',
        'microsoft/deberta-xlarge-mnli': (
            'https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/merges.txt'
        ),
    },
}

__UpperCAmelCase	=			{
    'microsoft/deberta-base': 512,
    'microsoft/deberta-large': 512,
    'microsoft/deberta-xlarge': 512,
    'microsoft/deberta-base-mnli': 512,
    'microsoft/deberta-large-mnli': 512,
    'microsoft/deberta-xlarge-mnli': 512,
}

__UpperCAmelCase	=			{
    'microsoft/deberta-base': {'do_lower_case': False},
    'microsoft/deberta-large': {'do_lower_case': False},
}







class        __lowercase     (      __lowerCamelCase   ):
  snake_case_			    =    VOCAB_FILES_NAMES
  snake_case_			    =    PRETRAINED_VOCAB_FILES_MAP
  snake_case_			    =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  snake_case_			    =    ["""input_ids""", """attention_mask""", """token_type_ids"""]
  snake_case_			    =    DebertaTokenizer

  def __init__(					self						:     Optional[Any]   ,A						:     Any=None   ,A						:     Any=None   ,A						:     Dict=None   ,A						:     Optional[int]="replace"   ,A						:     Optional[int]="[CLS]"   ,A						:     str="[SEP]"   ,A						:     Optional[int]="[SEP]"   ,A						:     List[Any]="[CLS]"   ,A						:     Dict="[UNK]"   ,A						:     List[str]="[PAD]"   ,A						:     Optional[Any]="[MASK]"   ,A						:     str=False   ,**A						:     Dict   ,):






   '''simple docstring'''
   super().__init__(
       A   ,A   ,tokenizer_file=A   ,errors=A   ,bos_token=A   ,eos_token=A   ,unk_token=A   ,sep_token=A   ,cls_token=A   ,pad_token=A   ,mask_token=A   ,add_prefix_space=A   ,**A   ,)
   UpperCAmelCase__   :					Tuple   				=   kwargs.pop("""add_bos_token"""   ,A      )

   UpperCAmelCase__   :					Tuple   				=   json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()      )
   if pre_tok_state.get("""add_prefix_space"""   ,A      ) != add_prefix_space:
    UpperCAmelCase__   :					List[Any]   				=   getattr(A   ,pre_tok_state.pop("""type"""      )      )
    UpperCAmelCase__   :					Any   				=   add_prefix_space
    UpperCAmelCase__   :					List[Any]   				=   pre_tok_class(**A      )

   UpperCAmelCase__   :					str   				=   add_prefix_space

  @property
  def 				__lowercase    (					self						:     str      ):






   '''simple docstring'''
   if self._mask_token is None:
    if self.verbose:
     logger.error("""Using mask_token, but it is not set yet."""      )
    return None
   return str(self._mask_token      )

  @mask_token.setter
  def 				__lowercase    (					self						:     Dict   ,A						:     str      ):






   '''simple docstring'''
   UpperCAmelCase__   :					str   				=   AddedToken(A   ,lstrip=A   ,rstrip=A      ) if isinstance(A   ,A      ) else value
   UpperCAmelCase__   :					List[str]   				=   value

  def 				__lowercase    (					self						:     Tuple   ,A						:     List[int]   ,A						:     Optional[List[int]] = None      ):






   '''simple docstring'''
   if token_ids_a is None:
    return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
   UpperCAmelCase__   :					Dict   				=   [self.cls_token_id]
   UpperCAmelCase__   :					str   				=   [self.sep_token_id]
   return cls + token_ids_a + sep + token_ids_a + sep

  def 				__lowercase    (					self						:     Tuple   ,A						:     List[int]   ,A						:     Optional[List[int]] = None      ):






   '''simple docstring'''
   UpperCAmelCase__   :					List[str]   				=   [self.sep_token_id]
   UpperCAmelCase__   :					str   				=   [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 				__lowercase    (					self						:     int   ,*A						:     Tuple   ,**A						:     Optional[int]      ):






   '''simple docstring'''
   UpperCAmelCase__   :					int   				=   kwargs.get("""is_split_into_words"""   ,A      )
   assert self.add_prefix_space or not is_split_into_words, (
       f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
       "to use it with pretokenized inputs."
   )

   return super()._batch_encode_plus(*A   ,**A      )

  def 				__lowercase    (					self						:     str   ,*A						:     List[str]   ,**A						:     str      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Optional[int]   				=   kwargs.get("""is_split_into_words"""   ,A      )

   assert self.add_prefix_space or not is_split_into_words, (
       f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
       "to use it with pretokenized inputs."
   )

   return super()._encode_plus(*A   ,**A      )

  def 				__lowercase    (					self						:     Tuple   ,A						:     str   ,A						:     Optional[str] = None      ):






   '''simple docstring'''
   UpperCAmelCase__   :					int   				=   self._tokenizer.model.save(A   ,name=A      )
   return tuple(A      )




  def 				__lowercase    (					self						:     List[str]   ,A						:     "Conversation"      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Dict   				=   []
   for is_user, text in conversation.iter_texts():
    input_ids.extend(self.encode(A   ,add_special_tokens=A      ) + [self.eos_token_id]      )

   if len(A      ) > self.model_max_length:
    UpperCAmelCase__   :					Optional[int]   				=   input_ids[-self.model_max_length :]
   return input_ids





