






import tempfile
import unittest

import numpy as np

import transformers
from transformers import GPTaTokenizer, GPTJConfig, is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax, tooslow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
     import jax
     import jax.numpy as jnp

     from transformers.modeling_flax_pytorch_utils import (
         convert_pytorch_state_dict_to_flax,
         load_flax_weights_in_pytorch_model,
     )
     from transformers.models.gptj.modeling_flax_gptj import FlaxGPTJForCausalLM, FlaxGPTJModel

if is_torch_available():
     import torch




class 			snake_case__   :

       '''simple docstring'''



       def __init__(							self			,						a__			,						a__=14			,						a__=7			,						a__=True			,						a__=True			,						a__=False			,						a__=True			,						a__=99			,						a__=32			,						a__=4			,						a__=4			,						a__=4			,						a__=37			,						a__="gelu"			,						a__=0.1			,						a__=0.1			,						a__=5_12			,						a__=0.02			,						) ->      Dict:






            '''simple docstring'''





            __snake_case			:Union[str, Any]          =						parent
            __snake_case			:Tuple          =						batch_size
            __snake_case			:Any          =						seq_length
            __snake_case			:Union[str, Any]          =						is_training
            __snake_case			:Tuple          =						use_input_mask
            __snake_case			:Dict          =						use_token_type_ids
            __snake_case			:str          =						use_labels
            __snake_case			:Optional[int]          =						vocab_size
            __snake_case			:str          =						hidden_size
            __snake_case			:Union[str, Any]          =						rotary_dim
            __snake_case			:int          =						num_hidden_layers
            __snake_case			:Dict          =						num_attention_heads
            __snake_case			:List[Any]          =						intermediate_size
            __snake_case			:Tuple          =						hidden_act
            __snake_case			:int          =						hidden_dropout_prob
            __snake_case			:List[Any]          =						attention_probs_dropout_prob
            __snake_case			:str          =						max_position_embeddings
            __snake_case			:Optional[Any]          =						initializer_range
            __snake_case			:Optional[Any]          =						None
            __snake_case			:List[str]          =						vocab_size - 1
            __snake_case			:Optional[int]          =						vocab_size - 1
            __snake_case			:Dict          =						vocab_size - 1



       def 					__lowercase						(							self    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:List[Any]          =						ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size    )

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

            __snake_case			:List[Any]          =						GPTJConfig(
                vocab_size=self.vocab_size			,						n_embd=self.hidden_size			,						n_layer=self.num_hidden_layers			,						n_head=self.num_attention_heads			,						n_positions=self.max_position_embeddings			,						use_cache=a__			,						bos_token_id=self.bos_token_id			,						eos_token_id=self.eos_token_id			,						pad_token_id=self.pad_token_id			,						rotary_dim=self.rotary_dim			,						)

            return (config, input_ids, input_mask)



       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:Dict          =						self.prepare_config_and_inputs()
            __snake_case       , __snake_case       , __snake_case			:Optional[Any]          =						config_and_inputs
            __snake_case			:List[str]          =						{"""input_ids""": input_ids, """attention_mask""": attention_mask}
            return config, inputs_dict



       def 					__lowercase						(							self			,						a__			,						a__			,						a__			,						a__    ) ->      str:






            '''simple docstring'''





            __snake_case			:List[str]          =						20
            __snake_case			:Tuple          =						model_class_name(a__    )

            __snake_case			:Dict          =						model.init_cache(input_ids.shape[0]			,						a__    )
            __snake_case			:Union[str, Any]          =						jnp.ones((input_ids.shape[0], max_decoder_length)			,						dtype="""i4"""    )

            __snake_case			:Any          =						jnp.broadcast_to(
                jnp.arange(input_ids.shape[-1] - 1    )[None, :]			,						(input_ids.shape[0], input_ids.shape[-1] - 1)    )
            __snake_case			:Optional[int]          =						model(
                input_ids[:, :-1]			,						attention_mask=a__			,						past_key_values=a__			,						position_ids=a__			,						)

            __snake_case			:Tuple          =						jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]			,						dtype="""i4"""    )
            __snake_case			:Any          =						model(
                input_ids[:, -1:]			,						attention_mask=a__			,						past_key_values=outputs_cache.past_key_values			,						position_ids=a__			,						)

            __snake_case			:Any          =						model(a__    )

            __snake_case			:int          =						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])    )    )
            self.parent.assertTrue(diff < 1e-3			,						msg=F'''Max diff is {diff}'''    )



       def 					__lowercase						(							self			,						a__			,						a__			,						a__			,						a__    ) ->      Tuple:






            '''simple docstring'''





            __snake_case			:Optional[Any]          =						20
            __snake_case			:List[str]          =						model_class_name(a__    )

            __snake_case			:Optional[Any]          =						jnp.concatenate(
                [attention_mask, jnp.zeros((attention_mask.shape[0], max_decoder_length - attention_mask.shape[1])    )]			,						axis=-1			,						)

            __snake_case			:List[str]          =						model.init_cache(input_ids.shape[0]			,						a__    )
            __snake_case			:Optional[int]          =						jnp.broadcast_to(
                jnp.arange(input_ids.shape[-1] - 1    )[None, :]			,						(input_ids.shape[0], input_ids.shape[-1] - 1)    )

            __snake_case			:Tuple          =						model(
                input_ids[:, :-1]			,						attention_mask=a__			,						past_key_values=a__			,						position_ids=a__			,						)
            __snake_case			:Optional[int]          =						jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]			,						dtype="""i4"""    )
            __snake_case			:Union[str, Any]          =						model(
                input_ids[:, -1:]			,						past_key_values=outputs_cache.past_key_values			,						attention_mask=a__			,						position_ids=a__			,						)

            __snake_case			:Dict          =						model(a__			,						attention_mask=a__    )

            __snake_case			:Tuple          =						np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])    )    )
            self.parent.assertTrue(diff < 1e-3			,						msg=F'''Max diff is {diff}'''    )




@require_flax
class 			snake_case__   (							lowercase_	,    lowercase_	,    unittest.TestCase):

       '''simple docstring'''
       lowerCamelCase							:				List[Any] 				= (FlaxGPTJModel, FlaxGPTJForCausalLM) if is_flax_available() else ()
       lowerCamelCase							:				Any 				= (FlaxGPTJForCausalLM,) if is_flax_available() else ()



       def 					__lowercase						(							self    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case			:List[Any]          =						FlaxGPTJModelTester(self    )



       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            for model_class_name in self.all_model_classes:
                 __snake_case       , __snake_case       , __snake_case			:List[Any]          =						self.model_tester.prepare_config_and_inputs()
                 self.model_tester.check_use_cache_forward(a__			,						a__			,						a__			,						a__    )



       def 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





            for model_class_name in self.all_model_classes:
                 __snake_case       , __snake_case       , __snake_case			:Dict          =						self.model_tester.prepare_config_and_inputs()
                 self.model_tester.check_use_cache_forward_with_attn_mask(
                     a__			,						a__			,						a__			,						a__    )



       @tooslow
       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            __snake_case			:List[Any]          =						GPTaTokenizer.from_pretrained("""gpt2"""			,						pad_token="""<|endoftext|>"""			,						padding_side="""left"""    )
            __snake_case			:Tuple          =						tokenizer(["""Hello this is a long string""", """Hey"""]			,						return_tensors="""np"""			,						padding=a__			,						truncation=a__    )

            __snake_case			:Tuple          =						FlaxGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""    )
            __snake_case			:Dict          =						False
            __snake_case			:List[Any]          =						model.config.eos_token_id

            __snake_case			:int          =						jax.jit(model.generate    )

            __snake_case			:Optional[int]          =						jit_generate(
                inputs["""input_ids"""]			,						attention_mask=inputs["""attention_mask"""]			,						pad_token_id=tokenizer.pad_token_id    ).sequences

            __snake_case			:str          =						tokenizer.batch_decode(a__			,						skip_special_tokens=a__    )

            __snake_case			:List[Any]          =						[
                """Hello this is a long string of text.\n\nI'm trying to get the text of the""",
                """Hey, I'm a little late to the party. I'm going to""",
            ]

            self.assertListEqual(a__			,						a__    )



       @is_pt_flax_cross_test
       def 					__lowercase						(							self    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case       , __snake_case			:List[str]          =						self.model_tester.prepare_config_and_inputs_for_common()

            for model_class in self.all_model_classes:
                 with self.subTest(model_class.__name__    ):
                      # prepare inputs
                      __snake_case			:int          =						self._prepare_for_class(a__			,						a__    )
                      __snake_case			:Union[str, Any]          =						{k: torch.tensor(v.tolist()    ) for k, v in prepared_inputs_dict.items()}

                      # load corresponding PyTorch class
                      __snake_case			:Any          =						model_class.__name__[4:]  # Skip the "Flax" at the beginning
                      __snake_case			:Dict          =						getattr(a__			,						a__    )

                      __snake_case       , __snake_case			:Tuple          =						pt_inputs["""input_ids"""].shape
                      __snake_case			:str          =						np.random.randint(0			,						seq_length - 1			,						size=(batch_size,)    )
                      for batch_idx, start_index in enumerate(a__    ):
                           __snake_case			:Union[str, Any]          =						0
                           __snake_case			:List[Any]          =						1
                           __snake_case			:Optional[Any]          =						0
                           __snake_case			:Union[str, Any]          =						1
                      __snake_case			:str          =						pt_model_class(a__    ).eval()
                      __snake_case			:Optional[Any]          =						model_class(a__			,						dtype=jnp.floataa    )

                      __snake_case			:int          =						convert_pytorch_state_dict_to_flax(pt_model.state_dict()			,						a__    )
                      __snake_case			:List[Any]          =						fx_state

                      with torch.no_grad():
                           __snake_case			:List[str]          =						pt_model(**a__    ).to_tuple()

                      __snake_case			:Union[str, Any]          =						fx_model(**a__    ).to_tuple()
                      self.assertEqual(len(a__    )			,						len(a__    )			,						"""Output lengths differ between Flax and PyTorch"""    )
                      for fx_output, pt_output in zip(a__			,						a__    ):
                           self.assert_almost_equals(fx_output[:, -1]			,						pt_output[:, -1].numpy()			,						4e-2    )

                      with tempfile.TemporaryDirectory() as tmpdirname:
                           pt_model.save_pretrained(a__    )
                           __snake_case			:Optional[Any]          =						model_class.from_pretrained(a__			,						from_pt=a__    )

                      __snake_case			:Union[str, Any]          =						fx_model_loaded(**a__    ).to_tuple()
                      self.assertEqual(
                          len(a__    )			,						len(a__    )			,						"""Output lengths differ between Flax and PyTorch"""    )
                      for fx_output_loaded, pt_output in zip(a__			,						a__    ):
                           self.assert_almost_equals(fx_output_loaded[:, -1]			,						pt_output[:, -1].numpy()			,						4e-2    )



       @is_pt_flax_cross_test
       def 					__lowercase						(							self    ) ->      Union[str, Any]:






            '''simple docstring'''





            __snake_case       , __snake_case			:Optional[Any]          =						self.model_tester.prepare_config_and_inputs_for_common()
            for model_class in self.all_model_classes:
                 with self.subTest(model_class.__name__    ):
                      # prepare inputs
                      __snake_case			:str          =						self._prepare_for_class(a__			,						a__    )
                      __snake_case			:Any          =						{k: torch.tensor(v.tolist()    ) for k, v in prepared_inputs_dict.items()}

                      # load corresponding PyTorch class
                      __snake_case			:Dict          =						model_class.__name__[4:]  # Skip the "Flax" at the beginning
                      __snake_case			:List[Any]          =						getattr(a__			,						a__    )

                      __snake_case			:List[Any]          =						pt_model_class(a__    ).eval()
                      __snake_case			:Optional[Any]          =						model_class(a__			,						dtype=jnp.floataa    )

                      __snake_case			:Tuple          =						load_flax_weights_in_pytorch_model(a__			,						fx_model.params    )
                      __snake_case       , __snake_case			:Optional[Any]          =						pt_inputs["""input_ids"""].shape
                      __snake_case			:str          =						np.random.randint(0			,						seq_length - 1			,						size=(batch_size,)    )
                      for batch_idx, start_index in enumerate(a__    ):
                           __snake_case			:List[Any]          =						0
                           __snake_case			:Dict          =						1
                           __snake_case			:List[str]          =						0
                           __snake_case			:str          =						1

                      # make sure weights are tied in PyTorch
                      pt_model.tie_weights()

                      with torch.no_grad():
                           __snake_case			:List[Any]          =						pt_model(**a__    ).to_tuple()

                      __snake_case			:Any          =						fx_model(**a__    ).to_tuple()
                      self.assertEqual(len(a__    )			,						len(a__    )			,						"""Output lengths differ between Flax and PyTorch"""    )
                      for fx_output, pt_output in zip(a__			,						a__    ):
                           self.assert_almost_equals(fx_output[:, -1]			,						pt_output[:, -1].numpy()			,						4e-2    )

                      with tempfile.TemporaryDirectory() as tmpdirname:
                           fx_model.save_pretrained(a__    )
                           __snake_case			:str          =						pt_model_class.from_pretrained(a__			,						from_flax=a__    )

                      with torch.no_grad():
                           __snake_case			:Optional[Any]          =						pt_model_loaded(**a__    ).to_tuple()

                      self.assertEqual(
                          len(a__    )			,						len(a__    )			,						"""Output lengths differ between Flax and PyTorch"""    )
                      for fx_output, pt_output in zip(a__			,						a__    ):
                           self.assert_almost_equals(fx_output[:, -1]			,						pt_output[:, -1].numpy()			,						4e-2    )



       @tooslow
       def 					__lowercase						(							self    ) ->      int:






            '''simple docstring'''





            for model_class_name in self.all_model_classes:
                 __snake_case			:List[Any]          =						model_class_name.from_pretrained("""EleutherAI/gpt-j-6B"""    )
                 __snake_case			:List[Any]          =						model(np.ones((1, 1)    )    )
                 self.assertIsNotNone(a__    )










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.
lowerCamelCase__							=     {"""LayoutLMv2Config""", """LayoutLMv3Config"""}




@is_pipeline_test
class 			snake_case__   (							unittest.TestCase):

       '''simple docstring'''
       lowerCamelCase							:				List[Any] 				= MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
       lowerCamelCase							:				Tuple 				= TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

       if model_mapping is not None:
              lowerCamelCase							:				List[Any] 				= {config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
       if tf_model_mapping is not None:
              lowerCamelCase							:				List[str] 				= {
                  config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
              }



       def 					__lowercase						(							self			,						a__			,						a__			,						a__    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:Union[str, Any]          =						ZeroShotClassificationPipeline(
                model=a__			,						tokenizer=a__			,						candidate_labels=["""polics""", """health"""]    )
            return classifier, ["Who are you voting for in 2020?", "My stomach hurts."]



       def 					__lowercase						(							self			,						a__			,						a__    ) ->      Optional[int]:






            '''simple docstring'''





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

            # No kwarg
            __snake_case			:Optional[int]          =						classifier("""Who are you voting for in 2020?"""			,						["""politics"""]    )
            self.assertEqual(a__			,						{"""sequence""": ANY(a__    ), """labels""": [ANY(a__    )], """scores""": [ANY(a__    )]}    )

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

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

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

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

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

            with self.assertRaises(a__    ):
                 classifier(""""""			,						candidate_labels="""politics"""    )

            with self.assertRaises(a__    ):
                 classifier(a__			,						candidate_labels="""politics"""    )

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

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

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

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

            self.run_entailment_id(a__    )



       def 					__lowercase						(							self			,						a__    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:Optional[Any]          =						zero_shot_classifier.model.config
            __snake_case			:Optional[Any]          =						config.labelaid
            __snake_case			:Dict          =						zero_shot_classifier.entailment_id

            __snake_case			:List[Any]          =						{"""LABEL_0""": 0, """LABEL_1""": 1, """LABEL_2""": 2}
            self.assertEqual(zero_shot_classifier.entailment_id			,						-1    )

            __snake_case			:Optional[int]          =						{"""entailment""": 0, """neutral""": 1, """contradiction""": 2}
            self.assertEqual(zero_shot_classifier.entailment_id			,						0    )

            __snake_case			:List[Any]          =						{"""ENTAIL""": 0, """NON-ENTAIL""": 1}
            self.assertEqual(zero_shot_classifier.entailment_id			,						0    )

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

            __snake_case			:Union[str, Any]          =						original_labelaid
            self.assertEqual(a__			,						zero_shot_classifier.entailment_id    )



       @require_torch
       def 					__lowercase						(							self    ) ->      int:






            '''simple docstring'''





            __snake_case			:str          =						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_00			,						candidate_labels=["""politics""", """public health""", """science"""]    )



       @require_torch
       def 					__lowercase						(							self    ) ->      List[str]:






            '''simple docstring'''





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

            self.assertEqual(
                nested_simplify(a__    )			,						{
                    """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 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





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

            self.assertEqual(
                nested_simplify(a__    )			,						{
                    """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 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





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

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






            '''simple docstring'''





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

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


