



"""simple docstring"""




import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
     import tensorflow as tf

     from transformers.activations_tf import get_tf_activation


@require_tf
class   a__		(						unittest.TestCase     ):


   def        lowercase				(							self      :							List[Any]			)    ->       Optional[int]:
         lowercase  :      int					=   tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]			)
         lowercase  :      List[str]					=   get_tf_activation('gelu'			)
         lowercase  :      str					=   get_tf_activation('gelu_10'			)

         lowercase  :      Dict					=   gelu(lowerCAmelCase			)
         lowercase  :      Optional[Any]					=   geluaa(lowerCAmelCase			)

         lowercase  :      Dict					=   tf.where(y_gelu_aa < 10.0,     1.0,     0.0			)

         self.assertEqual(tf.math.reduce_max(lowerCAmelCase			).numpy().item(),     10.0			)
         self.assertTrue(np.allclose(y_gelu * clipped_mask,     y_gelu_aa * clipped_mask			)			)






   def        lowercase				(							self      :							List[str]			)    ->       str:
         get_tf_activation('gelu'			)
         get_tf_activation('gelu_10'			)
         get_tf_activation('gelu_fast'			)
         get_tf_activation('gelu_new'			)
         get_tf_activation('glu'			)
         get_tf_activation('mish'			)
         get_tf_activation('quick_gelu'			)
         get_tf_activation('relu'			)
         get_tf_activation('sigmoid'			)
         get_tf_activation('silu'			)
         get_tf_activation('swish'			)
         get_tf_activation('tanh'			)
         with self.assertRaises(lowerCAmelCase			):
               get_tf_activation('bogus'			)
         with self.assertRaises(lowerCAmelCase			):
               get_tf_activation(lowerCAmelCase			)





"""simple docstring"""




import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin


class   a__		(						SCREAMING_SNAKE_CASE__     ):
   _lowerCamelCase												=				'AutoFeatureExtractor'
   _lowerCamelCase												=				'Speech2Text2Tokenizer'


   def __init__(							self      :							str,     lowerCAmelCase      :							List[str],     lowerCAmelCase      :							Optional[Any]			)    ->       Dict:
         super().__init__(lowerCAmelCase,     lowerCAmelCase			)
         lowercase  :      Tuple					=   self.feature_extractor
         lowercase  :      Any					=   False


   def __call__(							self      :							Tuple,     *lowerCAmelCase      :							Tuple,     **lowerCAmelCase      :							Tuple			)    ->       Dict:
         # For backward compatibility
         if self._in_target_context_manager:
               return self.current_processor(*lowerCAmelCase,     **lowerCAmelCase			)

         if "raw_speech" in kwargs:
               warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'			)
               lowercase  :      str					=   kwargs.pop('raw_speech'			)
         else:
               lowercase  :      str					=   kwargs.pop('audio',     lowerCAmelCase			)
         lowercase  :      Dict					=   kwargs.pop('sampling_rate',     lowerCAmelCase			)
         lowercase  :      Optional[Any]					=   kwargs.pop('text',     lowerCAmelCase			)
         if len(lowerCAmelCase			) > 0:
               lowercase  :      Any					=   args[0]
               lowercase  :      int					=   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:
               lowercase  :      List[Any]					=   self.feature_extractor(lowerCAmelCase,     *lowerCAmelCase,     sampling_rate=lowerCAmelCase,     **lowerCAmelCase			)
         if text is not None:
               lowercase  :      str					=   self.tokenizer(lowerCAmelCase,     **lowerCAmelCase			)

         if text is None:
               return inputs
         elif audio is None:
               return encodings
         else:
               lowercase  :      Tuple					=   encodings['input_ids']
               return inputs


   def        lowercase				(							self      :							str,     *lowerCAmelCase      :							List[str],     **lowerCAmelCase      :							Union[str, Any]			)    ->       str:
         return self.tokenizer.batch_decode(*lowerCAmelCase,     **lowerCAmelCase			)


   def        lowercase				(							self      :							Tuple,     *lowerCAmelCase      :							Union[str, Any],     **lowerCAmelCase      :							int			)    ->       Dict:
         return self.tokenizer.decode(*lowerCAmelCase,     **lowerCAmelCase			)






   @contextmanager
   def        lowercase				(							self      :							str			)    ->       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.'			)
         lowercase  :      Optional[Any]					=   True
         lowercase  :      Any					=   self.tokenizer
         yield
         lowercase  :      Any					=   self.feature_extractor
         lowercase  :      Any					=   False
