






import argparse
import math
import os
from copy import deepcopy

import torch
from audio_diffusion.models import DiffusionAttnUnetaD
from diffusion import sampling
from torch import nn

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel


_a      	=  {
    '''gwf-440k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/gwf-440k.ckpt''',
        '''sample_rate''': 48000,
        '''sample_size''': 65536,
    },
    '''jmann-small-190k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/jmann-small-190k.ckpt''',
        '''sample_rate''': 48000,
        '''sample_size''': 65536,
    },
    '''jmann-large-580k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/jmann-large-580k.ckpt''',
        '''sample_rate''': 48000,
        '''sample_size''': 131072,
    },
    '''maestro-uncond-150k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/maestro-uncond-150k.ckpt''',
        '''sample_rate''': 16000,
        '''sample_size''': 65536,
    },
    '''unlocked-uncond-250k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/unlocked-uncond-250k.ckpt''',
        '''sample_rate''': 16000,
        '''sample_size''': 65536,
    },
    '''honk-140k''': {
        '''url''': '''https://model-server.zqevans2.workers.dev/honk-140k.ckpt''',
        '''sample_rate''': 16000,
        '''sample_size''': 65536,
    },
}


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  int:





						"""simple docstring"""



						return torch.atana(__lowerCAmelCase ,		__lowerCAmelCase	) / math.pi * 2


def __A    (      __lowerCAmelCase	)->  int:





						"""simple docstring"""



						_UpperCAmelCase									=			torch.sin(t * math.pi / 2	) ** 2
						_UpperCAmelCase									=			(1 - sigma**2) ** 0.5
						return alpha_sigma_to_t(__lowerCAmelCase ,		__lowerCAmelCase	)





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""






	pass





class __lowerCamelCase (      nn.Module):





	"""simple docstring"""






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







							super().__init__()

							_UpperCAmelCase									=			DiffusionAttnUnetaD(UpperCAmelCase       ,    n_attn_layers=4    )
							_UpperCAmelCase									=			deepcopy(self.diffusion    )
							_UpperCAmelCase									=			torch.quasirandom.SobolEngine(1       ,    scramble=UpperCAmelCase    )



def __A    (      __lowerCAmelCase	)->  Any:





						"""simple docstring"""



						_UpperCAmelCase									=			MODELS_MAP[model_name]['url']
						os.system(F"""wget {url} ./"""	)

						return F"""./{model_name}.ckpt"""


_a      	=  {
    '''1''': '''resnets.0''',
    '''2''': '''attentions.0''',
    '''3''': '''resnets.1''',
    '''4''': '''attentions.1''',
    '''5''': '''resnets.2''',
    '''6''': '''attentions.2''',
}
_a      	=  {
    '''8''': '''resnets.0''',
    '''9''': '''attentions.0''',
    '''10''': '''resnets.1''',
    '''11''': '''attentions.1''',
    '''12''': '''resnets.2''',
    '''13''': '''attentions.2''',
}
_a      	=  {
    '''1''': '''resnets.0''',
    '''2''': '''attentions.0''',
    '''3''': '''resnets.1''',
    '''4''': '''attentions.1''',
    '''5''': '''resnets.2''',
    '''6''': '''attentions.2''',
    '''8''': '''resnets.3''',
    '''9''': '''attentions.3''',
    '''10''': '''resnets.4''',
    '''11''': '''attentions.4''',
    '''12''': '''resnets.5''',
    '''13''': '''attentions.5''',
}
_a      	=  {
    '''0''': '''resnets.0''',
    '''1''': '''resnets.1''',
    '''2''': '''resnets.2''',
    '''4''': '''resnets.0''',
    '''5''': '''resnets.1''',
    '''6''': '''resnets.2''',
}

_a      	=  {
    '''skip''': '''conv_skip''',
    '''main.0''': '''conv_1''',
    '''main.1''': '''group_norm_1''',
    '''main.3''': '''conv_2''',
    '''main.4''': '''group_norm_2''',
}

_a      	=  {
    '''norm''': '''group_norm''',
    '''qkv_proj''': ['''query''', '''key''', '''value'''],
    '''out_proj''': ['''proj_attn'''],
}


def __A    (      __lowerCAmelCase	)->  Any:





						"""simple docstring"""



						if name.startswith('skip'	):
												return name.replace('skip' ,		RES_CONV_MAP['skip']	)

						# name has to be of format main.{digit}
						if not name.startswith('main.'	):
												raise ValueError(F"""ResConvBlock error with {name}"""	)

						return name.replace(name[:6] ,		RES_CONV_MAP[name[:6]]	)


def __A    (      __lowerCAmelCase	)->  List[Any]:





						"""simple docstring"""



						for key, value in ATTN_MAP.items():
												if name.startswith(__lowerCAmelCase	) and not isinstance(__lowerCAmelCase ,		__lowerCAmelCase	):
																		return name.replace(__lowerCAmelCase ,		__lowerCAmelCase	)
												elif name.startswith(__lowerCAmelCase	):
																		return [name.replace(__lowerCAmelCase ,		__lowerCAmelCase	) for v in value]
						raise ValueError(F"""Attn error with {name}"""	)


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase=13	)->  List[str]:





						"""simple docstring"""



						_UpperCAmelCase									=			input_string

						if string.split('.'	)[0] == "timestep_embed":
												return string.replace('timestep_embed' ,		'time_proj'	)

						_UpperCAmelCase									=			0
						if string.startswith('net.3.'	):
												depth += 1
												_UpperCAmelCase									=			string[6:]
						elif string.startswith('net.'	):
												_UpperCAmelCase									=			string[4:]

						while string.startswith('main.7.'	):
												depth += 1
												_UpperCAmelCase									=			string[7:]

						if string.startswith('main.'	):
												_UpperCAmelCase									=			string[5:]

						# mid block
						if string[:2].isdigit():
												_UpperCAmelCase									=			string[:2]
												_UpperCAmelCase									=			string[2:]
						else:
												_UpperCAmelCase									=			string[0]
												_UpperCAmelCase									=			string[1:]

						if depth == max_depth:
												_UpperCAmelCase									=			MID_NUM_TO_LAYER[layer_num]
												_UpperCAmelCase									=			'mid_block'
						elif depth > 0 and int(__lowerCAmelCase	) < 7:
												_UpperCAmelCase									=			DOWN_NUM_TO_LAYER[layer_num]
												_UpperCAmelCase									=			F"""down_blocks.{depth}"""
						elif depth > 0 and int(__lowerCAmelCase	) > 7:
												_UpperCAmelCase									=			UP_NUM_TO_LAYER[layer_num]
												_UpperCAmelCase									=			F"""up_blocks.{max_depth - depth - 1}"""
						elif depth == 0:
												_UpperCAmelCase									=			DEPTH_0_TO_LAYER[layer_num]
												_UpperCAmelCase									=			F"""up_blocks.{max_depth - 1}""" if int(__lowerCAmelCase	) > 3 else 'down_blocks.0'

						if not string_left.startswith('.'	):
												raise ValueError(F"""Naming error with {input_string} and string_left: {string_left}."""	)

						_UpperCAmelCase									=			string_left[1:]

						if "resnets" in new_layer:
												_UpperCAmelCase									=			convert_resconv_naming(__lowerCAmelCase	)
						elif "attentions" in new_layer:
												_UpperCAmelCase									=			convert_attn_naming(__lowerCAmelCase	)
												_UpperCAmelCase									=			new_string_left

						if not isinstance(__lowerCAmelCase ,		__lowerCAmelCase	):
												_UpperCAmelCase									=			prefix + '.' + new_layer + '.' + string_left
						else:
												_UpperCAmelCase									=			[prefix + '.' + new_layer + '.' + s for s in string_left]
						return new_string


def __A    (      __lowerCAmelCase	)->  List[Any]:





						"""simple docstring"""



						_UpperCAmelCase									=			{}
						for k, v in state_dict.items():
												if k.endswith('kernel'	):
																		# up- and downsample layers, don't have trainable weights
																		continue

												_UpperCAmelCase									=			rename(__lowerCAmelCase	)

												# check if we need to transform from Conv => Linear for attention
												if isinstance(__lowerCAmelCase ,		__lowerCAmelCase	):
																		_UpperCAmelCase									=			transform_conv_attns(__lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase	)
												else:
																		_UpperCAmelCase									=			v

						return new_state_dict


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase	)->  Optional[Any]:





						"""simple docstring"""



						if len(__lowerCAmelCase	) == 1:
												if len(v.shape	) == 3:
																		# weight
																		_UpperCAmelCase									=			v[:, :, 0]
												else:
																		# bias
																		_UpperCAmelCase									=			v
						else:
												# qkv matrices
												_UpperCAmelCase									=			v.shape[0]
												_UpperCAmelCase									=			trippled_shape // 3
												for i in range(3	):
																		if len(v.shape	) == 3:
																								_UpperCAmelCase									=			v[i * single_shape : (i + 1) * single_shape, :, 0]
																		else:
																								_UpperCAmelCase									=			v[i * single_shape : (i + 1) * single_shape]
						return new_state_dict


def __A    (      __lowerCAmelCase	)->  Tuple:





						"""simple docstring"""



						_UpperCAmelCase									=			torch.device('cuda' if torch.cuda.is_available() else 'cpu'	)

						_UpperCAmelCase									=			args.model_path.split('/'	)[-1].split('.'	)[0]
						if not os.path.isfile(args.model_path	):
												assert (
												    model_name == args.model_path
												), F"""Make sure to provide one of the official model names {MODELS_MAP.keys()}"""
												_UpperCAmelCase									=			download(__lowerCAmelCase	)

						_UpperCAmelCase									=			MODELS_MAP[model_name]['sample_rate']
						_UpperCAmelCase									=			MODELS_MAP[model_name]['sample_size']

						_UpperCAmelCase									=			Object()
						_UpperCAmelCase									=			sample_size
						_UpperCAmelCase									=			sample_rate
						_UpperCAmelCase									=			0

						_UpperCAmelCase									=			UNetaDModel(sample_size=__lowerCAmelCase ,		sample_rate=__lowerCAmelCase	)
						_UpperCAmelCase									=			diffusers_model.state_dict()

						_UpperCAmelCase									=			DiffusionUncond(__lowerCAmelCase	)
						orig_model.load_state_dict(torch.load(args.model_path ,		map_location=__lowerCAmelCase	)['state_dict']	)
						_UpperCAmelCase									=			orig_model.diffusion_ema.eval()
						_UpperCAmelCase									=			orig_model.state_dict()
						_UpperCAmelCase									=			rename_orig_weights(__lowerCAmelCase	)

						_UpperCAmelCase									=			set(renamed_state_dict.keys()	) - set(diffusers_state_dict.keys()	)
						_UpperCAmelCase									=			set(diffusers_state_dict.keys()	) - set(renamed_state_dict.keys()	)

						assert len(__lowerCAmelCase	) == 0, F"""Problem with {renamed_minus_diffusers}"""
						assert all(k.endswith('kernel'	) for k in list(__lowerCAmelCase	)	), F"""Problem with {diffusers_minus_renamed}"""

						for key, value in renamed_state_dict.items():
												assert (
												    diffusers_state_dict[key].squeeze().shape == value.squeeze().shape
												), F"""Shape for {key} doesn't match. Diffusers: {diffusers_state_dict[key].shape} vs. {value.shape}"""
												if key == "time_proj.weight":
																		_UpperCAmelCase									=			value.squeeze()

												_UpperCAmelCase									=			value

						diffusers_model.load_state_dict(__lowerCAmelCase	)

						_UpperCAmelCase									=			100
						_UpperCAmelCase									=			33

						_UpperCAmelCase									=			IPNDMScheduler(num_train_timesteps=__lowerCAmelCase	)

						_UpperCAmelCase									=			torch.manual_seed(__lowerCAmelCase	)
						_UpperCAmelCase									=			torch.randn([1, 2, config.sample_size] ,		generator=__lowerCAmelCase	).to(__lowerCAmelCase	)

						_UpperCAmelCase									=			torch.linspace(1 ,		0 ,		steps + 1 ,		device=__lowerCAmelCase	)[:-1]
						_UpperCAmelCase									=			get_crash_schedule(__lowerCAmelCase	)

						_UpperCAmelCase									=			DanceDiffusionPipeline(unet=__lowerCAmelCase ,		scheduler=__lowerCAmelCase	)

						_UpperCAmelCase									=			torch.manual_seed(33	)
						_UpperCAmelCase									=			pipe(num_inference_steps=__lowerCAmelCase ,		generator=__lowerCAmelCase	).audios

						_UpperCAmelCase									=			sampling.iplms_sample(__lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase ,		{}	)
						_UpperCAmelCase									=			generated.clamp(-1 ,		1	)

						_UpperCAmelCase									=			(generated - audio).abs().sum()
						_UpperCAmelCase									=			(generated - audio).abs().max()

						if args.save:
												pipe.save_pretrained(args.checkpoint_path	)

						print('Diff sum' ,		__lowerCAmelCase	)
						print('Diff max' ,		__lowerCAmelCase	)

						assert diff_max < 1E-3, F"""Diff max: {diff_max} is too much :-/"""

						print(F"""Conversion for {model_name} successful!"""	)


if __name__ == "__main__":
		_a      	=  argparse.ArgumentParser()

		parser.add_argument('''--model_path''', default=None, type=str, required=True, help='''Path to the model to convert.''')
		parser.add_argument(
		    '''--save''', default=True, type=bool, required=False, help='''Whether to save the converted model or not.'''
		)
		parser.add_argument('''--checkpoint_path''', default=None, type=str, required=True, help='''Path to the output model.''')
		_a      	=  parser.parse_args()

		main(args)








import unittest

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

from .test_pipelines_common import ANY


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





@is_pipeline_test
class __lowerCamelCase (      unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								=      MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
	UpperCamelCase__								=      TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

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

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







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

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







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

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

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

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

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

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

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

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

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

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

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

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

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

							self.run_entailment_id(UpperCAmelCase    )

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







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

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

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

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

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

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

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







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

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







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

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

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







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

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

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







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

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

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







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

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