






from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor




class 		UpperCAmelCase_						:


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=3		,				_SCREAMING_SNAKE_CASE=32		,				_SCREAMING_SNAKE_CASE=3		,				_SCREAMING_SNAKE_CASE=10		,				_SCREAMING_SNAKE_CASE=[10, 20, 30, 40]		,				_SCREAMING_SNAKE_CASE=[1, 1, 2, 1]		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE="relu"		,				_SCREAMING_SNAKE_CASE=3		,				_SCREAMING_SNAKE_CASE=None		,				) ->				List[str]:
								snake_case_				:							str						 =       parent
								snake_case_				:							Optional[int]						 =       batch_size
								snake_case_				:							Dict						 =       image_size
								snake_case_				:							Tuple						 =       num_channels
								snake_case_				:							Union[str, Any]						 =       embeddings_size
								snake_case_				:							int						 =       hidden_sizes
								snake_case_				:							Optional[int]						 =       depths
								snake_case_				:							Dict						 =       is_training
								snake_case_				:							Tuple						 =       use_labels
								snake_case_				:							int						 =       hidden_act
								snake_case_				:							List[str]						 =       num_labels
								snake_case_				:							List[Any]						 =       scope
								snake_case_				:							Union[str, Any]						 =       len(_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							Union[str, Any]						 =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

								snake_case_				:							Optional[Any]						 =       None
								if self.use_labels:
										snake_case_				:							Any						 =       ids_tensor([self.batch_size]		,				self.num_labels				)

								snake_case_				:							Optional[int]						 =       self.get_config()
								return config, pixel_values, labels






						def       _lowerCAmelCase       (	self				) ->				Optional[int]:
								return RegNetConfig(
								    num_channels=self.num_channels		,				embeddings_size=self.embeddings_size		,				hidden_sizes=self.hidden_sizes		,				depths=self.depths		,				hidden_act=self.hidden_act		,				num_labels=self.num_labels		,				)






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Union[str, Any]:
								snake_case_				:							Union[str, Any]						 =       TFRegNetModel(config=_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[str]						 =       model(_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)
								# expected last hidden states: B, C, H // 32, W // 32
								self.parent.assertEqual(
								    result.last_hidden_state.shape		,				(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)		,				)






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Tuple:
								snake_case_				:							Optional[int]						 =       self.num_labels
								snake_case_				:							Tuple						 =       TFRegNetForImageClassification(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							List[str]						 =       model(_SCREAMING_SNAKE_CASE		,				labels=_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)
								self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_labels)				)






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




@require_tf
class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					,  SCREAMING_SNAKE_CASE__					,  unittest.TestCase					):


						'''simple docstring'''




						A     :   Optional[int]						=					(TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
						A     :   Dict						=					(
						    {'feature-extraction': TFRegNetModel, 'image-classification': TFRegNetForImageClassification}
						    if is_tf_available()
						    else {}
						)

						A     :   List[Any]						=					False
						A     :   List[str]						=					False
						A     :   Optional[Any]						=					False
						A     :   List[Any]						=					False
						A     :   List[Any]						=					False






						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							List[Any]						 =       TFRegNetModelTester(self				)
								snake_case_				:							Any						 =       ConfigTester(self		,				config_class=_SCREAMING_SNAKE_CASE		,				has_text_modality=_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								return






						@unittest.skip(reason="RegNet does not use inputs_embeds"				)
						def       _lowerCAmelCase       (	self				) ->				Dict:
								pass






						@unittest.skipIf(
						    not is_tf_available() or len(tf.config.list_physical_devices("GPU"				)				) == 0		,				reason="TF does not support backprop for grouped convolutions on CPU."		,				)
						@slow
						def       _lowerCAmelCase       (	self				) ->				Any:
								super().test_keras_fit()






						@unittest.skip(reason="RegNet does not support input and output embeddings"				)
						def       _lowerCAmelCase       (	self				) ->				str:
								pass






						def       _lowerCAmelCase       (	self				) ->				int:
								snake_case_ ,       snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
										snake_case_				:							int						 =       model_class(_SCREAMING_SNAKE_CASE				)
										snake_case_				:							str						 =       inspect.signature(model.call				)
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										snake_case_				:							List[str]						 =       [*signature.parameters.keys()]

										snake_case_				:							Dict						 =       ["pixel_values"]
										self.assertListEqual(arg_names[:1]		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Tuple:
								def check_hidden_states_output(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       model_class(_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Tuple						 =       model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)		,				training=_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Union[str, Any]						 =       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										snake_case_				:							Any						 =       self.model_tester.num_stages
										self.assertEqual(len(_SCREAMING_SNAKE_CASE				)		,				expected_num_stages + 1				)

										# RegNet's feature maps are of shape (batch_size, num_channels, height, width)
										self.assertListEqual(
										    list(hidden_states[0].shape[-2:]				)		,				[self.model_tester.image_size // 2, self.model_tester.image_size // 2]		,				)

								snake_case_ ,       snake_case_				:							Dict						 =       self.model_tester.prepare_config_and_inputs_for_common()
								snake_case_				:							Optional[int]						 =       ["basic", "bottleneck"]
								for model_class in self.all_model_classes:
										for layer_type in layers_type:
												snake_case_				:							Any						 =       layer_type
												snake_case_				:							int						 =       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"]
												snake_case_				:							Any						 =       True

												check_hidden_states_output(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				Optional[Any]:
								snake_case_ ,       snake_case_				:							List[Any]						 =       self.model_tester.prepare_config_and_inputs_for_common()

								def check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE={}				):
										snake_case_				:							List[Any]						 =       model(_SCREAMING_SNAKE_CASE		,				return_dict=_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)
										snake_case_				:							List[Any]						 =       model(_SCREAMING_SNAKE_CASE		,				return_dict=_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				).to_tuple()

										def recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
												if isinstance(_SCREAMING_SNAKE_CASE		,				(List, Tuple)				):
														for tuple_iterable_value, dict_iterable_value in zip(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
																recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
												elif tuple_object is None:
														return
												else:
														self.assertTrue(
														    all(tf.equal(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)				)		,				msg=(
														        "Tuple and dict output are not equal. Difference:"
														        f''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object				)				)}'''
														    )		,				)

												recursive_check(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								for model_class in self.all_model_classes:
										snake_case_				:							str						 =       model_class(_SCREAMING_SNAKE_CASE				)

										snake_case_				:							List[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Optional[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

										snake_case_				:							Optional[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				{"output_hidden_states": True}				)

										snake_case_				:							List[Any]						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Dict						 =       self._prepare_for_class(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				return_labels=_SCREAMING_SNAKE_CASE				)
										check_equivalence(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				{"output_hidden_states": True}				)






						def       _lowerCAmelCase       (	self				) ->				List[str]:
								snake_case_				:							List[str]						 =       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE				)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Any:
								for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case_				:							Dict						 =       TFRegNetModel.from_pretrained(_SCREAMING_SNAKE_CASE				)
										self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)




def      lowerCAmelCase__	(    ):
		snake_case_				:							int						 =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
		return image




@require_tf
@require_vision
class 		UpperCAmelCase_						(	unittest.TestCase					):


						'''simple docstring'''




						@cached_property
						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								return (
								    AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)
								    if is_vision_available()
								    else None
								)






						@slow
						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							str						 =       TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)

								snake_case_				:							int						 =       self.default_image_processor
								snake_case_				:							List[Any]						 =       prepare_img()
								snake_case_				:							str						 =       image_processor(images=_SCREAMING_SNAKE_CASE		,				return_tensors="tf"				)

								# forward pass
								snake_case_				:							Any						 =       model(**_SCREAMING_SNAKE_CASE		,				training=_SCREAMING_SNAKE_CASE				)

								# verify the logits
								snake_case_				:							List[str]						 =       tf.TensorShape((1, 1000)				)
								self.assertEqual(outputs.logits.shape		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       tf.constant([-0.4180, -1.5051, -3.4836]				)

								tf.debugging.assert_near(outputs.logits[0, :3]		,				_SCREAMING_SNAKE_CASE		,				atol=1e-4				)








from typing import List, Union

import numpy as np

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, logging
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, ChunkPipeline


lowercase  :							Dict			  =    logging.get_logger(__name__)




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				List[Any]:
								if isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       [label.strip() for label in labels.split(","				) if label.strip()]
								return labels






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								if len(_SCREAMING_SNAKE_CASE				) == 0 or len(_SCREAMING_SNAKE_CASE				) == 0:
										raise ValueError("You must include at least one label and at least one sequence."				)
								if hypothesis_template.format(labels[0]				) == hypothesis_template:
										raise ValueError(
										    (
										        "The provided hypothesis_template \"{}\" was not able to be formatted with the target labels. "
										        "Make sure the passed template includes formatting syntax such as {{}} where the label should go."
										    ).format(_SCREAMING_SNAKE_CASE				)				)

								if isinstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				):
										snake_case_				:							List[str]						 =       [sequences]

								snake_case_				:							List[str]						 =       []
								for sequence in sequences:
										sequence_pairs.extend([[sequence, hypothesis_template.format(_SCREAMING_SNAKE_CASE				)] for label in labels]				)

								return sequence_pairs, sequences




@add_end_docstrings(SCREAMING_SNAKE_CASE__					)
class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						def __init__(	self		,				_SCREAMING_SNAKE_CASE=ZeroShotClassificationArgumentHandler()		,				*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
								snake_case_				:							Dict						 =       args_parser
								super().__init__(*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)
								if self.entailment_id == -1:
										logger.warning(
										    "Failed to determine 'entailment' label id from the label2id mapping in the model config. Setting to "
										    "-1. Define a descriptive label2id mapping in the model config to ensure correct outputs."				)






						@property
						def       _lowerCAmelCase       (	self				) ->				str:
								for label, ind in self.model.config.labelaid.items():
										if label.lower().startswith("entail"				):
												return ind
								return -1






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=True		,				_SCREAMING_SNAKE_CASE=TruncationStrategy.ONLY_FIRST		,				**_SCREAMING_SNAKE_CASE				) ->				Dict:
								snake_case_				:							List[Any]						 =       self.framework
								if self.tokenizer.pad_token is None:
										# Override for tokenizers not supporting padding
										logger.error(
										    "Tokenizer was not supporting padding necessary for zero-shot, attempting to use "
										    " `pad_token=eos_token`"				)
										snake_case_				:							List[str]						 =       self.tokenizer.eos_token
								try:
										snake_case_				:							Union[str, Any]						 =       self.tokenizer(
										    _SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE		,				return_tensors=_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				truncation=_SCREAMING_SNAKE_CASE		,				)
								except Exception as e:
										if "too short" in str(_SCREAMING_SNAKE_CASE				):
												# tokenizers might yell that we want to truncate
												# to a value that is not even reached by the input.
												# In that case we don't want to truncate.
												# It seems there's not a really better way to catch that
												# exception.

												snake_case_				:							Union[str, Any]						 =       self.tokenizer(
												    _SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE		,				return_tensors=_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				truncation=TruncationStrategy.DO_NOT_TRUNCATE		,				)
										else:
												raise e

								return inputs






						def       _lowerCAmelCase       (	self		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[int]:
								if kwargs.get("multi_class"		,				_SCREAMING_SNAKE_CASE				) is not None:
										snake_case_				:							Any						 =       kwargs["multi_class"]
										logger.warning(
										    "The `multi_class` argument has been deprecated and renamed to `multi_label`. "
										    "`multi_class` will be removed in a future version of Transformers."				)
								snake_case_				:							Any						 =       {}
								if "candidate_labels" in kwargs:
										snake_case_				:							Tuple						 =       self._args_parser._parse_labels(kwargs["candidate_labels"]				)
								if "hypothesis_template" in kwargs:
										snake_case_				:							Optional[Any]						 =       kwargs["hypothesis_template"]

								snake_case_				:							Dict						 =       {}
								if "multi_label" in kwargs:
										snake_case_				:							List[Any]						 =       kwargs["multi_label"]
								return preprocess_params, {}, postprocess_params






						def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				*_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE		,				) ->				str:
								if len(_SCREAMING_SNAKE_CASE				) == 0:
										pass
								elif len(_SCREAMING_SNAKE_CASE				) == 1 and "candidate_labels" not in kwargs:
										snake_case_				:							int						 =       args[0]
								else:
										raise ValueError(f'''Unable to understand extra arguments {args}'''				)

								return super().__call__(_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE="This example is {}."				) ->				str:
								snake_case_ ,       snake_case_				:							Optional[int]						 =       self._args_parser(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								for i, (candidate_label, sequence_pair) in enumerate(zip(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)				):
										snake_case_				:							str						 =       self._parse_and_tokenize([sequence_pair]				)

										yield {
										    "candidate_label": candidate_label,
										    "sequence": sequences[0],
										    "is_last": i == len(_SCREAMING_SNAKE_CASE				) - 1,
										    **model_input,
										}






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				Any:
								snake_case_				:							Optional[Any]						 =       inputs["candidate_label"]
								snake_case_				:							Dict						 =       inputs["sequence"]
								snake_case_				:							Optional[int]						 =       {k: inputs[k] for k in self.tokenizer.model_input_names}
								snake_case_				:							Dict						 =       self.model(**_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       {
								    "candidate_label": candidate_label,
								    "sequence": sequence,
								    "is_last": inputs["is_last"],
								    **outputs,
								}
								return model_outputs






						def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=False				) ->				Any:
								snake_case_				:							str						 =       [outputs["candidate_label"] for outputs in model_outputs]
								snake_case_				:							Union[str, Any]						 =       [outputs["sequence"] for outputs in model_outputs]
								snake_case_				:							List[Any]						 =       np.concatenate([output["logits"].numpy() for output in model_outputs]				)
								snake_case_				:							Tuple						 =       logits.shape[0]
								snake_case_				:							List[Any]						 =       len(_SCREAMING_SNAKE_CASE				)
								snake_case_				:							int						 =       N // n
								snake_case_				:							Optional[Any]						 =       logits.reshape((num_sequences, n, -1)				)

								if multi_label or len(_SCREAMING_SNAKE_CASE				) == 1:
										# softmax over the entailment vs. contradiction dim for each label independently
										snake_case_				:							Any						 =       self.entailment_id
										snake_case_				:							List[str]						 =       -1 if entailment_id == 0 else 0
										snake_case_				:							Dict						 =       reshaped_outputs[..., [contradiction_id, entailment_id]]
										snake_case_				:							List[str]						 =       np.exp(_SCREAMING_SNAKE_CASE				) / np.exp(_SCREAMING_SNAKE_CASE				).sum(-1		,				keepdims=_SCREAMING_SNAKE_CASE				)
										snake_case_				:							Union[str, Any]						 =       scores[..., 1]
								else:
										# softmax the "entailment" logits over all candidate labels
										snake_case_				:							List[str]						 =       reshaped_outputs[..., self.entailment_id]
										snake_case_				:							Optional[Any]						 =       np.exp(_SCREAMING_SNAKE_CASE				) / np.exp(_SCREAMING_SNAKE_CASE				).sum(-1		,				keepdims=_SCREAMING_SNAKE_CASE				)

								snake_case_				:							int						 =       list(reversed(scores[0].argsort()				)				)
								return {
								    "sequence": sequences[0],
								    "labels": [candidate_labels[i] for i in top_inds],
								    "scores": scores[0, top_inds].tolist(),
								}
