



import os
import re
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A__	      =       logging.get_logger(__name__)

A__	      =       {"""vocab_file""": """spiece.model"""}

A__	      =       {
    """vocab_file""": {
        """google/bigbird-roberta-base""": """https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model""",
        """google/bigbird-roberta-large""": (
            """https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model"""
        ),
        """google/bigbird-base-trivia-itc""": (
            """https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model"""
        ),
    }
}

A__	      =       {
    """google/bigbird-roberta-base""": 40_96,
    """google/bigbird-roberta-large""": 40_96,
    """google/bigbird-base-trivia-itc""": 40_96,
}





class 					__lowerCAmelCase (     __lowerCamelCase       ):
				__lowerCamelCase =				VOCAB_FILES_NAMES
				__lowerCamelCase =				PRETRAINED_VOCAB_FILES_MAP
				__lowerCamelCase =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				__lowerCamelCase =				["input_ids", "attention_mask"]
				__lowerCamelCase =				[]




				def __init__(							self						,				_snake_case						,				_snake_case="<unk>"						,				_snake_case="<s>"						,				_snake_case="</s>"						,				_snake_case="<pad>"						,				_snake_case="[SEP]"						,				_snake_case="[MASK]"						,				_snake_case="[CLS]"						,				_snake_case = None						,				**_snake_case						,				):



									"""simple docstring"""





									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else bos_token
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else eos_token
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else unk_token
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else pad_token
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else cls_token
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else sep_token

									# Mask token behave like a normal word, i.e. include the space before it
									_lowerCAmelCase						=    AddedToken(_snake_case						,				lstrip=_snake_case						,				rstrip=_snake_case		) if isinstance(_snake_case						,				_snake_case		) else mask_token

									_lowerCAmelCase						=    {} if sp_model_kwargs is None else sp_model_kwargs

									super().__init__(
									    bos_token=_snake_case						,				eos_token=_snake_case						,				unk_token=_snake_case						,				pad_token=_snake_case						,				sep_token=_snake_case						,				mask_token=_snake_case						,				cls_token=_snake_case						,				sp_model_kwargs=self.sp_model_kwargs						,				**_snake_case						,				)

									_lowerCAmelCase						=    vocab_file

									_lowerCAmelCase						=    spm.SentencePieceProcessor(**self.sp_model_kwargs		)
									self.sp_model.Load(_snake_case		)




				@property
				def 							snake_case   (							self		):



									"""simple docstring"""





									return self.sp_model.get_piece_size()




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    {self.convert_ids_to_tokens(_snake_case		): i for i in range(self.vocab_size		)}
									vocab.update(self.added_tokens_encoder		)
									return vocab




				def __getstate__(							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.__dict__.copy()
									_lowerCAmelCase						=    None
									return state




				def __setstate__(							self						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    d

									# for backward compatibility
									if not hasattr(self						,				"""sp_model_kwargs"""		):
														_lowerCAmelCase						=    {}

									_lowerCAmelCase						=    spm.SentencePieceProcessor(**self.sp_model_kwargs		)
									self.sp_model.Load(self.vocab_file		)




				def 							snake_case   (							self						,				_snake_case		):



									"""simple docstring"""





									return self.sp_model.encode(_snake_case						,				out_type=_snake_case		)




				def 							snake_case   (							self						,				_snake_case		):



									"""simple docstring"""





									return self.sp_model.piece_to_id(_snake_case		)




				def 							snake_case   (							self						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.sp_model.IdToPiece(_snake_case		)
									return token




				def 							snake_case   (							self						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    []
									_lowerCAmelCase						=    ''''''
									_lowerCAmelCase						=    False
									for token in tokens:
														# make sure that special tokens are not decoded using sentencepiece model
														if token in self.all_special_tokens:
																			if not prev_is_special:
																								out_string += " "
																			out_string += self.sp_model.decode(_snake_case		) + token
																			_lowerCAmelCase						=    True
																			_lowerCAmelCase						=    []
														else:
																			current_sub_tokens.append(_snake_case		)
																			_lowerCAmelCase						=    False
									out_string += self.sp_model.decode(_snake_case		)
									return out_string.strip()




				def 							snake_case   (							self						,				_snake_case						,				_snake_case = False						,				_snake_case = None						,				_snake_case = True						,				**_snake_case						,				):



									"""simple docstring"""





									_lowerCAmelCase						=    kwargs.pop("""use_source_tokenizer"""						,				_snake_case		)

									_lowerCAmelCase						=    self.convert_ids_to_tokens(_snake_case						,				skip_special_tokens=_snake_case		)

									# To avoid mixing byte-level and unicode for byte-level BPT
									# we need to build string separately for added tokens and byte-level tokens
									# cf. https://github.com/huggingface/transformers/issues/1133
									_lowerCAmelCase						=    []
									_lowerCAmelCase						=    []
									for token in filtered_tokens:
														if skip_special_tokens and token in self.all_special_ids:
																			continue
														if token in self.added_tokens_encoder:
																			if current_sub_text:
																								sub_texts.append(self.convert_tokens_to_string(_snake_case		)		)
																								_lowerCAmelCase						=    []
																			sub_texts.append(_snake_case		)
														else:
																			current_sub_text.append(_snake_case		)
									if current_sub_text:
														sub_texts.append(self.convert_tokens_to_string(_snake_case		)		)

									# Mimic the behavior of the Rust tokenizer:
									# No space before [MASK] and [SEP]
									if spaces_between_special_tokens:
														_lowerCAmelCase						=    re.sub(R""" (\[(MASK|SEP)\])"""						,				R"""\1"""						,				""" """.join(_snake_case		)		)
									else:
														_lowerCAmelCase						=    ''''''.join(_snake_case		)

									_lowerCAmelCase						=    (
									    clean_up_tokenization_spaces
									    if clean_up_tokenization_spaces is not None
									    else self.clean_up_tokenization_spaces
									)
									if clean_up_tokenization_spaces:
														_lowerCAmelCase						=    self.clean_up_tokenization(_snake_case		)
														return clean_text
									else:
														return text




				def 							snake_case   (							self						,				_snake_case						,				_snake_case = None		):



									"""simple docstring"""





									if not os.path.isdir(_snake_case		):
														logger.error(F'Vocabulary path ({save_directory}) should be a directory'		)
														return
									_lowerCAmelCase						=    os.path.join(
									    _snake_case						,				(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]		)

									if os.path.abspath(self.vocab_file		) != os.path.abspath(_snake_case		) and os.path.isfile(self.vocab_file		):
														copyfile(self.vocab_file						,				_snake_case		)
									elif not os.path.isfile(self.vocab_file		):
														with open(_snake_case						,				"""wb"""		) as fi:
																			_lowerCAmelCase						=    self.sp_model.serialized_model_proto()
																			fi.write(_snake_case		)

									return (out_vocab_file,)




				def 							snake_case   (							self						,				_snake_case						,				_snake_case = None		):



									"""simple docstring"""





									if token_ids_a is None:
														return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									_lowerCAmelCase						=    [self.cls_token_id]
									_lowerCAmelCase						=    [self.sep_token_id]
									return cls + token_ids_a + sep + token_ids_a + sep




				def 							snake_case   (							self						,				_snake_case						,				_snake_case = None						,				_snake_case = False		):



									"""simple docstring"""





									if already_has_special_tokens:
														return super().get_special_tokens_mask(
														    token_ids_a=_snake_case						,				token_ids_a=_snake_case						,				already_has_special_tokens=_snake_case		)

									if token_ids_a is None:
														return [1] + ([0] * len(_snake_case		)) + [1]
									return [1] + ([0] * len(_snake_case		)) + [1] + ([0] * len(_snake_case		)) + [1]




				def 							snake_case   (							self						,				_snake_case						,				_snake_case = None		):



									"""simple docstring"""





									_lowerCAmelCase						=    [self.sep_token_id]
									_lowerCAmelCase						=    [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]










from typing import List, Optional, Union

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


UpperCAmelCase_     							= logging.get_logger(__name__)

UpperCAmelCase_     							= {
    '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     lowercase__       (	__lowerCamelCase				):

   '''simple docstring'''


   a						:							Optional[int]   		=		"informer"
   a						:							Tuple   		=		{
       "hidden_size": "d_model",
       "num_attention_heads": "encoder_attention_heads",
       "num_hidden_layers": "encoder_layers",
   }




   def __init__(    self,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__ = "student_t",		__magic_name__ = "nll",		__magic_name__ = 1,		__magic_name__ = None,		__magic_name__ = "mean",		__magic_name__ = 0,		__magic_name__ = 0,		__magic_name__ = 0,		__magic_name__ = 0,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__ = 64,		__magic_name__ = 32,		__magic_name__ = 32,		__magic_name__ = 2,		__magic_name__ = 2,		__magic_name__ = 2,		__magic_name__ = 2,		__magic_name__ = True,		__magic_name__ = "gelu",		__magic_name__ = 0.05,		__magic_name__ = 0.1,		__magic_name__ = 0.1,		__magic_name__ = 0.1,		__magic_name__ = 0.1,		__magic_name__ = 100,		__magic_name__ = 0.02,		__magic_name__=True,		__magic_name__ = "prob",		__magic_name__ = 5,		__magic_name__ = True,		**__magic_name__,		) ->      Optional[int]:






       """simple docstring"""
       # time series specific configuration
       UpperCamelCase__							:				List[Any]          =      prediction_length
       UpperCamelCase__							:				Any          =      context_length or prediction_length
       UpperCamelCase__							:				Optional[int]          =      distribution_output
       UpperCamelCase__							:				Union[str, Any]          =      loss
       UpperCamelCase__							:				Optional[Any]          =      input_size
       UpperCamelCase__							:				Dict          =      num_time_features
       UpperCamelCase__							:				Dict          =      lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
       UpperCamelCase__							:				Optional[int]          =      scaling
       UpperCamelCase__							:				Any          =      num_dynamic_real_features
       UpperCamelCase__							:				Optional[int]          =      num_static_real_features
       UpperCamelCase__							:				Optional[Any]          =      num_static_categorical_features

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

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

       UpperCamelCase__							:				Optional[Any]          =      num_parallel_samples

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

       UpperCamelCase__							:				Optional[Any]          =      dropout
       UpperCamelCase__							:				List[Any]          =      attention_dropout
       UpperCamelCase__							:				Any          =      activation_dropout
       UpperCamelCase__							:				Optional[int]          =      encoder_layerdrop
       UpperCamelCase__							:				Union[str, Any]          =      decoder_layerdrop

       UpperCamelCase__							:				Tuple          =      activation_function
       UpperCamelCase__							:				List[str]          =      init_std

       UpperCamelCase__							:				int          =      use_cache

       # Informer
       UpperCamelCase__							:				Optional[int]          =      attention_type
       UpperCamelCase__							:				Optional[int]          =      sampling_factor
       UpperCamelCase__							:				Dict          =      distil

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




   @property
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       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
       )

