
"""simple docstring"""



import warnings

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


_snake_case          =						logging.get_logger(__name__)

_snake_case          =						{
    '''xlnet-base-cased''': '''https://huggingface.co/xlnet-base-cased/resolve/main/config.json''',
    '''xlnet-large-cased''': '''https://huggingface.co/xlnet-large-cased/resolve/main/config.json''',
}
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Optional[Any]							=					"xlnet"
				SCREAMING_SNAKE_CASE_:							Optional[Any]							=					["mems"]
				SCREAMING_SNAKE_CASE_:							Optional[Any]							=					{
				    "n_token": "vocab_size",  # Backward compatibility
				    "hidden_size": "d_model",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}


				def __init__(					self	:			Any				,     UpperCAmelCase_	:			List[Any]=32_000				,     UpperCAmelCase_	:			List[str]=1_024				,     UpperCAmelCase_	:			str=24				,     UpperCAmelCase_	:			List[Any]=16				,     UpperCAmelCase_	:			Tuple=4_096				,     UpperCAmelCase_	:			Union[str, Any]="gelu"				,     UpperCAmelCase_	:			str=True				,     UpperCAmelCase_	:			List[Any]="bi"				,     UpperCAmelCase_	:			Tuple=0.02				,     UpperCAmelCase_	:			int=1E-1_2				,     UpperCAmelCase_	:			str=0.1				,     UpperCAmelCase_	:			Any=512				,     UpperCAmelCase_	:			Union[str, Any]=None				,     UpperCAmelCase_	:			Dict=True				,     UpperCAmelCase_	:			List[str]=False				,     UpperCAmelCase_	:			int=False				,     UpperCAmelCase_	:			str=-1				,     UpperCAmelCase_	:			Tuple=False				,     UpperCAmelCase_	:			Tuple="last"				,     UpperCAmelCase_	:			int=True				,     UpperCAmelCase_	:			int="tanh"				,     UpperCAmelCase_	:			Union[str, Any]=0.1				,     UpperCAmelCase_	:			str=5				,     UpperCAmelCase_	:			List[Any]=5				,     UpperCAmelCase_	:			Optional[Any]=5				,     UpperCAmelCase_	:			Any=1				,     UpperCAmelCase_	:			List[str]=2				,     **UpperCAmelCase_	:			Any				,     )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			vocab_size
											_lowerCAmelCase  	=			d_model
											_lowerCAmelCase  	=			n_layer
											_lowerCAmelCase  	=			n_head
											if d_model % n_head != 0:
																		raise ValueError(F"""'d_model % n_head' ({d_model % n_head}) should be equal to 0"""  )
											if "d_head" in kwargs:
																		if kwargs["d_head"] != d_model // n_head:
																									raise ValueError(
																									    F"""`d_head` ({kwargs['d_head']}) should be equal to `d_model // n_head` ({d_model // n_head})"""  )
											_lowerCAmelCase  	=			d_model // n_head
											_lowerCAmelCase  	=			ff_activation
											_lowerCAmelCase  	=			d_inner
											_lowerCAmelCase  	=			untie_r
											_lowerCAmelCase  	=			attn_type

											_lowerCAmelCase  	=			initializer_range
											_lowerCAmelCase  	=			layer_norm_eps

											_lowerCAmelCase  	=			dropout
											_lowerCAmelCase  	=			mem_len
											_lowerCAmelCase  	=			reuse_len
											_lowerCAmelCase  	=			bi_data
											_lowerCAmelCase  	=			clamp_len
											_lowerCAmelCase  	=			same_length

											_lowerCAmelCase  	=			summary_type
											_lowerCAmelCase  	=			summary_use_proj
											_lowerCAmelCase  	=			summary_activation
											_lowerCAmelCase  	=			summary_last_dropout
											_lowerCAmelCase  	=			start_n_top
											_lowerCAmelCase  	=			end_n_top

											_lowerCAmelCase  	=			bos_token_id
											_lowerCAmelCase  	=			pad_token_id
											_lowerCAmelCase  	=			eos_token_id

											if "use_cache" in kwargs:
																		warnings.warn(
																		    'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
																		    ' instead.'				,     UpperCAmelCase_				,     )
																		_lowerCAmelCase  	=			kwargs['use_cache']

											_lowerCAmelCase  	=			use_mems_eval
											_lowerCAmelCase  	=			use_mems_train
											super().__init__(pad_token_id=UpperCAmelCase_				,     bos_token_id=UpperCAmelCase_				,     eos_token_id=UpperCAmelCase_				,     **UpperCAmelCase_  )


				@property
				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  str:







											"""simple docstring"""




											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 				__lowerCamelCase	(					self	:			Dict				,     UpperCAmelCase_	:			Optional[int]  )		->  int:







											"""simple docstring"""




											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        _SCREAMING_SNAKE_CASE  (  unittest.TestCase							):






				'''simple docstring'''



				def 				__lowerCamelCase	(					self	:			Any  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			10


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[Any]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
											_lowerCAmelCase  	=			[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
											self.assertEqual(truncate_or_pad(UpperCAmelCase_				,     self.block_size				,     0  )				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			str  )		->  Optional[int]:







											"""simple docstring"""




											_lowerCAmelCase  	=			'It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this.'
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )
											self.assertEqual(UpperCAmelCase_				,     []  )


				def 				__lowerCamelCase	(					self	:			Dict  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			''
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )
											self.assertEqual(UpperCAmelCase_				,     []  )
											self.assertEqual(UpperCAmelCase_				,     []  )


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  List[str]:







											"""simple docstring"""




											_lowerCAmelCase  	=			(
											    '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'
											)
											_lowerCAmelCase	,		_lowerCAmelCase  	=			process_story(UpperCAmelCase_  )

											_lowerCAmelCase  	=			[
											    '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(UpperCAmelCase_				,     UpperCAmelCase_  )

											_lowerCAmelCase  	=			['It was the best of times.']
											self.assertEqual(UpperCAmelCase_				,     UpperCAmelCase_  )


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([1, 2, 3, 4]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     0  ).numpy()				,     expected.numpy()  )


				def 				__lowerCamelCase	(					self	:			int  )		->  str:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([1, 2, 3, 4, 23, 23, 23]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1, 0, 0, 0]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     23  ).numpy()				,     expected.numpy()  )


				def 				__lowerCamelCase	(					self	:			int  )		->  Union[str, Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			torch.tensor([8, 2, 3, 4, 1, 1, 1]  )
											_lowerCAmelCase  	=			torch.tensor([1, 1, 1, 1, 0, 0, 0]  )
											np.testing.assert_array_equal(build_mask(UpperCAmelCase_				,     1  ).numpy()				,     expected.numpy()  )







				def 				__lowerCamelCase	(					self	:			str  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			101
											_lowerCAmelCase  	=			torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]  )
											_lowerCAmelCase  	=			torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]  )

											_lowerCAmelCase  	=			compute_token_type_ids(UpperCAmelCase_				,     UpperCAmelCase_  )
											np.testing.assert_array_equal(UpperCAmelCase_				,     UpperCAmelCase_  )






