'''simple docstring'''






from typing import List, Optional

import numpy as np

from ...processing_utils import ProcessorMixin
from ...utils import to_numpy




class    a (       __lowerCAmelCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					"""EncodecFeatureExtractor"""
  __lowerCAmelCase				      =					("""T5Tokenizer""", """T5TokenizerFast""")







  def __init__(							self   ,    snake_case_   ,    snake_case_					):

    '''simple docstring'''







    super().__init__(snake_case_   ,    snake_case_					)
    __UpperCAmelCase:					Any		= self.feature_extractor
    __UpperCAmelCase:					Optional[Any]		= False







  def    lowercase_  (							self   ,    snake_case_=None   ,    snake_case_=None   ,    snake_case_=True					):

    '''simple docstring'''







    return self.tokenizer.get_decoder_prompt_ids(task=snake_case_   ,    language=snake_case_   ,    no_timestamps=snake_case_					)







  def __call__(							self   ,    *snake_case_   ,    **snake_case_					):

    '''simple docstring'''







    if self._in_target_context_manager:
      return self.current_processor(*snake_case_   ,    **snake_case_					)

    __UpperCAmelCase:					Any		= kwargs.pop("""audio"""   ,    snake_case_					)
    __UpperCAmelCase:					str		= kwargs.pop("""sampling_rate"""   ,    snake_case_					)
    __UpperCAmelCase:					Union[str, Any]		= kwargs.pop("""text"""   ,    snake_case_					)
    if len(snake_case_					) > 0:
      __UpperCAmelCase:					List[str]		= args[0]
      __UpperCAmelCase:					Union[str, 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 text is not None:
      __UpperCAmelCase:					str		= self.tokenizer(snake_case_   ,    **snake_case_					)

    if audio is not None:
      __UpperCAmelCase:					str		= self.feature_extractor(snake_case_   ,    *snake_case_   ,    sampling_rate=snake_case_   ,    **snake_case_					)

    if audio is None:
      return inputs

    elif text is None:
      return audio_inputs

    else:
      __UpperCAmelCase:					Optional[Any]		= audio_inputs["""input_values"""]
      if "padding_mask" in audio_inputs:
        __UpperCAmelCase:					Optional[int]		= audio_inputs["""padding_mask"""]
      return inputs







  def    lowercase_  (							self   ,    *snake_case_   ,    **snake_case_					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= kwargs.pop("""audio"""   ,    snake_case_					)
    __UpperCAmelCase:					Tuple		= kwargs.pop("""padding_mask"""   ,    snake_case_					)

    if len(snake_case_					) > 0:
      __UpperCAmelCase:					Dict		= args[0]
      __UpperCAmelCase:					Any		= args[1:]

    if audio_values is not None:
      return self._decode_audio(snake_case_   ,    padding_mask=snake_case_					)
    else:
      return self.tokenizer.batch_decode(*snake_case_   ,    **snake_case_					)







  def    lowercase_  (							self   ,    *snake_case_   ,    **snake_case_					):

    '''simple docstring'''







    return self.tokenizer.decode(*snake_case_   ,    **snake_case_					)







  def    lowercase_  (							self   ,    snake_case_   ,    snake_case_ = None					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= to_numpy(snake_case_					)
    __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase:					Union[str, Any]		= audio_values.shape

    if padding_mask is None:
      return list(snake_case_					)

    __UpperCAmelCase:					List[str]		= to_numpy(snake_case_					)

    # match the sequence length of the padding mask to the generated audio arrays by padding with the **non-padding**
    # token (so that the generated audio values are **not** treated as padded tokens)
    __UpperCAmelCase:					int		= seq_len - padding_mask.shape[-1]
    __UpperCAmelCase:					Any		= 1 - self.feature_extractor.padding_value
    __UpperCAmelCase:					Optional[int]		= np.pad(snake_case_   ,    ((0, 0), (0, difference))   ,    """constant"""   ,    constant_values=snake_case_					)

    __UpperCAmelCase:					List[str]		= audio_values.tolist()
    for i in range(snake_case_					):
      __UpperCAmelCase:					Any		= np.asarray(audio_values[i]					)[
          padding_mask[i][None, :] != self.feature_extractor.padding_value
      ]
      __UpperCAmelCase:					List[Any]		= sliced_audio.reshape(snake_case_   ,    -1					)

    return audio_values
'''simple docstring'''






import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
    import jax.numpy as jnp

    from transformers.models.albert.modeling_flax_albert import (
        FlaxAlbertForMaskedLM,
        FlaxAlbertForMultipleChoice,
        FlaxAlbertForPreTraining,
        FlaxAlbertForQuestionAnswering,
        FlaxAlbertForSequenceClassification,
        FlaxAlbertForTokenClassification,
        FlaxAlbertModel,
    )




class    a (       unittest.TestCase				):



  """simple docstring"""







  def __init__(							self   ,    snake_case_   ,    snake_case_=13   ,    snake_case_=7   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=True   ,    snake_case_=99   ,    snake_case_=32   ,    snake_case_=5   ,    snake_case_=4   ,    snake_case_=37   ,    snake_case_="gelu"   ,    snake_case_=0.1   ,    snake_case_=0.1   ,    snake_case_=512   ,    snake_case_=16   ,    snake_case_=2   ,    snake_case_=0.0_2   ,    snake_case_=4   ,    ):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= parent
    __UpperCAmelCase:					List[str]		= batch_size
    __UpperCAmelCase:					Optional[int]		= seq_length
    __UpperCAmelCase:					Optional[Any]		= is_training
    __UpperCAmelCase:					Any		= use_attention_mask
    __UpperCAmelCase:					List[str]		= use_token_type_ids
    __UpperCAmelCase:					List[str]		= use_labels
    __UpperCAmelCase:					List[str]		= vocab_size
    __UpperCAmelCase:					Optional[Any]		= hidden_size
    __UpperCAmelCase:					List[Any]		= num_hidden_layers
    __UpperCAmelCase:					List[Any]		= num_attention_heads
    __UpperCAmelCase:					Tuple		= intermediate_size
    __UpperCAmelCase:					Dict		= hidden_act
    __UpperCAmelCase:					Dict		= hidden_dropout_prob
    __UpperCAmelCase:					Tuple		= attention_probs_dropout_prob
    __UpperCAmelCase:					List[str]		= max_position_embeddings
    __UpperCAmelCase:					List[Any]		= type_vocab_size
    __UpperCAmelCase:					List[Any]		= type_sequence_label_size
    __UpperCAmelCase:					List[str]		= initializer_range
    __UpperCAmelCase:					List[Any]		= num_choices







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					int		= ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size					)

    __UpperCAmelCase:					str		= None
    if self.use_attention_mask:
      __UpperCAmelCase:					Any		= random_attention_mask([self.batch_size, self.seq_length]					)

    __UpperCAmelCase:					List[Any]		= None
    if self.use_token_type_ids:
      __UpperCAmelCase:					Optional[int]		= ids_tensor([self.batch_size, self.seq_length]   ,    self.type_vocab_size					)

    __UpperCAmelCase:					List[Any]		= AlbertConfig(
        vocab_size=self.vocab_size   ,    hidden_size=self.hidden_size   ,    num_hidden_layers=self.num_hidden_layers   ,    num_attention_heads=self.num_attention_heads   ,    intermediate_size=self.intermediate_size   ,    hidden_act=self.hidden_act   ,    hidden_dropout_prob=self.hidden_dropout_prob   ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,    max_position_embeddings=self.max_position_embeddings   ,    type_vocab_size=self.type_vocab_size   ,    is_decoder=snake_case_   ,    initializer_range=self.initializer_range   ,    )

    return config, input_ids, token_type_ids, attention_mask







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Tuple		= self.prepare_config_and_inputs()
    __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase:					List[str]		= config_and_inputs
    __UpperCAmelCase:					List[Any]		= {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
    return config, inputs_dict




@require_flax
class    a (       __lowerCAmelCase						,  unittest.TestCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					(
      (
          FlaxAlbertModel,
          FlaxAlbertForPreTraining,
          FlaxAlbertForMaskedLM,
          FlaxAlbertForMultipleChoice,
          FlaxAlbertForQuestionAnswering,
          FlaxAlbertForSequenceClassification,
          FlaxAlbertForTokenClassification,
          FlaxAlbertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= FlaxAlbertModelTester(self					)







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    for model_class_name in self.all_model_classes:
      __UpperCAmelCase:					str		= model_class_name.from_pretrained("""albert-base-v2"""					)
      __UpperCAmelCase:					int		= model(np.ones((1, 1)					)					)
      self.assertIsNotNone(snake_case_					)




@require_flax
class    a (       unittest.TestCase				):



  """simple docstring"""







  @slow
  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					str		= FlaxAlbertModel.from_pretrained("""albert-base-v2"""					)
    __UpperCAmelCase:					Dict		= np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]					)
    __UpperCAmelCase:					int		= np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
    __UpperCAmelCase:					Optional[int]		= model(snake_case_   ,    attention_mask=snake_case_					)[0]
    __UpperCAmelCase:					Optional[int]		= (1, 11, 768)
    self.assertEqual(output.shape   ,    snake_case_					)
    __UpperCAmelCase:					str		= np.array(
        [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]					)

    self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]   ,    snake_case_   ,    atol=1e-4					)					)