'''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		,						__A		,						__A=13		,						__A=7		,						__A=True		,						__A=True		,						__A=True		,						__A=True		,						__A=99		,						__A=[1, 1, 2]		,						__A=1		,						__A=32		,						__A=4		,						__A=8		,						__A=37		,						__A="gelu_new"		,						__A=0.1		,						__A=0.1		,						__A=0.0		,						__A=512		,						__A=3		,						__A=0.02		,						__A=3		,						__A=4		,						__A=None		,						__A=False		,						) ->     str:
								_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 		UpperCamelCase__       (   self				) ->     str:
								_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 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Optional[Any]:
								_lowerCAmelCase										=TFFunnelModel(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)

								_lowerCAmelCase										=[input_ids, input_mask]
								_lowerCAmelCase										=model(__A				)

								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.last_hidden_state.shape		,						(self.batch_size, self.seq_length, self.d_model)				)

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

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






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Any:
								_lowerCAmelCase										=TFFunnelBaseModel(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)

								_lowerCAmelCase										=[input_ids, input_mask]
								_lowerCAmelCase										=model(__A				)

								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.last_hidden_state.shape		,						(self.batch_size, 2, self.d_model)				)

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

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






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Optional[int]:
								_lowerCAmelCase										=TFFunnelForPreTraining(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.seq_length)				)






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Union[str, Any]:
								_lowerCAmelCase										=TFFunnelForMaskedLM(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.seq_length, self.vocab_size)				)






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Any:
								_lowerCAmelCase										=self.num_labels
								_lowerCAmelCase										=TFFunnelForSequenceClassification(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.num_labels)				)






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Tuple:
								_lowerCAmelCase										=self.num_choices
								_lowerCAmelCase										=TFFunnelForMultipleChoice(config=__A				)
								_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						1				)		,						(1, self.num_choices, 1)				)
								_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						1				)		,						(1, self.num_choices, 1)				)
								_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						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(__A				)
								self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.num_choices)				)






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Tuple:
								_lowerCAmelCase										=self.num_labels
								_lowerCAmelCase										=TFFunnelForTokenClassification(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)
								self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.seq_length, self.num_labels)				)






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						) ->     Tuple:
								_lowerCAmelCase										=TFFunnelForQuestionAnswering(config=__A				)
								_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								_lowerCAmelCase										=model(__A				)
								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 		UpperCamelCase__       (   self				) ->     int:
								_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   SCREAMING_SNAKE_CASE			(						__lowercase    ,			__lowercase    ,			unittest.TestCase):







		"""simple docstring"""
		lowercase   :      Tuple       =							(
		    (
		        TFFunnelModel,
		        TFFunnelForMaskedLM,
		        TFFunnelForPreTraining,
		        TFFunnelForQuestionAnswering,
		        TFFunnelForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		lowercase   :      Union[str, Any]       =							(
		    {
		        'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
		        'fill-mask': TFFunnelForMaskedLM,
		        'question-answering': TFFunnelForQuestionAnswering,
		        'text-classification': TFFunnelForSequenceClassification,
		        'token-classification': TFFunnelForTokenClassification,
		        'zero-shot': TFFunnelForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		lowercase   :      Tuple       =							False
		lowercase   :      Union[str, Any]       =							False






		def 		UpperCamelCase__       (   self				) ->     Dict:
								_lowerCAmelCase										=TFFunnelModelTester(self				)
								_lowerCAmelCase										=ConfigTester(self		,						config_class=__A				)






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






		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__A				)






		def 		UpperCamelCase__       (   self				) ->     List[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*__A				)






		def 		UpperCamelCase__       (   self				) ->     str:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*__A				)






		def 		UpperCamelCase__       (   self				) ->     List[str]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*__A				)






		def 		UpperCamelCase__       (   self				) ->     str:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*__A				)

@require_tf
class   SCREAMING_SNAKE_CASE			(						__lowercase    ,			unittest.TestCase):







		"""simple docstring"""
		lowercase   :      Tuple       =							(
		    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
		)
		lowercase   :      List[Any]       =							False
		lowercase   :      Optional[Any]       =							False






		def 		UpperCamelCase__       (   self				) ->     Optional[int]:
								_lowerCAmelCase										=TFFunnelModelTester(self		,						base=__A				)
								_lowerCAmelCase										=ConfigTester(self		,						config_class=__A				)






		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								self.config_tester.run_common_tests()






		def 		UpperCamelCase__       (   self				) ->     int:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_base_model(*__A				)






		def 		UpperCamelCase__       (   self				) ->     List[str]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*__A				)






		def 		UpperCamelCase__       (   self				) ->     List[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*__A				)






'''simple docstring'''

import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


lowercase_     		= logging.get_logger(__name__)

lowercase_     		= {'''vocab_file''': '''vocab.txt'''}

lowercase_     		= {
    '''vocab_file''': {
        '''YituTech/conv-bert-base''': '''https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt''',
        '''YituTech/conv-bert-medium-small''': (
            '''https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'''
        ),
        '''YituTech/conv-bert-small''': '''https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt''',
    }
}

lowercase_     		= {
    '''YituTech/conv-bert-base''': 512,
    '''YituTech/conv-bert-medium-small''': 512,
    '''YituTech/conv-bert-small''': 512,
}


lowercase_     		= {
    '''YituTech/conv-bert-base''': {'''do_lower_case''': True},
    '''YituTech/conv-bert-medium-small''': {'''do_lower_case''': True},
    '''YituTech/conv-bert-small''': {'''do_lower_case''': True},
}
class   SCREAMING_SNAKE_CASE			(						__lowercase):







		"""simple docstring"""
		lowercase   :      Union[str, Any]       =							VOCAB_FILES_NAMES
		lowercase   :      Tuple       =							PRETRAINED_VOCAB_FILES_MAP
		lowercase   :      Optional[int]       =							PRETRAINED_INIT_CONFIGURATION
		lowercase   :      int       =							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		lowercase   :      List[str]       =							ConvBertTokenizer






		def __init__(   self		,						__A=None		,						__A=None		,						__A=True		,						__A="[UNK]"		,						__A="[SEP]"		,						__A="[PAD]"		,						__A="[CLS]"		,						__A="[MASK]"		,						__A=True		,						__A=None		,						**__A		,						) ->     Union[str, Any]:
								super().__init__(
								    __A		,						tokenizer_file=__A		,						do_lower_case=__A		,						unk_token=__A		,						sep_token=__A		,						pad_token=__A		,						cls_token=__A		,						mask_token=__A		,						tokenize_chinese_chars=__A		,						strip_accents=__A		,						**__A		,						)

								_lowerCAmelCase										=json.loads(self.backend_tokenizer.normalizer.__getstate__()				)
								if (
								    normalizer_state.get('lowercase'		,						__A				) != do_lower_case
								    or normalizer_state.get('strip_accents'		,						__A				) != strip_accents
								    or normalizer_state.get('handle_chinese_chars'		,						__A				) != tokenize_chinese_chars
								):
														_lowerCAmelCase										=getattr(__A		,						normalizer_state.pop('type'				)				)
														_lowerCAmelCase										=do_lower_case
														_lowerCAmelCase										=strip_accents
														_lowerCAmelCase										=tokenize_chinese_chars
														_lowerCAmelCase										=normalizer_class(**__A				)

								_lowerCAmelCase										=do_lower_case






		def 		UpperCamelCase__       (   self		,						__A		,						__A=None				) ->     int:
								_lowerCAmelCase										=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

								if token_ids_a:
														output += token_ids_a + [self.sep_token_id]

								return output






		def 		UpperCamelCase__       (   self		,						__A		,						__A = None				) ->     List[int]:
								_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				) * [0] + len(token_ids_a + sep				) * [1]






		def 		UpperCamelCase__       (   self		,						__A		,						__A = None				) ->     Tuple[str]:
								_lowerCAmelCase										=self._tokenizer.model.save(__A		,						name=__A				)
								return tuple(__A				)





