
import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    MobileBertForMaskedLM,
					    MobileBertForMultipleChoice,
					    MobileBertForNextSentencePrediction,
					    MobileBertForPreTraining,
					    MobileBertForQuestionAnswering,
					    MobileBertForSequenceClassification,
					    MobileBertForTokenClassification,
					    MobileBertModel,
					)





class 							UpperCAmelCase      :




	'''simple docstring'''





	def __init__(       self					: Union[str, Any]							,A					: Tuple							,A					: Union[str, Any]=13							,A					: List[Any]=7							,A					: List[Any]=True							,A					: List[str]=True							,A					: List[str]=True							,A					: Tuple=True							,A					: Optional[Any]=99							,A					: Union[str, Any]=64							,A					: str=32							,A					: int=5							,A					: Union[str, Any]=4							,A					: Union[str, Any]=37							,A					: List[Any]="gelu"							,A					: Any=0.1							,A					: Any=0.1							,A					: Any=5_12							,A					: Optional[Any]=16							,A					: int=2							,A					: Union[str, Any]=0.02							,A					: Any=3							,A					: Union[str, Any]=4							,A					: Union[str, Any]=None							,):
					__A   			= parent
					__A   			= batch_size
					__A   			= seq_length
					__A   			= is_training
					__A   			= use_input_mask
					__A   			= use_token_type_ids
					__A   			= use_labels
					__A   			= vocab_size
					__A   			= hidden_size
					__A   			= embedding_size
					__A   			= num_hidden_layers
					__A   			= num_attention_heads
					__A   			= intermediate_size
					__A   			= hidden_act
					__A   			= hidden_dropout_prob
					__A   			= attention_probs_dropout_prob
					__A   			= max_position_embeddings
					__A   			= type_vocab_size
					__A   			= type_sequence_label_size
					__A   			= initializer_range
					__A   			= num_labels
					__A   			= num_choices
					__A   			= scope






	def 				UpperCamelCase_  (       self					: Optional[int] ):
					__A   			= ids_tensor([self.batch_size, self.seq_length]							,self.vocab_size )

					__A   			= None
					if self.use_input_mask:
									__A   			= random_attention_mask([self.batch_size, self.seq_length] )

					__A   			= None
					if self.use_token_type_ids:
									__A   			= ids_tensor([self.batch_size, self.seq_length]							,self.type_vocab_size )

					__A   			= None
					__A   			= None
					__A   			= None
					if self.use_labels:
									__A   			= ids_tensor([self.batch_size]							,self.type_sequence_label_size )
									__A   			= ids_tensor([self.batch_size, self.seq_length]							,self.num_labels )
									__A   			= ids_tensor([self.batch_size]							,self.num_choices )

					__A   			= self.get_config()

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






	def 				UpperCamelCase_  (       self					: int ):
					return MobileBertConfig(
					    vocab_size=self.vocab_size							,hidden_size=self.hidden_size							,num_hidden_layers=self.num_hidden_layers							,num_attention_heads=self.num_attention_heads							,intermediate_size=self.intermediate_size							,embedding_size=self.embedding_size							,hidden_act=self.hidden_act							,hidden_dropout_prob=self.hidden_dropout_prob							,attention_probs_dropout_prob=self.attention_probs_dropout_prob							,max_position_embeddings=self.max_position_embeddings							,type_vocab_size=self.type_vocab_size							,is_decoder=A							,initializer_range=self.initializer_range							,)






	def 				UpperCamelCase_  (       self					: Dict							,A					: int							,A					: Tuple							,A					: Optional[int]							,A					: List[Any]							,A					: Optional[int]							,A					: Optional[int]							,A					: Optional[Any] ):
					__A   			= MobileBertModel(config=A )
					model.to(A )
					model.eval()
					__A   			= model(A							,attention_mask=A							,token_type_ids=A )
					__A   			= model(A							,token_type_ids=A )
					__A   			= model(A )

					self.parent.assertEqual(result.last_hidden_state.shape							,(self.batch_size, self.seq_length, self.hidden_size) )
					self.parent.assertEqual(result.pooler_output.shape							,(self.batch_size, self.hidden_size) )






	def 				UpperCamelCase_  (       self					: Tuple							,A					: Tuple							,A					: Union[str, Any]							,A					: Tuple							,A					: Union[str, Any]							,A					: Union[str, Any]							,A					: int							,A					: Optional[int] ):
					__A   			= MobileBertForMaskedLM(config=A )
					model.to(A )
					model.eval()
					__A   			= model(A							,attention_mask=A							,token_type_ids=A							,labels=A )
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.seq_length, self.vocab_size) )






	def 				UpperCamelCase_  (       self					: Optional[int]							,A					: str							,A					: Any							,A					: Optional[int]							,A					: Optional[Any]							,A					: List[Any]							,A					: Tuple							,A					: Dict ):
					__A   			= MobileBertForNextSentencePrediction(config=A )
					model.to(A )
					model.eval()
					__A   			= model(
					    A							,attention_mask=A							,token_type_ids=A							,labels=A							,)
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, 2) )






	def 				UpperCamelCase_  (       self					: str							,A					: Optional[Any]							,A					: Optional[int]							,A					: Optional[Any]							,A					: Tuple							,A					: List[str]							,A					: Optional[int]							,A					: Dict ):
					__A   			= MobileBertForPreTraining(config=A )
					model.to(A )
					model.eval()
					__A   			= model(
					    A							,attention_mask=A							,token_type_ids=A							,labels=A							,next_sentence_label=A							,)
					self.parent.assertEqual(result.prediction_logits.shape							,(self.batch_size, self.seq_length, self.vocab_size) )
					self.parent.assertEqual(result.seq_relationship_logits.shape							,(self.batch_size, 2) )






	def 				UpperCamelCase_  (       self					: Optional[Any]							,A					: Any							,A					: List[str]							,A					: List[str]							,A					: Optional[int]							,A					: Dict							,A					: Optional[int]							,A					: Any ):
					__A   			= MobileBertForQuestionAnswering(config=A )
					model.to(A )
					model.eval()
					__A   			= model(
					    A							,attention_mask=A							,token_type_ids=A							,start_positions=A							,end_positions=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					: str							,A					: int							,A					: Tuple							,A					: Optional[Any]							,A					: int							,A					: Union[str, Any]							,A					: List[Any]							,A					: Dict ):
					__A   			= self.num_labels
					__A   			= MobileBertForSequenceClassification(A )
					model.to(A )
					model.eval()
					__A   			= model(A							,attention_mask=A							,token_type_ids=A							,labels=A )
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels) )






	def 				UpperCamelCase_  (       self					: Optional[int]							,A					: Optional[Any]							,A					: List[str]							,A					: List[str]							,A					: Optional[int]							,A					: int							,A					: Any							,A					: Any ):
					__A   			= self.num_labels
					__A   			= MobileBertForTokenClassification(config=A )
					model.to(A )
					model.eval()
					__A   			= model(A							,attention_mask=A							,token_type_ids=A							,labels=A )
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.seq_length, self.num_labels) )






	def 				UpperCamelCase_  (       self					: int							,A					: Dict							,A					: List[str]							,A					: List[str]							,A					: List[Any]							,A					: Optional[Any]							,A					: str							,A					: Any ):
					__A   			= self.num_choices
					__A   			= MobileBertForMultipleChoice(config=A )
					model.to(A )
					model.eval()
					__A   			= input_ids.unsqueeze(1 ).expand(-1							,self.num_choices							,-1 ).contiguous()
					__A   			= token_type_ids.unsqueeze(1 ).expand(-1							,self.num_choices							,-1 ).contiguous()
					__A   			= input_mask.unsqueeze(1 ).expand(-1							,self.num_choices							,-1 ).contiguous()
					__A   			= model(
					    A							,attention_mask=A							,token_type_ids=A							,labels=A							,)
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_choices) )







	def 				UpperCamelCase_  (       self					: Any ):
					__A   			= self.prepare_config_and_inputs()
					(
					    (
					    __A 
					)			,							(
					    __A 
					)			,							(
					    __A 
					)			,							(
					    __A 
					)			,							(
					    __A 
					)			,							(
					    __A 
					)			,							(
					    __A 
					)			,							 
					)   			= config_and_inputs
					__A   			= {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
					return config, inputs_dict





@require_torch
class 							UpperCAmelCase      (  snake_case__			,			snake_case__			,			unittest.TestCase  ):




	'''simple docstring'''





	snake_case_					    =     (
	    (
	        MobileBertModel,
	        MobileBertForMaskedLM,
	        MobileBertForMultipleChoice,
	        MobileBertForNextSentencePrediction,
	        MobileBertForPreTraining,
	        MobileBertForQuestionAnswering,
	        MobileBertForSequenceClassification,
	        MobileBertForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	snake_case_					    =     (
	    {
	        "feature-extraction": MobileBertModel,
	        "fill-mask": MobileBertForMaskedLM,
	        "question-answering": MobileBertForQuestionAnswering,
	        "text-classification": MobileBertForSequenceClassification,
	        "token-classification": MobileBertForTokenClassification,
	        "zero-shot": MobileBertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	snake_case_					    =     True






	def 				UpperCamelCase_  (       self					: int							,A					: Dict							,A					: Optional[int]							,A					: int=False ):
					__A   			= super()._prepare_for_class(A							,A							,return_labels=A )

					if return_labels:
									if model_class in get_values(A ):
													__A   			= torch.zeros(
													    (self.model_tester.batch_size, self.model_tester.seq_length)							,dtype=torch.long							,device=A )
													__A   			= torch.zeros(
													    self.model_tester.batch_size							,dtype=torch.long							,device=A )
					return inputs_dict






	def 				UpperCamelCase_  (       self					: List[str] ):
					__A   			= MobileBertModelTester(self )
					__A   			= ConfigTester(self							,config_class=A							,hidden_size=37 )






	def 				UpperCamelCase_  (       self					: List[str] ):
					self.config_tester.run_common_tests()






	def 				UpperCamelCase_  (       self					: Optional[int] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_model(*A )






	def 				UpperCamelCase_  (       self					: List[Any] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_masked_lm(*A )






	def 				UpperCamelCase_  (       self					: int ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_multiple_choice(*A )






	def 				UpperCamelCase_  (       self					: List[Any] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*A )






	def 				UpperCamelCase_  (       self					: Any ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_pretraining(*A )






	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_question_answering(*A )






	def 				UpperCamelCase_  (       self					: Dict ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_sequence_classification(*A )







	def 				UpperCamelCase_  (       self					: Tuple ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_token_classification(*A )





def 						UpperCAmelCase			(	a_						)		->	Optional[Any]:







				"""simple docstring"""



				return torch.tensor(
				    __lowerCAmelCase		,   dtype=torch.long		,   device=__lowerCAmelCase		,   )


SCREAMING_SNAKE_CASE							:Union[str, Any]							 =				1E-3





@require_torch
@require_sentencepiece
@require_tokenizers
class 							UpperCAmelCase      (  unittest.TestCase  ):




	'''simple docstring'''





	@slow
	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					__A   			= MobileBertModel.from_pretrained("google/mobilebert-uncased" ).to(A )
					__A   			= _long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]] )
					with torch.no_grad():
									__A   			= model(A )[0]
					__A   			= torch.Size((1, 9, 5_12) )
					self.assertEqual(output.shape							,A )
					__A   			= torch.tensor(
					    [
					        [
					            [-2.4736526E07, 8.2691656E04, 1.6521838E05],
					            [-5.7541704E-01, 3.9056022E00, 4.4011507E00],
					            [2.6047359E00, 1.5677652E00, -1.7324188E-01],
					        ]
					    ]							,device=A							,)

					# MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
					# ~1 difference, it's therefore not a good idea to measure using addition.
					# Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
					# result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
					__A   			= torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE )
					__A   			= torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE )

					self.assertTrue(lower_bound and upper_bound )








import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    Pipeline,
    ZeroShotClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
_a      	=  {'''LayoutLMv2Config''', '''LayoutLMv3Config'''}





@is_pipeline_test
class __lowerCamelCase (      unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								=      MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
	UpperCamelCase__								=      TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

	if model_mapping is not None:
		UpperCamelCase__								=      {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
	if tf_model_mapping is not None:
		UpperCamelCase__								=      {
		    config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
		}

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase    ):
							"""simple docstring"""







							_UpperCAmelCase									=			ZeroShotClassificationPipeline(
							    model=UpperCAmelCase       ,    tokenizer=UpperCAmelCase       ,    candidate_labels=['polics', 'health']    )
							return classifier, ["Who are you voting for in 2020?", "My stomach hurts."]

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase    ):
							"""simple docstring"""







							_UpperCAmelCase									=			classifier('Who are you voting for in 2020?'       ,    candidate_labels='politics'    )
							self.assertEqual(UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    )]}    )

							# No kwarg
							_UpperCAmelCase									=			classifier('Who are you voting for in 2020?'       ,    ['politics']    )
							self.assertEqual(UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    )]}    )

							_UpperCAmelCase									=			classifier('Who are you voting for in 2020?'       ,    candidate_labels=['politics']    )
							self.assertEqual(UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    )]}    )

							_UpperCAmelCase									=			classifier('Who are you voting for in 2020?'       ,    candidate_labels='politics, public health'    )
							self.assertEqual(
							    UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )]}    )
							self.assertAlmostEqual(sum(nested_simplify(outputs['scores']    )    )       ,    1.0    )

							_UpperCAmelCase									=			classifier('Who are you voting for in 2020?'       ,    candidate_labels=['politics', 'public health']    )
							self.assertEqual(
							    UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )]}    )
							self.assertAlmostEqual(sum(nested_simplify(outputs['scores']    )    )       ,    1.0    )

							_UpperCAmelCase									=			classifier(
							    'Who are you voting for in 2020?'       ,    candidate_labels='politics'       ,    hypothesis_template='This text is about {}'    )
							self.assertEqual(UpperCAmelCase       ,    {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    )]}    )

							# https://github.com/huggingface/transformers/issues/13846
							_UpperCAmelCase									=			classifier(['I am happy']       ,    ['positive', 'negative']    )
							self.assertEqual(
							    UpperCAmelCase       ,    [
							        {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )]}
							        for i in range(1    )
							    ]       ,    )
							_UpperCAmelCase									=			classifier(['I am happy', 'I am sad']       ,    ['positive', 'negative']    )
							self.assertEqual(
							    UpperCAmelCase       ,    [
							        {'sequence': ANY(UpperCAmelCase    ), 'labels': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )], 'scores': [ANY(UpperCAmelCase    ), ANY(UpperCAmelCase    )]}
							        for i in range(2    )
							    ]       ,    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier(''       ,    candidate_labels='politics'    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier(UpperCAmelCase       ,    candidate_labels='politics'    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier('Who are you voting for in 2020?'       ,    candidate_labels=''    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier('Who are you voting for in 2020?'       ,    candidate_labels=UpperCAmelCase    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier(
													    'Who are you voting for in 2020?'       ,    candidate_labels='politics'       ,    hypothesis_template='Not formatting template'       ,    )

							with self.assertRaises(UpperCAmelCase    ):
													classifier(
													    'Who are you voting for in 2020?'       ,    candidate_labels='politics'       ,    hypothesis_template=UpperCAmelCase       ,    )

							self.run_entailment_id(UpperCAmelCase    )

	def        UpperCamelCase    (							self       ,    UpperCAmelCase    ):
							"""simple docstring"""







							_UpperCAmelCase									=			zero_shot_classifier.model.config
							_UpperCAmelCase									=			config.labelaid
							_UpperCAmelCase									=			zero_shot_classifier.entailment_id

							_UpperCAmelCase									=			{'LABEL_0': 0, 'LABEL_1': 1, 'LABEL_2': 2}
							self.assertEqual(zero_shot_classifier.entailment_id       ,    -1    )

							_UpperCAmelCase									=			{'entailment': 0, 'neutral': 1, 'contradiction': 2}
							self.assertEqual(zero_shot_classifier.entailment_id       ,    0    )

							_UpperCAmelCase									=			{'ENTAIL': 0, 'NON-ENTAIL': 1}
							self.assertEqual(zero_shot_classifier.entailment_id       ,    0    )

							_UpperCAmelCase									=			{'ENTAIL': 2, 'NEUTRAL': 1, 'CONTR': 0}
							self.assertEqual(zero_shot_classifier.entailment_id       ,    2    )

							_UpperCAmelCase									=			original_labelaid
							self.assertEqual(UpperCAmelCase       ,    zero_shot_classifier.entailment_id    )

	@require_torch
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			pipeline(
							    'zero-shot-classification'       ,    model='sshleifer/tiny-distilbert-base-cased-distilled-squad'       ,    framework='pt'       ,    )
							# There was a regression in 4.10 for this
							# Adding a test so we don't make the mistake again.
							# https://github.com/huggingface/transformers/issues/13381#issuecomment-912343499
							zero_shot_classifier(
							    'Who are you voting for in 2020?' * 100       ,    candidate_labels=['politics', 'public health', 'science']    )

	@require_torch
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			pipeline(
							    'zero-shot-classification'       ,    model='sshleifer/tiny-distilbert-base-cased-distilled-squad'       ,    framework='pt'       ,    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'Who are you voting for in 2020?'       ,    candidate_labels=['politics', 'public health', 'science']    )

							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': 'Who are you voting for in 2020?',
							        'labels': ['science', 'public health', 'politics'],
							        'scores': [0.3_33, 0.3_33, 0.3_33],
							    }       ,    )

	@require_tf
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			pipeline(
							    'zero-shot-classification'       ,    model='sshleifer/tiny-distilbert-base-cased-distilled-squad'       ,    framework='tf'       ,    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'Who are you voting for in 2020?'       ,    candidate_labels=['politics', 'public health', 'science']    )

							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': 'Who are you voting for in 2020?',
							        'labels': ['science', 'public health', 'politics'],
							        'scores': [0.3_33, 0.3_33, 0.3_33],
							    }       ,    )

	@slow
	@require_torch
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			pipeline('zero-shot-classification'       ,    model='roberta-large-mnli'       ,    framework='pt'    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'Who are you voting for in 2020?'       ,    candidate_labels=['politics', 'public health', 'science']    )

							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': 'Who are you voting for in 2020?',
							        'labels': ['politics', 'public health', 'science'],
							        'scores': [0.9_76, 0.0_15, 0.0_09],
							    }       ,    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'The dominant sequence transduction models are based on complex recurrent or convolutional neural networks'
							    ' in an encoder-decoder configuration. The best performing models also connect the encoder and decoder'
							    ' through an attention mechanism. We propose a new simple network architecture, the Transformer, based'
							    ' solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two'
							    ' machine translation tasks show these models to be superior in quality while being more parallelizable'
							    ' and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014'
							    ' English-to-German translation task, improving over the existing best results, including ensembles by'
							    ' over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new'
							    ' single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small'
							    ' fraction of the training costs of the best models from the literature. We show that the Transformer'
							    ' generalizes well to other tasks by applying it successfully to English constituency parsing both with'
							    ' large and limited training data.'       ,    candidate_labels=['machine learning', 'statistics', 'translation', 'vision']       ,    multi_label=UpperCAmelCase       ,    )
							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': (
							            'The dominant sequence transduction models are based on complex recurrent or convolutional neural'
							            ' networks in an encoder-decoder configuration. The best performing models also connect the'
							            ' encoder and decoder through an attention mechanism. We propose a new simple network'
							            ' architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence'
							            ' and convolutions entirely. Experiments on two machine translation tasks show these models to be'
							            ' superior in quality while being more parallelizable and requiring significantly less time to'
							            ' train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,'
							            ' improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014'
							            ' English-to-French translation task, our model establishes a new single-model state-of-the-art'
							            ' BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training'
							            ' costs of the best models from the literature. We show that the Transformer generalizes well to'
							            ' other tasks by applying it successfully to English constituency parsing both with large and'
							            ' limited training data.'
							        ),
							        'labels': ['translation', 'machine learning', 'vision', 'statistics'],
							        'scores': [0.8_17, 0.7_13, 0.0_18, 0.0_18],
							    }       ,    )

	@slow
	@require_tf
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			pipeline('zero-shot-classification'       ,    model='roberta-large-mnli'       ,    framework='tf'    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'Who are you voting for in 2020?'       ,    candidate_labels=['politics', 'public health', 'science']    )

							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': 'Who are you voting for in 2020?',
							        'labels': ['politics', 'public health', 'science'],
							        'scores': [0.9_76, 0.0_15, 0.0_09],
							    }       ,    )
							_UpperCAmelCase									=			zero_shot_classifier(
							    'The dominant sequence transduction models are based on complex recurrent or convolutional neural networks'
							    ' in an encoder-decoder configuration. The best performing models also connect the encoder and decoder'
							    ' through an attention mechanism. We propose a new simple network architecture, the Transformer, based'
							    ' solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two'
							    ' machine translation tasks show these models to be superior in quality while being more parallelizable'
							    ' and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014'
							    ' English-to-German translation task, improving over the existing best results, including ensembles by'
							    ' over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new'
							    ' single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small'
							    ' fraction of the training costs of the best models from the literature. We show that the Transformer'
							    ' generalizes well to other tasks by applying it successfully to English constituency parsing both with'
							    ' large and limited training data.'       ,    candidate_labels=['machine learning', 'statistics', 'translation', 'vision']       ,    multi_label=UpperCAmelCase       ,    )
							self.assertEqual(
							    nested_simplify(UpperCAmelCase    )       ,    {
							        'sequence': (
							            'The dominant sequence transduction models are based on complex recurrent or convolutional neural'
							            ' networks in an encoder-decoder configuration. The best performing models also connect the'
							            ' encoder and decoder through an attention mechanism. We propose a new simple network'
							            ' architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence'
							            ' and convolutions entirely. Experiments on two machine translation tasks show these models to be'
							            ' superior in quality while being more parallelizable and requiring significantly less time to'
							            ' train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task,'
							            ' improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014'
							            ' English-to-French translation task, our model establishes a new single-model state-of-the-art'
							            ' BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training'
							            ' costs of the best models from the literature. We show that the Transformer generalizes well to'
							            ' other tasks by applying it successfully to English constituency parsing both with large and'
							            ' limited training data.'
							        ),
							        'labels': ['translation', 'machine learning', 'vision', 'statistics'],
							        'scores': [0.8_17, 0.7_13, 0.0_18, 0.0_18],
							    }       ,    )
