


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
   import torch

   from transformers.activations import gelu_new, gelu_python, get_activation







@require_torch
class        a					(			unittest.TestCase   ):





     def  SCREAMING_SNAKE_CASE__       (    self					:				List[Any]							):
        __lowerCamelCase:				Optional[Any]     =	torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]							)
        __lowerCamelCase:				int     =	get_activation("""gelu"""							)
        self.assertTrue(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE_							)    ,	torch_builtin(SCREAMING_SNAKE_CASE_							)							)							)
        self.assertFalse(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE_							)    ,	gelu_new(SCREAMING_SNAKE_CASE_							)							)							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Dict							):
        __lowerCamelCase:				Optional[int]     =	torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]							)
        __lowerCamelCase:				Optional[int]     =	get_activation("""gelu"""							)
        __lowerCamelCase:				Any     =	get_activation("""gelu_10"""							)

        __lowerCamelCase:				Dict     =	torch_builtin(SCREAMING_SNAKE_CASE_							)
        __lowerCamelCase:				List[str]     =	geluaa(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Union[str, Any]     =	torch.where(y_gelu_aa < 10.0    ,	1    ,	0							)

        self.assertTrue(torch.max(SCREAMING_SNAKE_CASE_							).item() == 10.0							)
        self.assertTrue(torch.allclose(y_gelu * clipped_mask    ,	y_gelu_aa * clipped_mask							)							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Dict							):
        get_activation("""gelu"""							)
        get_activation("""gelu_10"""							)
        get_activation("""gelu_fast"""							)
        get_activation("""gelu_new"""							)
        get_activation("""gelu_python"""							)
        get_activation("""gelu_pytorch_tanh"""							)
        get_activation("""linear"""							)
        get_activation("""mish"""							)
        get_activation("""quick_gelu"""							)
        get_activation("""relu"""							)
        get_activation("""sigmoid"""							)
        get_activation("""silu"""							)
        get_activation("""swish"""							)
        get_activation("""tanh"""							)
        with self.assertRaises(SCREAMING_SNAKE_CASE_							):
           get_activation("""bogus"""							)
        with self.assertRaises(SCREAMING_SNAKE_CASE_							):
           get_activation(SCREAMING_SNAKE_CASE_							)







     def  SCREAMING_SNAKE_CASE__       (    self					:				Any							):
        __lowerCamelCase:				Any     =	get_activation("""gelu"""							)
        __lowerCamelCase:				int     =	1
        __lowerCamelCase:				Any     =	get_activation("""gelu"""							)
        self.assertEqual(acta.a    ,	1							)
        with self.assertRaises(SCREAMING_SNAKE_CASE_							):
           __lowerCamelCase:				str     =	acta.a






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin



class        a					(			_UpperCAmelCase   ):
     UpperCAmelCase__ :  Dict						      =	"Speech2TextFeatureExtractor"
     UpperCAmelCase__ :  str						      =	"Speech2TextTokenizer"





     def __init__(    self					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				List[str]    ,	SCREAMING_SNAKE_CASE_					:				Optional[int]							):
        super().__init__(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)
        __lowerCamelCase:				Any     =	self.feature_extractor
        __lowerCamelCase:				List[Any]     =	False





     def __call__(    self					:				List[str]    ,	*SCREAMING_SNAKE_CASE_					:				Union[str, Any]    ,	**SCREAMING_SNAKE_CASE_					:				List[Any]							):
        # For backward compatibility
        if self._in_target_context_manager:
           return self.current_processor(*SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_							)

        if "raw_speech" in kwargs:
           warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""							)
           __lowerCamelCase:				Dict     =	kwargs.pop("""raw_speech"""							)
        else:
           __lowerCamelCase:				int     =	kwargs.pop("""audio"""    ,	SCREAMING_SNAKE_CASE_							)
        __lowerCamelCase:				Dict     =	kwargs.pop("""sampling_rate"""    ,	SCREAMING_SNAKE_CASE_							)
        __lowerCamelCase:				int     =	kwargs.pop("""text"""    ,	SCREAMING_SNAKE_CASE_							)
        if len(SCREAMING_SNAKE_CASE_							) > 0:
           __lowerCamelCase:				Dict     =	args[0]
           __lowerCamelCase:				Optional[Any]     =	args[1:]

        if audio is None and text is None:
           raise ValueError("""You need to specify either an `audio` or `text` input to process."""							)

        if audio is not None:
           __lowerCamelCase:				List[str]     =	self.feature_extractor(SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_    ,	sampling_rate=SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_							)
        if text is not None:
           __lowerCamelCase:				Any     =	self.tokenizer(SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_							)

        if text is None:
           return inputs
        elif audio is None:
           return encodings
        else:
           __lowerCamelCase:				List[Any]     =	encodings["""input_ids"""]
           return inputs





     def  SCREAMING_SNAKE_CASE__       (    self					:				List[str]    ,	*SCREAMING_SNAKE_CASE_					:				Optional[Any]    ,	**SCREAMING_SNAKE_CASE_					:				str							):
        return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_							)





     def  SCREAMING_SNAKE_CASE__       (    self					:				Tuple    ,	*SCREAMING_SNAKE_CASE_					:				Any    ,	**SCREAMING_SNAKE_CASE_					:				List[Any]							):
        return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_    ,	**SCREAMING_SNAKE_CASE_							)







     @contextmanager
     def  SCREAMING_SNAKE_CASE__       (    self					:				Any							):
        warnings.warn(
            """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
            """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
            """your audio inputs, or in a separate call."""							)
        __lowerCamelCase:				Any     =	True
        __lowerCamelCase:				Any     =	self.tokenizer
        yield
        __lowerCamelCase:				Any     =	self.feature_extractor
        __lowerCamelCase:				Optional[Any]     =	False


