


"""simple docstring"""







import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow






@is_pipeline_test
@require_torch
class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    @require_torch
    def 	__snake_case							(					self				:    Union[str, Any]):
      a						:		Tuple      							=			pipeline(
          task="zero-shot-audio-classification"				, model="hf-internal-testing/tiny-clap-htsat-unfused")
      a						:		Optional[Any]      							=			load_dataset("ashraq/esc50")
      a						:		Dict      							=			dataset["train"]["audio"][-1]["array"]
      a						:		List[str]      							=			audio_classifier(__UpperCAmelCase				, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])
      self.assertEqual(
          nested_simplify(__UpperCAmelCase)				, [{"score": 0.501, "label": "Sound of a dog"}, {"score": 0.499, "label": "Sound of vaccum cleaner"}]				, )






    @unittest.skip("No models are available in TF")
    def 	__snake_case							(					self				:    List[str]):
      pass






    @slow
    @require_torch
    def 	__snake_case							(					self				:    str):
      a						:		Optional[int]      							=			pipeline(
          task="zero-shot-audio-classification"				, model="laion/clap-htsat-unfused"				, )
      # This is an audio of a dog
      a						:		str      							=			load_dataset("ashraq/esc50")
      a						:		Union[str, Any]      							=			dataset["train"]["audio"][-1]["array"]
      a						:		Dict      							=			audio_classifier(__UpperCAmelCase				, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])

      self.assertEqual(
          nested_simplify(__UpperCAmelCase)				, [
              {"score": 0.999, "label": "Sound of a dog"},
              {"score": 0.001, "label": "Sound of vaccum cleaner"},
          ]				, )

      a						:		Dict      							=			audio_classifier([audio] * 5				, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])
      self.assertEqual(
          nested_simplify(__UpperCAmelCase)				, [
              [
                  {"score": 0.999, "label": "Sound of a dog"},
                  {"score": 0.001, "label": "Sound of vaccum cleaner"},
              ],
          ]
          * 5				, )
      a						:		Any      							=			audio_classifier(
          [audio] * 5				, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]				, batch_size=5)
      self.assertEqual(
          nested_simplify(__UpperCAmelCase)				, [
              [
                  {"score": 0.999, "label": "Sound of a dog"},
                  {"score": 0.001, "label": "Sound of vaccum cleaner"},
              ],
          ]
          * 5				, )






    @unittest.skip("No models are available in TF")
    def 	__snake_case							(					self				:    List[str]):
      pass













'''simple docstring'''


from typing import List, Optional

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


lowerCAmelCase					:     Optional[int]												=logging.get_logger(__name__)

lowerCAmelCase					:     Tuple												={
    '''huggingface/autoformer-tourism-monthly''': '''https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json''',
}
class       a_   (				_lowerCAmelCase							):
     __A      =			"autoformer"
     __A      =			{
         "hidden_size": "d_model",
         "num_attention_heads": "encoder_attention_heads",
         "num_hidden_layers": "encoder_layers",
     }





     def __init__( self		:					Any	,      lowercase		:					Optional[int] = None	,      lowercase		:					Optional[int] = None	,      lowercase		:					str = "student_t"	,      lowercase		:					str = "nll"	,      lowercase		:					int = 1	,      lowercase		:					List[int] = [1, 2, 3, 4, 5, 6, 7]	,      lowercase		:					bool = True	,      lowercase		:					int = 0	,      lowercase		:					int = 0	,      lowercase		:					int = 0	,      lowercase		:					int = 0	,      lowercase		:					Optional[List[int]] = None	,      lowercase		:					Optional[List[int]] = None	,      lowercase		:					int = 64	,      lowercase		:					int = 2	,      lowercase		:					int = 2	,      lowercase		:					int = 2	,      lowercase		:					int = 2	,      lowercase		:					int = 32	,      lowercase		:					int = 32	,      lowercase		:					str = "gelu"	,      lowercase		:					float = 0.1	,      lowercase		:					float = 0.1	,      lowercase		:					float = 0.1	,      lowercase		:					float = 0.1	,      lowercase		:					float = 0.1	,      lowercase		:					int = 100	,      lowercase		:					float = 0.02	,      lowercase		:					bool = True	,      lowercase		:					int=True	,      lowercase		:					int = 10	,      lowercase		:					int = 25	,      lowercase		:					int = 3	,      **lowercase		:					Dict	,      ):





        """simple docstring"""




        lowercase_			:str    			= prediction_length
        lowercase_			:Dict    			= context_length if context_length is not None else prediction_length
        lowercase_			:Any    			= distribution_output
        lowercase_			:Tuple    			= loss
        lowercase_			:Dict    			= input_size
        lowercase_			:Tuple    			= num_time_features
        lowercase_			:int    			= lags_sequence
        lowercase_			:Tuple    			= scaling
        lowercase_			:List[Any]    			= num_dynamic_real_features
        lowercase_			:Union[str, Any]    			= num_static_real_features
        lowercase_			:str    			= num_static_categorical_features
        if cardinality is not None and num_static_categorical_features > 0:
           if len(lowercase						) != num_static_categorical_features:
              raise ValueError(
                  "The cardinality should be a list of the same length as `num_static_categorical_features`"						)
           lowercase_			:Optional[int]    			= cardinality
        else:
           lowercase_			:Optional[int]    			= [0]
        if embedding_dimension is not None and num_static_categorical_features > 0:
           if len(lowercase						) != 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_			:Dict    			= [min(50	,      (cat + 1) // 2						) for cat in self.cardinality]
        lowercase_			:Any    			= num_parallel_samples

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

        lowercase_			:Dict    			= dropout
        lowercase_			:Dict    			= attention_dropout
        lowercase_			:str    			= activation_dropout
        lowercase_			:int    			= encoder_layerdrop
        lowercase_			:Dict    			= decoder_layerdrop

        lowercase_			:List[str]    			= activation_function
        lowercase_			:int    			= init_std

        lowercase_			:Optional[int]    			= use_cache

        # Autoformer
        lowercase_			:List[str]    			= label_length
        lowercase_			:List[str]    			= moving_average
        lowercase_			:Optional[int]    			= autocorrelation_factor

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







     @property
     def 							lowercase__      ( self		:					int						):





        """simple docstring"""




        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
        )


