"""simple docstring"""







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


__SCREAMING_SNAKE_CASE								=logging.get_logger(__name__)

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

__SCREAMING_SNAKE_CASE								={
    "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"
        ),
    },
}

__SCREAMING_SNAKE_CASE								={
    "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,
}

__SCREAMING_SNAKE_CASE								={
    "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  UpperCamelCase	(    lowercase_						):
   lowercase							=						VOCAB_FILES_NAMES
   lowercase							=						PRETRAINED_VOCAB_FILES_MAP
   lowercase							=						PRETRAINED_INIT_CONFIGURATION
   lowercase							=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowercase							=						RealmTokenizer
   def __init__(    self  ,__UpperCamelCase=None  ,__UpperCamelCase=None  ,__UpperCamelCase=True  ,__UpperCamelCase="[UNK]"  ,__UpperCamelCase="[SEP]"  ,__UpperCamelCase="[PAD]"  ,__UpperCamelCase="[CLS]"  ,__UpperCamelCase="[MASK]"  ,__UpperCamelCase=True  ,__UpperCamelCase=None  ,**__UpperCamelCase  ,)			->   Tuple:


        '''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  ,)

        lowercase_			:       List[str]									=			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
        ):
             lowercase_			:       int									=			getattr(__UpperCamelCase  ,normalizer_state.pop('type'    )    )
             lowercase_			:       str									=			do_lower_case
             lowercase_			:       Dict									=			strip_accents
             lowercase_			:       str									=			tokenize_chinese_chars
             lowercase_			:       Any									=			normalizer_class(**__UpperCamelCase    )

        lowercase_			:       Optional[Any]									=			do_lower_case
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,**__UpperCamelCase    )			->   List[Any]:


        '''simple docstring'''


        lowercase_			:       Dict									=			PaddingStrategy.MAX_LENGTH

        lowercase_			:       Tuple									=			text
        lowercase_			:       Any									=			kwargs.pop('text_pair'  ,__UpperCamelCase    )
        lowercase_			:       List[Any]									=			kwargs.pop('return_tensors'  ,__UpperCamelCase    )

        lowercase_			:       Dict									=			{
            'input_ids': [],
            'attention_mask': [],
            'token_type_ids': [],
        }

        for idx, candidate_text in enumerate(__UpperCamelCase    ):
             if batch_text_pair is not None:
                  lowercase_			:       List[str]									=			batch_text_pair[idx]
             else:
                  lowercase_			:       Dict									=			None

             lowercase_			:       Tuple									=			super().__call__(__UpperCamelCase  ,__UpperCamelCase  ,return_tensors=__UpperCamelCase  ,**__UpperCamelCase    )

             lowercase_			:       Union[str, Any]									=			encoded_candidates.get('input_ids'    )
             lowercase_			:       Any									=			encoded_candidates.get('attention_mask'    )
             lowercase_			:       Tuple									=			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    )

        lowercase_			:       List[str]									=			{key: item for key, item in output_data.items() if len(__UpperCamelCase    ) != 0}

        return BatchEncoding(__UpperCamelCase  ,tensor_type=__UpperCamelCase    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase=None    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       int									=			[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  ,__UpperCamelCase  ,__UpperCamelCase = None    )			->   List[int]:


        '''simple docstring'''


        lowercase_			:       List[str]									=			[self.sep_token_id]
        lowercase_			:       List[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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase = None    )			->   Tuple[str]:


        '''simple docstring'''


        lowercase_			:       List[str]									=			self._tokenizer.model.save(__UpperCamelCase  ,name=__UpperCamelCase    )
        return tuple(__UpperCamelCase    )


"""simple docstring"""







import functools
import operator

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


__SCREAMING_SNAKE_CASE								=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE								={
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}







class  UpperCamelCase	(    lowercase_						):
   lowercase							=						'wav2vec2'
   def __init__(    self  ,__UpperCamelCase=32  ,__UpperCamelCase=768  ,__UpperCamelCase=12  ,__UpperCamelCase=12  ,__UpperCamelCase=3072  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.0  ,__UpperCamelCase=0.0  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.02  ,__UpperCamelCase=1e-5  ,__UpperCamelCase="group"  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=(512, 512, 512, 512, 512, 512, 512)  ,__UpperCamelCase=(5, 2, 2, 2, 2, 2, 2)  ,__UpperCamelCase=(10, 3, 3, 3, 3, 2, 2)  ,__UpperCamelCase=False  ,__UpperCamelCase=128  ,__UpperCamelCase=16  ,__UpperCamelCase=False  ,__UpperCamelCase=True  ,__UpperCamelCase=0.05  ,__UpperCamelCase=10  ,__UpperCamelCase=2  ,__UpperCamelCase=0.0  ,__UpperCamelCase=10  ,__UpperCamelCase=0  ,__UpperCamelCase=320  ,__UpperCamelCase=2  ,__UpperCamelCase=0.1  ,__UpperCamelCase=100  ,__UpperCamelCase=256  ,__UpperCamelCase=256  ,__UpperCamelCase=0.1  ,__UpperCamelCase="sum"  ,__UpperCamelCase=False  ,__UpperCamelCase=False  ,__UpperCamelCase=256  ,__UpperCamelCase=(512, 512, 512, 512, 1500)  ,__UpperCamelCase=(5, 3, 3, 1, 1)  ,__UpperCamelCase=(1, 2, 3, 1, 1)  ,__UpperCamelCase=512  ,__UpperCamelCase=0  ,__UpperCamelCase=1  ,__UpperCamelCase=2  ,__UpperCamelCase=False  ,__UpperCamelCase=3  ,__UpperCamelCase=2  ,__UpperCamelCase=3  ,__UpperCamelCase=None  ,__UpperCamelCase=None  ,**__UpperCamelCase  ,)			->   Optional[Any]:


        '''simple docstring'''


        super().__init__(**__UpperCamelCase  ,pad_token_id=__UpperCamelCase  ,bos_token_id=__UpperCamelCase  ,eos_token_id=__UpperCamelCase    )
        lowercase_			:       Optional[Any]									=			hidden_size
        lowercase_			:       Tuple									=			feat_extract_norm
        lowercase_			:       Dict									=			feat_extract_activation
        lowercase_			:       List[str]									=			list(__UpperCamelCase    )
        lowercase_			:       str									=			list(__UpperCamelCase    )
        lowercase_			:       Dict									=			list(__UpperCamelCase    )
        lowercase_			:       Optional[Any]									=			conv_bias
        lowercase_			:       Dict									=			num_conv_pos_embeddings
        lowercase_			:       List[str]									=			num_conv_pos_embedding_groups
        lowercase_			:       Optional[Any]									=			len(self.conv_dim    )
        lowercase_			:       Any									=			num_hidden_layers
        lowercase_			:       List[Any]									=			intermediate_size
        lowercase_			:       List[Any]									=			hidden_act
        lowercase_			:       Optional[int]									=			num_attention_heads
        lowercase_			:       int									=			hidden_dropout
        lowercase_			:       Dict									=			attention_dropout
        lowercase_			:       Union[str, Any]									=			activation_dropout
        lowercase_			:       Tuple									=			feat_proj_dropout
        lowercase_			:       List[str]									=			final_dropout
        lowercase_			:       Union[str, Any]									=			layerdrop
        lowercase_			:       List[str]									=			layer_norm_eps
        lowercase_			:       Optional[int]									=			initializer_range
        lowercase_			:       List[Any]									=			vocab_size
        lowercase_			:       Optional[int]									=			do_stable_layer_norm
        lowercase_			:       Union[str, Any]									=			use_weighted_layer_sum

        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
        lowercase_			:       Dict									=			apply_spec_augment
        lowercase_			:       Optional[int]									=			mask_time_prob
        lowercase_			:       Union[str, Any]									=			mask_time_length
        lowercase_			:       List[str]									=			mask_time_min_masks
        lowercase_			:       List[str]									=			mask_feature_prob
        lowercase_			:       Any									=			mask_feature_length
        lowercase_			:       List[Any]									=			mask_feature_min_masks

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

        # ctc loss
        lowercase_			:       Tuple									=			ctc_loss_reduction
        lowercase_			:       int									=			ctc_zero_infinity

        # adapter
        lowercase_			:       int									=			add_adapter
        lowercase_			:       Dict									=			adapter_kernel_size
        lowercase_			:       List[str]									=			adapter_stride
        lowercase_			:       Dict									=			num_adapter_layers
        lowercase_			:       Dict									=			output_hidden_size or hidden_size
        lowercase_			:       Optional[Any]									=			adapter_attn_dim

        # SequenceClassification-specific parameter. Feel free to ignore for other classes.
        lowercase_			:       Dict									=			classifier_proj_size

        # XVector-specific parameters. Feel free to ignore for other classes.
        lowercase_			:       Any									=			list(__UpperCamelCase    )
        lowercase_			:       str									=			list(__UpperCamelCase    )
        lowercase_			:       Any									=			list(__UpperCamelCase    )
        lowercase_			:       Tuple									=			xvector_output_dim







   @property
   def     _UpperCAmelCase     (    self    )			->   str:


        '''simple docstring'''


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

