'''simple docstring'''




from typing import List, Optional

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


_A								=   logging.get_logger(__name__)

_A								=   {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}


class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   A							:       int     =    '''autoformer'''
   A							:       int     =    {
       '''hidden_size''': '''d_model''',
       '''num_attention_heads''': '''encoder_attention_heads''',
       '''num_hidden_layers''': '''encoder_layers''',
   }
   def __init__(self       ,				_a = None       ,				_a = None       ,				_a = "student_t"       ,				_a = "nll"       ,				_a = 1       ,				_a = [1, 2, 3, 4, 5, 6, 7]       ,				_a = True       ,				_a = 0       ,				_a = 0       ,				_a = 0       ,				_a = 0       ,				_a = None       ,				_a = None       ,				_a = 64       ,				_a = 2       ,				_a = 2       ,				_a = 2       ,				_a = 2       ,				_a = 32       ,				_a = 32       ,				_a = "gelu"       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 0.1       ,				_a = 100       ,				_a = 0.02       ,				_a = True       ,				_a=True       ,				_a = 10       ,				_a = 25       ,				_a = 3       ,				**_a       ,				)    ->     Optional[Any]:
        # time series specific configuration
        lowercase_					:       Optional[Any]     				=					prediction_length
        lowercase_					:       str     				=					context_length if context_length is not None else prediction_length
        lowercase_					:       List[Any]     				=					distribution_output
        lowercase_					:       List[Any]     				=					loss
        lowercase_					:       int     				=					input_size
        lowercase_					:       Tuple     				=					num_time_features
        lowercase_					:       Dict     				=					lags_sequence
        lowercase_					:       int     				=					scaling
        lowercase_					:       Optional[int]     				=					num_dynamic_real_features
        lowercase_					:       str     				=					num_static_real_features
        lowercase_					:       List[Any]     				=					num_static_categorical_features
        if cardinality is not None and num_static_categorical_features > 0:
             if len(_a				) != num_static_categorical_features:
                  raise ValueError(
                      'The cardinality should be a list of the same length as `num_static_categorical_features`'				)
             lowercase_					:       Any     				=					cardinality
        else:
             lowercase_					:       str     				=					[0]
        if embedding_dimension is not None and num_static_categorical_features > 0:
             if len(_a				) != num_static_categorical_features:
                  raise ValueError(
                      'The embedding dimension should be a list of the same length as `num_static_categorical_features`'				)
             lowercase_					:       Tuple     				=					embedding_dimension
        else:
             lowercase_					:       str     				=					[min(50       ,				(cat + 1) // 2				) for cat in self.cardinality]
        lowercase_					:       Any     				=					num_parallel_samples

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

        lowercase_					:       Any     				=					dropout
        lowercase_					:       Dict     				=					attention_dropout
        lowercase_					:       Optional[int]     				=					activation_dropout
        lowercase_					:       Tuple     				=					encoder_layerdrop
        lowercase_					:       Optional[int]     				=					decoder_layerdrop

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

        lowercase_					:       str     				=					use_cache

        # Autoformer
        lowercase_					:       List[Any]     				=					label_length
        lowercase_					:       Union[str, Any]     				=					moving_average
        lowercase_					:       Union[str, Any]     				=					autocorrelation_factor

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





   @property
   def 		_lowerCamelCase (self				)    ->     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
        )





'''simple docstring'''




import os
import unittest

from transformers.models.transfo_xl.tokenization_transfo_xl import VOCAB_FILES_NAMES, TransfoXLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin


class       UpperCAmelCase__  (       _snake_case					,     unittest.TestCase			):






   """simple docstring"""
   A							:       str     =    TransfoXLTokenizer
   A							:       Optional[int]     =    False
   A							:       List[str]     =    False
   def 		_lowerCamelCase (self				)    ->     List[Any]:
        super().setUp()

        lowercase_					:       Any     				=					[
            '<unk>',
            '[CLS]',
            '[SEP]',
            'want',
            'unwanted',
            'wa',
            'un',
            'running',
            ',',
            'low',
            'l',
        ]
        lowercase_					:       Any     				=					os.path.join(self.tmpdirname       ,				VOCAB_FILES_NAMES['vocab_file']				)
        with open(self.vocab_file       ,				'w'       ,				encoding='utf-8'				) as vocab_writer:
             vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]				)				)
   def 		_lowerCamelCase (self       ,				**_a				)    ->     Union[str, Any]:
        lowercase_					:       str     				=					True
        return TransfoXLTokenizer.from_pretrained(self.tmpdirname       ,				**_a				)
   def 		_lowerCamelCase (self       ,				_a				)    ->     Union[str, Any]:
        lowercase_					:       int     				=					'<unk> UNwanted , running'
        lowercase_					:       int     				=					'<unk> unwanted, running'
        return input_text, output_text
   def 		_lowerCamelCase (self				)    ->     Tuple:
        lowercase_					:       Any     				=					TransfoXLTokenizer(vocab_file=self.vocab_file       ,				lower_case=_a				)

        lowercase_					:       Optional[Any]     				=					tokenizer.tokenize('<unk> UNwanted , running'				)
        self.assertListEqual(_a       ,				['<unk>', 'unwanted', ',', 'running']				)

        self.assertListEqual(tokenizer.convert_tokens_to_ids(_a				)       ,				[0, 4, 8, 7]				)
   def 		_lowerCamelCase (self				)    ->     Union[str, Any]:
        lowercase_					:       List[str]     				=					TransfoXLTokenizer(lower_case=_a				)

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo ! how  \n Are yoU ?  '				)       ,				['hello', '!', 'how', 'are', 'you', '?']				)
   def 		_lowerCamelCase (self				)    ->     int:
        lowercase_					:       Dict     				=					TransfoXLTokenizer(lower_case=_a				)

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo ! how  \n Are yoU ?  '				)       ,				['HeLLo', '!', 'how', 'Are', 'yoU', '?']				)
   def 		_lowerCamelCase (self				)    ->     Optional[Any]:
        lowercase_					:       Dict     				=					TransfoXLTokenizer(lower_case=_a				)
        lowercase_					:       int     				=					'Hello (bracket) and side-scrolled [and] Henry\'s $5,000 with 3.34 m. What\'s up!?'
        lowercase_					:       List[str]     				=					[
            'Hello',
            '(',
            'bracket',
            ')',
            'and',
            'side',
            '@-@',
            'scrolled',
            '[',
            'and',
            ']',
            'Henry',
            '\'s',
            '$',
            '5',
            '@,@',
            '000',
            'with',
            '3',
            '@.@',
            '34',
            'm',
            '.',
            'What',
            '\'s',
            'up',
            '!',
            '?',
        ]

        self.assertListEqual(tokenizer.tokenize(_a				)       ,				_a				)

        self.assertEqual(tokenizer.convert_tokens_to_string(_a				)       ,				_a				)





   def 		_lowerCamelCase (self				)    ->     Any:
        lowercase_					:       Optional[int]     				=					self.get_tokenizer()
        lowercase_					:       str     				=					len(_a				)

        tokenizer.add_tokens(['new1', 'new2']				)
        tokenizer.move_added_token('new1'       ,				1				)

        # Check that moved token is not copied (duplicate)
        self.assertEqual(len(_a				)       ,				original_len + 2				)
        # Check that token is moved to specified id
        self.assertEqual(tokenizer.encode('new1'				)       ,				[1]				)
        self.assertEqual(tokenizer.decode([1]				)       ,				'new1'				)




