


"""simple docstring"""



import unittest

from transformers import GPTNeoXJapaneseConfig, is_torch_available
from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer
from transformers.testing_utils import 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 GPTNeoXJapaneseForCausalLM, GPTNeoXJapaneseModel
class 					__magic_name__		:






       def __init__(   self  :    Tuple  ,     snake_case__  :    Optional[int]  ,     snake_case__  :    List[str]=1_3  ,     snake_case__  :    List[str]=7  ,     snake_case__  :    Optional[Any]=True  ,     snake_case__  :    Optional[Any]=True  ,     snake_case__  :    List[str]=True  ,     snake_case__  :    Optional[int]=True  ,     snake_case__  :    Dict=9_9  ,     snake_case__  :    Union[str, Any]=3_2  ,     snake_case__  :    Optional[Any]=5  ,     snake_case__  :    Union[str, Any]=4  ,     snake_case__  :    Dict=4  ,     snake_case__  :    str="gelu"  ,     snake_case__  :    Optional[int]=0.0  ,     snake_case__  :    Tuple=0.1  ,     snake_case__  :    Optional[Any]=True  ,     snake_case__  :    Tuple=5_1_2  ,     snake_case__  :    str=1_6  ,     snake_case__  :    List[Any]=2  ,     snake_case__  :    Any=0.02  ,     snake_case__  :    List[str]=3  ,     snake_case__  :    Optional[int]=4  ,     snake_case__  :    int=None  ,     ):

              '''simple docstring'''






              lowercase		:Optional[Any]       							=				parent
              lowercase		:Union[str, Any]       							=				batch_size
              lowercase		:Optional[int]       							=				seq_length
              lowercase		:Optional[Any]       							=				is_training
              lowercase		:Optional[int]       							=				use_input_mask
              lowercase		:Any       							=				use_token_type_ids
              lowercase		:str       							=				use_labels
              lowercase		:int       							=				vocab_size
              lowercase		:str       							=				hidden_size
              lowercase		:Optional[int]       							=				num_hidden_layers
              lowercase		:Optional[Any]       							=				num_attention_heads
              lowercase		:Any       							=				intermediate_multiple_size
              lowercase		:Optional[Any]       							=				hidden_act
              lowercase		:Dict       							=				hidden_dropout
              lowercase		:Union[str, Any]       							=				attention_dropout
              lowercase		:List[Any]       							=				weight_tying
              lowercase		:Optional[int]       							=				max_position_embeddings
              lowercase		:Tuple       							=				type_vocab_size
              lowercase		:List[Any]       							=				type_sequence_label_size
              lowercase		:Any       							=				initializer_range
              lowercase		:List[Any]       							=				num_labels
              lowercase		:List[Any]       							=				num_choices
              lowercase		:Union[str, Any]       							=				scope






       def  __snake_case						(   self  :    Optional[Any]				):

              '''simple docstring'''






              lowercase		:Optional[Any]       							=				ids_tensor([self.batch_size, self.seq_length]  ,     self.vocab_size				)

              lowercase		:List[Any]       							=				None
              if self.use_input_mask:
                     lowercase		:List[Any]       							=				random_attention_mask([self.batch_size, self.seq_length]				)

              lowercase		:Any       							=				None
              if self.use_labels:
                     lowercase		:Tuple       							=				ids_tensor([self.batch_size, self.seq_length]  ,     self.num_labels				)

              lowercase		:Optional[int]       							=				self.get_config()

              return config, input_ids, input_mask, token_labels






       def  __snake_case						(   self  :    int				):

              '''simple docstring'''






              return GPTNeoXJapaneseConfig(
                  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_multiple_size=self.intermediate_multiple_size  ,     hidden_act=self.hidden_act  ,     hidden_dropout=self.hidden_dropout  ,     attention_dropout=self.attention_dropout  ,     weight_tying=self.weight_tying  ,     max_position_embeddings=self.max_position_embeddings  ,     type_vocab_size=self.type_vocab_size  ,     is_decoder=snake_case__  ,     initializer_range=self.initializer_range  ,     )






       def  __snake_case						(   self  :    Optional[Any]				):

              '''simple docstring'''






              lowercase							,  lowercase							,  lowercase							,  lowercase		:Any       							=				self.prepare_config_and_inputs()

              lowercase		:str       							=				True

              return config, input_ids, input_mask, token_labels






       def  __snake_case						(   self  :    Union[str, Any]  ,     snake_case__  :    List[Any]  ,     snake_case__  :    List[str]  ,     snake_case__  :    str				):

              '''simple docstring'''






              lowercase		:Dict       							=				GPTNeoXJapaneseModel(config=snake_case__				)
              model.to(snake_case__				)
              model.eval()
              lowercase		:int       							=				model(snake_case__  ,     attention_mask=snake_case__				)
              lowercase		:Optional[Any]       							=				model(snake_case__				)
              self.parent.assertEqual(result.last_hidden_state.shape  ,     (self.batch_size, self.seq_length, self.hidden_size)				)






       def  __snake_case						(   self  :    Union[str, Any]  ,     snake_case__  :    Optional[Any]  ,     snake_case__  :    Optional[int]  ,     snake_case__  :    Tuple				):

              '''simple docstring'''






              lowercase		:Dict       							=				True
              lowercase		:str       							=				GPTNeoXJapaneseModel(snake_case__				)
              model.to(snake_case__				)
              model.eval()
              lowercase		:Tuple       							=				model(snake_case__  ,     attention_mask=snake_case__				)
              self.parent.assertEqual(result.last_hidden_state.shape  ,     (self.batch_size, self.seq_length, self.hidden_size)				)






       def  __snake_case						(   self  :    Union[str, Any]  ,     snake_case__  :    Tuple  ,     snake_case__  :    List[str]  ,     snake_case__  :    Any  ,     snake_case__  :    int				):

              '''simple docstring'''






              lowercase		:Any       							=				GPTNeoXJapaneseForCausalLM(config=snake_case__				)
              model.to(snake_case__				)
              model.eval()
              lowercase		:Optional[Any]       							=				model(snake_case__  ,     attention_mask=snake_case__  ,     labels=snake_case__				)
              self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.seq_length, self.vocab_size)				)






       def  __snake_case						(   self  :    List[Any]  ,     snake_case__  :    Dict  ,     snake_case__  :    Any  ,     snake_case__  :    int				):

              '''simple docstring'''






              lowercase		:Any       							=				True
              lowercase		:Tuple       							=				GPTNeoXJapaneseForCausalLM(config=snake_case__				)
              model.to(snake_case__				)
              model.eval()

              # first forward pass
              lowercase		:Any       							=				model(snake_case__  ,     attention_mask=snake_case__  ,     use_cache=snake_case__				)
              lowercase		:Union[str, Any]       							=				outputs.past_key_values

              # create hypothetical multiple next token and extent to next_input_ids
              lowercase		:List[str]       							=				ids_tensor((self.batch_size, 3)  ,     config.vocab_size				)
              lowercase		:Dict       							=				ids_tensor((self.batch_size, 3)  ,     vocab_size=2				)

              # append to next input_ids and
              lowercase		:Optional[int]       							=				torch.cat([input_ids, next_tokens]  ,     dim=-1				)
              lowercase		:Optional[Any]       							=				torch.cat([input_mask, next_mask]  ,     dim=-1				)

              lowercase		:Tuple       							=				model(snake_case__  ,     attention_mask=snake_case__  ,     output_hidden_states=snake_case__				)
              lowercase		:List[Any]       							=				output_from_no_past['''hidden_states'''][0]
              lowercase		:Any       							=				model(
                  snake_case__  ,     attention_mask=snake_case__  ,     past_key_values=snake_case__  ,     output_hidden_states=snake_case__  ,     )['''hidden_states'''][0]

              # select random slice
              lowercase		:int       							=				ids_tensor((1,)  ,     output_from_past.shape[-1]				).item()
              lowercase		:str       							=				output_from_no_past[:, -3:, random_slice_idx].detach()
              lowercase		:Optional[int]       							=				output_from_past[:, :, random_slice_idx].detach()

              self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]				)

              # test that outputs are equal for slice
              self.parent.assertTrue(torch.allclose(snake_case__  ,     snake_case__  ,     atol=1e-3				)				)







       def  __snake_case						(   self  :    Optional[int]				):

              '''simple docstring'''






              lowercase		:Tuple       							=				self.prepare_config_and_inputs()
              lowercase							,  lowercase							,  lowercase							,  lowercase		:int       							=				config_and_inputs
              lowercase		:List[Any]       							=				{'''input_ids''': input_ids, '''attention_mask''': input_mask}
              return config, inputs_dict







@require_torch
class 					__magic_name__		(			__UpperCAmelCase			,						__UpperCAmelCase			,						unittest.TestCase     ):
       __A			:      Dict        =   (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
       __A			:      Optional[Any]        =   (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
       __A			:      List[str]        =   (
           {"feature-extraction": GPTNeoXJapaneseModel, "text-generation": GPTNeoXJapaneseForCausalLM}
           if is_torch_available()
           else {}
       )
       __A			:      Any        =   False
       __A			:      Dict        =   False
       __A			:      int        =   False
       __A			:      int        =   False






       def  __snake_case						(   self  :    int				):

              '''simple docstring'''






              lowercase		:int       							=				GPTNeoXJapaneseModelTester(self				)
              lowercase		:Union[str, Any]       							=				ConfigTester(self  ,     config_class=snake_case__  ,     hidden_size=3_7				)






       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






              self.config_tester.run_common_tests()






       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase							,  lowercase							,  lowercase							,  lowercase		:Optional[Any]       							=				self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(snake_case__  ,     snake_case__  ,     snake_case__				)






       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






              lowercase							,  lowercase							,  lowercase							,  lowercase		:Optional[int]       							=				self.model_tester.prepare_config_and_inputs_for_decoder()
              self.model_tester.create_and_check_model_as_decoder(snake_case__  ,     snake_case__  ,     snake_case__				)






       def  __snake_case						(   self  :    Tuple				):

              '''simple docstring'''






              lowercase							,  lowercase							,  lowercase							,  lowercase		:int       							=				self.model_tester.prepare_config_and_inputs_for_decoder()

              lowercase		:Optional[int]       							=				None

              self.model_tester.create_and_check_model_as_decoder(snake_case__  ,     snake_case__  ,     snake_case__				)






       def  __snake_case						(   self  :    Optional[int]				):

              '''simple docstring'''






              lowercase							,  lowercase							,  lowercase							,  lowercase		:Optional[int]       							=				self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_decoder_model_past_large_inputs(snake_case__  ,     snake_case__  ,     snake_case__				)






       def  __snake_case						(   self  :    List[Any]				):

              '''simple docstring'''






              lowercase		:List[str]       							=				self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_causal_lm(*snake_case__				)







       @slow
       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase		:str       							=				'''abeja/gpt-neox-japanese-2.7b'''

              lowercase		:Any       							=				['''データサイエンティストとは、''', '''100年後に必要とされる会社は、''', '''フルリモートの環境で働くために必要なことは、''', '''国境の長いトンネルを抜けると''', '''美味しい日本食といえば、''']

              lowercase		:List[str]       							=				[
                  '''データサイエンティストとは、データを分析し、ビジネスに役立つ知見を導き出す専門家のことです。''',
                  '''100年後に必要とされる会社は、「人」が中心の会社です。''',
                  '''フルリモートの環境で働くために必要なことは、「自分の時間をコントロールする」ことです。''',
                  '''国境の長いトンネルを抜けると、そこは雪国だった。''',
                  '''美味しい日本食といえば、やっぱりお寿司ですよね。''',
              ]

              lowercase		:List[str]       							=				GPTNeoXJapaneseTokenizer.from_pretrained(snake_case__				)
              lowercase		:int       							=				GPTNeoXJapaneseForCausalLM.from_pretrained(snake_case__				)

              lowercase		:str       							=				[]
              for prompt in prompts:
                     lowercase		:Dict       							=				tokenizer(snake_case__  ,     return_tensors='''pt'''				).input_ids
                     lowercase		:Dict       							=				model.generate(snake_case__  ,     max_length=5_0				)
                     lowercase		:Optional[int]       							=				tokenizer.batch_decode(snake_case__  ,     skip_special_tokens=snake_case__				)
                     predicted_outputs += generated_string
              self.assertListEqual(snake_case__  ,     snake_case__				)





"""simple docstring"""



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.
UpperCAmelCase      		=			{'''LayoutLMv2Config''', '''LayoutLMv3Config'''}
@is_pipeline_test
class 					__magic_name__		(			unittest.TestCase     ):
       __A			:      int        =   MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
       __A			:      List[str]        =   TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

       if model_mapping is not None:
              __A			:      int        =   {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
       if tf_model_mapping is not None:
              __A			:      Optional[int]        =   {
                  config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
              }






       def  __snake_case						(   self  :    Tuple  ,     snake_case__  :    Any  ,     snake_case__  :    Union[str, Any]  ,     snake_case__  :    int				):

              '''simple docstring'''






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






       def  __snake_case						(   self  :    Any  ,     snake_case__  :    Union[str, Any]  ,     snake_case__  :    Tuple				):

              '''simple docstring'''






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

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

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

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

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

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

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

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

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

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

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

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

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

              self.run_entailment_id(snake_case__				)






       def  __snake_case						(   self  :    Any  ,     snake_case__  :    Pipeline				):

              '''simple docstring'''






              lowercase		:List[Any]       							=				zero_shot_classifier.model.config
              lowercase		:int       							=				config.labelaid
              lowercase		:str       							=				zero_shot_classifier.entailment_id

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

              lowercase		:Optional[Any]       							=				{'''entailment''': 0, '''neutral''': 1, '''contradiction''': 2}
              self.assertEqual(zero_shot_classifier.entailment_id  ,     0				)

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

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

              lowercase		:Optional[Any]       							=				original_labelaid
              self.assertEqual(snake_case__  ,     zero_shot_classifier.entailment_id				)






       @require_torch
       def  __snake_case						(   self  :    List[str]				):

              '''simple docstring'''






              lowercase		:List[Any]       							=				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?''' * 1_0_0  ,     candidate_labels=['''politics''', '''public health''', '''science''']				)






       @require_torch
       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






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

              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''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  __snake_case						(   self  :    List[str]				):

              '''simple docstring'''






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

              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''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  __snake_case						(   self  :    Optional[int]				):

              '''simple docstring'''






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

              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''sequence''': '''Who are you voting for in 2020?''',
                      '''labels''': ['''politics''', '''public health''', '''science'''],
                      '''scores''': [0.9_76, 0.0_15, 0.0_09],
                  }  ,     )
              lowercase		:Optional[Any]       							=				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=snake_case__  ,     )
              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''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  __snake_case						(   self  :    Any				):

              '''simple docstring'''






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

              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''sequence''': '''Who are you voting for in 2020?''',
                      '''labels''': ['''politics''', '''public health''', '''science'''],
                      '''scores''': [0.9_76, 0.0_15, 0.0_09],
                  }  ,     )
              lowercase		:str       							=				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=snake_case__  ,     )
              self.assertEqual(
                  nested_simplify(snake_case__				)  ,     {
                      '''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],
                  }  ,     )

