






from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import (
         TFFunnelBaseModel,
         TFFunnelForMaskedLM,
         TFFunnelForMultipleChoice,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForSequenceClassification,
         TFFunnelForTokenClassification,
         TFFunnelModel,
     )




class       snake_case__ :

       '''simple docstring'''



       def __init__(				self      ,    a__      ,    a__=13      ,    a__=7      ,    a__=True      ,    a__=True      ,    a__=True      ,    a__=True      ,    a__=99      ,    a__=[1, 1, 2]      ,    a__=1      ,    a__=32      ,    a__=4      ,    a__=8      ,    a__=37      ,    a__="gelu_new"      ,    a__=0.1      ,    a__=0.1      ,    a__=0.0      ,    a__=5_12      ,    a__=3      ,    a__=0.02      ,    a__=3      ,    a__=4      ,    a__=None      ,    a__=False      ,    )			->   Dict:






            '''simple docstring'''





            __snake_case      :List[Any] 							=    parent
            __snake_case      :int 							=    batch_size
            __snake_case      :Any 							=    seq_length
            __snake_case      :Any 							=    is_training
            __snake_case      :Dict 							=    use_input_mask
            __snake_case      :Any 							=    use_token_type_ids
            __snake_case      :Union[str, Any] 							=    use_labels
            __snake_case      :Any 							=    vocab_size
            __snake_case      :int 							=    block_sizes
            __snake_case      :Tuple 							=    num_decoder_layers
            __snake_case      :List[str] 							=    d_model
            __snake_case      :Tuple 							=    n_head
            __snake_case      :Dict 							=    d_head
            __snake_case      :str 							=    d_inner
            __snake_case      :int 							=    hidden_act
            __snake_case      :Dict 							=    hidden_dropout
            __snake_case      :Any 							=    attention_dropout
            __snake_case      :Optional[int] 							=    activation_dropout
            __snake_case      :List[Any] 							=    max_position_embeddings
            __snake_case      :Union[str, Any] 							=    type_vocab_size
            __snake_case      :Tuple 							=    2
            __snake_case      :Any 							=    num_labels
            __snake_case      :Tuple 							=    num_choices
            __snake_case      :List[Any] 							=    scope
            __snake_case      :Union[str, Any] 							=    initializer_std

            # Used in the tests to check the size of the first attention layer
            __snake_case      :Any 							=    n_head
            # Used in the tests to check the size of the first hidden state
            __snake_case      :Optional[Any] 							=    self.d_model
            # Used in the tests to check the number of output hidden states/attentions
            __snake_case      :int 							=    sum(self.block_sizes     ) + (0 if base else self.num_decoder_layers)
            # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
            # the last hidden state of the first block (which is the first hidden state of the decoder).
            if not base:
                 __snake_case      :Tuple 							=    self.num_hidden_layers + 2



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            __snake_case      :str 							=    ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size     )

            __snake_case      :str 							=    None
            if self.use_input_mask:
                 __snake_case      :Dict 							=    random_attention_mask([self.batch_size, self.seq_length]     )

            __snake_case      :Dict 							=    None
            if self.use_token_type_ids:
                 __snake_case      :Dict 							=    ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size     )

            __snake_case      :str 							=    None
            __snake_case      :List[str] 							=    None
            __snake_case      :int 							=    None
            if self.use_labels:
                 __snake_case      :List[Any] 							=    ids_tensor([self.batch_size]      ,    self.type_sequence_label_size     )
                 __snake_case      :Tuple 							=    ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels     )
                 __snake_case      :List[str] 							=    ids_tensor([self.batch_size]      ,    self.num_choices     )

            __snake_case      :Tuple 							=    FunnelConfig(
                vocab_size=self.vocab_size      ,    block_sizes=self.block_sizes      ,    num_decoder_layers=self.num_decoder_layers      ,    d_model=self.d_model      ,    n_head=self.n_head      ,    d_head=self.d_head      ,    d_inner=self.d_inner      ,    hidden_act=self.hidden_act      ,    hidden_dropout=self.hidden_dropout      ,    attention_dropout=self.attention_dropout      ,    activation_dropout=self.activation_dropout      ,    max_position_embeddings=self.max_position_embeddings      ,    type_vocab_size=self.type_vocab_size      ,    initializer_std=self.initializer_std      ,    )

            return (
                config,
                input_ids,
                token_type_ids,
                input_mask,
                sequence_labels,
                token_labels,
                choice_labels,
            )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Union[str, Any]:






            '''simple docstring'''





            __snake_case      :int 							=    TFFunnelModel(config=a__     )
            __snake_case      :Optional[Any] 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :Optional[int] 							=    model(a__     )

            __snake_case      :Optional[int] 							=    [input_ids, input_mask]
            __snake_case      :str 							=    model(a__     )

            __snake_case      :str 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model)     )

            __snake_case      :Dict 							=    False
            __snake_case      :Any 							=    TFFunnelModel(config=a__     )
            __snake_case      :Union[str, Any] 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model)     )

            __snake_case      :Dict 							=    False
            __snake_case      :Tuple 							=    TFFunnelModel(config=a__     )
            __snake_case      :int 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.d_model)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :List[str] 							=    TFFunnelBaseModel(config=a__     )
            __snake_case      :int 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :int 							=    model(a__     )

            __snake_case      :Tuple 							=    [input_ids, input_mask]
            __snake_case      :Optional[int] 							=    model(a__     )

            __snake_case      :Optional[int] 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, 2, self.d_model)     )

            __snake_case      :Any 							=    False
            __snake_case      :Optional[int] 							=    TFFunnelBaseModel(config=a__     )
            __snake_case      :Optional[int] 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, 3, self.d_model)     )

            __snake_case      :List[Any] 							=    False
            __snake_case      :Any 							=    TFFunnelBaseModel(config=a__     )
            __snake_case      :Any 							=    model(a__     )
            self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, 2, self.d_model)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Tuple:






            '''simple docstring'''





            __snake_case      :List[Any] 							=    TFFunnelForPreTraining(config=a__     )
            __snake_case      :List[Any] 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :Dict 							=    model(a__     )
            self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   List[str]:






            '''simple docstring'''





            __snake_case      :Optional[Any] 							=    TFFunnelForMaskedLM(config=a__     )
            __snake_case      :List[str] 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :int 							=    model(a__     )
            self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Tuple:






            '''simple docstring'''





            __snake_case      :List[str] 							=    self.num_labels
            __snake_case      :Any 							=    TFFunnelForSequenceClassification(config=a__     )
            __snake_case      :Union[str, Any] 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :Tuple 							=    model(a__     )
            self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Tuple:






            '''simple docstring'''





            __snake_case      :Dict 							=    self.num_choices
            __snake_case      :Dict 							=    TFFunnelForMultipleChoice(config=a__     )
            __snake_case      :Any 							=    tf.tile(tf.expand_dims(a__      ,    1     )      ,    (1, self.num_choices, 1)     )
            __snake_case      :Dict 							=    tf.tile(tf.expand_dims(a__      ,    1     )      ,    (1, self.num_choices, 1)     )
            __snake_case      :List[str] 							=    tf.tile(tf.expand_dims(a__      ,    1     )      ,    (1, self.num_choices, 1)     )
            __snake_case      :Any 							=    {
                """input_ids""": multiple_choice_inputs_ids,
                """attention_mask""": multiple_choice_input_mask,
                """token_type_ids""": multiple_choice_token_type_ids,
            }
            __snake_case      :Union[str, Any] 							=    model(a__     )
            self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_choices)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Tuple:






            '''simple docstring'''





            __snake_case      :Dict 							=    self.num_labels
            __snake_case      :Optional[int] 							=    TFFunnelForTokenClassification(config=a__     )
            __snake_case      :List[str] 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :Dict 							=    model(a__     )
            self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels)     )



       def        __lowercase    (				self      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    a__      ,    )			->   Dict:






            '''simple docstring'''





            __snake_case      :List[Any] 							=    TFFunnelForQuestionAnswering(config=a__     )
            __snake_case      :Dict 							=    {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
            __snake_case      :Optional[int] 							=    model(a__     )
            self.parent.assertEqual(result.start_logits.shape      ,    (self.batch_size, self.seq_length)     )
            self.parent.assertEqual(result.end_logits.shape      ,    (self.batch_size, self.seq_length)     )



       def        __lowercase    (				self     )			->   Optional[int]:






            '''simple docstring'''





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




@require_tf
class       snake_case__ (				lowercase_						,     lowercase_						,     unittest.TestCase):

       '''simple docstring'''
       lowerCamelCase				:					str								=			(
           (
               TFFunnelModel,
               TFFunnelForMaskedLM,
               TFFunnelForPreTraining,
               TFFunnelForQuestionAnswering,
               TFFunnelForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       lowerCamelCase				:					List[str]								=			(
           {
               "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
               "fill-mask": TFFunnelForMaskedLM,
               "question-answering": TFFunnelForQuestionAnswering,
               "text-classification": TFFunnelForSequenceClassification,
               "token-classification": TFFunnelForTokenClassification,
               "zero-shot": TFFunnelForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       lowerCamelCase				:					Any								=			False
       lowerCamelCase				:					int								=			False



       def        __lowercase    (				self     )			->   List[Any]:






            '''simple docstring'''





            __snake_case      :Any 							=    TFFunnelModelTester(self     )
            __snake_case      :Tuple 							=    ConfigTester(self      ,    config_class=a__     )



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            self.config_tester.run_common_tests()



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            __snake_case      :Dict 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*a__     )



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :Tuple 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_pretraining(*a__     )



       def        __lowercase    (				self     )			->   Optional[int]:






            '''simple docstring'''





            __snake_case      :str 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_masked_lm(*a__     )



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :Optional[int] 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_token_classification(*a__     )



       def        __lowercase    (				self     )			->   Dict:






            '''simple docstring'''





            __snake_case      :Optional[Any] 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_question_answering(*a__     )




@require_tf
class       snake_case__ (				lowercase_						,     unittest.TestCase):

       '''simple docstring'''
       lowerCamelCase				:					Optional[Any]								=			(
           (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
       )
       lowerCamelCase				:					str								=			False
       lowerCamelCase				:					int								=			False



       def        __lowercase    (				self     )			->   Union[str, Any]:






            '''simple docstring'''





            __snake_case      :Any 							=    TFFunnelModelTester(self      ,    base=a__     )
            __snake_case      :Any 							=    ConfigTester(self      ,    config_class=a__     )



       def        __lowercase    (				self     )			->   Optional[int]:






            '''simple docstring'''





            self.config_tester.run_common_tests()



       def        __lowercase    (				self     )			->   Optional[Any]:






            '''simple docstring'''





            __snake_case      :List[str] 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_base_model(*a__     )



       def        __lowercase    (				self     )			->   Any:






            '''simple docstring'''





            __snake_case      :str 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_sequence_classification(*a__     )



       def        __lowercase    (				self     )			->   str:






            '''simple docstring'''





            __snake_case      :Tuple 							=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_multiple_choice(*a__     )










import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, ClassLabel, Features
from .base import TaskTemplate




@dataclass(frozen=lowercase_)
class       snake_case__ (				lowercase_):

       '''simple docstring'''
       lowerCamelCase				:					str								=			field(default="audio-classification"						,     metadata={"include_in_asdict_even_if_is_default": True})
       lowerCamelCase				:					ClassVar[Features]								=			Features({"audio": Audio()})
       lowerCamelCase				:					ClassVar[Features]								=			Features({"labels": ClassLabel})
       lowerCamelCase				:					str								=			"audio"
       lowerCamelCase				:					str								=			"labels"



       def        __lowercase    (				self      ,    a__     )			->   Dict:






            '''simple docstring'''





            if self.label_column not in features:
                 raise ValueError(F'''Column {self.label_column} is not present in features.'''     )
            if not isinstance(features[self.label_column]      ,    a__     ):
                 raise ValueError(F'''Column {self.label_column} is not a ClassLabel.'''     )
            __snake_case      :Any 							=    copy.deepcopy(self     )
            __snake_case      :List[Any] 							=    self.label_schema.copy()
            __snake_case      :List[Any] 							=    features[self.label_column]
            __snake_case      :Optional[Any] 							=    label_schema
            return task_template



       @property
       def        __lowercase    (				self     )			->   Dict[str, str]:






            '''simple docstring'''





            return {
                self.audio_column: "audio",
                self.label_column: "labels",
            }


