class_docstr: WIT widget for Jupyter.
class_docstr_tok: ["WIT","widget","for","Jupyter","."]
code: def generate_next_inference_batch(self):
      # Parse out the inferences from the returned structure and empty the
      # structure of contents, keeping its nested structure.
      # Chunks of the inference results will be sent to the front-end and
      # re-assembled.
      indices = self.inferences["inferences"]["indices"][:]
      self.inferences["inferences"]["indices"] = []
      res2 = []
      extra = {}
      extra2 = {}
      model_inference = self.inferences["inferences"]["results"][0]
      if (
          "extra_outputs" in self.inferences
          and len(self.inferences["extra_outputs"])
          and self.inferences["extra_outputs"][0]
      ):
          for key in self.inferences["extra_outputs"][0]:
              extra[key] = self.inferences["extra_outputs"][0][key][:]
              self.inferences["extra_outputs"][0][key] = []
      if "classificationResult" in model_inference:
          res = model_inference["classificationResult"][
              "classifications"
          ][:]
          model_inference["classificationResult"][
              "classifications"
          ] = []
      else:
          res = model_inference["regressionResult"]["regressions"][:]
          model_inference["regressionResult"]["regressions"] = []
  
      if len(self.inferences["inferences"]["results"]) > 1:
          if (
              "extra_outputs" in self.inferences
              and len(self.inferences["extra_outputs"]) > 1
              and self.inferences["extra_outputs"][1]
          ):
              for key in self.inferences["extra_outputs"][1]:
                  extra2[key] = self.inferences["extra_outputs"][1][
                      key
                  ][:]
                  self.inferences["extra_outputs"][1][key] = []
          model_2_inference = self.inferences["inferences"]["results"][
              1
          ]
          if "classificationResult" in model_2_inference:
              res2 = model_2_inference["classificationResult"][
                  "classifications"
              ][:]
              model_2_inference["classificationResult"][
                  "classifications"
              ] = []
          else:
              res2 = model_2_inference["regressionResult"][
                  "regressions"
              ][:]
              model_2_inference["regressionResult"]["regressions"] = []
  
      num_pieces = math.ceil(len(indices) / self.batch_size)
      i = 0
  
      while num_pieces > 0:
          num_pieces -= 1
  
          piece = [res[i : i + self.batch_size]]
          extra_piece = [{}]
          for key in extra:
              extra_piece[0][key] = extra[key][i : i + self.batch_size]
          if res2:
              piece.append(res2[i : i + self.batch_size])
              extra_piece.append({})
              for key in extra2:
                  extra_piece[1][key] = extra2[key][
                      i : i + self.batch_size
                  ]
          ind_piece = indices[i : i + self.batch_size]
          data = {
              "results": piece,
              "indices": ind_piece,
              "extra": extra_piece,
              "counter": self.infer_counter,
          }
          self.infer_counter += 1
          # For the first segment to send, also send the blank inferences
          # structure to be filled in. This was cleared of contents above but is
          # used to maintain the nested structure of the results.
          if i == 0:
              data["inferences"] = self.inferences
          i += self.batch_size
          yield data, num_pieces
  
imports: import math
  import ipywidgets
  import tensorflow
  from IPython.core.display import display, HTML
  from ipywidgets import Layout
  from traitlets import Dict
  from traitlets import Int
  from traitlets import List
  from traitlets import observe
  from traitlets import Unicode
  from traitlets import Set
  from witwidget.notebook import base
label_desc: Use image node_id 8 for calling the WitWidget obj's underlying member method code with example usage: obj.generate_next_inference_batch() without return types