



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


lowercase__		:				Tuple          =	logging.get_logger(__name__)

lowercase__		:				Optional[int]          =	{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

lowercase__		:				str          =	{
    """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"""
        ),
    },
}

lowercase__		:				Dict          =	{
    """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,
}

lowercase__		:				List[str]          =	{
    """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_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     VOCAB_FILES_NAMES
      _SCREAMING_SNAKE_CASE  				=     PRETRAINED_VOCAB_FILES_MAP
      _SCREAMING_SNAKE_CASE  				=     PRETRAINED_INIT_CONFIGURATION
      _SCREAMING_SNAKE_CASE  				=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      _SCREAMING_SNAKE_CASE  				=     RealmTokenizer



      def __init__(      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      Tuple=None    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=None    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=True    ,			SCREAMING_SNAKE_CASE_				:      List[Any]="[UNK]"    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]="[SEP]"    ,			SCREAMING_SNAKE_CASE_				:      Dict="[PAD]"    ,			SCREAMING_SNAKE_CASE_				:      List[str]="[CLS]"    ,			SCREAMING_SNAKE_CASE_				:      Tuple="[MASK]"    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=True    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=None    ,			**SCREAMING_SNAKE_CASE_				:      List[str]    ,			):
        super().__init__(
            SCREAMING_SNAKE_CASE_    ,			tokenizer_file=SCREAMING_SNAKE_CASE_    ,			do_lower_case=SCREAMING_SNAKE_CASE_    ,			unk_token=SCREAMING_SNAKE_CASE_    ,			sep_token=SCREAMING_SNAKE_CASE_    ,			pad_token=SCREAMING_SNAKE_CASE_    ,			cls_token=SCREAMING_SNAKE_CASE_    ,			mask_token=SCREAMING_SNAKE_CASE_    ,			tokenize_chinese_chars=SCREAMING_SNAKE_CASE_    ,			strip_accents=SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_    ,			)

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

        lowerCAmelCase_   :				Union[str, Any]								= do_lower_case



      def      SCREAMING_SNAKE_CASE__ (      self				:      Dict    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        lowerCAmelCase_   :				Optional[int]								= PaddingStrategy.MAX_LENGTH

        lowerCAmelCase_   :				Tuple								= text
        lowerCAmelCase_   :				Optional[int]								= kwargs.pop('text_pair'    ,			SCREAMING_SNAKE_CASE_       )
        lowerCAmelCase_   :				int								= kwargs.pop('return_tensors'    ,			SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				str								= {
            'input_ids': [],
            'attention_mask': [],
            'token_type_ids': [],
        }

        for idx, candidate_text in enumerate(SCREAMING_SNAKE_CASE_       ):
          if batch_text_pair is not None:
            lowerCAmelCase_   :				Optional[Any]								= batch_text_pair[idx]
          else:
            lowerCAmelCase_   :				Tuple								= None

          lowerCAmelCase_   :				Optional[Any]								= super().__call__(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			return_tensors=SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_       )

          lowerCAmelCase_   :				Any								= encoded_candidates.get('input_ids'       )
          lowerCAmelCase_   :				Any								= encoded_candidates.get('attention_mask'       )
          lowerCAmelCase_   :				int								= encoded_candidates.get('token_type_ids'       )

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

        lowerCAmelCase_   :				Union[str, Any]								= {key: item for key, item in output_data.items() if len(SCREAMING_SNAKE_CASE_       ) != 0}

        return BatchEncoding(SCREAMING_SNAKE_CASE_    ,			tensor_type=SCREAMING_SNAKE_CASE_       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Dict    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=None       ):
        lowerCAmelCase_   :				Union[str, Any]								= [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      SCREAMING_SNAKE_CASE__ (      self				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      List[int]    ,			SCREAMING_SNAKE_CASE_				:      Optional[List[int]] = None       ):
        lowerCAmelCase_   :				List[Any]								= [self.sep_token_id]
        lowerCAmelCase_   :				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      SCREAMING_SNAKE_CASE__ (      self				:      Any    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Optional[str] = None       ):
        lowerCAmelCase_   :				Any								= self._tokenizer.model.save(SCREAMING_SNAKE_CASE_    ,			name=SCREAMING_SNAKE_CASE_       )
        return tuple(SCREAMING_SNAKE_CASE_       )










"""simple docstring"""







from typing import List, Optional, Union

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


lowercase__		:				Union[str, Any]          =	logging.get_logger(__name__)

lowercase__		:				List[str]          =	{
    """huggingface/informer-tourism-monthly""": (
        """https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}







class       UpperCamelCase__   (	lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     """informer"""
      _SCREAMING_SNAKE_CASE  				=     {
          """hidden_size""": """d_model""",
          """num_attention_heads""": """encoder_attention_heads""",
          """num_hidden_layers""": """encoder_layers""",
      }



      def __init__(      self				:      Any    ,			SCREAMING_SNAKE_CASE_				:      Optional[int] = None    ,			SCREAMING_SNAKE_CASE_				:      Optional[int] = None    ,			SCREAMING_SNAKE_CASE_				:      str = "student_t"    ,			SCREAMING_SNAKE_CASE_				:      str = "nll"    ,			SCREAMING_SNAKE_CASE_				:      int = 1    ,			SCREAMING_SNAKE_CASE_				:      List[int] = None    ,			SCREAMING_SNAKE_CASE_				:      Optional[Union[str, bool]] = "mean"    ,			SCREAMING_SNAKE_CASE_				:      int = 0    ,			SCREAMING_SNAKE_CASE_				:      int = 0    ,			SCREAMING_SNAKE_CASE_				:      int = 0    ,			SCREAMING_SNAKE_CASE_				:      int = 0    ,			SCREAMING_SNAKE_CASE_				:      Optional[List[int]] = None    ,			SCREAMING_SNAKE_CASE_				:      Optional[List[int]] = None    ,			SCREAMING_SNAKE_CASE_				:      int = 6_4    ,			SCREAMING_SNAKE_CASE_				:      int = 3_2    ,			SCREAMING_SNAKE_CASE_				:      int = 3_2    ,			SCREAMING_SNAKE_CASE_				:      int = 2    ,			SCREAMING_SNAKE_CASE_				:      int = 2    ,			SCREAMING_SNAKE_CASE_				:      int = 2    ,			SCREAMING_SNAKE_CASE_				:      int = 2    ,			SCREAMING_SNAKE_CASE_				:      bool = True    ,			SCREAMING_SNAKE_CASE_				:      str = "gelu"    ,			SCREAMING_SNAKE_CASE_				:      float = 0.05    ,			SCREAMING_SNAKE_CASE_				:      float = 0.1    ,			SCREAMING_SNAKE_CASE_				:      float = 0.1    ,			SCREAMING_SNAKE_CASE_				:      float = 0.1    ,			SCREAMING_SNAKE_CASE_				:      float = 0.1    ,			SCREAMING_SNAKE_CASE_				:      int = 1_0_0    ,			SCREAMING_SNAKE_CASE_				:      float = 0.02    ,			SCREAMING_SNAKE_CASE_				:      str=True    ,			SCREAMING_SNAKE_CASE_				:      str = "prob"    ,			SCREAMING_SNAKE_CASE_				:      int = 5    ,			SCREAMING_SNAKE_CASE_				:      bool = True    ,			**SCREAMING_SNAKE_CASE_				:      int    ,			):
        # time series specific configuration
        lowerCAmelCase_   :				Dict								= prediction_length
        lowerCAmelCase_   :				List[str]								= context_length or prediction_length
        lowerCAmelCase_   :				List[Any]								= distribution_output
        lowerCAmelCase_   :				int								= loss
        lowerCAmelCase_   :				Optional[int]								= input_size
        lowerCAmelCase_   :				Tuple								= num_time_features
        lowerCAmelCase_   :				List[str]								= lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
        lowerCAmelCase_   :				int								= scaling
        lowerCAmelCase_   :				List[Any]								= num_dynamic_real_features
        lowerCAmelCase_   :				Union[str, Any]								= num_static_real_features
        lowerCAmelCase_   :				Optional[int]								= num_static_categorical_features

        # set cardinality
        if cardinality and num_static_categorical_features > 0:
          if len(SCREAMING_SNAKE_CASE_       ) != num_static_categorical_features:
            raise ValueError(
                'The cardinality should be a list of the same length as `num_static_categorical_features`'       )
          lowerCAmelCase_   :				str								= cardinality
        else:
          lowerCAmelCase_   :				Any								= [0]

        # set embedding_dimension
        if embedding_dimension and num_static_categorical_features > 0:
          if len(SCREAMING_SNAKE_CASE_       ) != num_static_categorical_features:
            raise ValueError(
                'The embedding dimension should be a list of the same length as `num_static_categorical_features`'       )
          lowerCAmelCase_   :				Optional[int]								= embedding_dimension
        else:
          lowerCAmelCase_   :				Union[str, Any]								= [min(5_0    ,			(cat + 1) // 2       ) for cat in self.cardinality]

        lowerCAmelCase_   :				Optional[int]								= num_parallel_samples

        # Transformer architecture configuration
        lowerCAmelCase_   :				Any								= input_size * len(self.lags_sequence       ) + self._number_of_features
        lowerCAmelCase_   :				Any								= d_model
        lowerCAmelCase_   :				Union[str, Any]								= encoder_attention_heads
        lowerCAmelCase_   :				Optional[Any]								= decoder_attention_heads
        lowerCAmelCase_   :				Any								= encoder_ffn_dim
        lowerCAmelCase_   :				List[str]								= decoder_ffn_dim
        lowerCAmelCase_   :				Optional[Any]								= encoder_layers
        lowerCAmelCase_   :				Tuple								= decoder_layers

        lowerCAmelCase_   :				Optional[int]								= dropout
        lowerCAmelCase_   :				Dict								= attention_dropout
        lowerCAmelCase_   :				int								= activation_dropout
        lowerCAmelCase_   :				Dict								= encoder_layerdrop
        lowerCAmelCase_   :				str								= decoder_layerdrop

        lowerCAmelCase_   :				Union[str, Any]								= activation_function
        lowerCAmelCase_   :				Union[str, Any]								= init_std

        lowerCAmelCase_   :				Union[str, Any]								= use_cache

        # Informer
        lowerCAmelCase_   :				Optional[int]								= attention_type
        lowerCAmelCase_   :				Any								= sampling_factor
        lowerCAmelCase_   :				int								= distil

        super().__init__(is_encoder_decoder=SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_       )





      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      Any       ):
        return (
            sum(self.embedding_dimension       )
            + self.num_dynamic_real_features
            + self.num_time_features
            + self.num_static_real_features
            + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
        )





