






'''simple docstring'''




import argparse
import json
import os

import fairseq
import torch
from torch import nn

from transformers import (
    SpeechaTextaConfig,
    SpeechaTextaForCausalLM,
    SpeechaTextaTokenizer,
    SpeechEncoderDecoderConfig,
    SpeechEncoderDecoderModel,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaModel,
    logging,
)


logging.set_verbosity_info()
__lowerCamelCase   :					Dict   							=  logging.get_logger(__name__)

__lowerCamelCase   :					List[str]   							=  {
    '''post_extract_proj''': '''feature_projection.projection''',
    '''encoder.pos_conv.0''': '''encoder.pos_conv_embed.conv''',
    '''self_attn.k_proj''': '''encoder.layers.*.attention.k_proj''',
    '''self_attn.v_proj''': '''encoder.layers.*.attention.v_proj''',
    '''self_attn.q_proj''': '''encoder.layers.*.attention.q_proj''',
    '''self_attn.out_proj''': '''encoder.layers.*.attention.out_proj''',
    '''self_attn_layer_norm''': '''encoder.layers.*.layer_norm''',
    '''fc1''': '''encoder.layers.*.feed_forward.intermediate_dense''',
    '''fc2''': '''encoder.layers.*.feed_forward.output_dense''',
    '''final_layer_norm''': '''encoder.layers.*.final_layer_norm''',
    '''encoder.layer_norm''': '''encoder.layer_norm''',
    '''w2v_model.layer_norm''': '''feature_projection.layer_norm''',
    '''quantizer.weight_proj''': '''quantizer.weight_proj''',
    '''quantizer.vars''': '''quantizer.codevectors''',
    '''project_q''': '''project_q''',
    '''final_proj''': '''project_hid''',
    '''w2v_encoder.proj''': '''lm_head''',
    '''mask_emb''': '''masked_spec_embed''',
}
__lowerCamelCase   :					str   							=  [
    '''lm_head''',
    '''quantizer.weight_proj''',
    '''quantizer.codevectors''',
    '''project_q''',
    '''project_hid''',
]

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__						)->    Dict:



			"""simple docstring"""



			for attribute in key.split("."						):
						snake_case_				:					Tuple   =       getattr(__a     ,__a						)

			if weight_type is not None:
						snake_case_				:					List[str]   =       getattr(__a     ,__a						).shape
			else:
						snake_case_				:					Dict   =       hf_pointer.shape

			assert hf_shape == value.shape, (
			    F'''Shape of hf {key + '.' + weight_type if weight_type is not None else ''} is {hf_shape}, but should be'''
			    F''' {value.shape} for {full_name}'''
			)

			if weight_type == "weight":
						snake_case_				:					Union[str, Any]   =       value
			elif weight_type == "weight_g":
						snake_case_				:					Tuple   =       value
			elif weight_type == "weight_v":
						snake_case_				:					Dict   =       value
			elif weight_type == "bias":
						snake_case_				:					Dict   =       value
			else:
						snake_case_				:					Union[str, Any]   =       value

			logger.info(F'''{key + '.' + weight_type if weight_type is not None else ''} was initialized from {full_name}.'''						)

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__						)->    str:



			"""simple docstring"""



			snake_case_				:					str   =       []
			snake_case_				:					str   =       fairseq_model.state_dict()

			snake_case_				:					Dict   =       hf_model.feature_extractor

			# if encoder has different dim to decoder -> use proj_weight
			snake_case_				:					Optional[int]   =       None

			for name, value in fairseq_dict.items():
						snake_case_				:					Optional[int]   =       False
						if "conv_layers" in name:
									load_conv_layer(
									    __a     ,__a     ,__a     ,__a     ,hf_model.config.feat_extract_norm == "group"     ,)
									snake_case_				:					Optional[int]   =       True
						elif name.split("."						)[0] == "proj":
									snake_case_				:					Optional[int]   =       fairseq_model.proj
									snake_case_				:					Optional[Any]   =       True
						else:
									for key, mapped_key in MAPPING.items():
												if key in name or key.split("w2v_model."						)[-1] == name.split("."						)[0]:
															snake_case_				:					List[str]   =       True
															if "*" in mapped_key:
																		snake_case_				:					List[Any]   =       name.split(__a						)[0].split("."						)[-2]
																		snake_case_				:					Any   =       mapped_key.replace("*"     ,__a						)
															if "weight_g" in name:
																		snake_case_				:					Dict   =       "weight_g"
															elif "weight_v" in name:
																		snake_case_				:					Any   =       "weight_v"
															elif "bias" in name:
																		snake_case_				:					Optional[int]   =       "bias"
															elif "weight" in name:
																		snake_case_				:					str   =       "weight"
															else:
																		snake_case_				:					Union[str, Any]   =       None
															set_recursively(__a     ,__a     ,__a     ,__a     ,__a						)
												continue
						if not is_used:
									unused_weights.append(__a						)

			logger.warning(F'''Unused weights: {unused_weights}'''						)

			return proj_weight

def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__						)->    Tuple:



			"""simple docstring"""



			snake_case_				:					Optional[Any]   =       full_name.split("conv_layers."						)[-1]
			snake_case_				:					Optional[Any]   =       name.split("."						)
			snake_case_				:					List[Any]   =       int(items[0]						)
			snake_case_				:					Tuple   =       int(items[1]						)

			if type_id == 0:
						if "bias" in name:
									assert value.shape == feature_extractor.conv_layers[layer_id].conv.bias.data.shape, (
									    F'''{full_name} has size {value.shape}, but'''
									    F''' {feature_extractor.conv_layers[layer_id].conv.bias.data.shape} was found.'''
									)
									snake_case_				:					str   =       value
									logger.info(F'''Feat extract conv layer {layer_id} was initialized from {full_name}.'''						)
						elif "weight" in name:
									assert value.shape == feature_extractor.conv_layers[layer_id].conv.weight.data.shape, (
									    F'''{full_name} has size {value.shape}, but'''
									    F''' {feature_extractor.conv_layers[layer_id].conv.weight.data.shape} was found.'''
									)
									snake_case_				:					Dict   =       value
									logger.info(F'''Feat extract conv layer {layer_id} was initialized from {full_name}.'''						)
			elif (type_id == 2 and not use_group_norm) or (type_id == 2 and layer_id == 0 and use_group_norm):
						if "bias" in name:
									assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape, (
									    F'''{full_name} has size {value.shape}, but {feature_extractor[layer_id].layer_norm.bias.data.shape} was'''
									    " found."
									)
									snake_case_				:					int   =       value
									logger.info(F'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''						)
						elif "weight" in name:
									assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape, (
									    F'''{full_name} has size {value.shape}, but'''
									    F''' {feature_extractor[layer_id].layer_norm.weight.data.shape} was found.'''
									)
									snake_case_				:					Optional[int]   =       value
									logger.info(F'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''						)
			else:
						unused_weights.append(__a						)

def 	__UpperCAmelCase       ( __magic_name__						)->    Tuple:



			"""simple docstring"""



			snake_case_,	snake_case_				:					List[Any]   =       emb.weight.shape
			snake_case_				:					List[Any]   =       nn.Linear(__a     ,__a     ,bias=__a						)
			snake_case_				:					Optional[int]   =       emb.weight.data
			return lin_layer

def 	__UpperCAmelCase       ( __magic_name__						)->    int:



			"""simple docstring"""



			with open(__a     ,"r"     ,encoding="utf-8"						) as f:
						snake_case_				:					Tuple   =       f.readlines()
						snake_case_				:					Union[str, Any]   =       [line.split(" "						)[0] for line in lines]

			snake_case_				:					Optional[Any]   =       len(__a						)

			snake_case_				:					Optional[int]   =       {
			    "<s>": 0,
			    "<pad>": 1,
			    "</s>": 2,
			    "<unk>": 3,
			}

			vocab_dict.update(dict(zip(__a     ,range(4     ,num_words + 4						)						)						)						)
			return vocab_dict

@torch.no_grad()
def 	__UpperCAmelCase       ( __magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,__magic_name__     ,)->    Tuple:



			"""simple docstring"""



			snake_case_				:					Union[str, Any]   =       WavaVecaConfig.from_pretrained(__a						)
			snake_case_				:					Tuple   =       SpeechaTextaConfig.from_pretrained(
			    __a     ,vocab_size=__a     ,decoder_layers=__a     ,do_stable_layer_norm=__a						)

			snake_case_				:					Optional[Any]   =       WavaVecaFeatureExtractor(
			    feature_size=1     ,sampling_rate=1_6000     ,padding_value=0     ,do_normalize=__a     ,return_attention_mask=__a     ,)

			snake_case_,	snake_case_,	snake_case_				:					Tuple   =       fairseq.checkpoint_utils.load_model_ensemble_and_task(
			    [checkpoint_path]     ,arg_overrides={"data": "/".join(dict_path.split("/"						)[:-1]						)}						)
			snake_case_				:					List[Any]   =       model[0].eval()

			# set weights for wav2vec2 encoder
			snake_case_				:					Any   =       WavaVecaModel(__a						)
			snake_case_				:					Union[str, Any]   =       recursively_load_weights_wavaveca(model.encoder     ,__a						)

			snake_case_				:					Tuple   =       SpeechaTextaForCausalLM(__a						)
			snake_case_,	snake_case_				:					List[str]   =       hf_decoder.model.decoder.load_state_dict(model.decoder.state_dict()     ,strict=__a						)

			# set output linear layer
			unexpected_keys.remove("embed_out"						)
			snake_case_				:					Optional[Any]   =       nn.Parameter(model.decoder.embed_out.detach()						)

			# layer norm is init to identity matrix so leaving it is fine
			logger.warning(F'''The following keys are missing when loading the decoder weights: {missing_keys}'''						)
			logger.warning(F'''The following keys are unexpected when loading the decoder weights: {unexpected_keys}'''						)

			snake_case_				:					Tuple   =       SpeechEncoderDecoderModel(encoder=__a     ,decoder=__a						)
			snake_case_				:					Any   =       False

			# add projection layer
			snake_case_				:					Tuple   =       nn.Parameter(projection_layer.weight						)
			snake_case_				:					Dict   =       nn.Parameter(projection_layer.bias						)

			snake_case_				:					Optional[Any]   =       create_vocab_dict(__a						)

			with open(os.path.join(__a     ,"vocab.json"						)     ,"w"						) as fp:
						json.dump(__a     ,__a						)

			snake_case_				:					Any   =       SpeechaTextaTokenizer(os.path.join(__a     ,"vocab.json"						)						)
			tokenizer.save_pretrained(__a						)

			snake_case_				:					int   =       hf_wavavec.config.to_dict()
			snake_case_				:					List[str]   =       tokenizer.pad_token_id
			snake_case_				:					List[str]   =       tokenizer.bos_token_id
			snake_case_				:					List[Any]   =       tokenizer.eos_token_id
			snake_case_				:					str   =       "speech_to_text_2"
			snake_case_				:					Optional[int]   =       "wav2vec2"

			snake_case_				:					Dict   =       SpeechEncoderDecoderConfig.from_dict(__a						)

			hf_wavavec.save_pretrained(__a						)
			feature_extractor.save_pretrained(__a						)


if __name__ == "__main__":
		__lowerCamelCase   :					Optional[Any]   							=  argparse.ArgumentParser()
		parser.add_argument('''--pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model.''')
		parser.add_argument('''--checkpoint_path''', default=None, type=str, help='''Path to fairseq checkpoint''')
		parser.add_argument('''--dict_path''', default=None, type=str, help='''Path to dict of fine-tuned model''')
		parser.add_argument(
		    '''--encoder_config_path''',
		    default='''facebook/wav2vec2-large-lv60''',
		    type=str,
		    help='''Path to hf encoder wav2vec2 checkpoint config''',
		)
		parser.add_argument(
		    '''--decoder_config_path''',
		    default='''facebook/s2t-small-mustc-en-fr-st''',
		    type=str,
		    help='''Path to hf decoder s2t checkpoint config''',
		)
		parser.add_argument('''--vocab_size''', default=10224, type=int, help='''Vocab size of decoder''')
		parser.add_argument('''--num_decoder_layers''', default=7, type=int, help='''Number of decoder layers''')

		__lowerCamelCase   :					List[str]   							=  parser.parse_args()
		convert_wavaveca_checkpoint(
		    args.checkpoint_path,
		    args.pytorch_dump_folder_path,
		    args.dict_path,
		    encoder_config_path=args.encoder_config_path,
		    decoder_config_path=args.decoder_config_path,
		    vocab_size=args.vocab_size,
		    num_decoder_layers=args.num_decoder_layers,
		)












'''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.
__lowerCamelCase   :					List[str]   							=					{'''LayoutLMv2Config''', '''LayoutLMv3Config'''}







@is_pipeline_test
class    A_	(unittest.TestCase							):
							"""simple docstring"""




							a__   		=	MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
							a__   		=	TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

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

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Tuple       ,							lowerCAmelCase__			:Union[str, Any]       ,							lowerCAmelCase__			:Dict				)				->  Any:


										'''simple docstring'''




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

							def 							_A	(		self			:List[str]       ,							lowerCAmelCase__			:Optional[int]       ,							lowerCAmelCase__			:Any				)				->  Optional[Any]:


										'''simple docstring'''




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

										# No kwarg
										snake_case_				:					List[Any]   =       classifier("Who are you voting for in 2020?"       ,							["politics"]				)
										self.assertEqual(lowerCAmelCase__       ,							{"sequence": ANY(lowerCAmelCase__				), "labels": [ANY(lowerCAmelCase__				)], "scores": [ANY(lowerCAmelCase__				)]}				)

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

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

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

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

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

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

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

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

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

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

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

										self.run_entailment_id(lowerCAmelCase__				)

							def 							_A	(		self			:List[Any]       ,							lowerCAmelCase__			:Pipeline				)				->  Union[str, Any]:


										'''simple docstring'''




										snake_case_				:					int   =       zero_shot_classifier.model.config
										snake_case_				:					Optional[int]   =       config.labelaid
										snake_case_				:					Tuple   =       zero_shot_classifier.entailment_id

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

										snake_case_				:					Tuple   =       {"entailment": 0, "neutral": 1, "contradiction": 2}
										self.assertEqual(zero_shot_classifier.entailment_id       ,							0				)

										snake_case_				:					str   =       {"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_				:					List[str]   =       original_labelaid
										self.assertEqual(lowerCAmelCase__       ,							zero_shot_classifier.entailment_id				)

							@require_torch
							def 							_A	(		self			:Tuple				)				->  Any:


										'''simple docstring'''




										snake_case_				:					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?" * 100       ,							candidate_labels=["politics", "public health", "science"]				)

							@require_torch
							def 							_A	(		self			:Optional[Any]				)				->  Tuple:


										'''simple docstring'''




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

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

							@require_tf
							def 							_A	(		self			:Union[str, Any]				)				->  Dict:


										'''simple docstring'''




										snake_case_				:					List[str]   =       pipeline(
										    "zero-shot-classification"       ,							model="sshleifer/tiny-distilbert-base-cased-distilled-squad"       ,							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(lowerCAmelCase__				)       ,							{
										        "sequence": "Who are you voting for in 2020?",
										        "labels": ["science", "public health", "politics"],
										        "scores": [0.3_3_3, 0.3_3_3, 0.3_3_3],
										    }       ,							)

							@slow
							@require_torch
							def 							_A	(		self			:Union[str, Any]				)				->  int:


										'''simple docstring'''




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

										self.assertEqual(
										    nested_simplify(lowerCAmelCase__				)       ,							{
										        "sequence": "Who are you voting for in 2020?",
										        "labels": ["politics", "public health", "science"],
										        "scores": [0.9_7_6, 0.0_1_5, 0.0_0_9],
										    }       ,							)
										snake_case_				:					Optional[int]   =       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=lowerCAmelCase__       ,							)
										self.assertEqual(
										    nested_simplify(lowerCAmelCase__				)       ,							{
										        "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_1_7, 0.7_1_3, 0.0_1_8, 0.0_1_8],
										    }       ,							)






							@slow
							@require_tf
							def 							_A	(		self			:List[str]				)				->  str:


										'''simple docstring'''




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

										self.assertEqual(
										    nested_simplify(lowerCAmelCase__				)       ,							{
										        "sequence": "Who are you voting for in 2020?",
										        "labels": ["politics", "public health", "science"],
										        "scores": [0.9_7_6, 0.0_1_5, 0.0_0_9],
										    }       ,							)
										snake_case_				:					Tuple   =       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=lowerCAmelCase__       ,							)
										self.assertEqual(
										    nested_simplify(lowerCAmelCase__				)       ,							{
										        "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_1_7, 0.7_1_3, 0.0_1_8, 0.0_1_8],
										    }       ,							)




