





'''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


_a   :					Optional[Any]           =       logging.get_logger(__name__)





class        _UpperCAmelCase				(		lowerCAmelCase_  ):
		def     lowerCamelCase__     (    self,__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					if isinstance(lowerCAmelCase__,lowerCAmelCase__     ):
								__lowerCAmelCase   		=							[label.strip() for label in labels.split(""","""     ) if label.strip()]
					return labels







		def __call__(    self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					if len(lowerCAmelCase__     ) == 0 or len(lowerCAmelCase__     ) == 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(lowerCAmelCase__     )     )

					if isinstance(lowerCAmelCase__,lowerCAmelCase__     ):
								__lowerCAmelCase   		=							[sequences]

					__lowerCAmelCase   		=							[]
					for sequence in sequences:
								sequence_pairs.extend([[sequence, hypothesis_template.format(lowerCAmelCase__     )] for label in labels]     )

					return sequence_pairs, sequences





@add_end_docstrings(lowerCAmelCase_  )
class        _UpperCAmelCase				(		lowerCAmelCase_  ):
		def __init__(    self,__SCREAMING_SNAKE_CASE=ZeroShotClassificationArgumentHandler(),*__SCREAMING_SNAKE_CASE,**__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							args_parser
					super().__init__(*lowerCAmelCase__,**lowerCAmelCase__     )
					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     ):



					'''simple docstring'''

					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     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							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`"""     )
								__lowerCAmelCase   		=							self.tokenizer.eos_token
					try:
								__lowerCAmelCase   		=							self.tokenizer(
								    lowerCAmelCase__,add_special_tokens=lowerCAmelCase__,return_tensors=lowerCAmelCase__,padding=lowerCAmelCase__,truncation=lowerCAmelCase__,)
					except Exception as e:
								if "too short" in str(lowerCAmelCase__     ):
											# 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.

											__lowerCAmelCase   		=							self.tokenizer(
											    lowerCAmelCase__,add_special_tokens=lowerCAmelCase__,return_tensors=lowerCAmelCase__,padding=lowerCAmelCase__,truncation=TruncationStrategy.DO_NOT_TRUNCATE,)
								else:
											raise e

					return inputs
		def     lowerCamelCase__     (    self,**__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					if kwargs.get("""multi_class""",lowerCAmelCase__     ) is not None:
								__lowerCAmelCase   		=							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."""     )
					__lowerCAmelCase   		=							{}
					if "candidate_labels" in kwargs:
								__lowerCAmelCase   		=							self._args_parser._parse_labels(kwargs["""candidate_labels"""]     )
					if "hypothesis_template" in kwargs:
								__lowerCAmelCase   		=							kwargs["""hypothesis_template"""]

					__lowerCAmelCase   		=							{}
					if "multi_label" in kwargs:
								__lowerCAmelCase   		=							kwargs["""multi_label"""]
					return preprocess_params, {}, postprocess_params
		def __call__(    self,__SCREAMING_SNAKE_CASE,*__SCREAMING_SNAKE_CASE,**__SCREAMING_SNAKE_CASE,):



					'''simple docstring'''

					if len(lowerCAmelCase__     ) == 0:
								pass
					elif len(lowerCAmelCase__     ) == 1 and "candidate_labels" not in kwargs:
								__lowerCAmelCase   		=							args[0]
					else:
								raise ValueError(f'Unable to understand extra arguments {args}'     )

					return super().__call__(lowerCAmelCase__,**lowerCAmelCase__     )
		def     lowerCamelCase__     (    self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE=None,__SCREAMING_SNAKE_CASE="This example is {}."     ):



					'''simple docstring'''

					__lowerCAmelCase		,			__lowerCAmelCase   		=							self._args_parser(lowerCAmelCase__,lowerCAmelCase__,lowerCAmelCase__     )

					for i, (candidate_label, sequence_pair) in enumerate(zip(lowerCAmelCase__,lowerCAmelCase__     )     ):
								__lowerCAmelCase   		=							self._parse_and_tokenize([sequence_pair]     )

								yield {
								    "candidate_label": candidate_label,
								    "sequence": sequences[0],
								    "is_last": i == len(lowerCAmelCase__     ) - 1,
								    **model_input,
								}
		def     lowerCamelCase__     (    self,__SCREAMING_SNAKE_CASE     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							inputs["""candidate_label"""]
					__lowerCAmelCase   		=							inputs["""sequence"""]
					__lowerCAmelCase   		=							{k: inputs[k] for k in self.tokenizer.model_input_names}
					__lowerCAmelCase   		=							self.model(**lowerCAmelCase__     )

					__lowerCAmelCase   		=							{
					    """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     ):



					'''simple docstring'''

					__lowerCAmelCase   		=							[outputs["""candidate_label"""] for outputs in model_outputs]
					__lowerCAmelCase   		=							[outputs["""sequence"""] for outputs in model_outputs]
					__lowerCAmelCase   		=							np.concatenate([output["""logits"""].numpy() for output in model_outputs]     )
					__lowerCAmelCase   		=							logits.shape[0]
					__lowerCAmelCase   		=							len(lowerCAmelCase__     )
					__lowerCAmelCase   		=							N // n
					__lowerCAmelCase   		=							logits.reshape((num_sequences, n, -1)     )

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

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








'''simple docstring'''

def    a__							(							lowercase   :	str )						->						int:





     """simple docstring"""

     assert column_title.isupper()
     _UpperCamelCase							       =			0
     _UpperCamelCase							       =			len(lowercase ) - 1
     _UpperCamelCase							       =			0

     while index >= 0:
          _UpperCamelCase							       =			(ord(column_title[index] ) - 64) * pow(26,   lowercase )
          answer += value
          power += 1
          index -= 1

     return answer


if __name__ == "__main__":
   from doctest import testmod

   testmod()



