
import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
						import torch
						from torch import nn

						from transformers import (
						    MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
						    VideoMAEForPreTraining,
						    VideoMAEForVideoClassification,
						    VideoMAEModel,
						)
						from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from transformers import VideoMAEImageProcessor
class  lowercase__:



	"""simple docstring"""




	def __init__(       self  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=1_3       ,							SCREAMING_SNAKE_CASE_  :			Dict=1_0       ,							SCREAMING_SNAKE_CASE_  :			List[str]=3       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=2       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=2       ,							SCREAMING_SNAKE_CASE_  :			Dict=2       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=True       ,							SCREAMING_SNAKE_CASE_  :			Dict=True       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3_2       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=5       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=4       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3_7       ,							SCREAMING_SNAKE_CASE_  :			Dict="gelu"       ,							SCREAMING_SNAKE_CASE_  :			str=0.1       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=0.1       ,							SCREAMING_SNAKE_CASE_  :			str=1_0       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=0.02       ,							SCREAMING_SNAKE_CASE_  :			Any=0.9       ,							SCREAMING_SNAKE_CASE_  :			List[str]=None       ,							)       ->     Optional[Any]:
					lowercase_       =					parent
					lowercase_       =					batch_size
					lowercase_       =					image_size
					lowercase_       =					num_channels
					lowercase_       =					patch_size
					lowercase_       =					tubelet_size
					lowercase_       =					num_frames
					lowercase_       =					is_training
					lowercase_       =					use_labels
					lowercase_       =					hidden_size
					lowercase_       =					num_hidden_layers
					lowercase_       =					num_attention_heads
					lowercase_       =					intermediate_size
					lowercase_       =					hidden_act
					lowercase_       =					hidden_dropout_prob
					lowercase_       =					attention_probs_dropout_prob
					lowercase_       =					type_sequence_label_size
					lowercase_       =					initializer_range
					lowercase_       =					mask_ratio
					lowercase_       =					scope

					# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
					lowercase_       =					(image_size // patch_size) ** 2
					lowercase_       =					(num_frames // tubelet_size) * self.num_patches_per_frame

					# use this variable to define bool_masked_pos
					lowercase_       =					int(mask_ratio * self.seq_length       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     List[Any]:
					lowercase_       =					floats_tensor(
					    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]       )

					lowercase_       =					None
					if self.use_labels:
									lowercase_       =					ids_tensor([self.batch_size]       ,							self.type_sequence_label_size       )

					lowercase_       =					self.get_config()

					return config, pixel_values, labels
	def 						_lowercase  (       self  :			List[str]       )       ->     Optional[Any]:
					return VideoMAEConfig(
					    image_size=self.image_size       ,							patch_size=self.patch_size       ,							num_channels=self.num_channels       ,							num_frames=self.num_frames       ,							tubelet_size=self.tubelet_size       ,							hidden_size=self.hidden_size       ,							num_hidden_layers=self.num_hidden_layers       ,							num_attention_heads=self.num_attention_heads       ,							intermediate_size=self.intermediate_size       ,							hidden_act=self.hidden_act       ,							hidden_dropout_prob=self.hidden_dropout_prob       ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,							is_decoder=SCREAMING_SNAKE_CASE_       ,							initializer_range=self.initializer_range       ,							)
	def 						_lowercase  (       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			str       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       )       ->     Optional[Any]:
					lowercase_       =					VideoMAEModel(config=SCREAMING_SNAKE_CASE_       )
					model.to(SCREAMING_SNAKE_CASE_       )
					model.eval()
					lowercase_       =					model(SCREAMING_SNAKE_CASE_       )
					self.parent.assertEqual(result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)       )
	def 						_lowercase  (       self  :			int       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       )       ->     Optional[int]:
					lowercase_       =					VideoMAEForPreTraining(SCREAMING_SNAKE_CASE_       )
					model.to(SCREAMING_SNAKE_CASE_       )
					model.eval()
					# important: each video needs to have the same number of masked patches
					# hence we define a single mask, which we then repeat for each example in the batch
					lowercase_       =					torch.ones((self.num_masks,)       )
					lowercase_       =					torch.cat([mask, torch.zeros(self.seq_length - mask.size(0       )       )]       )
					lowercase_       =					mask.expand(self.batch_size       ,							-1       ).bool()

					lowercase_       =					model(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )
					# model only returns predictions for masked patches
					lowercase_       =					mask.sum().item()
					lowercase_       =					3 * self.tubelet_size * self.patch_size**2
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, num_masked_patches, decoder_num_labels)       )




	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     Optional[int]:
					lowercase_       =					self.prepare_config_and_inputs()
					lowercase_       =					config_and_inputs
					lowercase_       =					{"""pixel_values""": pixel_values}
					return config, inputs_dict

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



	"""simple docstring"""




	a			:Optional[int]         =	(
	    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
	)
	a			:Any         =	(
	    {'feature-extraction': VideoMAEModel, 'video-classification': VideoMAEForVideoClassification}
	    if is_torch_available()
	    else {}
	)

	a			:int         =	False
	a			:str         =	False
	a			:List[str]         =	False
	a			:List[Any]         =	False
	def 						_lowercase  (       self  :			Tuple       )       ->     Optional[Any]:
					lowercase_       =					VideoMAEModelTester(self       )
					lowercase_       =					ConfigTester(self       ,							config_class=SCREAMING_SNAKE_CASE_       ,							has_text_modality=SCREAMING_SNAKE_CASE_       ,							hidden_size=3_7       )
	def 						_lowercase  (       self  :			str       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=False       )       ->     int:
					lowercase_       =					copy.deepcopy(SCREAMING_SNAKE_CASE_       )

					if model_class == VideoMAEForPreTraining:
									# important: each video needs to have the same number of masked patches
									# hence we define a single mask, which we then repeat for each example in the batch
									lowercase_       =					torch.ones((self.model_tester.num_masks,)       )
									lowercase_       =					torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0       )       )]       )
									lowercase_       =					mask.expand(self.model_tester.batch_size       ,							-1       ).bool()
									lowercase_       =					bool_masked_pos.to(SCREAMING_SNAKE_CASE_       )

					if return_labels:
									if model_class in [
									    *get_values(SCREAMING_SNAKE_CASE_       ),
									]:
													lowercase_       =					torch.zeros(
													    self.model_tester.batch_size       ,							dtype=torch.long       ,							device=SCREAMING_SNAKE_CASE_       )

					return inputs_dict
	def 						_lowercase  (       self  :			Dict       )       ->     Tuple:
					self.config_tester.run_common_tests()
	@unittest.skip(reason='''VideoMAE does not use inputs_embeds'''       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     int:
					pass
	def 						_lowercase  (       self  :			List[str]       )       ->     Dict:
					lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
									lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
									self.assertIsInstance(model.get_input_embeddings()       ,							(nn.Module)       )
									lowercase_       =					model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_       ,							nn.Linear       )       )
	def 						_lowercase  (       self  :			int       )       ->     Dict:
					lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
									lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
									lowercase_       =					inspect.signature(model.forward       )
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									lowercase_       =					[*signature.parameters.keys()]

									lowercase_       =					["""pixel_values"""]
									self.assertListEqual(arg_names[:1]       ,							SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			Dict       )       ->     Tuple:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			str       )       ->     List[str]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_       )
	@slow
	def 						_lowercase  (       self  :			List[Any]       )       ->     int:
					for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowercase_       =					VideoMAEModel.from_pretrained(SCREAMING_SNAKE_CASE_       )
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     Optional[int]:
					if not self.has_attentions:
									pass

					else:
									lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()
									lowercase_       =					True

									for model_class in self.all_model_classes:
													lowercase_       =					self.model_tester.seq_length - self.model_tester.num_masks
													lowercase_       =					(
													    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
													)

													lowercase_       =					True
													lowercase_       =					False
													lowercase_       =					True
													lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
													model.to(SCREAMING_SNAKE_CASE_       )
													model.eval()
													with torch.no_grad():
																	lowercase_       =					model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )       )
													lowercase_       =					outputs.attentions
													self.assertEqual(len(SCREAMING_SNAKE_CASE_       )       ,							self.model_tester.num_hidden_layers       )

													# check that output_attentions also work using config
													del inputs_dict["output_attentions"]
													lowercase_       =					True
													lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
													model.to(SCREAMING_SNAKE_CASE_       )
													model.eval()
													with torch.no_grad():
																	lowercase_       =					model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )       )
													lowercase_       =					outputs.attentions
													self.assertEqual(len(SCREAMING_SNAKE_CASE_       )       ,							self.model_tester.num_hidden_layers       )

													self.assertListEqual(
													    list(attentions[0].shape[-3:]       )       ,							[self.model_tester.num_attention_heads, seq_len, seq_len]       ,							)
													lowercase_       =					len(SCREAMING_SNAKE_CASE_       )

													# Check attention is always last and order is fine
													lowercase_       =					True
													lowercase_       =					True
													lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
													model.to(SCREAMING_SNAKE_CASE_       )
													model.eval()
													with torch.no_grad():
																	lowercase_       =					model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )       )

													self.assertEqual(out_len + 1       ,							len(SCREAMING_SNAKE_CASE_       )       )

													lowercase_       =					outputs.attentions

													self.assertEqual(len(SCREAMING_SNAKE_CASE_       )       ,							self.model_tester.num_hidden_layers       )
													self.assertListEqual(
													    list(self_attentions[0].shape[-3:]       )       ,							[self.model_tester.num_attention_heads, seq_len, seq_len]       ,							)
	def 						_lowercase  (       self  :			List[Any]       )       ->     Any:
					def check_hidden_states_output(SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Any       ):
									lowercase_       =					model_class(SCREAMING_SNAKE_CASE_       )
									model.to(SCREAMING_SNAKE_CASE_       )
									model.eval()

									with torch.no_grad():
													lowercase_       =					model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )       )

									lowercase_       =					outputs.hidden_states
									lowercase_       =					self.model_tester.num_hidden_layers + 1
									self.assertEqual(len(SCREAMING_SNAKE_CASE_       )       ,							SCREAMING_SNAKE_CASE_       )

									lowercase_       =					self.model_tester.seq_length - self.model_tester.num_masks
									lowercase_       =					num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]       )       ,							[seq_length, self.model_tester.hidden_size]       ,							)

					lowercase_       =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
									lowercase_       =					True
									check_hidden_states_output(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									lowercase_       =					True

									check_hidden_states_output(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       )




	@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''       )
	def 						_lowercase  (       self  :			int       )       ->     str:
					pass




def 				a						(							):


				'''simple docstring'''
				lowercase_       =					hf_hub_download(
				    repo_id='''hf-internal-testing/spaghetti-video'''						,   filename='''eating_spaghetti.npy'''						,   repo_type='''dataset'''					)
				lowercase_       =					np.load(_lowercase					)
				return list(_lowercase					)


@require_torch
@require_vision
class  lowercase__(				unittest.TestCase							):



	"""simple docstring"""




	@cached_property
	def 						_lowercase  (       self  :			str       )       ->     List[str]:
					# logits were tested with a different mean and std, so we use the same here
					return (
					    VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]       ,							image_std=[0.5, 0.5, 0.5]       )
					    if is_vision_available()
					    else None
					)
	@slow
	def 						_lowercase  (       self  :			Optional[Any]       )       ->     Optional[Any]:
					lowercase_       =					VideoMAEForVideoClassification.from_pretrained('''MCG-NJU/videomae-base-finetuned-kinetics'''       ).to(
					    SCREAMING_SNAKE_CASE_       )

					lowercase_       =					self.default_image_processor
					lowercase_       =					prepare_video()
					lowercase_       =					image_processor(SCREAMING_SNAKE_CASE_       ,							return_tensors='''pt'''       ).to(SCREAMING_SNAKE_CASE_       )

					# forward pass
					with torch.no_grad():
									lowercase_       =					model(**SCREAMING_SNAKE_CASE_       )

					# verify the logits
					lowercase_       =					torch.Size((1, 4_0_0)       )
					self.assertEqual(outputs.logits.shape       ,							SCREAMING_SNAKE_CASE_       )

					lowercase_       =					torch.tensor([0.36_69, -0.06_88, -0.24_21]       ).to(SCREAMING_SNAKE_CASE_       )

					self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,							SCREAMING_SNAKE_CASE_       ,							atol=1e-4       )       )




	@slow
	def 						_lowercase  (       self  :			List[Any]       )       ->     Union[str, Any]:
					lowercase_       =					VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''       ).to(SCREAMING_SNAKE_CASE_       )

					lowercase_       =					self.default_image_processor
					lowercase_       =					prepare_video()
					lowercase_       =					image_processor(SCREAMING_SNAKE_CASE_       ,							return_tensors='''pt'''       ).to(SCREAMING_SNAKE_CASE_       )

					# add boolean mask, indicating which patches to mask
					lowercase_       =					hf_hub_download(repo_id='''hf-internal-testing/bool-masked-pos'''       ,							filename='''bool_masked_pos.pt'''       )
					lowercase_       =					torch.load(SCREAMING_SNAKE_CASE_       )

					# forward pass
					with torch.no_grad():
									lowercase_       =					model(**SCREAMING_SNAKE_CASE_       )

					# verify the logits
					lowercase_       =					torch.Size([1, 1_4_0_8, 1_5_3_6]       )
					lowercase_       =					torch.tensor(
					    [[0.79_94, 0.96_12, 0.85_08], [0.74_01, 0.89_58, 0.83_02], [0.58_62, 0.74_68, 0.73_25]]       ,							device=SCREAMING_SNAKE_CASE_       )
					self.assertEqual(outputs.logits.shape       ,							SCREAMING_SNAKE_CASE_       )
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]       ,							SCREAMING_SNAKE_CASE_       ,							atol=1e-4       )       )

					# verify the loss (`config.norm_pix_loss` = `True`)
					lowercase_       =					torch.tensor([0.51_42]       ,							device=SCREAMING_SNAKE_CASE_       )
					self.assertTrue(torch.allclose(outputs.loss       ,							SCREAMING_SNAKE_CASE_       ,							atol=1e-4       )       )

					# verify the loss (`config.norm_pix_loss` = `False`)
					lowercase_       =					VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''       ,							norm_pix_loss=SCREAMING_SNAKE_CASE_       ).to(
					    SCREAMING_SNAKE_CASE_       )

					with torch.no_grad():
									lowercase_       =					model(**SCREAMING_SNAKE_CASE_       )

					lowercase_       =					torch.tensor(torch.tensor([0.64_69]       )       ,							device=SCREAMING_SNAKE_CASE_       )
					self.assertTrue(torch.allclose(outputs.loss       ,							SCREAMING_SNAKE_CASE_       ,							atol=1e-4       )       )









'''simple docstring'''




from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
							from PIL import Image

							from ..image_utils import load_image

if is_torch_available():
							from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
							from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
							from ..tf_utils import stable_softmax

a   :			Union[str, Any]					  =    logging.get_logger(__name__)

@add_end_docstrings(__magic_name__			)
class 			UpperCamelCase_ (							__magic_name__			):





	def __init__(  self		,		**A    )			->			List[str]:
								super().__init__(**A    )

								requires_backends(self		,		"""vision"""    )
								self.check_model_type(
								    TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
								    if self.framework == """tf"""
								    else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING    )





	def __call__(  self		,		A		,		**A    )			->			Optional[Any]:
								return super().__call__(A		,		**A    )





	def  _lowercase(  self		,		**A    )			->			Optional[Any]:
								UpperCAmelCase     :		List[Any]							     =		{}
								if "candidate_labels" in kwargs:
															UpperCAmelCase     :		Dict							     =		kwargs["""candidate_labels"""]
								if "hypothesis_template" in kwargs:
															UpperCAmelCase     :		Optional[Any]							     =		kwargs["""hypothesis_template"""]

								return preprocess_params, {}, {}





	def  _lowercase(  self		,		A		,		A=None		,		A="This is a photo of {}."    )			->			Optional[Any]:
								UpperCAmelCase     :		int							     =		load_image(A    )
								UpperCAmelCase     :		List[str]							     =		self.image_processor(images=[image]		,		return_tensors=self.framework    )
								UpperCAmelCase     :		List[str]							     =		candidate_labels
								UpperCAmelCase     :		Tuple							     =		[hypothesis_template.format(A    ) for x in candidate_labels]
								UpperCAmelCase     :		Union[str, Any]							     =		self.tokenizer(A		,		return_tensors=self.framework		,		padding=A    )
								UpperCAmelCase     :		Union[str, Any]							     =		[text_inputs]
								return inputs





	def  _lowercase(  self		,		A    )			->			Optional[int]:
								UpperCAmelCase     :		List[Any]							     =		model_inputs.pop("""candidate_labels"""    )
								UpperCAmelCase     :		Optional[Any]							     =		model_inputs.pop("""text_inputs"""    )
								if isinstance(text_inputs[0]		,		A    ):
															UpperCAmelCase     :		Optional[Any]							     =		text_inputs[0]
								else:
															# Batching case.
															UpperCAmelCase     :		Any							     =		text_inputs[0][0]

								UpperCAmelCase     :		Dict							     =		self.model(**A		,		**A    )

								UpperCAmelCase     :		List[Any]							     =		{
								    """candidate_labels""": candidate_labels,
								    """logits""": outputs.logits_per_image,
								}
								return model_outputs






	def  _lowercase(  self		,		A    )			->			Union[str, Any]:
								UpperCAmelCase     :		int							     =		model_outputs.pop("""candidate_labels"""    )
								UpperCAmelCase     :		int							     =		model_outputs["""logits"""][0]
								if self.framework == "pt":
															UpperCAmelCase     :		Optional[int]							     =		logits.softmax(dim=-1    ).squeeze(-1    )
															UpperCAmelCase     :		Any							     =		probs.tolist()
															if not isinstance(A		,		A    ):
																						UpperCAmelCase     :		Any							     =		[scores]
								elif self.framework == "tf":
															UpperCAmelCase     :		List[str]							     =		stable_softmax(A		,		axis=-1    )
															UpperCAmelCase     :		Union[str, Any]							     =		probs.numpy().tolist()
								else:
															raise ValueError(f'''Unsupported framework: {self.framework}'''    )

								UpperCAmelCase     :		Any							     =		[
								    {"""score""": score, """label""": candidate_label}
								    for score, candidate_label in sorted(zip(A		,		A    )		,		key=lambda A    : -x[0]    )
								]
								return result

