






import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_UpperCAmelCase			:		int   				=    logging.get_logger(__name__)


_UpperCAmelCase			:		List[Any]   				=    {"vocab_file": "vocab.json", "merges_file": "merges.txt"}

# See all BART models at https://huggingface.co/models?filter=bart
_UpperCAmelCase			:		Dict   				=    {
    "vocab_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/vocab.json",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/vocab.json",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json",
    },
    "merges_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/merges.txt",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/merges.txt",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt",
    },
}

_UpperCAmelCase			:		Tuple   				=    {
    "facebook/bart-base": 1_024,
    "facebook/bart-large": 1_024,
    "facebook/bart-large-mnli": 1_024,
    "facebook/bart-large-cnn": 1_024,
    "facebook/bart-large-xsum": 1_024,
    "yjernite/bart_eli5": 1_024,
}





@lru_cache()
def 	lowerCAmelCase_		()		->    Union[str, Any]:


				'''simple docstring'''




				lowerCAmelCase__      			=						(
				    list(range(ord('''!'''       )     ,					ord('''~'''       ) + 1       )       ) + list(range(ord('''¡'''       )     ,					ord('''¬'''       ) + 1       )       ) + list(range(ord('''®'''       )     ,					ord('''ÿ'''       ) + 1       )       )
				)
				lowerCAmelCase__      			=						bs[:]
				lowerCAmelCase__      			=						0
				for b in range(2**8       ):
								if b not in bs:
												bs.append(lowercase__       )
												cs.append(2**8 + n       )
												n += 1
				lowerCAmelCase__      			=						[chr(lowercase__       ) for n in cs]
				return dict(zip(lowercase__     ,					lowercase__       )       )





def 	lowerCAmelCase_		(lowercase__						:       Optional[int]       )		->    Optional[int]:


				'''simple docstring'''




				lowerCAmelCase__      			=						set()
				lowerCAmelCase__      			=						word[0]
				for char in word[1:]:
								pairs.add((prev_char, char)       )
								lowerCAmelCase__      			=						char
				return pairs




class  lowerCAmelCase_       (				snake_case__					):
							UpperCamelCase_		:List[str]		      =    VOCAB_FILES_NAMES
							UpperCamelCase_		:Union[str, Any]		      =    PRETRAINED_VOCAB_FILES_MAP
							UpperCamelCase_		:Union[str, Any]		      =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							UpperCamelCase_		:str		      =    ['input_ids', 'attention_mask']




							def __init__(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   int="replace" ,							SCREAMING_SNAKE_CASE_     :   Tuple="<s>" ,							SCREAMING_SNAKE_CASE_     :   Any="</s>" ,							SCREAMING_SNAKE_CASE_     :   List[Any]="</s>" ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]="<s>" ,							SCREAMING_SNAKE_CASE_     :   Any="<unk>" ,							SCREAMING_SNAKE_CASE_     :   int="<pad>" ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]="<mask>" ,							SCREAMING_SNAKE_CASE_     :   Tuple=False ,							**SCREAMING_SNAKE_CASE_     :   Dict ,							):
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else bos_token
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else eos_token
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else sep_token
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else cls_token
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else unk_token
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else pad_token

											# Mask token behave like a normal word, i.e. include the space before it
											lowerCAmelCase__      			=						AddedToken(SCREAMING_SNAKE_CASE_ ,							lstrip=SCREAMING_SNAKE_CASE_ ,							rstrip=SCREAMING_SNAKE_CASE_	) if isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) else mask_token

											super().__init__(
											    errors=SCREAMING_SNAKE_CASE_ ,							bos_token=SCREAMING_SNAKE_CASE_ ,							eos_token=SCREAMING_SNAKE_CASE_ ,							unk_token=SCREAMING_SNAKE_CASE_ ,							sep_token=SCREAMING_SNAKE_CASE_ ,							cls_token=SCREAMING_SNAKE_CASE_ ,							pad_token=SCREAMING_SNAKE_CASE_ ,							mask_token=SCREAMING_SNAKE_CASE_ ,							add_prefix_space=SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_ ,							)

											with open(SCREAMING_SNAKE_CASE_ ,							encoding='''utf-8'''	) as vocab_handle:
															lowerCAmelCase__      			=						json.load(SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{v: k for k, v in self.encoder.items()}
											lowerCAmelCase__      			=						errors  # how to handle errors in decoding
											lowerCAmelCase__      			=						bytes_to_unicode()
											lowerCAmelCase__      			=						{v: k for k, v in self.byte_encoder.items()}
											with open(SCREAMING_SNAKE_CASE_ ,							encoding='''utf-8'''	) as merges_handle:
															lowerCAmelCase__      			=						merges_handle.read().split('''\n'''	)[1:-1]
											lowerCAmelCase__      			=						[tuple(merge.split()	) for merge in bpe_merges]
											lowerCAmelCase__      			=						dict(zip(SCREAMING_SNAKE_CASE_ ,							range(len(SCREAMING_SNAKE_CASE_	)	)	)	)
											lowerCAmelCase__      			=						{}
											lowerCAmelCase__      			=						add_prefix_space

											# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
											lowerCAmelCase__      			=						re.compile(R'''\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'''	)




							@property
							def 						__snake_case					(   self     :   List[str]	):
											return len(self.encoder	)




							def 						__snake_case					(   self     :   Union[str, Any]	):
											return dict(self.encoder ,							**self.added_tokens_encoder	)




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Tuple	):
											if token in self.cache:
															return self.cache[token]
											lowerCAmelCase__      			=						tuple(SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						get_pairs(SCREAMING_SNAKE_CASE_	)

											if not pairs:
															return token

											while True:
															lowerCAmelCase__      			=						min(SCREAMING_SNAKE_CASE_ ,							key=lambda SCREAMING_SNAKE_CASE_	: self.bpe_ranks.get(SCREAMING_SNAKE_CASE_ ,							float('''inf'''	)	)	)
															if bigram not in self.bpe_ranks:
																			break
															lowerCAmelCase__			,		lowerCAmelCase__      			=						bigram
															lowerCAmelCase__      			=						[]
															lowerCAmelCase__      			=						0
															while i < len(SCREAMING_SNAKE_CASE_	):
																			try:
																							lowerCAmelCase__      			=						word.index(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
																			except ValueError:
																							new_word.extend(word[i:]	)
																							break
																			else:
																							new_word.extend(word[i:j]	)
																							lowerCAmelCase__      			=						j

																			if word[i] == first and i < len(SCREAMING_SNAKE_CASE_	) - 1 and word[i + 1] == second:
																							new_word.append(first + second	)
																							i += 2
																			else:
																							new_word.append(word[i]	)
																							i += 1
															lowerCAmelCase__      			=						tuple(SCREAMING_SNAKE_CASE_	)
															lowerCAmelCase__      			=						new_word
															if len(SCREAMING_SNAKE_CASE_	) == 1:
																			break
															else:
																			lowerCAmelCase__      			=						get_pairs(SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						''' '''.join(SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						word
											return word




							def 						__snake_case					(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Any	):
											lowerCAmelCase__      			=						[]
											for token in re.findall(self.pat ,							SCREAMING_SNAKE_CASE_	):
															lowerCAmelCase__      			=						''''''.join(
															    self.byte_encoder[b] for b in token.encode('''utf-8'''	)	)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
															bpe_tokens.extend(bpe_token for bpe_token in self.bpe(SCREAMING_SNAKE_CASE_	).split(''' '''	)	)
											return bpe_tokens




							def 						__snake_case					(   self     :   Any ,							SCREAMING_SNAKE_CASE_     :   List[Any]	):
											return self.encoder.get(SCREAMING_SNAKE_CASE_ ,							self.encoder.get(self.unk_token	)	)




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   str	):
											return self.decoder.get(SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Any ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]	):
											lowerCAmelCase__      			=						''''''.join(SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						bytearray([self.byte_decoder[c] for c in text]	).decode('''utf-8''' ,							errors=self.errors	)
											return text




							def 						__snake_case					(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   Optional[str] = None	):
											if not os.path.isdir(SCREAMING_SNAKE_CASE_	):
															logger.error(f'Vocabulary path ({save_directory}) should be a directory'	)
															return
											lowerCAmelCase__      			=						os.path.join(
											    SCREAMING_SNAKE_CASE_ ,							(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']	)
											lowerCAmelCase__      			=						os.path.join(
											    SCREAMING_SNAKE_CASE_ ,							(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''merges_file''']	)

											with open(SCREAMING_SNAKE_CASE_ ,							'''w''' ,							encoding='''utf-8'''	) as f:
															f.write(json.dumps(self.encoder ,							indent=2 ,							sort_keys=SCREAMING_SNAKE_CASE_ ,							ensure_ascii=SCREAMING_SNAKE_CASE_	) + '''\n'''	)

											lowerCAmelCase__      			=						0
											with open(SCREAMING_SNAKE_CASE_ ,							'''w''' ,							encoding='''utf-8'''	) as writer:
															writer.write('''#version: 0.2\n'''	)
															for bpe_tokens, token_index in sorted(self.bpe_ranks.items() ,							key=lambda SCREAMING_SNAKE_CASE_	: kv[1]	):
																			if index != token_index:
																							logger.warning(
																							    f'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
																							    ''' Please check that the tokenizer is not corrupted!'''	)
																							lowerCAmelCase__      			=						token_index
																			writer.write(''' '''.join(SCREAMING_SNAKE_CASE_	) + '''\n'''	)
																			index += 1

											return vocab_file, merge_file




							def 						__snake_case					(   self     :   int ,							SCREAMING_SNAKE_CASE_     :   List[int] ,							SCREAMING_SNAKE_CASE_     :   Optional[List[int]] = None	):
											if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
											lowerCAmelCase__      			=						[self.cls_token_id]
											lowerCAmelCase__      			=						[self.sep_token_id]
											return cls + token_ids_a + sep + sep + token_ids_a + sep




							def 						__snake_case					(   self     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   List[int] ,							SCREAMING_SNAKE_CASE_     :   Optional[List[int]] = None ,							SCREAMING_SNAKE_CASE_     :   bool = False	):
											if already_has_special_tokens:
															return super().get_special_tokens_mask(
															    token_ids_a=SCREAMING_SNAKE_CASE_ ,							token_ids_a=SCREAMING_SNAKE_CASE_ ,							already_has_special_tokens=SCREAMING_SNAKE_CASE_	)

											if token_ids_a is None:
															return [1] + ([0] * len(SCREAMING_SNAKE_CASE_	)) + [1]
											return [1] + ([0] * len(SCREAMING_SNAKE_CASE_	)) + [1, 1] + ([0] * len(SCREAMING_SNAKE_CASE_	)) + [1]




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   List[int] ,							SCREAMING_SNAKE_CASE_     :   Optional[List[int]] = None	):
											lowerCAmelCase__      			=						[self.sep_token_id]
											lowerCAmelCase__      			=						[self.cls_token_id]

											if token_ids_a is None:
															return len(cls + token_ids_a + sep	) * [0]
											return len(cls + token_ids_a + sep + sep + token_ids_a + sep	) * [0]




							def 						__snake_case					(   self     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=False ,							**SCREAMING_SNAKE_CASE_     :   Optional[int]	):
											lowerCAmelCase__      			=						kwargs.pop('''add_prefix_space''' ,							self.add_prefix_space	)
											if (is_split_into_words or add_prefix_space) and (len(SCREAMING_SNAKE_CASE_	) > 0 and not text[0].isspace()):
															lowerCAmelCase__      			=						''' ''' + text
											return (text, kwargs)













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

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




							def 						__snake_case					(   self     :   Optional[int]	):
											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 						__snake_case					(   self     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Dict ,							):
											lowerCAmelCase__      			=						TFFunnelModel(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)

											lowerCAmelCase__      			=						[input_ids, input_mask]
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)

											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)
											self.parent.assertEqual(result.last_hidden_state.shape ,							(self.batch_size, self.seq_length, self.d_model)	)

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

											lowerCAmelCase__      			=						False
											lowerCAmelCase__      			=						TFFunnelModel(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						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     :   Any ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							):
											lowerCAmelCase__      			=						TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)

											lowerCAmelCase__      			=						[input_ids, input_mask]
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)

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

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

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




							def 						__snake_case					(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Any ,							):
											lowerCAmelCase__      			=						TFFunnelForPreTraining(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)
											self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.seq_length)	)




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




							def 						__snake_case					(   self     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   Any ,							):
											lowerCAmelCase__      			=						self.num_labels
											lowerCAmelCase__      			=						TFFunnelForSequenceClassification(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)
											self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.num_labels)	)




							def 						__snake_case					(   self     :   int ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							):
											lowerCAmelCase__      			=						self.num_choices
											lowerCAmelCase__      			=						TFFunnelForMultipleChoice(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_ ,							1	) ,							(1, self.num_choices, 1)	)
											lowerCAmelCase__      			=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_ ,							1	) ,							(1, self.num_choices, 1)	)
											lowerCAmelCase__      			=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_ ,							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(SCREAMING_SNAKE_CASE_	)
											self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.num_choices)	)




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							):
											lowerCAmelCase__      			=						self.num_labels
											lowerCAmelCase__      			=						TFFunnelForTokenClassification(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						model(SCREAMING_SNAKE_CASE_	)
											self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.seq_length, self.num_labels)	)




							def 						__snake_case					(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Any ,							):
											lowerCAmelCase__      			=						TFFunnelForQuestionAnswering(config=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
											lowerCAmelCase__      			=						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     :   List[str]	):
											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_       (				snake_case__     ,    snake_case__     ,    unittest.TestCase					):
							UpperCamelCase_		:Dict		      =    (
							    (
							        TFFunnelModel,
							        TFFunnelForMaskedLM,
							        TFFunnelForPreTraining,
							        TFFunnelForQuestionAnswering,
							        TFFunnelForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							UpperCamelCase_		:Dict		      =    (
							    {
							        '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_		:Tuple		      =    False
							UpperCamelCase_		:Tuple		      =    False




							def 						__snake_case					(   self     :   str	):
											lowerCAmelCase__      			=						TFFunnelModelTester(self	)
											lowerCAmelCase__      			=						ConfigTester(self ,							config_class=SCREAMING_SNAKE_CASE_	)




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




							def 						__snake_case					(   self     :   Union[str, Any]	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Union[str, Any]	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   int	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   str	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Dict	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_	)



@require_tf
class  lowerCAmelCase_       (				snake_case__     ,    unittest.TestCase					):
							UpperCamelCase_		:Optional[Any]		      =    (
							    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
							)
							UpperCamelCase_		:int		      =    False
							UpperCamelCase_		:Any		      =    False




							def 						__snake_case					(   self     :   List[str]	):
											lowerCAmelCase__      			=						TFFunnelModelTester(self ,							base=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						ConfigTester(self ,							config_class=SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Tuple	):
											self.config_tester.run_common_tests()




							def 						__snake_case					(   self     :   Union[str, Any]	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   int	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   List[str]	):
											lowerCAmelCase__      			=						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_	)





