



import shutil
import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, MBartTokenizer, MBartTokenizerFast, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


a_			=					get_tests_dir("""fixtures/test_sentencepiece.model""")


if is_torch_available():
 from transformers.models.mbart.modeling_mbart import shift_tokens_right

a_			=					250_004
a_			=					250_020



@require_sentencepiece
@require_tokenizers
class  __lowerCAmelCase     (	__snake_case  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  MBartTokenizer
 lowerCAmelCase__       					=  MBartTokenizerFast
 lowerCAmelCase__       					=  True
 lowerCAmelCase__       					=  True




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    super().setUp()

    # We have a SentencePiece fixture for testing
    __lowerCamelCase													=    MBartTokenizer(A_	,				keep_accents=A_				)
    tokenizer.save_pretrained(self.tmpdirname				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    MBartTokenizer(A_	,				keep_accents=A_				)

    __lowerCamelCase													=    tokenizer.tokenize('''This is a test'''				)
    self.assertListEqual(A_	,				['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']				)

    self.assertListEqual(
        tokenizer.convert_tokens_to_ids(A_				)	,				[value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]	,				)

    __lowerCamelCase													=    tokenizer.tokenize('''I was born in 92000, and this is falsé.'''				)
    self.assertListEqual(
        A_	,				[
            SPIECE_UNDERLINE + '''I''',
            SPIECE_UNDERLINE + '''was''',
            SPIECE_UNDERLINE + '''b''',
            '''or''',
            '''n''',
            SPIECE_UNDERLINE + '''in''',
            SPIECE_UNDERLINE + '''''',
            '''9''',
            '''2''',
            '''0''',
            '''0''',
            '''0''',
            ''',''',
            SPIECE_UNDERLINE + '''and''',
            SPIECE_UNDERLINE + '''this''',
            SPIECE_UNDERLINE + '''is''',
            SPIECE_UNDERLINE + '''f''',
            '''al''',
            '''s''',
            '''é''',
            '''.''',
        ]	,				)
    __lowerCamelCase													=    tokenizer.convert_tokens_to_ids(A_				)
    self.assertListEqual(
        A_	,				[
            value + tokenizer.fairseq_offset
            for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
            #                                       ^ unk: 2 + 1 = 3                  unk: 2 + 1 = 3 ^
        ]	,				)

    __lowerCamelCase													=    tokenizer.convert_ids_to_tokens(A_				)
    self.assertListEqual(
        A_	,				[
            SPIECE_UNDERLINE + '''I''',
            SPIECE_UNDERLINE + '''was''',
            SPIECE_UNDERLINE + '''b''',
            '''or''',
            '''n''',
            SPIECE_UNDERLINE + '''in''',
            SPIECE_UNDERLINE + '''''',
            '''<unk>''',
            '''2''',
            '''0''',
            '''0''',
            '''0''',
            ''',''',
            SPIECE_UNDERLINE + '''and''',
            SPIECE_UNDERLINE + '''this''',
            SPIECE_UNDERLINE + '''is''',
            SPIECE_UNDERLINE + '''f''',
            '''al''',
            '''s''',
            '''<unk>''',
            '''.''',
        ]	,				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''




    if not self.test_slow_tokenizer:
       # as we don't have a slow version, we can't compare the outputs between slow and fast versions
       return

    __lowerCamelCase													=    (self.rust_tokenizer_class, "hf-internal-testing/tiny-random-mbart", {})
    for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
       with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""				):
          __lowerCamelCase													=    self.rust_tokenizer_class.from_pretrained(A_	,				**A_				)
          __lowerCamelCase													=    self.tokenizer_class.from_pretrained(A_	,				**A_				)

          __lowerCamelCase													=    tempfile.mkdtemp()

          __lowerCamelCase													=    tokenizer_r.save_pretrained(A_				)
          __lowerCamelCase													=    tokenizer_p.save_pretrained(A_				)

          # Checks it save with the same files + the tokenizer.json file for the fast one
          self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files				)				)
          __lowerCamelCase													=    tuple(f for f in tokenizer_r_files if '''tokenizer.json''' not in f				)
          self.assertSequenceEqual(A_	,				A_				)

          # Checks everything loads correctly in the same way
          __lowerCamelCase													=    tokenizer_r.from_pretrained(A_				)
          __lowerCamelCase													=    tokenizer_p.from_pretrained(A_				)

          # Check special tokens are set accordingly on Rust and Python
          for key in tokenizer_pp.special_tokens_map:
             self.assertTrue(hasattr(A_	,				A_				)				)
             # self.assertEqual(getattr(tokenizer_rp, key), getattr(tokenizer_pp, key))
             # self.assertEqual(getattr(tokenizer_rp, key + "_id"), getattr(tokenizer_pp, key + "_id"))

          shutil.rmtree(A_				)

          # Save tokenizer rust, legacy_format=True
          __lowerCamelCase													=    tempfile.mkdtemp()

          __lowerCamelCase													=    tokenizer_r.save_pretrained(A_	,				legacy_format=A_				)
          __lowerCamelCase													=    tokenizer_p.save_pretrained(A_				)

          # Checks it save with the same files
          self.assertSequenceEqual(A_	,				A_				)

          # Checks everything loads correctly in the same way
          __lowerCamelCase													=    tokenizer_r.from_pretrained(A_				)
          __lowerCamelCase													=    tokenizer_p.from_pretrained(A_				)

          # Check special tokens are set accordingly on Rust and Python
          for key in tokenizer_pp.special_tokens_map:
             self.assertTrue(hasattr(A_	,				A_				)				)

          shutil.rmtree(A_				)

          # Save tokenizer rust, legacy_format=False
          __lowerCamelCase													=    tempfile.mkdtemp()

          __lowerCamelCase													=    tokenizer_r.save_pretrained(A_	,				legacy_format=A_				)
          __lowerCamelCase													=    tokenizer_p.save_pretrained(A_				)

          # Checks it saved the tokenizer.json file
          self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files				)				)

          # Checks everything loads correctly in the same way
          __lowerCamelCase													=    tokenizer_r.from_pretrained(A_				)
          __lowerCamelCase													=    tokenizer_p.from_pretrained(A_				)

          # Check special tokens are set accordingly on Rust and Python
          for key in tokenizer_pp.special_tokens_map:
             self.assertTrue(hasattr(A_	,				A_				)				)

          shutil.rmtree(A_				)



@require_torch
@require_sentencepiece
@require_tokenizers
class  __lowerCAmelCase     (	unittest.TestCase   ):
 lowerCAmelCase__       					=  'facebook/mbart-large-en-ro'
 lowerCAmelCase__       					=  [
     ' UN Chief Says There Is No Military Solution in Syria',
     ' Secretary-General Ban Ki-moon says his response to Russia\'s stepped up military support for Syria is that "there is no military solution" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.',
 ]
 lowerCAmelCase__       					=  [
     'Şeful ONU declară că nu există o soluţie militară în Siria',
     'Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei'
     ' pentru Siria este că "nu există o soluţie militară" la conflictul de aproape cinci ani şi că noi arme nu vor'
     ' face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.',
 ]
 lowerCAmelCase__       					=  [8_2_7_4, 1_2_7_8_7_3, 2_5_9_1_6, 7, 8_6_2_2, 2_0_7_1, 4_3_8, 6_7_4_8_5, 5_3, 1_8_7_8_9_5, 2_3, 5_1_7_1_2, 2, EN_CODE]




 @classmethod
 def        lowerCamelCase      (						cls				):



    '''simple docstring'''
    __lowerCamelCase													=    MBartTokenizer.from_pretrained(
        cls.checkpoint_name	,				src_lang='''en_XX'''	,				tgt_lang='''ro_RO'''				)
    __lowerCamelCase													=    1
    return cls




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ar_AR''']	,				250001				)
    self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''en_EN''']	,				250004				)
    self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ro_RO''']	,				250020				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer.batch_encode_plus(self.src_text				).input_ids[0]
    self.assertListEqual(self.expected_src_tokens	,				A_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.assertIn(A_	,				self.tokenizer.all_special_ids				)
    __lowerCamelCase													=    [RO_CODE, 884, 9019, 96, 9, 916, 86792, 36, 18743, 15596, 5, 2]
    __lowerCamelCase													=    self.tokenizer.decode(A_	,				skip_special_tokens=A_				)
    __lowerCamelCase													=    self.tokenizer.decode(generated_ids[1:]	,				skip_special_tokens=A_				)
    self.assertEqual(A_	,				A_				)
    self.assertNotIn(self.tokenizer.eos_token	,				A_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    ["this is gunna be a long sentence " * 20]
    assert isinstance(src_text[0]	,				A_				)
    __lowerCamelCase													=    10
    __lowerCamelCase													=    self.tokenizer(A_	,				max_length=A_	,				truncation=A_				).input_ids[0]
    self.assertEqual(ids[-2]	,				2				)
    self.assertEqual(ids[-1]	,				A_				)
    self.assertEqual(len(A_				)	,				A_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['''<mask>''', '''ar_AR''']				)	,				[250026, 250001]				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    tempfile.mkdtemp()
    __lowerCamelCase													=    self.tokenizer.fairseq_tokens_to_ids
    self.tokenizer.save_pretrained(A_				)
    __lowerCamelCase													=    MBartTokenizer.from_pretrained(A_				)
    self.assertDictEqual(new_tok.fairseq_tokens_to_ids	,				A_				)




 @require_torch
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer(self.src_text	,				text_target=self.tgt_text	,				padding=A_	,				return_tensors='''pt'''				)
    __lowerCamelCase													=    shift_tokens_right(batch['''labels''']	,				self.tokenizer.pad_token_id				)

    # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
    assert batch.input_ids[1][-2:].tolist() == [2, EN_CODE]
    assert batch.decoder_input_ids[1][0].tolist() == RO_CODE
    assert batch.decoder_input_ids[1][-1] == 2
    assert batch.labels[1][-2:].tolist() == [2, RO_CODE]




 @require_torch
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer(
        self.src_text	,				text_target=self.tgt_text	,				padding=A_	,				truncation=A_	,				max_length=len(self.expected_src_tokens				)	,				return_tensors='''pt'''	,				)

    __lowerCamelCase													=    shift_tokens_right(batch['''labels''']	,				self.tokenizer.pad_token_id				)

    self.assertIsInstance(A_	,				A_				)

    self.assertEqual((2, 14)	,				batch.input_ids.shape				)
    self.assertEqual((2, 14)	,				batch.attention_mask.shape				)
    __lowerCamelCase													=    batch.input_ids.tolist()[0]
    self.assertListEqual(self.expected_src_tokens	,				A_				)
    self.assertEqual(2	,				batch.decoder_input_ids[0, -1]				)  # EOS
    # Test that special tokens are reset
    self.assertEqual(self.tokenizer.prefix_tokens	,				[]				)
    self.assertEqual(self.tokenizer.suffix_tokens	,				[self.tokenizer.eos_token_id, EN_CODE]				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer(self.src_text	,				padding=A_	,				truncation=A_	,				max_length=3	,				return_tensors='''pt'''				)
    __lowerCamelCase													=    self.tokenizer(
        text_target=self.tgt_text	,				padding=A_	,				truncation=A_	,				max_length=10	,				return_tensors='''pt'''				)
    __lowerCamelCase													=    targets["input_ids"]
    __lowerCamelCase													=    shift_tokens_right(A_	,				self.tokenizer.pad_token_id				)

    self.assertEqual(batch.input_ids.shape[1]	,				3				)
    self.assertEqual(batch.decoder_input_ids.shape[1]	,				10				)




 @require_torch
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer._build_translation_inputs(
        '''A test'''	,				return_tensors='''pt'''	,				src_lang='''en_XX'''	,				tgt_lang='''ar_AR'''				)

    self.assertEqual(
        nested_simplify(A_				)	,				{
            # A, test, EOS, en_XX
            '''input_ids''': [[62, 3034, 2, 250004]],
            '''attention_mask''': [[1, 1, 1, 1]],
            # ar_AR
            '''forced_bos_token_id''': 250001,
        }	,				)











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  __lowerCAmelCase     :




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase=13	,				__UpperCAmelCase=7	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=99	,				__UpperCAmelCase=[1, 1, 2]	,				__UpperCAmelCase=1	,				__UpperCAmelCase=32	,				__UpperCAmelCase=4	,				__UpperCAmelCase=8	,				__UpperCAmelCase=37	,				__UpperCAmelCase="gelu_new"	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=512	,				__UpperCAmelCase=3	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=3	,				__UpperCAmelCase=4	,				__UpperCAmelCase=None	,				__UpperCAmelCase=False	,				):



    '''simple docstring'''
    __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        lowerCamelCase      (						self				):



    '''simple docstring'''
    __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        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)

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

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

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

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




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelBaseModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)

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

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

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

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




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForPreTraining(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForMaskedLM(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.vocab_size)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_labels
    __lowerCamelCase													=    TFFunnelForSequenceClassification(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_labels)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_choices
    __lowerCamelCase													=    TFFunnelForMultipleChoice(config=__UpperCAmelCase				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				1				)	,				(1, self.num_choices, 1)				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				1				)	,				(1, self.num_choices, 1)				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				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(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_choices)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_labels
    __lowerCamelCase													=    TFFunnelForTokenClassification(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.num_labels)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForQuestionAnswering(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    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        lowerCamelCase      (						self				):



    '''simple docstring'''
    __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  __lowerCAmelCase     (	lowerCAmelCase__  ,	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  (
     (
         TFFunnelModel,
         TFFunnelForMaskedLM,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForTokenClassification,
     )
     if is_tf_available()
     else ()
 )
 lowerCAmelCase__       					=  (
     {
         """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__       					=  False
 lowerCAmelCase__       					=  False




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModelTester(self				)
    __lowerCamelCase													=    ConfigTester(self	,				config_class=__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.config_tester.run_common_tests()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase				)



@require_tf
class  __lowerCAmelCase     (	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  (
     (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
 )
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModelTester(self	,				base=__UpperCAmelCase				)
    __lowerCamelCase													=    ConfigTester(self	,				config_class=__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.config_tester.run_common_tests()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_base_model(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase				)






