class_docstr: NLI-based zero-shot classification pipeline using a `ModelForSequenceClassification` trained on NLI (natural
  language inference) tasks.
  
  Any combination of sequences and labels can be passed and each combination will be posed as a premise/hypothesis
  pair and passed to the pretrained model. Then, the logit for *entailment* is taken as the logit for the candidate
  label being valid. Any NLI model can be used, but the id of the *entailment* label must be included in the model
  config's :attr:*~transformers.PretrainedConfig.label2id*.
  
  This NLI pipeline can currently be loaded from [`pipeline`] using the following task identifier:
  `"zero-shot-classification"`.
  
  The models that this pipeline can use are models that have been fine-tuned on an NLI task. See the up-to-date list
  of available models on [huggingface.co/models](https://huggingface.co/models?search=nli).
class_docstr_tok: ["NLI-based","zero-shot","classification","pipeline","using","a","`","ModelForSequenceClassification","`","trained","on","NLI","(","natural","language","inference",")","tasks",".","Any","combination","of","sequences","and","labels","can","be","passed","and","each","combination","will","be","posed","as","a","premise\/hypothesis","pair","and","passed","to","the","pretrained","model",".","Then",",","the","logit","for","*","entailment","*","is","taken","as","the","logit","for","the","candidate","label","being","valid",".","Any","NLI","model","can","be","used",",","but","the","id","of","the","*","entailment","*","label","must","be","included","in","the","model","config","'s",":","attr",":","*","~transformers.PretrainedConfig.label2id","*",".","This","NLI","pipeline","can","currently","be","loaded","from","[","`","pipeline","`","]","using","the","following","task","identifier",":","`","``","zero-shot-classification","''","`",".","The","models","that","this","pipeline","can","use","are","models","that","have","been","fine-tuned","on","an","NLI","task",".","See","the","up-to-date","list","of","available","models","on","[","huggingface.co\/models","]","(","https",":","\/\/huggingface.co\/models","?","search=nli",")","."]
code: def postprocess(self, model_outputs, multi_label=False):
      candidate_labels = [
          outputs["candidate_label"] for outputs in model_outputs
      ]
      sequences = [outputs["sequence"] for outputs in model_outputs]
      logits = np.concatenate(
          [output["logits"].numpy() for output in model_outputs]
      )
      N = logits.shape[0]
      n = len(candidate_labels)
      num_sequences = N // n
      reshaped_outputs = logits.reshape((num_sequences, n, -1))
  
      if multi_label or len(candidate_labels) == 1:
          # softmax over the entailment vs. contradiction dim for each label independently
          entailment_id = self.entailment_id
          contradiction_id = -1 if entailment_id == 0 else 0
          entail_contr_logits = reshaped_outputs[
              ..., [contradiction_id, entailment_id]
          ]
          scores = np.exp(entail_contr_logits) / np.exp(
              entail_contr_logits
          ).sum(-1, keepdims=True)
          scores = scores[..., 1]
      else:
          # softmax the "entailment" logits over all candidate labels
          entail_logits = reshaped_outputs[..., self.entailment_id]
          scores = np.exp(entail_logits) / np.exp(entail_logits).sum(
              -1, keepdims=True
          )
  
      top_inds = list(reversed(scores[0].argsort()))
      return {
          "sequence": sequences[0],
          "labels": [candidate_labels[i] for i in top_inds],
          "scores": scores[0, top_inds].tolist(),
      }
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/pipelines/zero_shot_classification.py
imports: from typing import List, Union
  import numpy
  from ..tokenization_utils import TruncationStrategy
  from ..utils import add_end_docstrings, logging
  from .base import PIPELINE_INIT_ARGS, ArgumentHandler, ChunkPipeline
label_desc: Use image node_id 8 for calling the ZeroShotClassificationPipeline obj's underlying member method code with example usage: obj.postprocess(model_outputs, multi_label) and returns: dict