
"""simple docstring"""







import pickle
import shutil
import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, XLMRobertaTokenizer, XLMRobertaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


__A   :  List[Any]					=      get_tests_dir('fixtures/test_sentencepiece.model')




@require_sentencepiece
@require_tokenizers
class       lowerCAmelCase__       (			lowerCAmelCase_  ,			unittest.TestCase    ):


				"""simple docstring"""





				__UpperCAmelCase :     Tuple       =      XLMRobertaTokenizer
				__UpperCAmelCase :     Union[str, Any]       =      XLMRobertaTokenizerFast
				__UpperCAmelCase :     Optional[int]       =      True
				__UpperCAmelCase :     Any       =      True



				def       snake_case    (     self					:	List[Any]						):
						super().setUp()

						# We have a SentencePiece fixture for testing
						__lowercase				:		Dict												=				XLMRobertaTokenizer(lowercase__    ,   keep_accents=lowercase__						)
						tokenizer.save_pretrained(self.tmpdirname						)



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		Tuple												=				"<pad>"
						__lowercase				:		Optional[Any]												=				1

						self.assertEqual(self.get_tokenizer()._convert_token_to_id(lowercase__						)    ,   lowercase__						)
						self.assertEqual(self.get_tokenizer()._convert_id_to_token(lowercase__						)    ,   lowercase__						)



				def       snake_case    (     self					:	Optional[Any]						):
						__lowercase				:		List[str]												=				list(self.get_tokenizer().get_vocab().keys()						)

						self.assertEqual(vocab_keys[0]    ,   "<s>"						)
						self.assertEqual(vocab_keys[1]    ,   "<pad>"						)
						self.assertEqual(vocab_keys[-1]    ,   "<mask>"						)
						self.assertEqual(len(lowercase__						)    ,   1_0_0_2						)



				def       snake_case    (     self					:	str						):
						self.assertEqual(self.get_tokenizer().vocab_size    ,   1_0_0_2						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Tuple												=				XLMRobertaTokenizer(lowercase__    ,   keep_accents=lowercase__						)

						__lowercase				:		Dict												=				tokenizer.tokenize("This is a test"						)
						self.assertListEqual(lowercase__    ,   ["▁This", "▁is", "▁a", "▁t", "est"]						)

						self.assertListEqual(
						    tokenizer.convert_tokens_to_ids(lowercase__						)    ,   [value + tokenizer.fairseq_offset for value in [2_8_5, 4_6, 1_0, 1_7_0, 3_8_2]]    ,   )

						__lowercase				:		str												=				tokenizer.tokenize("I was born in 92000, and this is falsé."						)
						self.assertListEqual(
						    lowercase__    ,   [
						        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",
						        "é",
						        ".",
						    ]    ,   )
						__lowercase				:		List[str]												=				tokenizer.convert_tokens_to_ids(lowercase__						)
						self.assertListEqual(
						    lowercase__    ,   [
						        value + tokenizer.fairseq_offset
						        for value in [8, 2_1, 8_4, 5_5, 2_4, 1_9, 7, 2, 6_0_2, 3_4_7, 3_4_7, 3_4_7, 3, 1_2, 6_6, 4_6, 7_2, 8_0, 6, 2, 4]
						        #                                       ^ unk: 2 + 1 = 3                  unk: 2 + 1 = 3 ^
						    ]    ,   )

						__lowercase				:		Dict												=				tokenizer.convert_ids_to_tokens(lowercase__						)
						self.assertListEqual(
						    lowercase__    ,   [
						        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       snake_case    (     self					:	Dict						):
						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

						__lowercase				:		List[str]												=				(self.rust_tokenizer_class, "hf-internal-testing/tiny-xlm-roberta", {})
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
								with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'						):
										__lowercase				:		int												=				self.rust_tokenizer_class.from_pretrained(lowercase__    ,   **lowercase__						)
										__lowercase				:		List[Any]												=				self.tokenizer_class.from_pretrained(lowercase__    ,   **lowercase__						)

										__lowercase				:		Optional[Any]												=				tempfile.mkdtemp()

										__lowercase				:		Union[str, Any]												=				tokenizer_r.save_pretrained(lowercase__						)
										__lowercase				:		int												=				tokenizer_p.save_pretrained(lowercase__						)

										# 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						)						)
										__lowercase				:		Tuple												=				tuple(f for f in tokenizer_r_files if "tokenizer.json" not in f						)
										self.assertSequenceEqual(lowercase__    ,   lowercase__						)

										# Checks everything loads correctly in the same way
										__lowercase				:		List[Any]												=				tokenizer_r.from_pretrained(lowercase__						)
										__lowercase				:		Tuple												=				tokenizer_p.from_pretrained(lowercase__						)

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

										shutil.rmtree(lowercase__						)

										# Save tokenizer rust, legacy_format=True
										__lowercase				:		List[str]												=				tempfile.mkdtemp()

										__lowercase				:		Union[str, Any]												=				tokenizer_r.save_pretrained(lowercase__    ,   legacy_format=lowercase__						)
										__lowercase				:		Tuple												=				tokenizer_p.save_pretrained(lowercase__						)

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

										# Checks everything loads correctly in the same way
										__lowercase				:		List[str]												=				tokenizer_r.from_pretrained(lowercase__						)
										__lowercase				:		Dict												=				tokenizer_p.from_pretrained(lowercase__						)

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

										shutil.rmtree(lowercase__						)

										# Save tokenizer rust, legacy_format=False
										__lowercase				:		Dict												=				tempfile.mkdtemp()

										__lowercase				:		str												=				tokenizer_r.save_pretrained(lowercase__    ,   legacy_format=lowercase__						)
										__lowercase				:		List[str]												=				tokenizer_p.save_pretrained(lowercase__						)

										# 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
										__lowercase				:		Dict												=				tokenizer_r.from_pretrained(lowercase__						)
										__lowercase				:		Any												=				tokenizer_p.from_pretrained(lowercase__						)

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

										shutil.rmtree(lowercase__						)



				@cached_property
				def       snake_case    (     self					:	int						):
						return XLMRobertaTokenizer.from_pretrained("xlm-roberta-base"						)



				def       snake_case    (     self					:	List[Any]						):
						with tempfile.NamedTemporaryFile() as f:
								shutil.copyfile(lowercase__    ,   f.name						)
								__lowercase				:		Dict												=				XLMRobertaTokenizer(f.name    ,   keep_accents=lowercase__						)
								__lowercase				:		Dict												=				pickle.dumps(lowercase__						)
						pickle.loads(lowercase__						)



				def       snake_case    (     self					:	Tuple						):
						if not self.test_rust_tokenizer:
								return

						__lowercase				:		Union[str, Any]												=				self.get_tokenizer()
						__lowercase				:		Optional[int]												=				self.get_rust_tokenizer()

						__lowercase				:		Tuple												=				"I was born in 92000, and this is falsé."

						__lowercase				:		Dict												=				tokenizer.tokenize(lowercase__						)
						__lowercase				:		str												=				rust_tokenizer.tokenize(lowercase__						)
						self.assertListEqual(lowercase__    ,   lowercase__						)

						__lowercase				:		List[Any]												=				tokenizer.encode(lowercase__    ,   add_special_tokens=lowercase__						)
						__lowercase				:		Optional[Any]												=				rust_tokenizer.encode(lowercase__    ,   add_special_tokens=lowercase__						)
						self.assertListEqual(lowercase__    ,   lowercase__						)

						__lowercase				:		List[Any]												=				self.get_rust_tokenizer()
						__lowercase				:		Optional[Any]												=				tokenizer.encode(lowercase__						)
						__lowercase				:		Tuple												=				rust_tokenizer.encode(lowercase__						)
						self.assertListEqual(lowercase__    ,   lowercase__						)



				@slow
				def       snake_case    (     self					:	Optional[Any]						):
						__lowercase				:		List[Any]												=				"Hello World!"
						__lowercase				:		Any												=				[0, 3_5_3_7_8, 6_6_6_1, 3_8, 2]
						# xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')  # xlmr.large has same tokenizer
						# xlmr.eval()
						# xlmr.encode(symbols)

						self.assertListEqual(lowercase__    ,   self.big_tokenizer.encode(lowercase__						)						)



				@slow
				def       snake_case    (     self					:	Any						):
						__lowercase				:		Optional[Any]												=				(
						    "This is a very long text with a lot of weird characters, such as: . , ~ ? ( ) \" [ ] ! : - . Also we will"
						    " add words that should not exsist and be tokenized to <unk>, such as saoneuhaoesuth"
						)
						__lowercase				:		List[str]												=				[
						    0,
						    3_2_9_3,
						    8_3,
						    1_0,
						    4_5_5_2,
						    4_9_8_9,
						    7_9_8_6,
						    6_7_8,
						    1_0,
						    5_9_1_5,
						    1_1_1,
						    1_7_9_4_5_9,
						    1_2_4_8_5_0,
						    4,
						    6_0_4_4,
						    2_3_7,
						    1_2,
						    6,
						    5,
						    6,
						    4,
						    6_7_8_0,
						    7_0_5,
						    1_5,
						    1_3_8_8,
						    4_4,
						    3_7_8,
						    1_0_1_1_4,
						    7_1_1,
						    1_5_2,
						    2_0,
						    6,
						    5,
						    2_2_3_7_6,
						    6_4_2,
						    1_2_2_1,
						    1_5_1_9_0,
						    3_4_1_5_3,
						    4_5_0,
						    5_6_0_8,
						    9_5_9,
						    1_1_1_9,
						    5_7_7_0_2,
						    1_3_6,
						    1_8_6,
						    4_7,
						    1_0_9_8,
						    2_9_3_6_7,
						    4_7,
						    # 4426, # What fairseq tokenizes from "<unk>": "_<"
						    # 3678, # What fairseq tokenizes from "<unk>": "unk"
						    # 2740, # What fairseq tokenizes from "<unk>": ">"
						    3,  # What we tokenize from "<unk>": "<unk>"
						    6,  # Residue from the tokenization: an extra sentencepiece underline
						    4,
						    6_0_4_4,
						    2_3_7,
						    6_2_8_4,
						    5_0_9_0_1,
						    5_2_8,
						    3_1,
						    9_0,
						    3_4,
						    9_2_7,
						    2,
						]
						# xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')  # xlmr.large has same tokenizer
						# xlmr.eval()
						# xlmr.encode(symbols)

						self.assertListEqual(lowercase__    ,   self.big_tokenizer.encode(lowercase__						)						)



				@slow
				def       snake_case    (     self					:	List[Any]						):
						# fmt: off
						__lowercase				:		Any												=				{"input_ids": [[0, 1_1_0_6_2, 8_2_7_7_2, 7, 1_5, 8_2_7_7_2, 5_3_8, 5_1_5_2_9, 2_3_7, 1_7_1_9_8, 1_2_9_0, 2_0_6, 9, 2_1_5_1_7_5, 1_3_1_4, 1_3_6, 1_7_1_9_8, 1_2_9_0, 2_0_6, 9, 5_6_3_5_9, 4_2, 1_2_2_0_0_9, 9, 1_6_4_6_6, 1_6, 8_7_3_4_4, 4_5_3_7, 9, 4_7_1_7, 7_8_3_8_1, 6, 1_5_9_9_5_8, 7, 1_5, 2_4_4_8_0, 6_1_8, 4, 5_2_7, 2_2_6_9_3, 5_4_2_8, 4, 2_7_7_7, 2_4_4_8_0, 9_8_7_4, 4, 4_3_5_2_3, 5_9_4, 4, 8_0_3, 1_8_3_9_2, 3_3_1_8_9, 1_8, 4, 4_3_5_2_3, 2_4_4_4_7, 1_2_3_9_9, 1_0_0, 2_4_9_5_5, 8_3_6_5_8, 9_6_2_6, 1_4_4_0_5_7, 1_5, 8_3_9, 2_2_3_3_5, 1_6, 1_3_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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
						# fmt: on

						self.tokenizer_integration_test_util(
						    expected_encoding=lowercase__    ,   model_name="xlm-roberta-base"    ,   revision="d9d8a8ea5eb94b1c6654ae9249df7793cd2933d3"    ,   )






"""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       lowerCAmelCase__       :


				"""simple docstring"""





				def __init__(     self					:	Optional[Any]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	int=1_3    ,   lowercase__					:	Optional[int]=7    ,   lowercase__					:	Any=True    ,   lowercase__					:	int=True    ,   lowercase__					:	List[Any]=True    ,   lowercase__					:	Union[str, Any]=True    ,   lowercase__					:	Any=9_9    ,   lowercase__					:	Tuple=[1, 1, 2]    ,   lowercase__					:	str=1    ,   lowercase__					:	Union[str, Any]=3_2    ,   lowercase__					:	int=4    ,   lowercase__					:	Dict=8    ,   lowercase__					:	Tuple=3_7    ,   lowercase__					:	int="gelu_new"    ,   lowercase__					:	Tuple=0.1    ,   lowercase__					:	int=0.1    ,   lowercase__					:	Dict=0.0    ,   lowercase__					:	int=5_1_2    ,   lowercase__					:	str=3    ,   lowercase__					:	List[Any]=0.0_2    ,   lowercase__					:	Any=3    ,   lowercase__					:	Union[str, Any]=4    ,   lowercase__					:	Tuple=None    ,   lowercase__					:	List[Any]=False    ,   ):
						__lowercase				:		Any												=				parent
						__lowercase				:		Tuple												=				batch_size
						__lowercase				:		Union[str, Any]												=				seq_length
						__lowercase				:		List[Any]												=				is_training
						__lowercase				:		Tuple												=				use_input_mask
						__lowercase				:		Optional[int]												=				use_token_type_ids
						__lowercase				:		List[Any]												=				use_labels
						__lowercase				:		Any												=				vocab_size
						__lowercase				:		Union[str, Any]												=				block_sizes
						__lowercase				:		Optional[Any]												=				num_decoder_layers
						__lowercase				:		str												=				d_model
						__lowercase				:		Tuple												=				n_head
						__lowercase				:		Any												=				d_head
						__lowercase				:		Dict												=				d_inner
						__lowercase				:		Optional[Any]												=				hidden_act
						__lowercase				:		int												=				hidden_dropout
						__lowercase				:		int												=				attention_dropout
						__lowercase				:		Tuple												=				activation_dropout
						__lowercase				:		int												=				max_position_embeddings
						__lowercase				:		Optional[Any]												=				type_vocab_size
						__lowercase				:		Union[str, Any]												=				2
						__lowercase				:		Optional[int]												=				num_labels
						__lowercase				:		List[str]												=				num_choices
						__lowercase				:		List[Any]												=				scope
						__lowercase				:		List[str]												=				initializer_std

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



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Any												=				ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size						)

						__lowercase				:		Optional[int]												=				None
						if self.use_input_mask:
								__lowercase				:		Optional[int]												=				random_attention_mask([self.batch_size, self.seq_length]						)

						__lowercase				:		List[str]												=				None
						if self.use_token_type_ids:
								__lowercase				:		List[Any]												=				ids_tensor([self.batch_size, self.seq_length]    ,   self.type_vocab_size						)

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

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

						__lowercase				:		Optional[Any]												=				[input_ids, input_mask]
						__lowercase				:		int												=				model(lowercase__						)

						__lowercase				:		Tuple												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)						)

						__lowercase				:		int												=				False
						__lowercase				:		int												=				TFFunnelModel(config=lowercase__						)
						__lowercase				:		List[str]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)						)

						__lowercase				:		str												=				False
						__lowercase				:		int												=				TFFunnelModel(config=lowercase__						)
						__lowercase				:		Dict												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, self.seq_length, self.d_model)						)



				def       snake_case    (     self					:	Union[str, Any]    ,   lowercase__					:	List[Any]    ,   lowercase__					:	Union[str, Any]    ,   lowercase__					:	Optional[int]    ,   lowercase__					:	int    ,   lowercase__					:	str    ,   lowercase__					:	Dict    ,   lowercase__					:	Union[str, Any]    ,   ):
						__lowercase				:		List[str]												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		int												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		List[Any]												=				model(lowercase__						)

						__lowercase				:		List[Any]												=				[input_ids, input_mask]
						__lowercase				:		Optional[int]												=				model(lowercase__						)

						__lowercase				:		Optional[Any]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 2, self.d_model)						)

						__lowercase				:		Any												=				False
						__lowercase				:		Any												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		Union[str, Any]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 3, self.d_model)						)

						__lowercase				:		List[Any]												=				False
						__lowercase				:		Optional[int]												=				TFFunnelBaseModel(config=lowercase__						)
						__lowercase				:		Optional[int]												=				model(lowercase__						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,   (self.batch_size, 2, self.d_model)						)



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



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



				def       snake_case    (     self					:	Union[str, Any]    ,   lowercase__					:	str    ,   lowercase__					:	Any    ,   lowercase__					:	Any    ,   lowercase__					:	Union[str, Any]    ,   lowercase__					:	Dict    ,   lowercase__					:	int    ,   lowercase__					:	int    ,   ):
						__lowercase				:		str												=				self.num_labels
						__lowercase				:		List[Any]												=				TFFunnelForSequenceClassification(config=lowercase__						)
						__lowercase				:		Union[str, Any]												=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowercase				:		int												=				model(lowercase__						)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)						)



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



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



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


				"""simple docstring"""





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



				def       snake_case    (     self					:	Dict						):
						__lowercase				:		List[Any]												=				TFFunnelModelTester(self						)
						__lowercase				:		Tuple												=				ConfigTester(self    ,   config_class=lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						self.config_tester.run_common_tests()



				def       snake_case    (     self					:	Any						):
						__lowercase				:		Optional[int]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[int]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*lowercase__						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		List[str]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*lowercase__						)



				def       snake_case    (     self					:	Any						):
						__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*lowercase__						)



				def       snake_case    (     self					:	str						):
						__lowercase				:		Union[str, Any]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*lowercase__						)





@require_tf
class       lowerCAmelCase__       (			lowerCAmelCase_  ,			unittest.TestCase    ):


				"""simple docstring"""





				__UpperCAmelCase :     List[str]       =      (
				    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
				)
				__UpperCAmelCase :     str       =      False
				__UpperCAmelCase :     Optional[Any]       =      False



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[int]												=				TFFunnelModelTester(self    ,   base=lowercase__						)
						__lowercase				:		List[Any]												=				ConfigTester(self    ,   config_class=lowercase__						)



				def       snake_case    (     self					:	Union[str, Any]						):
						self.config_tester.run_common_tests()



				def       snake_case    (     self					:	List[str]						):
						__lowercase				:		Any												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*lowercase__						)



				def       snake_case    (     self					:	Union[str, Any]						):
						__lowercase				:		Tuple												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*lowercase__						)



				def       snake_case    (     self					:	List[Any]						):
						__lowercase				:		Optional[Any]												=				self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*lowercase__						)
