





'''simple docstring'''







import os
import unittest

from transformers import MobileBertTokenizer, MobileBertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english





@require_tokenizers
class        _UpperCAmelCase				(		_lowerCAmelCase      ,   unittest.TestCase  ):
		a  :  List[Any]      =MobileBertTokenizer
		a  :  Any      =MobileBertTokenizerFast
		a  :  Tuple      =True
		a  :  Dict      =True
		a  :  Optional[int]      =filter_non_english
		a  :  List[Any]      ="""google/mobilebert-uncased"""
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					super().setUp()

					__lowerCAmelCase   		=							[
					    """[UNK]""",
					    """[CLS]""",
					    """[SEP]""",
					    """[PAD]""",
					    """[MASK]""",
					    """want""",
					    """##want""",
					    """##ed""",
					    """wa""",
					    """un""",
					    """runn""",
					    """##ing""",
					    """,""",
					    """low""",
					    """lowest""",
					]
					__lowerCAmelCase   		=							os.path.join(self.tmpdirname,VOCAB_FILES_NAMES["""vocab_file"""]     )
					with open(self.vocab_file,"""w""",encoding="""utf-8"""     ) as vocab_writer:
								vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]     )     )

					__lowerCAmelCase   		=							[
					    (tokenizer_def[0], self.pre_trained_model_path, tokenizer_def[2])  # else the 'google/' prefix is stripped
					    for tokenizer_def in self.tokenizers_list
					]
		def     lowerCamelCase__     (    self,__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							"""UNwant\u00E9d,running"""
					__lowerCAmelCase   		=							"""unwanted, running"""
					return input_text, output_text
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							self.tokenizer_class(self.vocab_file     )

					__lowerCAmelCase   		=							tokenizer.tokenize("""UNwant\u00E9d,running"""     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]     )
					self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_     ),[9, 6, 7, 12, 10, 11]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					if not self.test_rust_tokenizer:
								return

					__lowerCAmelCase   		=							self.get_tokenizer()
					__lowerCAmelCase   		=							self.get_rust_tokenizer()

					__lowerCAmelCase   		=							"""UNwant\u00E9d,running"""

					__lowerCAmelCase   		=							tokenizer.tokenize(SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							tokenizer.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							self.get_rust_tokenizer()
					__lowerCAmelCase   		=							tokenizer.encode(SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.encode(SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					# With lower casing
					__lowerCAmelCase   		=							self.get_tokenizer(do_lower_case=SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							self.get_rust_tokenizer(do_lower_case=SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							"""UNwant\u00E9d,running"""

					__lowerCAmelCase   		=							tokenizer.tokenize(SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							tokenizer.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							self.get_rust_tokenizer()
					__lowerCAmelCase   		=							tokenizer.encode(SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							rust_tokenizer.encode(SCREAMING_SNAKE_CASE_     )
					self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer()

					self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""     ),["""ah""", """\u535A""", """\u63A8""", """zz"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """     ),["""hello""", """!""", """how""", """are""", """you""", """?"""]     )
					self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""     ),["""hello"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_,strip_accents=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """     ),["""hällo""", """!""", """how""", """are""", """you""", """?"""]     )
					self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""     ),["""h\u00E9llo"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_,strip_accents=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """     ),["""hallo""", """!""", """how""", """are""", """you""", """?"""]     )
					self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""     ),["""hello"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """     ),["""hallo""", """!""", """how""", """are""", """you""", """?"""]     )
					self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""     ),["""hello"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """     ),["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_,strip_accents=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """     ),["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_,strip_accents=SCREAMING_SNAKE_CASE_     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """     ),["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_,never_split=["""[UNK]"""]     )

					self.assertListEqual(
					    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""     ),["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

					__lowerCAmelCase   		=							{}
					for i, token in enumerate(SCREAMING_SNAKE_CASE_     ):
								__lowerCAmelCase   		=							i
					__lowerCAmelCase   		=							WordpieceTokenizer(vocab=SCREAMING_SNAKE_CASE_,unk_token="""[UNK]"""     )

					self.assertListEqual(tokenizer.tokenize(""""""     ),[]     )

					self.assertListEqual(tokenizer.tokenize("""unwanted running"""     ),["""un""", """##want""", """##ed""", """runn""", """##ing"""]     )

					self.assertListEqual(tokenizer.tokenize("""unwantedX running"""     ),["""[UNK]""", """runn""", """##ing"""]     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					self.assertTrue(_is_whitespace(""" """     )     )
					self.assertTrue(_is_whitespace("""\t"""     )     )
					self.assertTrue(_is_whitespace("""\r"""     )     )
					self.assertTrue(_is_whitespace("""\n"""     )     )
					self.assertTrue(_is_whitespace("""\u00A0"""     )     )

					self.assertFalse(_is_whitespace("""A"""     )     )
					self.assertFalse(_is_whitespace("""-"""     )     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					self.assertTrue(_is_control("""\u0005"""     )     )

					self.assertFalse(_is_control("""A"""     )     )
					self.assertFalse(_is_control(""" """     )     )
					self.assertFalse(_is_control("""\t"""     )     )
					self.assertFalse(_is_control("""\r"""     )     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					self.assertTrue(_is_punctuation("""-"""     )     )
					self.assertTrue(_is_punctuation("""$"""     )     )
					self.assertTrue(_is_punctuation("""`"""     )     )
					self.assertTrue(_is_punctuation("""."""     )     )

					self.assertFalse(_is_punctuation("""A"""     )     )
					self.assertFalse(_is_punctuation(""" """     )     )
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							self.get_tokenizer()
					__lowerCAmelCase   		=							self.get_rust_tokenizer()

					# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
					self.assertListEqual([tokenizer.tokenize(SCREAMING_SNAKE_CASE_     ) for t in ["""Test""", """\xad""", """test"""]],[["""[UNK]"""], [], ["""[UNK]"""]]     )

					self.assertListEqual(
					    [rust_tokenizer.tokenize(SCREAMING_SNAKE_CASE_     ) for t in ["""Test""", """\xad""", """test"""]],[["""[UNK]"""], [], ["""[UNK]"""]]     )
		@slow
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							self.tokenizer_class.from_pretrained("""google/mobilebert-uncased"""     )

					__lowerCAmelCase   		=							tokenizer.encode("""sequence builders""",add_special_tokens=SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							tokenizer.encode("""multi-sequence build""",add_special_tokens=SCREAMING_SNAKE_CASE_     )

					__lowerCAmelCase   		=							tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_     )
					__lowerCAmelCase   		=							tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

					assert encoded_sentence == [1_01] + text + [1_02]
					assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]
		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					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(SCREAMING_SNAKE_CASE_,**SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							f'A, naïve {tokenizer_r.mask_token} AllenNLP sentence.'
											__lowerCAmelCase   		=							tokenizer_r.encode_plus(
											    SCREAMING_SNAKE_CASE_,return_attention_mask=SCREAMING_SNAKE_CASE_,return_token_type_ids=SCREAMING_SNAKE_CASE_,return_offsets_mapping=SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_,)

											__lowerCAmelCase   		=							tokenizer_r.do_lower_case if hasattr(SCREAMING_SNAKE_CASE_,"""do_lower_case"""     ) else False
											__lowerCAmelCase   		=							(
											    [
											        ((0, 0), tokenizer_r.cls_token),
											        ((0, 1), """A"""),
											        ((1, 2), ""","""),
											        ((3, 5), """na"""),
											        ((5, 6), """##ï"""),
											        ((6, 8), """##ve"""),
											        ((9, 15), tokenizer_r.mask_token),
											        ((16, 21), """Allen"""),
											        ((21, 23), """##NL"""),
											        ((23, 24), """##P"""),
											        ((25, 33), """sentence"""),
											        ((33, 34), """."""),
											        ((0, 0), tokenizer_r.sep_token),
											    ]
											    if not do_lower_case
											    else [
											        ((0, 0), tokenizer_r.cls_token),
											        ((0, 1), """a"""),
											        ((1, 2), ""","""),
											        ((3, 8), """naive"""),
											        ((9, 15), tokenizer_r.mask_token),
											        ((16, 21), """allen"""),
											        ((21, 23), """##nl"""),
											        ((23, 24), """##p"""),
											        ((25, 33), """sentence"""),
											        ((33, 34), """."""),
											        ((0, 0), tokenizer_r.sep_token),
											    ]
											)

											self.assertEqual(
											    [e[1] for e in expected_results],tokenizer_r.convert_ids_to_tokens(tokens["""input_ids"""]     )     )
											self.assertEqual([e[0] for e in expected_results],tokens["""offset_mapping"""]     )







		def     lowerCamelCase__     (    self     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							["""的""", """人""", """有"""]
					__lowerCAmelCase   		=							"""""".join(SCREAMING_SNAKE_CASE_     )
					for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
								with self.subTest(f'{tokenizer.__class__.__name__} ({pretrained_name})'     ):
											__lowerCAmelCase   		=							True
											__lowerCAmelCase   		=							self.tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_,**SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							self.rust_tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_,**SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							tokenizer_p.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							tokenizer_r.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							tokenizer_r.convert_ids_to_tokens(SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							tokenizer_p.convert_ids_to_tokens(SCREAMING_SNAKE_CASE_     )

											# it is expected that each Chinese character is not preceded by "##"
											self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )
											self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							False
											__lowerCAmelCase   		=							self.rust_tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_,**SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							self.tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_,**SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							tokenizer_r.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							tokenizer_p.encode(SCREAMING_SNAKE_CASE_,add_special_tokens=SCREAMING_SNAKE_CASE_     )

											__lowerCAmelCase   		=							tokenizer_r.convert_ids_to_tokens(SCREAMING_SNAKE_CASE_     )
											__lowerCAmelCase   		=							tokenizer_p.convert_ids_to_tokens(SCREAMING_SNAKE_CASE_     )

											# it is expected that only the first Chinese character is not preceded by "##".
											__lowerCAmelCase   		=							[
											    f'##{token}' if idx != 0 else token for idx, token in enumerate(SCREAMING_SNAKE_CASE_     )
											]
											self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )
											self.assertListEqual(SCREAMING_SNAKE_CASE_,SCREAMING_SNAKE_CASE_     )






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

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

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

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Dict							      =     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size					)

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

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

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

						UpperCAmelCase_:		Dict							      =     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,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     [input_ids, input_mask]
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

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

						UpperCAmelCase_:		Optional[Any]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Any:
						UpperCAmelCase_:		Dict							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[int]							      =     [input_ids, input_mask]
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 2, self.d_model)					)

						UpperCAmelCase_:		List[str]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Any							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 3, self.d_model)					)

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

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelForPreTraining(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   str:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelForMaskedLM(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[str]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.vocab_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_labels
						UpperCAmelCase_:		Optional[int]							      =     TFFunnelForSequenceClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_choices
						UpperCAmelCase_:		List[str]							      =     TFFunnelForMultipleChoice(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Any							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Tuple							      =     {
						    """input_ids""": multiple_choice_inputs_ids,
						    """attention_mask""": multiple_choice_input_mask,
						    """token_type_ids""": multiple_choice_token_type_ids,
						}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_choices)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		List[Any]							      =     self.num_labels
						UpperCAmelCase_:		Dict							      =     TFFunnelForTokenClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.num_labels)					)

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







@require_tf
class 				_a				(   _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      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelModelTester(self					)
						UpperCAmelCase_:		List[str]							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Any:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		List[str]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Tuple							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   List[Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_					)







@require_tf
class 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelModelTester(self,   base=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_					)






