





import functools
import operator

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


lowerCAmelCase_						   =    logging.get_logger(__name__)

lowerCAmelCase_						   =    {
    """microsoft/unispeech-large-1500h-cv""": (
        """https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"""
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}



class        _lowerCAmelCase    (			__A							):


  '''simple docstring'''
  a_							:       Optional[int]      					="""unispeech"""







  def __init__(      self      :					List[str]      ,				UpperCamelCase      :					Union[str, Any]=32      ,				UpperCamelCase      :					Optional[Any]=7_68      ,				UpperCamelCase      :					Dict=12      ,				UpperCamelCase      :					Optional[int]=12      ,				UpperCamelCase      :					Any=30_72      ,				UpperCamelCase      :					List[Any]="gelu"      ,				UpperCamelCase      :					Tuple=0.1      ,				UpperCamelCase      :					Any=0.1      ,				UpperCamelCase      :					Any=0.1      ,				UpperCamelCase      :					Union[str, Any]=0.0      ,				UpperCamelCase      :					Dict=0.0      ,				UpperCamelCase      :					int=0.1      ,				UpperCamelCase      :					Union[str, Any]=0.1      ,				UpperCamelCase      :					int=0.02      ,				UpperCamelCase      :					Union[str, Any]=1e-5      ,				UpperCamelCase      :					List[str]="group"      ,				UpperCamelCase      :					Optional[int]="gelu"      ,				UpperCamelCase      :					int=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)      ,				UpperCamelCase      :					Tuple=(5, 2, 2, 2, 2, 2, 2)      ,				UpperCamelCase      :					Dict=(10, 3, 3, 3, 3, 2, 2)      ,				UpperCamelCase      :					Optional[int]=False      ,				UpperCamelCase      :					Any=1_28      ,				UpperCamelCase      :					Dict=16      ,				UpperCamelCase      :					int=False      ,				UpperCamelCase      :					Any=True      ,				UpperCamelCase      :					Any=0.05      ,				UpperCamelCase      :					Dict=10      ,				UpperCamelCase      :					int=2      ,				UpperCamelCase      :					str=0.0      ,				UpperCamelCase      :					Optional[Any]=10      ,				UpperCamelCase      :					Optional[Any]=0      ,				UpperCamelCase      :					int=3_20      ,				UpperCamelCase      :					str=2      ,				UpperCamelCase      :					Union[str, Any]=0.1      ,				UpperCamelCase      :					Tuple=1_00      ,				UpperCamelCase      :					Any=2_56      ,				UpperCamelCase      :					int=2_56      ,				UpperCamelCase      :					Dict=0.1      ,				UpperCamelCase      :					Optional[int]="mean"      ,				UpperCamelCase      :					int=False      ,				UpperCamelCase      :					Any=False      ,				UpperCamelCase      :					str=2_56      ,				UpperCamelCase      :					int=80      ,				UpperCamelCase      :					Dict=0      ,				UpperCamelCase      :					Dict=1      ,				UpperCamelCase      :					List[Any]=2      ,				UpperCamelCase      :					Optional[Any]=0.5      ,				**UpperCamelCase      :					Dict      ,				):


    '''simple docstring'''





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

    # parameters for pretraining with codevector quantized representations
    _snake_case   :				Any														=	num_codevectors_per_group
    _snake_case   :				Dict														=	num_codevector_groups
    _snake_case   :				Union[str, Any]														=	contrastive_logits_temperature
    _snake_case   :				Tuple														=	feat_quantizer_dropout
    _snake_case   :				Optional[int]														=	num_negatives
    _snake_case   :				Union[str, Any]														=	codevector_dim
    _snake_case   :				Tuple														=	proj_codevector_dim
    _snake_case   :				Union[str, Any]														=	diversity_loss_weight

    # ctc loss
    _snake_case   :				Any														=	ctc_loss_reduction
    _snake_case   :				int														=	ctc_zero_infinity

    # pretraining loss
    _snake_case   :				Optional[int]														=	replace_prob







  @property
  def UpperCamelCase_ (      self      :					int							):


    '''simple docstring'''





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











import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_realm import RealmTokenizer


lowerCAmelCase_						   =    logging.get_logger(__name__)

lowerCAmelCase_						   =    {"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

lowerCAmelCase_						   =    {
    """vocab_file""": {
        """google/realm-cc-news-pretrained-embedder""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/vocab.txt"""
        ),
        """google/realm-cc-news-pretrained-encoder""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/vocab.txt"""
        ),
        """google/realm-cc-news-pretrained-scorer""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/vocab.txt"""
        ),
        """google/realm-cc-news-pretrained-openqa""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/vocab.txt"""
        ),
        """google/realm-orqa-nq-openqa""": """https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/vocab.txt""",
        """google/realm-orqa-nq-reader""": """https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/vocab.txt""",
        """google/realm-orqa-wq-openqa""": """https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/vocab.txt""",
        """google/realm-orqa-wq-reader""": """https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """google/realm-cc-news-pretrained-embedder""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/tokenizer.jsont"""
        ),
        """google/realm-cc-news-pretrained-encoder""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/tokenizer.json"""
        ),
        """google/realm-cc-news-pretrained-scorer""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/tokenizer.json"""
        ),
        """google/realm-cc-news-pretrained-openqa""": (
            """https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/tokenizer.json"""
        ),
        """google/realm-orqa-nq-openqa""": (
            """https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/tokenizer.json"""
        ),
        """google/realm-orqa-nq-reader""": (
            """https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/tokenizer.json"""
        ),
        """google/realm-orqa-wq-openqa""": (
            """https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/tokenizer.json"""
        ),
        """google/realm-orqa-wq-reader""": (
            """https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/tokenizer.json"""
        ),
    },
}

lowerCAmelCase_						   =    {
    """google/realm-cc-news-pretrained-embedder""": 512,
    """google/realm-cc-news-pretrained-encoder""": 512,
    """google/realm-cc-news-pretrained-scorer""": 512,
    """google/realm-cc-news-pretrained-openqa""": 512,
    """google/realm-orqa-nq-openqa""": 512,
    """google/realm-orqa-nq-reader""": 512,
    """google/realm-orqa-wq-openqa""": 512,
    """google/realm-orqa-wq-reader""": 512,
}

lowerCAmelCase_						   =    {
    """google/realm-cc-news-pretrained-embedder""": {"""do_lower_case""": True},
    """google/realm-cc-news-pretrained-encoder""": {"""do_lower_case""": True},
    """google/realm-cc-news-pretrained-scorer""": {"""do_lower_case""": True},
    """google/realm-cc-news-pretrained-openqa""": {"""do_lower_case""": True},
    """google/realm-orqa-nq-openqa""": {"""do_lower_case""": True},
    """google/realm-orqa-nq-reader""": {"""do_lower_case""": True},
    """google/realm-orqa-wq-openqa""": {"""do_lower_case""": True},
    """google/realm-orqa-wq-reader""": {"""do_lower_case""": True},
}



class        _lowerCAmelCase    (			UpperCAmelCase_							):


  '''simple docstring'''
  a_							:       Union[str, Any]      					=VOCAB_FILES_NAMES
  a_							:       List[str]      					=PRETRAINED_VOCAB_FILES_MAP
  a_							:       str      					=PRETRAINED_INIT_CONFIGURATION
  a_							:       Optional[Any]      					=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  a_							:       List[Any]      					=RealmTokenizer







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


    '''simple docstring'''





    super().__init__(
        UpperCamelCase      ,				tokenizer_file=UpperCamelCase      ,				do_lower_case=UpperCamelCase      ,				unk_token=UpperCamelCase      ,				sep_token=UpperCamelCase      ,				pad_token=UpperCamelCase      ,				cls_token=UpperCamelCase      ,				mask_token=UpperCamelCase      ,				tokenize_chinese_chars=UpperCamelCase      ,				strip_accents=UpperCamelCase      ,				**UpperCamelCase      ,				)

    _snake_case   :				int														=	json.loads(self.backend_tokenizer.normalizer.__getstate__()							)
    if (
        normalizer_state.get('lowercase'      ,				UpperCamelCase							) != do_lower_case
        or normalizer_state.get('strip_accents'      ,				UpperCamelCase							) != strip_accents
        or normalizer_state.get('handle_chinese_chars'      ,				UpperCamelCase							) != tokenize_chinese_chars
    ):
      _snake_case   :				int														=	getattr(UpperCamelCase      ,				normalizer_state.pop('type'							)							)
      _snake_case   :				List[str]														=	do_lower_case
      _snake_case   :				List[Any]														=	strip_accents
      _snake_case   :				Dict														=	tokenize_chinese_chars
      _snake_case   :				Any														=	normalizer_class(**UpperCamelCase							)

    _snake_case   :				Optional[int]														=	do_lower_case







  def UpperCamelCase_ (      self      :					Dict      ,				UpperCamelCase      :					Any      ,				**UpperCamelCase      :					Union[str, Any]							):


    '''simple docstring'''





    _snake_case   :				Tuple														=	PaddingStrategy.MAX_LENGTH

    _snake_case   :				Any														=	text
    _snake_case   :				List[str]														=	kwargs.pop('text_pair'      ,				UpperCamelCase							)
    _snake_case   :				int														=	kwargs.pop('return_tensors'      ,				UpperCamelCase							)

    _snake_case   :				Optional[int]														=	{
        'input_ids': [],
        'attention_mask': [],
        'token_type_ids': [],
    }

    for idx, candidate_text in enumerate(UpperCamelCase							):
      if batch_text_pair is not None:
        _snake_case   :				List[Any]														=	batch_text_pair[idx]
      else:
        _snake_case   :				Optional[Any]														=	None

      _snake_case   :				Optional[int]														=	super().__call__(UpperCamelCase      ,				UpperCamelCase      ,				return_tensors=UpperCamelCase      ,				**UpperCamelCase							)

      _snake_case   :				str														=	encoded_candidates.get('input_ids'							)
      _snake_case   :				Tuple														=	encoded_candidates.get('attention_mask'							)
      _snake_case   :				List[str]														=	encoded_candidates.get('token_type_ids'							)

      if encoded_input_ids is not None:
        output_data["input_ids"].append(UpperCamelCase							)
      if encoded_attention_mask is not None:
        output_data["attention_mask"].append(UpperCamelCase							)
      if encoded_token_type_ids is not None:
        output_data["token_type_ids"].append(UpperCamelCase							)

    _snake_case   :				str														=	{key: item for key, item in output_data.items() if len(UpperCamelCase							) != 0}

    return BatchEncoding(UpperCamelCase      ,				tensor_type=UpperCamelCase							)







  def UpperCamelCase_ (      self      :					str      ,				UpperCamelCase      :					Optional[Any]      ,				UpperCamelCase      :					Union[str, Any]=None							):


    '''simple docstring'''





    _snake_case   :				Dict														=	[self.cls_token_id] + token_ids_a + [self.sep_token_id]

    if token_ids_a:
      output += token_ids_a + [self.sep_token_id]

    return output







  def UpperCamelCase_ (      self      :					Union[str, Any]      ,				UpperCamelCase      :					List[int]      ,				UpperCamelCase      :					Optional[List[int]] = None							):


    '''simple docstring'''





    _snake_case   :				int														=	[self.sep_token_id]
    _snake_case   :				Dict														=	[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 UpperCamelCase_ (      self      :					Union[str, Any]      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					Optional[str] = None							):


    '''simple docstring'''





    _snake_case   :				Optional[Any]														=	self._tokenizer.model.save(UpperCamelCase      ,				name=UpperCamelCase							)
    return tuple(UpperCamelCase							)




