class_docstr: TextClassificationModel to be trained on two- or three-class textual entailment data, to be used for zero shot intent recognition.
class_docstr_tok: ["TextClassificationModel","to","be","trained","on","two-","or","three-class","textual","entailment","data",",","to","be","used","for","zero","shot","intent","recognition","."]
docstr: Given a list of queries and a list of candidate labels, return a ranked list of labels and scores for each query.
  
  Example usage:
      queries = ["I'd like a veggie burger, fries, and a coke", "Turn off the lights in the living room",]
      candidate_labels = ["Food order", "Change lighting"]
      model.predict(queries, candidate_labels)
  
  Example output:
      [{'sentence': "I'd like a veggie burger, fries, and a coke",
        'labels': ['Food order', 'Change lighting'],
        'scores': [0.8557153344154358, 0.12036784738302231]},
       {'sentence': 'Turn off the lights in the living room',
        'labels': ['Change lighting', 'Food order'],
        'scores': [0.8506497144699097, 0.06594637036323547]}]
  
  
  Args:
      queries: the query or list of queries to classify
      candidate_labels: string or list of strings to be used as labels
      hypothesis_template: the template used to turn each label into an NLI-style hypothesis. Must include a {}
      or similar syntax for the candidate label to be inserted.
      batch_size: the batch size to use for inference.
      multi_label: whether or not multiple candidate labels can be true. If False, the scores are normalized
      such that all class probabilities sum to 1. If True, the labels are
      considered independent and probabilities are normalized for each candidate by doing a softmax of
      the entailment score vs. the contradiction score.
      entailment_idx: the index of the "entailment" class in the trained model; models trained on MNLI
       using NeMo's glue_benchmark.py or zero_shot_intent_model.py use an index of 1 by default.
      contradiction_idx: the index of the "contradiction" class in the trained model; models trained on MNLI
       using NeMo's glue_benchmark.py or zero_shot_intent_model.py use an index of 0 by default.
  
  Returns:
      list of dictionaries; one dict per input query. Each dict has keys "sentence", "labels", "scores".
      labels and scores are parallel lists (with each score corresponding to the label at the same index),
           sorted from highest to lowest score.
docstr_tok: ["Given","a","list","of","queries","and","a","list","of","candidate","labels",",","return","a","ranked","list","of","labels","and","scores","for","each","query",".","Example","usage",":","queries","=","[","``","I","'d","like","a","veggie","burger",",","fries",",","and","a","coke","''",",","``","Turn","off","the","lights","in","the","living","room","''",",","]","candidate_labels","=","[","``","Food","order","''",",","``","Change","lighting","''","]","model.predict","(","queries",",","candidate_labels",")","Example","output",":","[","{","'sentence","'",":","``","I","'d","like","a","veggie","burger",",","fries",",","and","a","coke","''",",","'labels","'",":","[","'Food","order","'",",","'Change","lighting","'","]",",","'scores","'",":","[","0.8557153344154358",",","0.12036784738302231","]","}",",","{","'sentence","'",":","'Turn","off","the","lights","in","the","living","room","'",",","'labels","'",":","[","'Change","lighting","'",",","'Food","order","'","]",",","'scores","'",":","[","0.8506497144699097",",","0.06594637036323547","]","}","]","Args",":","queries",":","the","query","or","list","of","queries","to","classify","candidate_labels",":","string","or","list","of","strings","to","be","used","as","labels","hypothesis_template",":","the","template","used","to","turn","each","label","into","an","NLI-style","hypothesis",".","Must","include","a","{","}","or","similar","syntax","for","the","candidate","label","to","be","inserted",".","batch_size",":","the","batch","size","to","use","for","inference",".","multi_label",":","whether","or","not","multiple","candidate","labels","can","be","true",".","If","False",",","the","scores","are","normalized","such","that","all","class","probabilities","sum","to","1",".","If","True",",","the","labels","are","considered","independent","and","probabilities","are","normalized","for","each","candidate","by","doing","a","softmax","of","the","entailment","score","vs.","the","contradiction","score",".","entailment_idx",":","the","index","of","the","``","entailment","''","class","in","the","trained","model",";","models","trained","on","MNLI","using","NeMo","'s","glue_benchmark.py","or","zero_shot_intent_model.py","use","an","index","of","1","by","default",".","contradiction_idx",":","the","index","of","the","``","contradiction","''","class","in","the","trained","model",";","models","trained","on","MNLI","using","NeMo","'s","glue_benchmark.py","or","zero_shot_intent_model.py","use","an","index","of","0","by","default",".","Returns",":","list","of","dictionaries",";","one","dict","per","input","query",".","Each","dict","has","keys","``","sentence","''",",","``","labels","''",",","``","scores","''",".","labels","and","scores","are","parallel","lists","(","with","each","score","corresponding","to","the","label","at","the","same","index",")",",","sorted","from","highest","to","lowest","score","."]
code: def predict(
      self,
      queries: Union[str, List[str]],
      candidate_labels: Union[str, List[str]],
      hypothesis_template="This example is {}.",
      batch_size=1,
      multi_label=True,
      entailment_idx=1,
      contradiction_idx=0,
  ) -> List[Dict]:
      """
      Given a list of queries and a list of candidate labels, return a ranked list of labels and scores for each query.
  
      Example usage:
          queries = ["I'd like a veggie burger, fries, and a coke", "Turn off the lights in the living room",]
          candidate_labels = ["Food order", "Change lighting"]
          model.predict(queries, candidate_labels)
  
      Example output:
          [{'sentence': "I'd like a veggie burger, fries, and a coke",
            'labels': ['Food order', 'Change lighting'],
            'scores': [0.8557153344154358, 0.12036784738302231]},
           {'sentence': 'Turn off the lights in the living room',
            'labels': ['Change lighting', 'Food order'],
            'scores': [0.8506497144699097, 0.06594637036323547]}]
  
  
      Args:
          queries: the query or list of queries to classify
          candidate_labels: string or list of strings to be used as labels
          hypothesis_template: the template used to turn each label into an NLI-style hypothesis. Must include a {}
          or similar syntax for the candidate label to be inserted.
          batch_size: the batch size to use for inference.
          multi_label: whether or not multiple candidate labels can be true. If False, the scores are normalized
          such that all class probabilities sum to 1. If True, the labels are
          considered independent and probabilities are normalized for each candidate by doing a softmax of
          the entailment score vs. the contradiction score.
          entailment_idx: the index of the "entailment" class in the trained model; models trained on MNLI
           using NeMo's glue_benchmark.py or zero_shot_intent_model.py use an index of 1 by default.
          contradiction_idx: the index of the "contradiction" class in the trained model; models trained on MNLI
           using NeMo's glue_benchmark.py or zero_shot_intent_model.py use an index of 0 by default.
  
      Returns:
          list of dictionaries; one dict per input query. Each dict has keys "sentence", "labels", "scores".
          labels and scores are parallel lists (with each score corresponding to the label at the same index),
               sorted from highest to lowest score.
  
      """
      if not queries:
          raise ValueError("No queries were passed for classification!")
      if not candidate_labels:
          raise ValueError("No candidate labels were provided!")
  
      queries = [queries] if isinstance(queries, str) else queries
      candidate_labels = (
          [candidate_labels]
          if isinstance(candidate_labels, str)
          else candidate_labels
      )
  
      if len(candidate_labels) == 1:
          multi_label = True
  
      mode = self.training
      try:
          device = "cuda" if torch.cuda.is_available() else "cpu"
  
          # Switch model to evaluation mode
          self.eval()
          self.to(device)
  
          infer_datalayer = self._setup_infer_dataloader(
              queries,
              candidate_labels,
              hypothesis_template=hypothesis_template,
              batch_size=batch_size,
              max_seq_length=self._cfg.dataset.max_seq_length,
          )
  
          all_batch_logits = []
          for batch in infer_datalayer:
              input_ids, input_type_ids, input_mask, _ = batch
  
              logits = self.forward(
                  input_ids=input_ids.to(device),
                  token_type_ids=input_type_ids.to(device),
                  attention_mask=input_mask.to(device),
              )
              all_batch_logits.append(logits.detach().cpu().numpy())
  
          all_logits = np.concatenate(all_batch_logits)
          outputs = all_logits.reshape(
              (len(queries), len(candidate_labels), -1)
          )
  
          if not multi_label:
              # softmax the "entailment" logits over all candidate labels
              entail_logits = outputs[..., entailment_idx]
              scores = np.exp(entail_logits) / np.exp(
                  entail_logits
              ).sum(-1, keepdims=True)
          else:
              # softmax over the entailment vs. contradiction dim for each label independently
              entail_contr_logits = outputs[
                  ..., [contradiction_idx, entailment_idx]
              ]
              scores = np.exp(entail_contr_logits) / np.exp(
                  entail_contr_logits
              ).sum(-1, keepdims=True)
              scores = scores[..., 1]
  
          result = []
          for i in range(len(queries)):
              sorted_idxs = list(reversed(scores[i].argsort()))
              result.append(
                  {
                      "sentence": queries[i],
                      "labels": [
                          candidate_labels[j] for j in sorted_idxs
                      ],
                      "scores": scores[i][sorted_idxs].tolist(),
                  }
              )
  
      finally:
          # set mode back to its original value
          self.train(mode=mode)
      return result
  
imports: import os
  from collections import defaultdict
  from typing import Dict, List, Optional, Union
  import numpy
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
  from nemo.collections.nlp.data.dialogue import DialogueSGDDataProcessor
  from nemo.collections.nlp.data.dialogue.data_processor.assistant_data_processor import DialogueAssistantDataProcessor
  from nemo.collections.nlp.data.dialogue.data_processor.design_data_processor import DialogueDesignDataProcessor
  from nemo.collections.nlp.data.dialogue.dataset.dialogue_zero_shot_intent_dataset import DialogueZeroShotIntentDataset
  from nemo.collections.nlp.data.zero_shot_intent_recognition.zero_shot_intent_dataset import ZeroShotIntentInferenceDataset, calc_class_weights_from_dataloader
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.metrics.dialogue_metrics import DialogueGenerationMetrics
  from nemo.collections.nlp.models import TextClassificationModel
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 10 for calling the DialogueZeroShotIntentModel obj's underlying member method code with example usage: obj.predict(queries, candidate_labels, hypothesis_template, batch_size, multi_label, entailment_idx, contradiction_idx) and returns: result