class_docstr: Text classification pipeline using any `ModelForSequenceClassification`. See the [sequence classification
  examples](../task_summary#sequence-classification) for more information.
  
  This text classification pipeline can currently be loaded from [`pipeline`] using the following task identifier:
  `"sentiment-analysis"` (for classifying sequences according to positive or negative sentiments).
  
  If multiple classification labels are available (`model.config.num_labels >= 2`), the pipeline will run a softmax
  over the results. If there is a single label, the pipeline will run a sigmoid over the result.
  
  The models that this pipeline can use are models that have been fine-tuned on a sequence classification task. See
  the up-to-date list of available models on
  [huggingface.co/models](https://huggingface.co/models?filter=text-classification).
class_docstr_tok: ["Text","classification","pipeline","using","any","`","ModelForSequenceClassification","`",".","See","the","[","sequence","classification","examples","]","(","..","\/task_summary","#","sequence-classification",")","for","more","information",".","This","text","classification","pipeline","can","currently","be","loaded","from","[","`","pipeline","`","]","using","the","following","task","identifier",":","`","``","sentiment-analysis","''","`","(","for","classifying","sequences","according","to","positive","or","negative","sentiments",")",".","If","multiple","classification","labels","are","available","(","`","model.config.num_labels",">","=","2","`",")",",","the","pipeline","will","run","a","softmax","over","the","results",".","If","there","is","a","single","label",",","the","pipeline","will","run","a","sigmoid","over","the","result",".","The","models","that","this","pipeline","can","use","are","models","that","have","been","fine-tuned","on","a","sequence","classification","task",".","See","the","up-to-date","list","of","available","models","on","[","huggingface.co\/models","]","(","https",":","\/\/huggingface.co\/models","?","filter=text-classification",")","."]
code: def postprocess(
      self, model_outputs, function_to_apply=None, top_k=1, _legacy=True
  ):
      # `_legacy` is used to determine if we're running the naked pipeline and in backward
      # compatibility mode, or if running the pipeline with `pipeline(..., top_k=1)` we're running
      # the more natural result containing the list.
      # Default value before `set_parameters`
      if function_to_apply is None:
          if (
              self.model.config.problem_type
              == "multi_label_classification"
              or self.model.config.num_labels == 1
          ):
              function_to_apply = ClassificationFunction.SIGMOID
          elif (
              self.model.config.problem_type
              == "single_label_classification"
              or self.model.config.num_labels > 1
          ):
              function_to_apply = ClassificationFunction.SOFTMAX
          elif (
              hasattr(self.model.config, "function_to_apply")
              and function_to_apply is None
          ):
              function_to_apply = self.model.config.function_to_apply
          else:
              function_to_apply = ClassificationFunction.NONE
  
      outputs = model_outputs["logits"][0]
      outputs = outputs.numpy()
  
      if function_to_apply == ClassificationFunction.SIGMOID:
          scores = sigmoid(outputs)
      elif function_to_apply == ClassificationFunction.SOFTMAX:
          scores = softmax(outputs)
      elif function_to_apply == ClassificationFunction.NONE:
          scores = outputs
      else:
          raise ValueError(
              f"Unrecognized `function_to_apply` argument: {function_to_apply}"
          )
  
      if top_k == 1 and _legacy:
          return {
              "label": self.model.config.id2label[
                  scores.argmax().item()
              ],
              "score": scores.max().item(),
          }
  
      dict_scores = [
          {
              "label": self.model.config.id2label[i],
              "score": score.item(),
          }
          for i, score in enumerate(scores)
      ]
      if not _legacy:
          dict_scores.sort(key=lambda x: x["score"], reverse=True)
          if top_k is not None:
              dict_scores = dict_scores[:top_k]
      return dict_scores
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/pipelines/text_classification.py
imports: import warnings
  from typing import Dict
  import numpy
  from ..utils import ExplicitEnum, add_end_docstrings, is_tf_available, is_torch_available
  from .base import PIPELINE_INIT_ARGS, GenericTensor, Pipeline
label_desc: Use image node_id 6 for calling the TextClassificationPipeline obj's underlying member method code with example usage: obj.postprocess(model_outputs, function_to_apply, top_k, _legacy) and returns: dict_scores, dict