class_docstr: Simple sentiment analysis model.
class_docstr_tok: ["Simple","sentiment","analysis","model","."]
code: def predict_minibatch(self, inputs):
      # Preprocess to ids and masks, and make the input batch.
      encoded_input = self.tokenizer.batch_encode_plus(
          [ex["sentence"] for ex in inputs],
          return_tensors="pt",
          add_special_tokens=True,
          max_length=128,
          padding="longest",
          truncation="longest_first",
      )
  
      # Check and send to cuda (GPU) if available
      if torch.cuda.is_available():
          self.model.cuda()
          for tensor in encoded_input:
              encoded_input[tensor] = encoded_input[tensor].cuda()
      # Run a forward pass.
      with torch.no_grad():  # remove this if you need gradients.
          out: SequenceClassifierOutput = self.model(**encoded_input)
  
      # Post-process outputs.
      batched_outputs = {
          "probas": torch.nn.functional.softmax(out.logits, dim=-1),
          "input_ids": encoded_input["input_ids"],
          "ntok": torch.sum(encoded_input["attention_mask"], dim=1),
          "cls_emb": out.hidden_states[-1][
              :, 0
          ],  # last layer, first token
      }
      # Return as NumPy for further processing.
      detached_outputs = {
          k: v.cpu().numpy() for k, v in batched_outputs.items()
      }
      # Unbatch outputs so we get one record per input example.
      for output in utils.unbatch_preds(detached_outputs):
          ntok = output.pop("ntok")
          output["tokens"] = self.tokenizer.convert_ids_to_tokens(
              output.pop("input_ids")[1 : ntok - 1]
          )
          yield output
  
imports: from collections.abc import Sequence
  import sys
  from typing import Optional
  from absl import app
  from absl import flags
  from absl import logging
  from lit_nlp import dev_server
  from lit_nlp import server_flags
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.datasets import glue
  from lit_nlp.lib import file_cache
  from lit_nlp.lib import utils
  import torch
  import transformers
label_desc: Use image node_id 3 for calling the SimpleSentimentModel obj's underlying member method code with example usage: obj.predict_minibatch(inputs) without return types