






"""simple docstring"""





import functools
import operator

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


_SCREAMING_SNAKE_CASE   :							Tuple          =		logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE   :							Dict          =		{
    '''microsoft/wavlm-base''': '''https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json''',
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}






class 	a		(   __snake_case						):
    SCREAMING_SNAKE_CASE		:	Optional[Any]		=					"""wavlm"""






    def __init__(			self	:				Optional[int]			,		__SCREAMING_SNAKE_CASE	:				int=32			,		__SCREAMING_SNAKE_CASE	:				Any=768			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=12			,		__SCREAMING_SNAKE_CASE	:				int=12			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=3072			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]="gelu"			,		__SCREAMING_SNAKE_CASE	:				Any=0.1			,		__SCREAMING_SNAKE_CASE	:				Any=0.1			,		__SCREAMING_SNAKE_CASE	:				List[str]=0.1			,		__SCREAMING_SNAKE_CASE	:				Any=0.0			,		__SCREAMING_SNAKE_CASE	:				List[Any]=0.1			,		__SCREAMING_SNAKE_CASE	:				str=0.1			,		__SCREAMING_SNAKE_CASE	:				Any=0.02			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=1e-5			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]="group"			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]="gelu"			,		__SCREAMING_SNAKE_CASE	:				List[str]=(512, 512, 512, 512, 512, 512, 512)			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=(5, 2, 2, 2, 2, 2, 2)			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=(10, 3, 3, 3, 3, 2, 2)			,		__SCREAMING_SNAKE_CASE	:				Dict=False			,		__SCREAMING_SNAKE_CASE	:				int=128			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=16			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=320			,		__SCREAMING_SNAKE_CASE	:				List[str]=800			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=False			,		__SCREAMING_SNAKE_CASE	:				Any=True			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=0.05			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=10			,		__SCREAMING_SNAKE_CASE	:				List[Any]=2			,		__SCREAMING_SNAKE_CASE	:				int=0.0			,		__SCREAMING_SNAKE_CASE	:				Any=10			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=320			,		__SCREAMING_SNAKE_CASE	:				Any=2			,		__SCREAMING_SNAKE_CASE	:				List[Any]=0.1			,		__SCREAMING_SNAKE_CASE	:				Tuple=100			,		__SCREAMING_SNAKE_CASE	:				str=256			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=256			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=0.1			,		__SCREAMING_SNAKE_CASE	:				Dict="mean"			,		__SCREAMING_SNAKE_CASE	:				int=False			,		__SCREAMING_SNAKE_CASE	:				str=False			,		__SCREAMING_SNAKE_CASE	:				Tuple=256			,		__SCREAMING_SNAKE_CASE	:				Dict=(512, 512, 512, 512, 1500)			,		__SCREAMING_SNAKE_CASE	:				int=(5, 3, 3, 1, 1)			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=(1, 2, 3, 1, 1)			,		__SCREAMING_SNAKE_CASE	:				Dict=512			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=80			,		__SCREAMING_SNAKE_CASE	:				Dict=0			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=1			,		__SCREAMING_SNAKE_CASE	:				Any=2			,		__SCREAMING_SNAKE_CASE	:				Tuple=False			,		__SCREAMING_SNAKE_CASE	:				str=3			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=2			,		__SCREAMING_SNAKE_CASE	:				int=3			,		__SCREAMING_SNAKE_CASE	:				Dict=None			,		**__SCREAMING_SNAKE_CASE	:				List[Any]			,		)	->						Dict:
      super().__init__(**__SCREAMING_SNAKE_CASE			,		pad_token_id=__SCREAMING_SNAKE_CASE			,		bos_token_id=__SCREAMING_SNAKE_CASE			,		eos_token_id=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		hidden_size
      lowerCamelCase_       	=		feat_extract_norm
      lowerCamelCase_       	=		feat_extract_activation
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		conv_bias
      lowerCamelCase_       	=		num_buckets
      lowerCamelCase_       	=		max_bucket_distance
      lowerCamelCase_       	=		num_conv_pos_embeddings
      lowerCamelCase_       	=		num_conv_pos_embedding_groups
      lowerCamelCase_       	=		len(self.conv_dim   )
      lowerCamelCase_       	=		num_hidden_layers
      lowerCamelCase_       	=		intermediate_size
      lowerCamelCase_       	=		hidden_act
      lowerCamelCase_       	=		num_attention_heads
      lowerCamelCase_       	=		hidden_dropout
      lowerCamelCase_       	=		attention_dropout
      lowerCamelCase_       	=		activation_dropout
      lowerCamelCase_       	=		feat_proj_dropout
      lowerCamelCase_       	=		final_dropout
      lowerCamelCase_       	=		layerdrop
      lowerCamelCase_       	=		layer_norm_eps
      lowerCamelCase_       	=		initializer_range
      lowerCamelCase_       	=		num_ctc_classes
      lowerCamelCase_       	=		vocab_size
      lowerCamelCase_       	=		do_stable_layer_norm
      lowerCamelCase_       	=		use_weighted_layer_sum
      lowerCamelCase_       	=		classifier_proj_size

      if (
          (len(self.conv_stride   ) != self.num_feat_extract_layers)
          or (len(self.conv_kernel   ) != self.num_feat_extract_layers)
          or (len(self.conv_dim   ) != self.num_feat_extract_layers)
      ):
        raise ValueError(
            'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
            ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
            F''' {len(self.conv_dim   )}`, `len(config.conv_stride) = {len(self.conv_stride   )}`,'''
            F''' `len(config.conv_kernel) = {len(self.conv_kernel   )}`.'''   )

      # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
      lowerCamelCase_       	=		apply_spec_augment
      lowerCamelCase_       	=		mask_time_prob
      lowerCamelCase_       	=		mask_time_length
      lowerCamelCase_       	=		mask_time_min_masks
      lowerCamelCase_       	=		mask_feature_prob
      lowerCamelCase_       	=		mask_feature_length

      # parameters for pretraining with codevector quantized representations
      lowerCamelCase_       	=		num_codevectors_per_group
      lowerCamelCase_       	=		num_codevector_groups
      lowerCamelCase_       	=		contrastive_logits_temperature
      lowerCamelCase_       	=		num_negatives
      lowerCamelCase_       	=		codevector_dim
      lowerCamelCase_       	=		proj_codevector_dim
      lowerCamelCase_       	=		diversity_loss_weight

      # ctc loss
      lowerCamelCase_       	=		ctc_loss_reduction
      lowerCamelCase_       	=		ctc_zero_infinity

      # adapter
      lowerCamelCase_       	=		add_adapter
      lowerCamelCase_       	=		adapter_kernel_size
      lowerCamelCase_       	=		adapter_stride
      lowerCamelCase_       	=		num_adapter_layers
      lowerCamelCase_       	=		output_hidden_size or hidden_size

      # SequenceClassification-specific parameter. Feel free to ignore for other classes.
      lowerCamelCase_       	=		classifier_proj_size

      # XVector-specific parameters. Feel free to ignore for other classes.
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		list(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		xvector_output_dim






    @property
    def   UpperCamelCase			(			self	:				Tuple   )	->						Optional[int]:
      return functools.reduce(operator.mul			,		self.conv_stride			,		1   )












"""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						):






    @require_torch
    def   UpperCamelCase			(			self	:				str   )	->						str:
      lowerCamelCase_       	=		pipeline(
          task='zero-shot-audio-classification'			,		model='hf-internal-testing/tiny-clap-htsat-unfused'   )
      lowerCamelCase_       	=		load_dataset('ashraq/esc50'   )
      lowerCamelCase_       	=		dataset['train']['audio'][-1]['array']
      lowerCamelCase_       	=		audio_classifier(__SCREAMING_SNAKE_CASE			,		candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']   )
      self.assertEqual(
          nested_simplify(__SCREAMING_SNAKE_CASE   )			,		[{'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   UpperCamelCase			(			self	:				Tuple   )	->						Optional[Any]:
      pass






    @slow
    @require_torch
    def   UpperCamelCase			(			self	:				Optional[Any]   )	->						Optional[Any]:
      lowerCamelCase_       	=		pipeline(
          task='zero-shot-audio-classification'			,		model='laion/clap-htsat-unfused'			,		)
      # This is an audio of a dog
      lowerCamelCase_       	=		load_dataset('ashraq/esc50'   )
      lowerCamelCase_       	=		dataset['train']['audio'][-1]['array']
      lowerCamelCase_       	=		audio_classifier(__SCREAMING_SNAKE_CASE			,		candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']   )

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

      lowerCamelCase_       	=		audio_classifier([audio] * 5			,		candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']   )
      self.assertEqual(
          nested_simplify(__SCREAMING_SNAKE_CASE   )			,		[
              [
                  {'score': 0.999, 'label': 'Sound of a dog'},
                  {'score': 0.001, 'label': 'Sound of vaccum cleaner'},
              ],
          ]
          * 5			,		)
      lowerCamelCase_       	=		audio_classifier(
          [audio] * 5			,		candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']			,		batch_size=5   )
      self.assertEqual(
          nested_simplify(__SCREAMING_SNAKE_CASE   )			,		[
              [
                  {'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   UpperCamelCase			(			self	:				Optional[int]   )	->						int:
      pass




