



'''simple docstring'''






import os
import unicodedata
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


UpperCamelCase__:     int										=    logging.get_logger(__name__)
UpperCamelCase__:     Any										=    {"vocab_file": "spiece.model"}

UpperCamelCase__:     Optional[Any]										=    {
    "vocab_file": {
        "albert-base-v1": "https://huggingface.co/albert-base-v1/resolve/main/spiece.model",
        "albert-large-v1": "https://huggingface.co/albert-large-v1/resolve/main/spiece.model",
        "albert-xlarge-v1": "https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model",
        "albert-xxlarge-v1": "https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model",
        "albert-base-v2": "https://huggingface.co/albert-base-v2/resolve/main/spiece.model",
        "albert-large-v2": "https://huggingface.co/albert-large-v2/resolve/main/spiece.model",
        "albert-xlarge-v2": "https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model",
        "albert-xxlarge-v2": "https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model",
    }
}

UpperCamelCase__:     List[str]										=    {
    "albert-base-v1": 512,
    "albert-large-v1": 512,
    "albert-xlarge-v1": 512,
    "albert-xxlarge-v1": 512,
    "albert-base-v2": 512,
    "albert-large-v2": 512,
    "albert-xlarge-v2": 512,
    "albert-xxlarge-v2": 512,
}

UpperCamelCase__:     Dict										=    "▁"

class        SCREAMING_SNAKE_CASE(							A__    ):







 """simple docstring"""






 lowerCamelCase__    				= VOCAB_FILES_NAMES
 lowerCamelCase__    				= PRETRAINED_VOCAB_FILES_MAP
 lowerCamelCase__    				= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES







 def __init__(		self    :  str	,    __snake_case    :  Union[str, Any]	,    __snake_case    :  int=True	,    __snake_case    :  List[Any]=True	,    __snake_case    :  Optional[Any]=False	,    __snake_case    :  str="[CLS]"	,    __snake_case    :  str="[SEP]"	,    __snake_case    :  int="<unk>"	,    __snake_case    :  Any="[SEP]"	,    __snake_case    :  List[Any]="<pad>"	,    __snake_case    :  Tuple="[CLS]"	,    __snake_case    :  Tuple="[MASK]"	,    __snake_case    :  Optional[Dict[str, Any]] = None	,    **__snake_case    :  List[Any]	,    )    ->	None:
        # Mask token behave like a normal word, i.e. include the space before it and
        # is included in the raw text, there should be a match in a non-normalized sentence.
        UpperCAmelCase				: Tuple											=	(
            AddedToken(__snake_case	,    lstrip=__snake_case	,    rstrip=__snake_case	,    normalized=__snake_case	)
            if isinstance(__snake_case	,    __snake_case	)
            else mask_token
        )

        UpperCAmelCase				: List[str]											=	{} if sp_model_kwargs is None else sp_model_kwargs

        super().__init__(
            do_lower_case=__snake_case	,    remove_space=__snake_case	,    keep_accents=__snake_case	,    bos_token=__snake_case	,    eos_token=__snake_case	,    unk_token=__snake_case	,    sep_token=__snake_case	,    pad_token=__snake_case	,    cls_token=__snake_case	,    mask_token=__snake_case	,    sp_model_kwargs=self.sp_model_kwargs	,    **__snake_case	,    )

        UpperCAmelCase				: Union[str, Any]											=	do_lower_case
        UpperCAmelCase				: List[str]											=	remove_space
        UpperCAmelCase				: Tuple											=	keep_accents
        UpperCAmelCase				: List[str]											=	vocab_file

        UpperCAmelCase				: Union[str, Any]											=	spm.SentencePieceProcessor(**self.sp_model_kwargs	)
        self.sp_model.Load(__snake_case	)







 @property
 def   A			(		self    :  Dict	)    ->	int:
        return len(self.sp_model	)







 def   A			(		self    :  Tuple	)    ->	Optional[Any]:
        UpperCAmelCase				: int											=	{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    :  int	)    ->	Any:
        UpperCAmelCase				: Tuple											=	self.__dict__.copy()
        UpperCAmelCase				: Any											=	None
        return state







 def __setstate__(		self    :  Dict	,    __snake_case    :  Dict	)    ->	List[Any]:
        UpperCAmelCase				: Optional[Any]											=	d

        # for backward compatibility
        if not hasattr(self	,    '''sp_model_kwargs'''	):
               UpperCAmelCase				: Dict											=	{}

        UpperCAmelCase				: str											=	spm.SentencePieceProcessor(**self.sp_model_kwargs	)
        self.sp_model.Load(self.vocab_file	)







 def   A			(		self    :  Union[str, Any]	,    __snake_case    :  Dict	)    ->	Any:
        if self.remove_space:
               UpperCAmelCase				: Optional[int]											=	''' '''.join(inputs.strip().split()	)
        else:
               UpperCAmelCase				: Optional[int]											=	inputs
        UpperCAmelCase				: List[str]											=	outputs.replace('''``'''	,    '''"'''	).replace('''\'\''''	,    '''"'''	)

        if not self.keep_accents:
               UpperCAmelCase				: str											=	unicodedata.normalize('''NFKD'''	,    __snake_case	)
               UpperCAmelCase				: Optional[Any]											=	''''''.join([c for c in outputs if not unicodedata.combining(__snake_case	)]	)
        if self.do_lower_case:
               UpperCAmelCase				: Optional[int]											=	outputs.lower()

        return outputs







 def   A			(		self    :  List[Any]	,    __snake_case    :  str	)    ->	List[str]:
        UpperCAmelCase				: Optional[int]											=	self.preprocess_text(__snake_case	)
        UpperCAmelCase				: List[Any]											=	self.sp_model.encode(__snake_case	,    out_type=__snake_case	)
        UpperCAmelCase				: List[str]											=	[]
        for piece in pieces:
               if len(__snake_case	) > 1 and piece[-1] == str(''','''	) and piece[-2].isdigit():
                      UpperCAmelCase				: Tuple											=	self.sp_model.EncodeAsPieces(piece[:-1].replace(__snake_case	,    ''''''	)	)
                      if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                             if len(cur_pieces[0]	) == 1:
                                    UpperCAmelCase				: List[Any]											=	cur_pieces[1:]
                             else:
                                    UpperCAmelCase				: List[Any]											=	cur_pieces[0][1:]
                      cur_pieces.append(piece[-1]	)
                      new_pieces.extend(__snake_case	)
               else:
                      new_pieces.append(__snake_case	)

        return new_pieces







 def   A			(		self    :  Any	,    __snake_case    :  Dict	)    ->	Dict:
        return self.sp_model.PieceToId(__snake_case	)







 def   A			(		self    :  Tuple	,    __snake_case    :  str	)    ->	int:
        return self.sp_model.IdToPiece(__snake_case	)







 def   A			(		self    :  Any	,    __snake_case    :  int	)    ->	Any:
        UpperCAmelCase				: Tuple											=	[]
        UpperCAmelCase				: List[Any]											=	''''''
        UpperCAmelCase				: str											=	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
                      UpperCAmelCase				: Union[str, Any]											=	True
                      UpperCAmelCase				: Union[str, Any]											=	[]
               else:
                      current_sub_tokens.append(__snake_case	)
                      UpperCAmelCase				: List[Any]											=	False
        out_string += self.sp_model.decode(__snake_case	)
        return out_string.strip()







 def   A			(		self    :  Union[str, Any]	,    __snake_case    :  List[int]	,    __snake_case    :  Optional[List[int]] = None	)    ->	List[int]:
        UpperCAmelCase				: Union[str, Any]											=	[self.sep_token_id]
        UpperCAmelCase				: Optional[int]											=	[self.cls_token_id]
        if token_ids_a is None:
               return cls + token_ids_a + sep
        return cls + token_ids_a + sep + token_ids_a + sep







 def   A			(		self    :  int	,    __snake_case    :  List[int]	,    __snake_case    :  Optional[List[int]] = None	,    __snake_case    :  bool = False	)    ->	List[int]:

        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 not None:
               return [1] + ([0] * len(__snake_case	)) + [1] + ([0] * len(__snake_case	)) + [1]
        return [1] + ([0] * len(__snake_case	)) + [1]







 def   A			(		self    :  List[str]	,    __snake_case    :  List[int]	,    __snake_case    :  Optional[List[int]] = None	)    ->	List[int]:
        UpperCAmelCase				: Union[str, Any]											=	[self.sep_token_id]
        UpperCAmelCase				: Union[str, Any]											=	[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   A			(		self    :  Dict	,    __snake_case    :  str	,    __snake_case    :  Optional[str] = None	)    ->	Tuple[str]:
        if not os.path.isdir(__snake_case	):
               logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""	)
               return
        UpperCAmelCase				: Optional[int]											=	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:
                      UpperCAmelCase				: List[str]											=	self.sp_model.serialized_model_proto()
                      fi.write(__snake_case	)

        return (out_vocab_file,)










'''simple docstring'''






from typing import List, Optional, Union

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


UpperCamelCase__:     Optional[Any]										=    logging.get_logger(__name__)

UpperCamelCase__:     Tuple										=    {
    "huggingface/time-series-transformer-tourism-monthly": (
        "https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}

class        SCREAMING_SNAKE_CASE(							A__    ):







	"""simple docstring"""






	lowerCamelCase__    				= """time_series_transformer"""
	lowerCamelCase__    				= {
	    """hidden_size""": """d_model""",
	    """num_attention_heads""": """encoder_attention_heads""",
	    """num_hidden_layers""": """encoder_layers""",
	}







	def __init__(		self    :  str	,    __snake_case    :  Optional[int] = None	,    __snake_case    :  Optional[int] = None	,    __snake_case    :  str = "student_t"	,    __snake_case    :  str = "nll"	,    __snake_case    :  int = 1	,    __snake_case    :  List[int] = [1, 2, 3, 4, 5, 6, 7]	,    __snake_case    :  Optional[Union[str, bool]] = "mean"	,    __snake_case    :  int = 0	,    __snake_case    :  int = 0	,    __snake_case    :  int = 0	,    __snake_case    :  int = 0	,    __snake_case    :  Optional[List[int]] = None	,    __snake_case    :  Optional[List[int]] = None	,    __snake_case    :  int = 32	,    __snake_case    :  int = 32	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  int = 2	,    __snake_case    :  bool = True	,    __snake_case    :  str = "gelu"	,    __snake_case    :  int = 64	,    __snake_case    :  float = 0.1	,    __snake_case    :  float = 0.1	,    __snake_case    :  float = 0.1	,    __snake_case    :  float = 0.1	,    __snake_case    :  float = 0.1	,    __snake_case    :  int = 100	,    __snake_case    :  float = 0.02	,    __snake_case    :  Optional[Any]=True	,    **__snake_case    :  List[Any]	,    )    ->	List[str]:
								# time series specific configuration
								UpperCAmelCase				: List[Any]											=	prediction_length
								UpperCAmelCase				: List[Any]											=	context_length or prediction_length
								UpperCAmelCase				: Tuple											=	distribution_output
								UpperCAmelCase				: Optional[Any]											=	loss
								UpperCAmelCase				: Tuple											=	input_size
								UpperCAmelCase				: Optional[int]											=	num_time_features
								UpperCAmelCase				: Dict											=	lags_sequence
								UpperCAmelCase				: Any											=	scaling
								UpperCAmelCase				: Tuple											=	num_dynamic_real_features
								UpperCAmelCase				: Any											=	num_static_real_features
								UpperCAmelCase				: Optional[int]											=	num_static_categorical_features
								if cardinality and num_static_categorical_features > 0:
															if len(__snake_case	) != num_static_categorical_features:
																						raise ValueError(
																						    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''	)
															UpperCAmelCase				: Any											=	cardinality
								else:
															UpperCAmelCase				: Optional[Any]											=	[0]
								if embedding_dimension and num_static_categorical_features > 0:
															if len(__snake_case	) != num_static_categorical_features:
																						raise ValueError(
																						    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''	)
															UpperCAmelCase				: Optional[int]											=	embedding_dimension
								else:
															UpperCAmelCase				: Optional[Any]											=	[min(50	,    (cat + 1) // 2	) for cat in self.cardinality]
								UpperCAmelCase				: List[Any]											=	num_parallel_samples

								# Transformer architecture configuration
								UpperCAmelCase				: int											=	input_size * len(__snake_case	) + self._number_of_features
								UpperCAmelCase				: int											=	d_model
								UpperCAmelCase				: str											=	encoder_attention_heads
								UpperCAmelCase				: str											=	decoder_attention_heads
								UpperCAmelCase				: List[str]											=	encoder_ffn_dim
								UpperCAmelCase				: Any											=	decoder_ffn_dim
								UpperCAmelCase				: Any											=	encoder_layers
								UpperCAmelCase				: str											=	decoder_layers

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

								UpperCAmelCase				: Tuple											=	activation_function
								UpperCAmelCase				: Dict											=	init_std

								UpperCAmelCase				: Optional[int]											=	use_cache

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







	@property
	def   A			(		self    :  Union[str, Any]	)    ->	int:
								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
								)





