



"""simple docstring"""






import pickle

import numpy as np
from matplotlib import pyplot as plt

class 	__SCREAMING_SNAKE_CASE     :


					'''simple docstring'''





					def __init__(	self							:  Optional[Any],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  str,  lowerCamelCase							:  str,  lowerCamelCase							:  Union[str, Any]=0.2,  lowerCamelCase							:  Union[str, Any]=0.2					)-> List[Any]:
								lowerCamelCase__		:		str		     =bp_numa
								lowerCamelCase__		:		Union[str, Any]		     =bp_numa
								lowerCamelCase__		:		Optional[int]		     =bp_numa
								lowerCamelCase__		:		List[str]		     =conva_get[:2]
								lowerCamelCase__		:		Dict		     =conva_get[2]
								lowerCamelCase__		:		Tuple		     =size_pa
								lowerCamelCase__		:		Dict		     =rate_w
								lowerCamelCase__		:		List[Any]		     =rate_t
								lowerCamelCase__		:		List[str]		     =[
								    np.mat(-1 * np.random.rand(self.conva[0],  self.conva[0]					) + 0.5					)
								    for i in range(self.conva[1]					)
								]
								lowerCamelCase__		:		Optional[int]		     =np.mat(-1 * np.random.rand(self.num_bpa,  self.num_bpa					) + 0.5					)
								lowerCamelCase__		:		Union[str, Any]		     =np.mat(-1 * np.random.rand(self.num_bpa,  self.num_bpa					) + 0.5					)
								lowerCamelCase__		:		Union[str, Any]		     =-2 * np.random.rand(self.conva[1]					) + 1
								lowerCamelCase__		:		int		     =-2 * np.random.rand(self.num_bpa					) + 1
								lowerCamelCase__		:		Tuple		     =-2 * np.random.rand(self.num_bpa					) + 1



					def 		snake_case	(	self							:  Tuple,  lowerCamelCase							:  Union[str, Any]					)-> str:
								# save model dict with pickle
								lowerCamelCase__		:		Any		     ={
								    '''num_bp1''': self.num_bpa,
								    '''num_bp2''': self.num_bpa,
								    '''num_bp3''': self.num_bpa,
								    '''conv1''': self.conva,
								    '''step_conv1''': self.step_conva,
								    '''size_pooling1''': self.size_poolinga,
								    '''rate_weight''': self.rate_weight,
								    '''rate_thre''': self.rate_thre,
								    '''w_conv1''': self.w_conva,
								    '''wkj''': self.wkj,
								    '''vji''': self.vji,
								    '''thre_conv1''': self.thre_conva,
								    '''thre_bp2''': self.thre_bpa,
								    '''thre_bp3''': self.thre_bpa,
								}
								with open(lowerCamelCase,  '''wb'''					) as f:
											pickle.dump(lowerCamelCase,  lowerCamelCase					)

								print(F'''Model saved： {save_path}'''					)



					@classmethod
					def 		snake_case	(	cls							:  Union[str, Any],  lowerCamelCase							:  Optional[Any]					)-> Union[str, Any]:
								# read saved model
								with open(lowerCamelCase,  '''rb'''					) as f:
											lowerCamelCase__		:		List[Any]		     =pickle.load(lowerCamelCase					)  # noqa: S301

								lowerCamelCase__		:		Any		     =model_dic.get('''conv1'''					)
								conv_get.append(model_dic.get('''step_conv1'''					)					)
								lowerCamelCase__		:		Optional[Any]		     =model_dic.get('''size_pooling1'''					)
								lowerCamelCase__		:		Optional[Any]		     =model_dic.get('''num_bp1'''					)
								lowerCamelCase__		:		List[str]		     =model_dic.get('''num_bp2'''					)
								lowerCamelCase__		:		Any		     =model_dic.get('''num_bp3'''					)
								lowerCamelCase__		:		Any		     =model_dic.get('''rate_weight'''					)
								lowerCamelCase__		:		List[Any]		     =model_dic.get('''rate_thre'''					)
								# create model instance
								lowerCamelCase__		:		Optional[Any]		     =CNN(lowerCamelCase,  lowerCamelCase,  lowerCamelCase,  lowerCamelCase,  lowerCamelCase,  lowerCamelCase,  lowerCamelCase					)
								# modify model parameter
								lowerCamelCase__		:		Tuple		     =model_dic.get('''w_conv1'''					)
								lowerCamelCase__		:		Dict		     =model_dic.get('''wkj'''					)
								lowerCamelCase__		:		List[str]		     =model_dic.get('''vji'''					)
								lowerCamelCase__		:		str		     =model_dic.get('''thre_conv1'''					)
								lowerCamelCase__		:		List[Any]		     =model_dic.get('''thre_bp2'''					)
								lowerCamelCase__		:		Dict		     =model_dic.get('''thre_bp3'''					)
								return conv_ins



					def 		snake_case	(	self							:  Union[str, Any],  lowerCamelCase							:  Any					)-> List[str]:
								return 1 / (1 + np.exp(-1 * x					))



					def 		snake_case	(	self							:  Tuple,  lowerCamelCase							:  List[str]					)-> List[Any]:
								return round(lowerCamelCase,  3					)



					def 		snake_case	(	self							:  Dict,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Any,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Union[str, Any]					)-> List[str]:
								# convolution process
								lowerCamelCase__		:		List[str]		     =convs[0]
								lowerCamelCase__		:		int		     =convs[1]
								lowerCamelCase__		:		List[str]		     =np.shape(lowerCamelCase					)[0]
								# get the data slice of original image data, data_focus
								lowerCamelCase__		:		List[Any]		     =[]
								for i_focus in range(0,  size_data - size_conv + 1,  lowerCamelCase					):
											for j_focus in range(0,  size_data - size_conv + 1,  lowerCamelCase					):
														lowerCamelCase__		:		Union[str, Any]		     =data[
														    i_focus : i_focus + size_conv, j_focus : j_focus + size_conv
														]
														data_focus.append(lowerCamelCase					)
        # calculate the feature map of every single kernel, and saved as list of matrix
								lowerCamelCase__		:		str		     =[]
								lowerCamelCase__		:		Tuple		     =int((size_data - size_conv) / conv_step + 1					)
								for i_map in range(lowerCamelCase					):
											lowerCamelCase__		:		Tuple		     =[]
											for i_focus in range(len(lowerCamelCase					)					):
														lowerCamelCase__		:		Dict		     =(
														    np.sum(np.multiply(data_focus[i_focus],  w_convs[i_map]					)					)
														    - thre_convs[i_map]
														)
														featuremap.append(self.sig(lowerCamelCase					)					)
											lowerCamelCase__		:		int		     =np.asmatrix(lowerCamelCase					).reshape(
											    lowerCamelCase,  lowerCamelCase					)
											data_featuremap.append(lowerCamelCase					)

								# expanding the data slice to One dimenssion
								lowerCamelCase__		:		Optional[int]		     =[]
								for each_focus in data_focus:
											focusa_list.extend(self.Expand_Mat(lowerCamelCase					)					)
								lowerCamelCase__		:		Union[str, Any]		     =np.asarray(lowerCamelCase					)
								return focus_list, data_featuremap



					def 		snake_case	(	self							:  Union[str, Any],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Optional[Any]="average_pool"					)-> List[Any]:
								# pooling process
								lowerCamelCase__		:		List[Any]		     =len(featuremaps[0]					)
								lowerCamelCase__		:		Dict		     =int(size_map / size_pooling					)
								lowerCamelCase__		:		int		     =[]
								for i_map in range(len(lowerCamelCase					)					):
											lowerCamelCase__		:		List[str]		     =featuremaps[i_map]
											lowerCamelCase__		:		int		     =[]
											for i_focus in range(0,  lowerCamelCase,  lowerCamelCase					):
														for j_focus in range(0,  lowerCamelCase,  lowerCamelCase					):
																	lowerCamelCase__		:		int		     =feature_map[
																	    i_focus : i_focus + size_pooling,
																	    j_focus : j_focus + size_pooling,
																	]
																	if pooling_type == "average_pool":
																				# average pooling
																				map_pooled.append(np.average(lowerCamelCase					)					)
																	elif pooling_type == "max_pooling":
																				# max pooling
																				map_pooled.append(np.max(lowerCamelCase					)					)
											lowerCamelCase__		:		Optional[int]		     =np.asmatrix(lowerCamelCase					).reshape(lowerCamelCase,  lowerCamelCase					)
											featuremap_pooled.append(lowerCamelCase					)
								return featuremap_pooled



					def 		snake_case	(	self							:  str,  lowerCamelCase							:  Optional[Any]					)-> Optional[int]:
								# expanding three dimension data to one dimension list
								lowerCamelCase__		:		List[str]		     =[]
								for i in range(len(lowerCamelCase					)					):
											lowerCamelCase__		:		List[str]		     =np.shape(data[i]					)
											lowerCamelCase__		:		int		     =data[i].reshape(1,  shapes[0] * shapes[1]					)
											lowerCamelCase__		:		Optional[Any]		     =data_listed.getA().tolist()[0]
											data_expanded.extend(lowerCamelCase					)
								lowerCamelCase__		:		Optional[int]		     =np.asarray(lowerCamelCase					)
								return data_expanded



					def 		snake_case	(	self							:  List[Any],  lowerCamelCase							:  int					)-> Union[str, Any]:
								# expanding matrix to one dimension list
								lowerCamelCase__		:		Dict		     =np.asarray(lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     =np.shape(lowerCamelCase					)
								lowerCamelCase__		:		Dict		     =data_mat.reshape(1,  shapes[0] * shapes[1]					)
								return data_expanded



					def 		snake_case	(	self							:  List[Any],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  List[str],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Optional[Any]					)-> Union[str, Any]:
								lowerCamelCase__		:		Optional[int]		     =[]
								lowerCamelCase__		:		Dict		     =0
								for i_map in range(lowerCamelCase					):
											lowerCamelCase__		:		Union[str, Any]		     =np.ones((size_map, size_map)					)
											for i in range(0,  lowerCamelCase,  lowerCamelCase					):
														for j in range(0,  lowerCamelCase,  lowerCamelCase					):
																	lowerCamelCase__		:		List[Any]		     =pd_pool[
																	    i_pool
																	]
																	lowerCamelCase__		:		List[str]		     =i_pool + 1
											lowerCamelCase__		:		str		     =np.multiply(
											    lowerCamelCase,  np.multiply(out_map[i_map],  (1 - out_map[i_map])					)					)
											pd_all.append(lowerCamelCase					)
								return pd_all



					def 		snake_case	(	self							:  List[str],  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Any,  lowerCamelCase							:  Dict,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Dict,  lowerCamelCase							:  List[Any]=bool					)-> Any:
								# model traning
								print('''----------------------Start Training-------------------------'''					)
								print((''' - - Shape: Train_Data  ''', np.shape(lowerCamelCase					))					)
								print((''' - - Shape: Teach_Data  ''', np.shape(lowerCamelCase					))					)
								lowerCamelCase__		:		List[Any]		     =0
								lowerCamelCase__		:		Optional[Any]		     =[]
								lowerCamelCase__		:		Dict		     =1_0000
								while rp < n_repeat and mse >= error_accuracy:
											lowerCamelCase__		:		Tuple		     =0
											print(F'''-------------Learning Time {rp}--------------'''					)
											for p in range(len(lowerCamelCase					)					):
														# print('------------Learning Image: %d--------------'%p)
														lowerCamelCase__		:		int		     =np.asmatrix(datas_train[p]					)
														lowerCamelCase__		:		Optional[Any]		     =np.asarray(datas_teach[p]					)
														lowerCamelCase__     ,       lowerCamelCase__		:		Optional[Any]		     =self.convolute(
														    lowerCamelCase,  self.conva,  self.w_conva,  self.thre_conva,  conv_step=self.step_conva,  )
														lowerCamelCase__		:		Optional[int]		     =self.pooling(lowerCamelCase,  self.size_poolinga					)
														lowerCamelCase__		:		Optional[Any]		     =np.shape(lowerCamelCase					)
														lowerCamelCase__		:		Optional[int]		     =self._expand(lowerCamelCase					)
														lowerCamelCase__		:		Optional[int]		     =data_bp_input

														lowerCamelCase__		:		List[str]		     =np.dot(lowerCamelCase,  self.vji.T					) - self.thre_bpa
														lowerCamelCase__		:		str		     =self.sig(lowerCamelCase					)
														lowerCamelCase__		:		int		     =np.dot(lowerCamelCase,  self.wkj.T					) - self.thre_bpa
														lowerCamelCase__		:		List[str]		     =self.sig(lowerCamelCase					)

														# --------------Model Leaning ------------------------
														# calculate error and gradient---------------
														lowerCamelCase__		:		Optional[int]		     =np.multiply(
														    (data_teach - bp_outa),  np.multiply(lowerCamelCase,  (1 - bp_outa)					)					)
														lowerCamelCase__		:		Optional[Any]		     =np.multiply(
														    np.dot(lowerCamelCase,  self.wkj					),  np.multiply(lowerCamelCase,  (1 - bp_outa)					)					)
														lowerCamelCase__		:		int		     =np.dot(lowerCamelCase,  self.vji					)

														lowerCamelCase__		:		int		     =pd_i_all / (self.size_poolinga * self.size_poolinga)
														lowerCamelCase__		:		Optional[int]		     =pd_conva_pooled.T.getA().tolist()
														lowerCamelCase__		:		int		     =self._calculate_gradient_from_pool(
														    lowerCamelCase,  lowerCamelCase,  shape_featuremapa[0],  shape_featuremapa[1],  self.size_poolinga,  )
														# weight and threshold learning process---------
														# convolution layer
														for k_conv in range(self.conva[1]					):
																	lowerCamelCase__		:		Optional[Any]		     =self._expand_mat(pd_conva_all[k_conv]					)
																	lowerCamelCase__		:		List[Any]		     =self.rate_weight * np.dot(lowerCamelCase,  lowerCamelCase					)

																	lowerCamelCase__		:		Dict		     =self.w_conva[k_conv] + delta_w.reshape(
																	    (self.conva[0], self.conva[0])					)

																	lowerCamelCase__		:		Optional[int]		     =(
																	    self.thre_conva[k_conv]
																	    - np.sum(pd_conva_all[k_conv]					) * self.rate_thre
																	)
														# all connected layer
														lowerCamelCase__		:		int		     =self.wkj + pd_k_all.T * bp_outa * self.rate_weight
														lowerCamelCase__		:		Dict		     =self.vji + pd_j_all.T * bp_outa * self.rate_weight
														lowerCamelCase__		:		List[str]		     =self.thre_bpa - pd_k_all * self.rate_thre
														lowerCamelCase__		:		int		     =self.thre_bpa - pd_j_all * self.rate_thre
														# calculate the sum error of all single image
														lowerCamelCase__		:		Tuple		     =np.sum(abs(data_teach - bp_outa					)					)
														error_count += errors
														# print('   ----Teach      ',data_teach)
														# print('   ----BP_output  ',bp_out3)
											lowerCamelCase__		:		Optional[int]		     =rp + 1
											lowerCamelCase__		:		Tuple		     =error_count / patterns
											all_mse.append(lowerCamelCase					)

								def draw_error():
											lowerCamelCase__		:		List[str]		     =[error_accuracy for i in range(int(n_repeat * 1.2					)					)]
											plt.plot(lowerCamelCase,  '''+-'''					)
											plt.plot(lowerCamelCase,  '''r--'''					)
											plt.xlabel('''Learning Times'''					)
											plt.ylabel('''All_mse'''					)
											plt.grid(lowerCamelCase,  alpha=0.5					)
											plt.show()

								print('''------------------Training Complished---------------------'''					)
								print((''' - - Training epoch: ''', rp, F'''     - - Mse: {mse:.6f}''')					)
								if draw_e:
											draw_error()
								return mse



					def 		snake_case	(	self							:  Tuple,  lowerCamelCase							:  Any					)-> Any:
								# model predict
								lowerCamelCase__		:		int		     =[]
								print('''-------------------Start Testing-------------------------'''					)
								print((''' - - Shape: Test_Data  ''', np.shape(lowerCamelCase					))					)
								for p in range(len(lowerCamelCase					)					):
											lowerCamelCase__		:		Any		     =np.asmatrix(datas_test[p]					)
											lowerCamelCase__     ,       lowerCamelCase__		:		int		     =self.convolute(
											    lowerCamelCase,  self.conva,  self.w_conva,  self.thre_conva,  conv_step=self.step_conva,  )
											lowerCamelCase__		:		List[Any]		     =self.pooling(lowerCamelCase,  self.size_poolinga					)
											lowerCamelCase__		:		Tuple		     =self._expand(lowerCamelCase					)

											lowerCamelCase__		:		Any		     =data_bp_input
											lowerCamelCase__		:		Tuple		     =bp_outa * self.vji.T - self.thre_bpa
											lowerCamelCase__		:		str		     =self.sig(lowerCamelCase					)
											lowerCamelCase__		:		Union[str, Any]		     =bp_outa * self.wkj.T - self.thre_bpa
											lowerCamelCase__		:		Any		     =self.sig(lowerCamelCase					)
											produce_out.extend(bp_outa.getA().tolist()					)
								lowerCamelCase__		:		str		     =[list(map(self.do_round,  lowerCamelCase					)					) for each in produce_out]
								return np.asarray(lowerCamelCase					)




					def 		snake_case	(	self							:  str,  lowerCamelCase							:  List[str]					)-> List[Any]:
								# return the data of image after convoluting process so we can check it out
								lowerCamelCase__		:		Tuple		     =np.asmatrix(lowerCamelCase					)
								lowerCamelCase__     ,       lowerCamelCase__		:		List[str]		     =self.convolute(
								    lowerCamelCase,  self.conva,  self.w_conva,  self.thre_conva,  conv_step=self.step_conva,  )
								lowerCamelCase__		:		int		     =self.pooling(lowerCamelCase,  self.size_poolinga					)

								return data_conveda, data_pooleda


if __name__ == "__main__":
		pass









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


					'''simple docstring'''





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

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



					def 		snake_case	(	self							:  int					)-> List[Any]:
								lowerCamelCase__		:		Dict		     =ids_tensor([self.batch_size, self.seq_length],  self.vocab_size					)

								lowerCamelCase__		:		Union[str, Any]		     =None
								if self.use_input_mask:
											lowerCamelCase__		:		Any		     =random_attention_mask([self.batch_size, self.seq_length]					)

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

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

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

								lowerCamelCase__		:		Optional[Any]		     =[input_ids, input_mask]
								lowerCamelCase__		:		List[Any]		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Any		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)

								lowerCamelCase__		:		int		     =False
								lowerCamelCase__		:		Any		     =TFFunnelModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)

								lowerCamelCase__		:		Dict		     =False
								lowerCamelCase__		:		Optional[int]		     =TFFunnelModel(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)



					def 		snake_case	(	self							:  Tuple,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Dict,  )-> Optional[Any]:
								lowerCamelCase__		:		List[str]		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Union[str, Any]		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Tuple		     =[input_ids, input_mask]
								lowerCamelCase__		:		Any		     =model(lowerCamelCase					)

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

								lowerCamelCase__		:		List[Any]		     =False
								lowerCamelCase__		:		Dict		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		int		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, 3, self.d_model)					)

								lowerCamelCase__		:		Union[str, Any]		     =False
								lowerCamelCase__		:		Optional[Any]		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, 2, self.d_model)					)



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



					def 		snake_case	(	self							:  str,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  str,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  int,  )-> List[Any]:
								lowerCamelCase__		:		Union[str, Any]		     =TFFunnelForMaskedLM(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		List[Any]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.vocab_size)					)



					def 		snake_case	(	self							:  Optional[int],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Any,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  Dict,  )-> Union[str, Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.num_labels
								lowerCamelCase__		:		Tuple		     =TFFunnelForSequenceClassification(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		List[str]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.num_labels)					)



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



					def 		snake_case	(	self							:  str,  lowerCamelCase							:  Dict,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Any,  lowerCamelCase							:  str,  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Dict,  )-> Optional[int]:
								lowerCamelCase__		:		Optional[Any]		     =self.num_labels
								lowerCamelCase__		:		Optional[Any]		     =TFFunnelForTokenClassification(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Union[str, Any]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.num_labels)					)



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





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


					'''simple docstring'''





					_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							:  str					)-> Tuple:
								lowerCamelCase__		:		Any		     =TFFunnelModelTester(self					)
								lowerCamelCase__		:		Any		     =ConfigTester(self,  config_class=lowerCamelCase					)



					def 		snake_case	(	self							:  List[str]					)-> Tuple:
								self.config_tester.run_common_tests()



					def 		snake_case	(	self							:  str					)-> List[Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*lowerCamelCase					)



					def 		snake_case	(	self							:  str					)-> Dict:
								lowerCamelCase__		:		int		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*lowerCamelCase					)



					def 		snake_case	(	self							:  int					)-> List[Any]:
								lowerCamelCase__		:		Tuple		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase					)



					def 		snake_case	(	self							:  Dict					)-> Any:
								lowerCamelCase__		:		str		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*lowerCamelCase					)




					def 		snake_case	(	self							:  Tuple					)-> Optional[Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*lowerCamelCase					)





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


					'''simple docstring'''





					_a             =							(
					    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
					)
					_a             =							False
					_a             =							False



					def 		snake_case	(	self							:  int					)-> Tuple:
								lowerCamelCase__		:		Union[str, Any]		     =TFFunnelModelTester(self,  base=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     =ConfigTester(self,  config_class=lowerCamelCase					)



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



					def 		snake_case	(	self							:  Optional[Any]					)-> Optional[Any]:
								lowerCamelCase__		:		Any		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_base_model(*lowerCamelCase					)



					def 		snake_case	(	self							:  Union[str, Any]					)-> int:
								lowerCamelCase__		:		Tuple		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase					)




					def 		snake_case	(	self							:  List[str]					)-> Optional[int]:
								lowerCamelCase__		:		List[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase					)




