






"""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


_A						=			logging.get_logger(__name__)

_A						=			{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

_A						=			{
    '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'
        ),
    },
}

_A						=			{
    'google/realm-cc-news-pretrained-embedder': 5_1_2,
    'google/realm-cc-news-pretrained-encoder': 5_1_2,
    'google/realm-cc-news-pretrained-scorer': 5_1_2,
    'google/realm-cc-news-pretrained-openqa': 5_1_2,
    'google/realm-orqa-nq-openqa': 5_1_2,
    'google/realm-orqa-nq-reader': 5_1_2,
    'google/realm-orqa-wq-openqa': 5_1_2,
    'google/realm-orqa-wq-reader': 5_1_2,
}

_A						=			{
    '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 	_lowercase       (    __UpperCAmelCase		):
	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_		,			)		->							str:
			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_		,			)

			lowerCamelCase					:      Tuple          =   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
			):
					lowerCamelCase					:      Optional[int]          =   getattr(UpperCAmelCase_		,			normalizer_state.pop('type' ) )
					lowerCamelCase					:      Tuple          =   do_lower_case
					lowerCamelCase					:      Dict          =   strip_accents
					lowerCamelCase					:      Dict          =   tokenize_chinese_chars
					lowerCamelCase					:      Union[str, Any]          =   normalizer_class(**UpperCAmelCase_ )

			lowerCamelCase					:      str          =   do_lower_case




	def       _UpperCamelCase   (			self		,			UpperCAmelCase_		,			**UpperCAmelCase_ )		->							Optional[Any]:
			lowerCamelCase					:      List[str]          =   PaddingStrategy.MAX_LENGTH

			lowerCamelCase					:      int          =   text
			lowerCamelCase					:      List[Any]          =   kwargs.pop('text_pair'		,			UpperCAmelCase_ )
			lowerCamelCase					:      Optional[Any]          =   kwargs.pop('return_tensors'		,			UpperCAmelCase_ )

			lowerCamelCase					:      Any          =   {
			    'input_ids': [],
			    'attention_mask': [],
			    'token_type_ids': [],
			}

			for idx, candidate_text in enumerate(UpperCAmelCase_ ):
					if batch_text_pair is not None:
							lowerCamelCase					:      Any          =   batch_text_pair[idx]
					else:
							lowerCamelCase					:      Union[str, Any]          =   None

					lowerCamelCase					:      Any          =   super().__call__(UpperCAmelCase_		,			UpperCAmelCase_		,			return_tensors=UpperCAmelCase_		,			**UpperCAmelCase_ )

					lowerCamelCase					:      str          =   encoded_candidates.get('input_ids' )
					lowerCamelCase					:      List[str]          =   encoded_candidates.get('attention_mask' )
					lowerCamelCase					:      Any          =   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_ )

			lowerCamelCase					:      Dict          =   {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 )		->							str:
			lowerCamelCase					:      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]:
			lowerCamelCase					:      Any          =   [self.sep_token_id]
			lowerCamelCase					:      Optional[int]          =   [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]:
			lowerCamelCase					:      Dict          =   self._tokenizer.model.save(UpperCAmelCase_		,			name=UpperCAmelCase_ )
			return tuple(UpperCAmelCase_ )








"""simple docstring"""

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_A						=			logging.get_logger(__name__)

_A						=			{
    'google/bigbird-roberta-base': 'https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json',
    'google/bigbird-roberta-large': 'https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json',
    'google/bigbird-base-trivia-itc': 'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json',
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}






class 	_lowercase       (    __UpperCAmelCase		):
	lowercase_				=     'big_bird'




	def __init__(			self		,			UpperCAmelCase_=50358		,			UpperCAmelCase_=768		,			UpperCAmelCase_=12		,			UpperCAmelCase_=12		,			UpperCAmelCase_=3072		,			UpperCAmelCase_="gelu_new"		,			UpperCAmelCase_=0.1		,			UpperCAmelCase_=0.1		,			UpperCAmelCase_=4096		,			UpperCAmelCase_=2		,			UpperCAmelCase_=0.02		,			UpperCAmelCase_=1E-1_2		,			UpperCAmelCase_=True		,			UpperCAmelCase_=0		,			UpperCAmelCase_=1		,			UpperCAmelCase_=2		,			UpperCAmelCase_=66		,			UpperCAmelCase_="block_sparse"		,			UpperCAmelCase_=True		,			UpperCAmelCase_=False		,			UpperCAmelCase_=64		,			UpperCAmelCase_=3		,			UpperCAmelCase_=None		,			**UpperCAmelCase_		,			)		->							Union[str, Any]:
			super().__init__(
			    pad_token_id=UpperCAmelCase_		,			bos_token_id=UpperCAmelCase_		,			eos_token_id=UpperCAmelCase_		,			sep_token_id=UpperCAmelCase_		,			**UpperCAmelCase_		,			)

			lowerCamelCase					:      Tuple          =   vocab_size
			lowerCamelCase					:      str          =   max_position_embeddings
			lowerCamelCase					:      str          =   hidden_size
			lowerCamelCase					:      Optional[int]          =   num_hidden_layers
			lowerCamelCase					:      List[str]          =   num_attention_heads
			lowerCamelCase					:      List[str]          =   intermediate_size
			lowerCamelCase					:      Optional[int]          =   hidden_act
			lowerCamelCase					:      Optional[int]          =   hidden_dropout_prob
			lowerCamelCase					:      Dict          =   attention_probs_dropout_prob
			lowerCamelCase					:      int          =   initializer_range
			lowerCamelCase					:      Union[str, Any]          =   type_vocab_size
			lowerCamelCase					:      Union[str, Any]          =   layer_norm_eps
			lowerCamelCase					:      int          =   use_cache

			lowerCamelCase					:      Tuple          =   rescale_embeddings
			lowerCamelCase					:      Dict          =   attention_type
			lowerCamelCase					:      Optional[int]          =   use_bias
			lowerCamelCase					:      Optional[int]          =   block_size
			lowerCamelCase					:      Tuple          =   num_random_blocks
			lowerCamelCase					:      List[Any]          =   classifier_dropout






class 	_lowercase       (    __UpperCAmelCase		):




	@property
	def       _UpperCamelCase   (			self )		->							Mapping[str, Mapping[int, str]]:
			if self.task == "multiple-choice":
					lowerCamelCase					:      Tuple          =   {0: 'batch', 1: 'choice', 2: 'sequence'}
			else:
					lowerCamelCase					:      int          =   {0: 'batch', 1: 'sequence'}
			return OrderedDict(
			    [
			        ('input_ids', dynamic_axis),
			        ('attention_mask', dynamic_axis),
			    ] )






