



'''simple docstring'''




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


lowerCamelCase							:Any				    =					logging.get_logger(__name__)

lowerCamelCase							:int				    =					{
    '''transfo-xl-wt103''': '''https://huggingface.co/transfo-xl-wt103/resolve/main/config.json''',
}







class 	_lowerCAmelCase							(			__UpperCAmelCase ):
	__SCREAMING_SNAKE_CASE   :		Optional[int]					=					'transfo-xl'
	__SCREAMING_SNAKE_CASE   :		Union[str, Any]					=					['mems']
	__SCREAMING_SNAKE_CASE   :		Union[str, Any]					=					{
	    'n_token': 'vocab_size',
	    'hidden_size': 'd_model',
	    'num_attention_heads': 'n_head',
	    'num_hidden_layers': 'n_layer',
	}


	def __init__(self       ,      lowercase=267735       ,      lowercase=[20000, 40000, 200000]       ,      lowercase=1024       ,      lowercase=1024       ,      lowercase=16       ,      lowercase=64       ,      lowercase=4096       ,      lowercase=4       ,      lowercase=False       ,      lowercase=18       ,      lowercase=1600       ,      lowercase=1000       ,      lowercase=True       ,      lowercase=True       ,      lowercase=0       ,      lowercase=-1       ,      lowercase=True       ,      lowercase=0.1       ,      lowercase=0.0       ,      lowercase=True       ,      lowercase="normal"       ,      lowercase=0.01       ,      lowercase=0.01       ,      lowercase=0.02       ,      lowercase=1E-5       ,      lowercase=0       ,      **lowercase       ,      ):
				A_	:						int	=     vocab_size
				A_	:						int	=     []
				self.cutoffs.extend(lowercase							)
				if proj_share_all_but_first:
							A_	:						Optional[Any]	=     [False] + [True] * len(self.cutoffs							)
				else:
							A_	:						List[Any]	=     [False] + [False] * len(self.cutoffs							)
				A_	:						str	=     d_model
				A_	:						Optional[Any]	=     d_embed
				A_	:						List[str]	=     d_head
				A_	:						Any	=     d_inner
				A_	:						List[Any]	=     div_val
				A_	:						Tuple	=     pre_lnorm
				A_	:						List[Any]	=     n_layer
				A_	:						List[str]	=     n_head
				A_	:						List[str]	=     mem_len
				A_	:						Dict	=     same_length
				A_	:						List[Any]	=     attn_type
				A_	:						Optional[int]	=     clamp_len
				A_	:						int	=     sample_softmax
				A_	:						List[str]	=     adaptive
				A_	:						Dict	=     dropout
				A_	:						int	=     dropatt
				A_	:						Optional[int]	=     untie_r
				A_	:						List[Any]	=     init
				A_	:						int	=     init_range
				A_	:						Dict	=     proj_init_std
				A_	:						Optional[int]	=     init_std
				A_	:						List[str]	=     layer_norm_epsilon
				super().__init__(eos_token_id=lowercase       ,      **lowercase							)


	@property
	def     _a	(self							):
				# Message copied from Transformer-XL documentation
				logger.info(F'The model {self.model_type} is one of the few models that has no sequence length limit.'							)
				return -1


	@max_position_embeddings.setter
	def     _a	(self       ,      lowercase							):
				# Message copied from Transformer-XL documentation
				raise NotImplementedError(
				    F'The model {self.model_type} is one of the few models that has no sequence length limit.'							)




'''simple docstring'''




import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad







class 	_lowerCAmelCase							(			unittest.TestCase ):


	def     _a	(self							):
				A_	:						Optional[Any]	=     10


	def     _a	(self							):
				A_	:						Dict	=     [1, 2, 3, 4]
				A_	:						List[Any]	=     [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						List[Any]	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				A_	:						Tuple	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						Optional[Any]	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
				A_	:						Any	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						List[str]	=     """It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this."""
				A_,    A_	:						Dict	=     process_story(lowercase							)
				self.assertEqual(lowercase       ,      []							)


	def     _a	(self							):
				A_	:						Optional[int]	=     """"""
				A_,    A_	:						List[str]	=     process_story(lowercase							)
				self.assertEqual(lowercase       ,      []							)
				self.assertEqual(lowercase       ,      []							)


	def     _a	(self							):
				A_	:						Optional[Any]	=     (
				    """It was the year of Our Lord one thousand seven hundred and """
				    """seventy-five\n\nSpiritual revelations were conceded to England """
				    """at that favoured period, as at this.\n@highlight\n\nIt was the best of times"""
				)
				A_,    A_	:						int	=     process_story(lowercase							)

				A_	:						Optional[Any]	=     [
				    """It was the year of Our Lord one thousand seven hundred and seventy-five.""",
				    """Spiritual revelations were conceded to England at that favoured period, as at this.""",
				]
				self.assertEqual(lowercase       ,      lowercase							)

				A_	:						Dict	=     ["""It was the best of times."""]
				self.assertEqual(lowercase       ,      lowercase							)


	def     _a	(self							):
				A_	:						Optional[int]	=     torch.tensor([1, 2, 3, 4]							)
				A_	:						Dict	=     torch.tensor([1, 1, 1, 1]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      0							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						str	=     torch.tensor([1, 2, 3, 4, 23, 23, 23]							)
				A_	:						str	=     torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      23							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						Any	=     torch.tensor([8, 2, 3, 4, 1, 1, 1]							)
				A_	:						List[str]	=     torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      1							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						List[Any]	=     101
				A_	:						List[Any]	=     torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]							)
				A_	:						List[str]	=     torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]							)

				A_	:						Dict	=     compute_token_type_ids(lowercase       ,      lowercase							)
				np.testing.assert_array_equal(lowercase       ,      lowercase							)