



'''simple docstring'''




from __future__ import annotations

import unittest

import numpy as np

from transformers import OPTConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, slow

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


if is_tf_available():
						import tensorflow as tf

						from transformers import GPTaTokenizer, TFOPTForCausalLM, TFOPTModel



def 	a			( lowerCamelCase__						,      lowerCamelCase__						,      lowerCamelCase__=None						,      lowerCamelCase__=None    ):
			'''simple docstring'''





			if attention_mask is None:
						A_	:						Optional[Any]	=     tf.cast(tf.math.not_equal(lowerCamelCase__						,      config.pad_token_id    )						,      tf.inta    )
			return {"input_ids": input_ids, "attention_mask": attention_mask}







@require_tf
class 	_lowerCAmelCase							:
	__SCREAMING_SNAKE_CASE   :		Union[str, Any]					=					OPTConfig
	__SCREAMING_SNAKE_CASE   :		int					=					{}
	__SCREAMING_SNAKE_CASE   :		Union[str, Any]					=					'gelu'


	def __init__(self       ,      lowercase       ,      lowercase=13       ,      lowercase=7       ,      lowercase=True       ,      lowercase=False       ,      lowercase=99       ,      lowercase=16       ,      lowercase=2       ,      lowercase=4       ,      lowercase=4       ,      lowercase="gelu"       ,      lowercase=0.1       ,      lowercase=0.1       ,      lowercase=20       ,      lowercase=2       ,      lowercase=1       ,      lowercase=0       ,      lowercase=16       ,      lowercase=16       ,      ):
				A_	:						Dict	=     parent
				A_	:						Dict	=     batch_size
				A_	:						List[str]	=     seq_length
				A_	:						Any	=     is_training
				A_	:						List[str]	=     use_labels
				A_	:						Dict	=     vocab_size
				A_	:						Dict	=     hidden_size
				A_	:						str	=     num_hidden_layers
				A_	:						Optional[Any]	=     num_attention_heads
				A_	:						int	=     intermediate_size
				A_	:						int	=     hidden_act
				A_	:						int	=     hidden_dropout_prob
				A_	:						List[str]	=     attention_probs_dropout_prob
				A_	:						str	=     max_position_embeddings
				A_	:						int	=     eos_token_id
				A_	:						List[str]	=     pad_token_id
				A_	:						Tuple	=     bos_token_id
				A_	:						Any	=     embed_dim
				A_	:						Union[str, Any]	=     word_embed_proj_dim
				A_	:						Optional[int]	=     False


	def     _a	(self							):
				A_	:						List[str]	=     ids_tensor([self.batch_size, self.seq_length - 1]       ,      self.vocab_size							)
				A_	:						Optional[int]	=     tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size							)       ,      1							)
				A_	:						List[str]	=     tf.concat([input_ids, eos_tensor]       ,      axis=1							)

				A_	:						List[str]	=     self.config_cls(
				    vocab_size=self.vocab_size       ,      hidden_size=self.hidden_size       ,      num_hidden_layers=self.num_hidden_layers       ,      num_attention_heads=self.num_attention_heads       ,      ffn_dim=self.intermediate_size       ,      dropout=self.hidden_dropout_prob       ,      attention_dropout=self.attention_probs_dropout_prob       ,      max_position_embeddings=self.max_position_embeddings       ,      eos_token_id=self.eos_token_id       ,      bos_token_id=self.bos_token_id       ,      pad_token_id=self.pad_token_id       ,      embed_dim=self.embed_dim       ,      word_embed_proj_dim=self.word_embed_proj_dim       ,      is_encoder_decoder=lowercase       ,      **self.config_updates       ,      )
				A_	:						List[Any]	=     prepare_opt_inputs_dict(lowercase       ,      lowercase							)
				return config, inputs_dict


	def     _a	(self       ,      lowercase       ,      lowercase							):
				A_	:						str	=     TFOPTModel(config=lowercase							)
				A_	:						Union[str, Any]	=     inputs_dict["""input_ids"""]

				A_	:						Optional[Any]	=     input_ids[:1, :]
				A_	:						Optional[Any]	=     inputs_dict["""attention_mask"""][:1, :]
				A_	:						Union[str, Any]	=     1

				# first forward pass
				A_	:						Optional[Any]	=     model(lowercase       ,      attention_mask=lowercase       ,      use_cache=lowercase							)

				A_,    A_	:						Optional[int]	=     outputs.to_tuple()

				# create hypothetical next token and extent to next_input_ids
				A_	:						str	=     ids_tensor((self.batch_size, 3)       ,      config.vocab_size							)
				A_	:						List[Any]	=     tf.cast(ids_tensor((self.batch_size, 3)       ,      2							)       ,      tf.inta							)

				# append to next input_ids and
				A_	:						List[Any]	=     tf.concat([input_ids, next_tokens]       ,      axis=-1							)
				A_	:						Any	=     tf.concat([attention_mask, next_attn_mask]       ,      axis=-1							)

				A_	:						Dict	=     model(lowercase       ,      attention_mask=lowercase							)[0]
				A_	:						str	=     model(lowercase       ,      attention_mask=lowercase       ,      past_key_values=lowercase							)[0]

				self.parent.assertEqual(next_tokens.shape[1]       ,      output_from_past.shape[1]							)

				# select random slice
				A_	:						Any	=     int(ids_tensor((1,)       ,      output_from_past.shape[-1]							)							)
				A_	:						List[str]	=     output_from_no_past[:, -3:, random_slice_idx]
				A_	:						Any	=     output_from_past[:, :, random_slice_idx]

				# test that outputs are equal for slice
				tf.debugging.assert_near(lowercase       ,      lowercase       ,      rtol=1E-3							)







@require_tf
class 	_lowerCAmelCase							(			__UpperCAmelCase      ,			__UpperCAmelCase      ,			unittest.TestCase ):
	__SCREAMING_SNAKE_CASE   :		List[str]					=					(TFOPTModel, TFOPTForCausalLM) if is_tf_available() else ()
	__SCREAMING_SNAKE_CASE   :		List[str]					=					(TFOPTForCausalLM,) if is_tf_available() else ()
	__SCREAMING_SNAKE_CASE   :		List[Any]					=					(
	    {'feature-extraction': TFOPTModel, 'text-generation': TFOPTForCausalLM} if is_tf_available() else {}
	)
	__SCREAMING_SNAKE_CASE   :		Tuple					=					False
	__SCREAMING_SNAKE_CASE   :		List[Any]					=					False
	__SCREAMING_SNAKE_CASE   :		Any					=					False
	__SCREAMING_SNAKE_CASE   :		List[Any]					=					10


	def     _a	(self							):
				A_	:						int	=     TFOPTModelTester(self							)
				A_	:						List[str]	=     ConfigTester(self       ,      config_class=lowercase							)


	def     _a	(self							):
				self.config_tester.run_common_tests()


	def     _a	(self							):
				A_	:						List[str]	=     self.model_tester.prepare_config_and_inputs_for_common()
				self.model_tester.check_decoder_model_past_large_inputs(*lowercase							)


	def     _a	(self							):
				A_,    A_	:						Tuple	=     self.model_tester.prepare_config_and_inputs_for_common()

				def _get_word_embedding_weight(lowercase       ,      lowercase							):
							if hasattr(lowercase       ,      """weight"""							):
										return embedding_layer.weight
							else:
										# Here we build the word embeddings weights if not exists.
										# And then we retry to get the attribute once built.
										model.build()
										if hasattr(lowercase       ,      """weight"""							):
													return embedding_layer.weight
										else:
													return None

				for model_class in self.all_model_classes:
							for size in [config.vocab_size - 10, config.vocab_size + 10]:
										# build the embeddings
										A_	:						Optional[int]	=     model_class(config=lowercase							)
										A_	:						Any	=     _get_word_embedding_weight(lowercase       ,      model.get_input_embeddings()							)
										A_	:						Tuple	=     _get_word_embedding_weight(lowercase       ,      model.get_output_embeddings()							)

										# reshape the embeddings
										model.resize_token_embeddings(lowercase							)
										A_	:						Dict	=     _get_word_embedding_weight(lowercase       ,      model.get_input_embeddings()							)
										A_	:						int	=     _get_word_embedding_weight(lowercase       ,      model.get_output_embeddings()							)

										# check that the resized embeddings size matches the desired size.
										A_	:						Any	=     size if size is not None else config.vocab_size

										self.assertEqual(new_input_embeddings.shape[0]       ,      lowercase							)

										# check that weights remain the same after resizing
										A_	:						Tuple	=     True
										for pa, pa in zip(old_input_embeddings.value()       ,      new_input_embeddings.value()							):
													if tf.math.reduce_sum(tf.math.abs(pa - pa							)							) > 0:
																A_	:						List[Any]	=     False
										self.assertTrue(lowercase							)

										if old_output_embeddings is not None and new_output_embeddings is not None:
													self.assertEqual(new_output_embeddings.shape[0]       ,      lowercase							)

													A_	:						int	=     True
													for pa, pa in zip(old_output_embeddings.value()       ,      new_output_embeddings.value()							):
																if tf.math.reduce_sum(tf.math.abs(pa - pa							)							) > 0:
																			A_	:						Optional[Any]	=     False
													self.assertTrue(lowercase							)






def 	a			( lowerCamelCase__    ):
			'''simple docstring'''





			return tf.constant(lowerCamelCase__						,      dtype=tf.intaa    )







@require_tf
class 	_lowerCAmelCase							(			unittest.TestCase ):
	__SCREAMING_SNAKE_CASE   :		Optional[Any]					=					99


	def     _a	(self							):
				A_	:						List[str]	=     tf.ones((4, 1)       ,      dtype=tf.intaa							) * 2
				A_	:						int	=     tf.concat([ids_tensor((4, 6)       ,      self.vocab_size - 3							) + 3, eos_column_vector]       ,      axis=1							)
				A_	:						str	=     input_ids.shape[0]
				A_	:						Union[str, Any]	=     OPTConfig(
				    vocab_size=self.vocab_size       ,      hidden_size=24       ,      num_hidden_layers=2       ,      num_attention_heads=2       ,      ffn_dim=32       ,      max_position_embeddings=48       ,      eos_token_id=2       ,      pad_token_id=1       ,      bos_token_id=0       ,      )
				return config, input_ids, batch_size







@require_sentencepiece
@require_tf
class 	_lowerCAmelCase							(			unittest.TestCase ):


	@slow
	def     _a	(self							):
				A_	:						List[Any]	=     TFOPTModel.from_pretrained("""facebook/opt-350m"""							)
				A_	:						Any	=     _long_tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]							)
				A_	:						str	=     tf.not_equal(lowercase       ,      model.config.pad_token_id							)
				with tf.GradientTape():
							A_	:						str	=     model(input_ids=lowercase       ,      attention_mask=lowercase							).last_hidden_state
				A_	:						List[Any]	=     (1, 11, 512)
				self.assertEqual(output.shape       ,      lowercase							)
				A_	:						Dict	=     tf.constant(
				    [[-0.28_73, -1.92_18, -0.30_33], [-1.27_10, -0.13_38, -0.19_02], [0.40_95, 0.12_14, -1.31_21]]							)
				self.assertTrue(np.allclose(output[:, :3, :3]       ,      lowercase       ,      atol=4E-3							)							)

				A_	:						int	=     tf.function(lowercase       ,      jit_compile=lowercase							)
				A_	:						Any	=     xla_generate(lowercase       ,      lowercase							)[0]
				self.assertTrue(np.allclose(output[:, :3, :3]       ,      lowercase       ,      atol=4E-2							)							)







@require_tf
@slow
class 	_lowerCAmelCase							(			unittest.TestCase ):


	def     _a	(self							):
				super().setUp()
				A_	:						Union[str, Any]	=     """facebook/opt-350m"""


	def     _a	(self							):
				A_	:						Any	=     TFOPTForCausalLM.from_pretrained(self.path_model							)
				A_	:						Optional[Any]	=     GPTaTokenizer.from_pretrained(self.path_model							)

				A_	:						Union[str, Any]	=     [
				    """Today is a beautiful day and I want to""",
				    """In the city of""",
				    """Paris is the capital of France and""",
				    """Computers and mobile phones have taken""",
				]
				# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
				A_	:						Optional[Any]	=     tokenizer(lowercase       ,      return_tensors="""tf"""       ,      padding=lowercase       ,      add_special_tokens=lowercase							)
				A_	:						int	=     tf.math.reduce_mean(model(inputs.input_ids       ,      attention_mask=inputs.attention_mask							)[0]       ,      axis=-1							)
				A_	:						int	=     tf.constant(
				    [
				        [1.38_51, -13.89_23, -10.52_29, -10.75_33, -0.23_09, -10.23_84, -0.53_65, -9.09_47, -5.16_70],
				        [-4.70_73, -10.62_76, -3.94_15, -21.52_42, -0.28_22, -0.28_22, -0.28_22, -0.28_22, -0.28_22],
				        [0.62_47, -3.42_29, -8.91_79, -1.42_97, -14.16_50, 1.41_46, -9.02_18, -0.27_03, -0.27_03],
				        [6.47_83, -1.99_13, -10.79_26, -2.33_36, 1.50_92, -0.99_74, -6.82_13, 1.34_77, 1.34_77],
				    ]							)
				self.assertTrue(np.allclose(lowercase       ,      lowercase       ,      atol=1E-4							)							)

				A_	:						Tuple	=     tf.function(lowercase       ,      jit_compile=lowercase							)
				A_	:						List[Any]	=     tf.math.reduce_mean(xla_generate(inputs.input_ids       ,      attention_mask=inputs.attention_mask							)[0]       ,      axis=-1							)
				self.assertTrue(np.allclose(lowercase       ,      lowercase       ,      atol=1E-4							)							)







@require_tf
@slow
class 	_lowerCAmelCase							(			unittest.TestCase ):


	@property
	def     _a	(self							):
				return [
				    "Today is a beautiful day and I want",
				    "In the city of",
				    "Paris is the capital of France and",
				    "Computers and mobile phones have taken",
				]


	def     _a	(self							):
				A_	:						Optional[Any]	=     """facebook/opt-125m"""

				A_	:						List[Any]	=     [
				    """Today is a beautiful day and I want to""",
				    """In the city of New York, the city""",
				    """Paris is the capital of France and the capital""",
				    """Computers and mobile phones have taken over the""",
				]

				A_	:						Dict	=     []
				A_	:						Tuple	=     GPTaTokenizer.from_pretrained(lowercase							)
				A_	:						Any	=     TFOPTForCausalLM.from_pretrained(lowercase							)

				for prompt in self.prompts:
							A_	:						Optional[int]	=     tokenizer(lowercase       ,      return_tensors="""tf"""							).input_ids

							A_	:						Union[str, Any]	=     model.generate(lowercase       ,      max_length=10							)

							A_	:						Optional[Any]	=     tokenizer.batch_decode(lowercase       ,      skip_special_tokens=lowercase							)
							predicted_outputs += generated_string

				self.assertListEqual(lowercase       ,      lowercase							)


	def     _a	(self							):
				A_	:						Dict	=     """facebook/opt-350m"""

				A_	:						int	=     GPTaTokenizer.from_pretrained(lowercase							)
				A_	:						List[str]	=     TFOPTForCausalLM.from_pretrained(lowercase							)

				A_	:						Any	=     """left"""

				# use different length sentences to test batching
				A_	:						Tuple	=     [
				    """Hello, my dog is a little""",
				    """Today, I""",
				]

				A_	:						Optional[int]	=     tokenizer(lowercase       ,      return_tensors="""tf"""       ,      padding=lowercase							)
				A_	:						List[Any]	=     inputs["""input_ids"""]

				A_	:						List[Any]	=     model.generate(input_ids=lowercase       ,      attention_mask=inputs["""attention_mask"""]							)

				A_	:						Dict	=     tokenizer(sentences[0]       ,      return_tensors="""tf"""							).input_ids
				A_	:						Tuple	=     model.generate(input_ids=lowercase							)

				A_	:						Tuple	=     inputs_non_padded.shape[-1] - tf.math.reduce_sum(
				    tf.cast(inputs["""attention_mask"""][-1]       ,      tf.intaa							)							)
				A_	:						Any	=     tokenizer(sentences[1]       ,      return_tensors="""tf"""							).input_ids
				A_	:						List[str]	=     model.generate(input_ids=lowercase       ,      max_length=model.config.max_length - num_paddings							)

				A_	:						Optional[Any]	=     tokenizer.batch_decode(lowercase       ,      skip_special_tokens=lowercase							)
				A_	:						Any	=     tokenizer.decode(output_non_padded[0]       ,      skip_special_tokens=lowercase							)
				A_	:						Any	=     tokenizer.decode(output_padded[0]       ,      skip_special_tokens=lowercase							)

				A_	:						Union[str, Any]	=     [
				    """Hello, my dog is a little bit of a dork.\nI'm a little bit""",
				    """Today, I was in the middle of a conversation with a friend about the""",
				]
				self.assertListEqual(lowercase       ,      lowercase							)
				self.assertListEqual(lowercase       ,      [non_padded_sentence, padded_sentence]							)


	def     _a	(self							):
				A_	:						Tuple	=     """facebook/opt-350m"""

				A_	:						Tuple	=     [
				    """Today is a beautiful day and I want to""",
				    """In the city of San Francisco, the city""",
				    """Paris is the capital of France and the capital""",
				    """Computers and mobile phones have taken over the""",
				]

				A_	:						Optional[int]	=     []
				A_	:						Optional[Any]	=     GPTaTokenizer.from_pretrained(lowercase							)
				A_	:						Dict	=     TFOPTForCausalLM.from_pretrained(lowercase							)

				for prompt in self.prompts:
							A_	:						Dict	=     tokenizer(lowercase       ,      return_tensors="""tf"""							).input_ids

							A_	:						Dict	=     model.generate(lowercase       ,      max_length=10							)

							A_	:						Tuple	=     tokenizer.batch_decode(lowercase       ,      skip_special_tokens=lowercase							)
							predicted_outputs += generated_string

				self.assertListEqual(lowercase       ,      lowercase							)




'''simple docstring'''




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


lowerCamelCase							:Tuple				    =					logging.get_logger(__name__)







class 	_lowerCAmelCase							(			__UpperCAmelCase ):


	def     _a	(self       ,      lowercase							):
				if isinstance(lowercase       ,      lowercase							):
							A_	:						Tuple	=     [label.strip() for label in labels.split(""","""							) if label.strip()]
				return labels


	def __call__(self       ,      lowercase       ,      lowercase       ,      lowercase							):
				if len(lowercase							) == 0 or len(lowercase							) == 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(lowercase							)							)

				if isinstance(lowercase       ,      lowercase							):
							A_	:						Optional[Any]	=     [sequences]

				A_	:						List[Any]	=     []
				for sequence in sequences:
							sequence_pairs.extend([[sequence, hypothesis_template.format(lowercase							)] for label in labels]							)

				return sequence_pairs, sequences







@add_end_docstrings(__UpperCAmelCase )
class 	_lowerCAmelCase							(			__UpperCAmelCase ):


	def __init__(self       ,      lowercase=ZeroShotClassificationArgumentHandler()       ,      *lowercase       ,      **lowercase							):
				A_	:						str	=     args_parser
				super().__init__(*lowercase       ,      **lowercase							)
				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     _a	(self							):
				for label, ind in self.model.config.labelaid.items():
							if label.lower().startswith("""entail"""							):
										return ind
				return -1


	def     _a	(self       ,      lowercase       ,      lowercase=True       ,      lowercase=True       ,      lowercase=TruncationStrategy.ONLY_FIRST       ,      **lowercase							):
				A_	:						Optional[int]	=     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`"""							)
							A_	:						Any	=     self.tokenizer.eos_token
				try:
							A_	:						Optional[Any]	=     self.tokenizer(
							    lowercase       ,      add_special_tokens=lowercase       ,      return_tensors=lowercase       ,      padding=lowercase       ,      truncation=lowercase       ,      )
				except Exception as e:
							if "too short" in str(lowercase							):
										# 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.

										A_	:						str	=     self.tokenizer(
										    lowercase       ,      add_special_tokens=lowercase       ,      return_tensors=lowercase       ,      padding=lowercase       ,      truncation=TruncationStrategy.DO_NOT_TRUNCATE       ,      )
							else:
										raise e

				return inputs


	def     _a	(self       ,      **lowercase							):
				if kwargs.get("""multi_class"""       ,      lowercase							) is not None:
							A_	:						Union[str, 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."""							)
				A_	:						Tuple	=     {}
				if "candidate_labels" in kwargs:
							A_	:						Optional[int]	=     self._args_parser._parse_labels(kwargs["""candidate_labels"""]							)
				if "hypothesis_template" in kwargs:
							A_	:						List[str]	=     kwargs["""hypothesis_template"""]

				A_	:						Union[str, Any]	=     {}
				if "multi_label" in kwargs:
							A_	:						Optional[int]	=     kwargs["""multi_label"""]
				return preprocess_params, {}, postprocess_params


	def __call__(self       ,      lowercase       ,      *lowercase       ,      **lowercase       ,      ):
				if len(lowercase							) == 0:
							pass
				elif len(lowercase							) == 1 and "candidate_labels" not in kwargs:
							A_	:						Any	=     args[0]
				else:
							raise ValueError(F'Unable to understand extra arguments {args}'							)

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


	def     _a	(self       ,      lowercase       ,      lowercase=None       ,      lowercase="This example is {}."							):
				A_,    A_	:						Any	=     self._args_parser(lowercase       ,      lowercase       ,      lowercase							)

				for i, (candidate_label, sequence_pair) in enumerate(zip(lowercase       ,      lowercase							)							):
							A_	:						List[Any]	=     self._parse_and_tokenize([sequence_pair]							)

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


	def     _a	(self       ,      lowercase							):
				A_	:						Dict	=     inputs["""candidate_label"""]
				A_	:						Any	=     inputs["""sequence"""]
				A_	:						List[Any]	=     {k: inputs[k] for k in self.tokenizer.model_input_names}
				A_	:						Optional[int]	=     self.model(**lowercase							)

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


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

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

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