'''simple docstring'''





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


_lowerCAmelCase	:Any						=     logging.get_logger(__name__)

_lowerCAmelCase	:Dict						=     {
    """transfo-xl-wt103""": """https://huggingface.co/transfo-xl-wt103/resolve/main/config.json""",
}






class 					UpperCAmelCase			(							snake_case_			):




    '''simple docstring'''







    snake_case__				: Union[str, Any]						    =    "transfo-xl"
    snake_case__				: List[Any]						    =    ["mems"]
    snake_case__				: int						    =    {
        "n_token": "vocab_size",
        "hidden_size": "d_model",
        "num_attention_heads": "n_head",
        "num_hidden_layers": "n_layer",
    }






    def __init__(							self     ,				lowercase__=267_735     ,				lowercase__=[20_000, 40_000, 200_000]     ,				lowercase__=1_024     ,				lowercase__=1_024     ,				lowercase__=16     ,				lowercase__=64     ,				lowercase__=4_096     ,				lowercase__=4     ,				lowercase__=False     ,				lowercase__=18     ,				lowercase__=1_600     ,				lowercase__=1_000     ,				lowercase__=True     ,				lowercase__=True     ,				lowercase__=0     ,				lowercase__=-1     ,				lowercase__=True     ,				lowercase__=0.1     ,				lowercase__=0.0     ,				lowercase__=True     ,				lowercase__="normal"     ,				lowercase__=0.0_1     ,				lowercase__=0.0_1     ,				lowercase__=0.0_2     ,				lowercase__=1E-5     ,				lowercase__=0     ,				**lowercase__     ,				)				->			Union[str, Any]:
         SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							vocab_size
         SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							[]
         self.cutoffs.extend(lowercase__			)
         if proj_share_all_but_first:
              SCREAMING_SNAKE_CASE       :      str     						=							[False] + [True] * len(self.cutoffs			)
         else:
              SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							[False] + [False] * len(self.cutoffs			)
         SCREAMING_SNAKE_CASE       :      str     						=							d_model
         SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							d_embed
         SCREAMING_SNAKE_CASE       :      Any     						=							d_head
         SCREAMING_SNAKE_CASE       :      str     						=							d_inner
         SCREAMING_SNAKE_CASE       :      Optional[int]     						=							div_val
         SCREAMING_SNAKE_CASE       :      List[str]     						=							pre_lnorm
         SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							n_layer
         SCREAMING_SNAKE_CASE       :      List[str]     						=							n_head
         SCREAMING_SNAKE_CASE       :      Any     						=							mem_len
         SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							same_length
         SCREAMING_SNAKE_CASE       :      List[str]     						=							attn_type
         SCREAMING_SNAKE_CASE       :      int     						=							clamp_len
         SCREAMING_SNAKE_CASE       :      Optional[int]     						=							sample_softmax
         SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							adaptive
         SCREAMING_SNAKE_CASE       :      Dict     						=							dropout
         SCREAMING_SNAKE_CASE       :      Any     						=							dropatt
         SCREAMING_SNAKE_CASE       :      Any     						=							untie_r
         SCREAMING_SNAKE_CASE       :      List[str]     						=							init
         SCREAMING_SNAKE_CASE       :      List[Any]     						=							init_range
         SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							proj_init_std
         SCREAMING_SNAKE_CASE       :      Optional[int]     						=							init_std
         SCREAMING_SNAKE_CASE       :      Dict     						=							layer_norm_epsilon
         super().__init__(eos_token_id=lowercase__     ,				**lowercase__			)






    @property
    def    _UpperCamelCase     (							self			)				->			int:
         # 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    _UpperCamelCase     (							self     ,				lowercase__			)				->			List[str]:
         # 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."""			)











import unittest

import numpy as np

from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
from transformers.pipelines import AudioClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torchaudio,
    slow,
)

from .test_pipelines_common import ANY




@is_pipeline_test
class 					UpperCamelCase_ (     unittest.TestCase							):



	'''simple docstring'''




	lowerCAmelCase						=					MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
	lowerCAmelCase						=					TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING




	def 				_UpperCamelCase     (			self			,     a			,     a			,     a   )			->       Union[str, Any]:
								snake_case_           =				AudioClassificationPipeline(model=a			,     feature_extractor=a   )

								# test with a raw waveform
								snake_case_           =				np.zeros((3_40_00,)   )
								snake_case_           =				np.zeros((1_40_00,)   )
								return audio_classifier, [audioa, audio]




	def 				_UpperCamelCase     (			self			,     a			,     a   )			->       Tuple:
								snake_case_     ,						snake_case_           =				examples
								snake_case_           =				audio_classifier(a   )
								# by default a model is initialized with num_labels=2
								self.assertEqual(
								    a			,     [
								        {'score': ANY(a   ), 'label': ANY(a   )},
								        {'score': ANY(a   ), 'label': ANY(a   )},
								    ]			,     )
								snake_case_           =				audio_classifier(a			,     top_k=1   )
								self.assertEqual(
								    a			,     [
								        {'score': ANY(a   ), 'label': ANY(a   )},
								    ]			,     )

								self.run_torchaudio(a   )




	@require_torchaudio
	def 				_UpperCamelCase     (			self			,     a   )			->       List[str]:
								import datasets

								# test with a local file
								snake_case_           =				datasets.load_dataset('hf-internal-testing/librispeech_asr_dummy'			,     'clean'			,     split='validation'   )
								snake_case_           =				dataset[0]['audio']['array']
								snake_case_           =				audio_classifier(a   )
								self.assertEqual(
								    a			,     [
								        {'score': ANY(a   ), 'label': ANY(a   )},
								        {'score': ANY(a   ), 'label': ANY(a   )},
								    ]			,     )




	@require_torch
	def 				_UpperCamelCase     (			self   )			->       Dict:
								snake_case_           =				'anton-l/wav2vec2-random-tiny-classifier'

								snake_case_           =				pipeline('audio-classification'			,     model=a   )

								snake_case_           =				np.ones((80_00,)   )
								snake_case_           =				audio_classifier(a			,     top_k=4   )

								snake_case_           =				[
								    {'score': 0.0_842, 'label': 'no'},
								    {'score': 0.0_838, 'label': 'up'},
								    {'score': 0.0_837, 'label': 'go'},
								    {'score': 0.0_834, 'label': 'right'},
								]
								snake_case_           =				[
								    {'score': 0.0_845, 'label': 'stop'},
								    {'score': 0.0_844, 'label': 'on'},
								    {'score': 0.0_841, 'label': 'right'},
								    {'score': 0.0_834, 'label': 'left'},
								]
								self.assertIn(nested_simplify(a			,     decimals=4   )			,     [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]   )

								snake_case_           =				{'array': np.ones((80_00,)   ), 'sampling_rate': audio_classifier.feature_extractor.sampling_rate}
								snake_case_           =				audio_classifier(a			,     top_k=4   )
								self.assertIn(nested_simplify(a			,     decimals=4   )			,     [EXPECTED_OUTPUT, EXPECTED_OUTPUT_PT_2]   )




	@require_torch
	@slow
	def 				_UpperCamelCase     (			self   )			->       str:
								import datasets

								snake_case_           =				'superb/wav2vec2-base-superb-ks'

								snake_case_           =				pipeline('audio-classification'			,     model=a   )
								snake_case_           =				datasets.load_dataset('anton-l/superb_dummy'			,     'ks'			,     split='test'   )

								snake_case_           =				np.array(dataset[3]['speech']			,     dtype=np.floataa   )
								snake_case_           =				audio_classifier(a			,     top_k=4   )
								self.assertEqual(
								    nested_simplify(a			,     decimals=3   )			,     [
								        {'score': 0.981, 'label': 'go'},
								        {'score': 0.007, 'label': 'up'},
								        {'score': 0.006, 'label': '_unknown_'},
								        {'score': 0.001, 'label': 'down'},
								    ]			,     )






	@require_tf
	@unittest.skip('Audio classification is not implemented for TF'   )
	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								pass





