


"""simple docstring"""




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   :




							def __init__(     self:    Any     ,							A_:    List[str]     ,							A_:    Optional[int]=13     ,							A_:    Tuple=7     ,							A_:    Optional[int]=True     ,							A_:    Optional[int]=True     ,							A_:    Optional[Any]=True     ,							A_:    Any=True     ,							A_:    List[str]=99     ,							A_:    Optional[int]=[1, 1, 2]     ,							A_:    int=1     ,							A_:    Optional[int]=32     ,							A_:    Any=4     ,							A_:    Optional[int]=8     ,							A_:    Tuple=37     ,							A_:    Any="gelu_new"     ,							A_:    Union[str, Any]=0.1     ,							A_:    Optional[Any]=0.1     ,							A_:    Optional[int]=0.0     ,							A_:    Dict=5_12     ,							A_:    Optional[int]=3     ,							A_:    Union[str, Any]=0.02     ,							A_:    List[Any]=3     ,							A_:    int=4     ,							A_:    Dict=None     ,							A_:    Optional[Any]=False     ,							):
										__lowerCamelCase          =      parent
										__lowerCamelCase          =      batch_size
										__lowerCamelCase          =      seq_length
										__lowerCamelCase          =      is_training
										__lowerCamelCase          =      use_input_mask
										__lowerCamelCase          =      use_token_type_ids
										__lowerCamelCase          =      use_labels
										__lowerCamelCase          =      vocab_size
										__lowerCamelCase          =      block_sizes
										__lowerCamelCase          =      num_decoder_layers
										__lowerCamelCase          =      d_model
										__lowerCamelCase          =      n_head
										__lowerCamelCase          =      d_head
										__lowerCamelCase          =      d_inner
										__lowerCamelCase          =      hidden_act
										__lowerCamelCase          =      hidden_dropout
										__lowerCamelCase          =      attention_dropout
										__lowerCamelCase          =      activation_dropout
										__lowerCamelCase          =      max_position_embeddings
										__lowerCamelCase          =      type_vocab_size
										__lowerCamelCase          =      2
										__lowerCamelCase          =      num_labels
										__lowerCamelCase          =      num_choices
										__lowerCamelCase          =      scope
										__lowerCamelCase          =      initializer_std

										# Used in the tests to check the size of the first attention layer
										__lowerCamelCase          =      n_head
										# Used in the tests to check the size of the first hidden state
										__lowerCamelCase          =      self.d_model
										# Used in the tests to check the number of output hidden states/attentions
										__lowerCamelCase          =      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:
													__lowerCamelCase          =      self.num_hidden_layers + 2




							def   __a   (     self:    Union[str, Any]   ):
										__lowerCamelCase          =      ids_tensor([self.batch_size, self.seq_length]     ,							self.vocab_size   )

										__lowerCamelCase          =      None
										if self.use_input_mask:
													__lowerCamelCase          =      random_attention_mask([self.batch_size, self.seq_length]   )

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

										__lowerCamelCase          =      None
										__lowerCamelCase          =      None
										__lowerCamelCase          =      None
										if self.use_labels:
													__lowerCamelCase          =      ids_tensor([self.batch_size]     ,							self.type_sequence_label_size   )
													__lowerCamelCase          =      ids_tensor([self.batch_size, self.seq_length]     ,							self.num_labels   )
													__lowerCamelCase          =      ids_tensor([self.batch_size]     ,							self.num_choices   )

										__lowerCamelCase          =      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   __a   (     self:    str     ,							A_:    Union[str, Any]     ,							A_:    str     ,							A_:    List[str]     ,							A_:    Union[str, Any]     ,							A_:    Optional[Any]     ,							A_:    Optional[Any]     ,							A_:    int     ,							):
										__lowerCamelCase          =      TFFunnelModel(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      model(A_   )

										__lowerCamelCase          =      [input_ids, input_mask]
										__lowerCamelCase          =      model(A_   )

										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.d_model)   )

										__lowerCamelCase          =      False
										__lowerCamelCase          =      TFFunnelModel(config=A_   )
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.d_model)   )

										__lowerCamelCase          =      False
										__lowerCamelCase          =      TFFunnelModel(config=A_   )
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.d_model)   )




							def   __a   (     self:    Union[str, Any]     ,							A_:    Optional[Any]     ,							A_:    Any     ,							A_:    Union[str, Any]     ,							A_:    Any     ,							A_:    Tuple     ,							A_:    Any     ,							A_:    str     ,							):
										__lowerCamelCase          =      TFFunnelBaseModel(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      model(A_   )

										__lowerCamelCase          =      [input_ids, input_mask]
										__lowerCamelCase          =      model(A_   )

										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, 2, self.d_model)   )

										__lowerCamelCase          =      False
										__lowerCamelCase          =      TFFunnelBaseModel(config=A_   )
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, 3, self.d_model)   )

										__lowerCamelCase          =      False
										__lowerCamelCase          =      TFFunnelBaseModel(config=A_   )
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, 2, self.d_model)   )




							def   __a   (     self:    List[Any]     ,							A_:    int     ,							A_:    Tuple     ,							A_:    List[str]     ,							A_:    int     ,							A_:    List[str]     ,							A_:    Tuple     ,							A_:    Optional[int]     ,							):
										__lowerCamelCase          =      TFFunnelForPreTraining(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length)   )




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




							def   __a   (     self:    Tuple     ,							A_:    Union[str, Any]     ,							A_:    List[Any]     ,							A_:    List[Any]     ,							A_:    Optional[Any]     ,							A_:    List[str]     ,							A_:    Any     ,							A_:    int     ,							):
										__lowerCamelCase          =      self.num_labels
										__lowerCamelCase          =      TFFunnelForSequenceClassification(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.num_labels)   )




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




							def   __a   (     self:    Union[str, Any]     ,							A_:    Optional[int]     ,							A_:    Union[str, Any]     ,							A_:    Union[str, Any]     ,							A_:    Optional[Any]     ,							A_:    Union[str, Any]     ,							A_:    Optional[int]     ,							A_:    str     ,							):
										__lowerCamelCase          =      self.num_labels
										__lowerCamelCase          =      TFFunnelForTokenClassification(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      model(A_   )
										self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length, self.num_labels)   )




							def   __a   (     self:    List[str]     ,							A_:    Union[str, Any]     ,							A_:    Tuple     ,							A_:    Optional[int]     ,							A_:    Tuple     ,							A_:    List[str]     ,							A_:    Optional[int]     ,							A_:    Optional[int]     ,							):
										__lowerCamelCase          =      TFFunnelForQuestionAnswering(config=A_   )
										__lowerCamelCase          =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
										__lowerCamelCase          =      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   __a   (     self:    Union[str, Any]   ):
										__lowerCamelCase          =      self.prepare_config_and_inputs()
										(
										    (
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,(
										    __lowerCamelCase
										)     ,
										)          =      config_and_inputs
										__lowerCamelCase          =      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
										return config, inputs_dict




@require_tf
class 			__snake_case   (lowerCamelCase			,		lowerCamelCase			,		unittest.TestCase  ):
							__a					 =       (
							    (
							        TFFunnelModel,
							        TFFunnelForMaskedLM,
							        TFFunnelForPreTraining,
							        TFFunnelForQuestionAnswering,
							        TFFunnelForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							__a					 =       (
							    {
							        '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
							        '''fill-mask''': TFFunnelForMaskedLM,
							        '''question-answering''': TFFunnelForQuestionAnswering,
							        '''text-classification''': TFFunnelForSequenceClassification,
							        '''token-classification''': TFFunnelForTokenClassification,
							        '''zero-shot''': TFFunnelForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							__a					 =       False
							__a					 =       False




							def   __a   (     self:    Union[str, Any]   ):
										__lowerCamelCase          =      TFFunnelModelTester(self   )
										__lowerCamelCase          =      ConfigTester(self     ,							config_class=A_   )




							def   __a   (     self:    Optional[Any]   ):
										self.config_tester.run_common_tests()




							def   __a   (     self:    Optional[Any]   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*A_   )




							def   __a   (     self:    Tuple   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*A_   )




							def   __a   (     self:    Tuple   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*A_   )




							def   __a   (     self:    Optional[int]   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*A_   )




							def   __a   (     self:    Any   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*A_   )




@require_tf
class 			__snake_case   (lowerCamelCase			,		unittest.TestCase  ):
							__a					 =       (
							    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
							)
							__a					 =       False
							__a					 =       False




							def   __a   (     self:    Optional[int]   ):
										__lowerCamelCase          =      TFFunnelModelTester(self     ,							base=A_   )
										__lowerCamelCase          =      ConfigTester(self     ,							config_class=A_   )




							def   __a   (     self:    Dict   ):
										self.config_tester.run_common_tests()




							def   __a   (     self:    Tuple   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_base_model(*A_   )




							def   __a   (     self:    Optional[Any]   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*A_   )




							def   __a   (     self:    str   ):
										__lowerCamelCase          =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*A_   )








"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


__magic_name__						: Tuple    =				{}


try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__magic_name__						: str    =				['MLukeTokenizer']

if TYPE_CHECKING:
					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_mluke import MLukeTokenizer


else:
					import sys

					__magic_name__						: int    =				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




