code: def get_predicted_dialog(
      dialog: dict,
      all_predictions: dict,
      schemas: object,
      state_tracker: str,
  ) -> dict:
      """Overwrite the labels in the turn with the predictions from the model. For test set, these labels are missing from the data and hence they are added.
      Args:
          dialog: ground truth dialog
          all_predictions: predictions
          schemas: schema object of all services of all datasets
          state_tracker: state tracker option, e.g. nemotracker
      Returns:
          dialog: dialog overwritten with prediction information
      """
      dialog_id = dialog["dialogue_id"]
      if state_tracker == "baseline":
          sys_slots_agg = {}
      else:
          sys_slots_agg = defaultdict(OrderedDict)
      all_slot_values = defaultdict(dict)
      for turn_idx, turn in enumerate(dialog["turns"]):
          if (
              turn["speaker"] == "SYSTEM"
              and state_tracker == "nemotracker"
          ):
              for frame in turn["frames"]:
                  if frame["service"] not in sys_slots_agg:
                      sys_slots_agg[frame["service"]] = OrderedDict()
                  for action in frame["actions"]:
                      if action["slot"] and len(action["values"]) > 0:
                          sys_slots_agg[frame["service"]][
                              action["slot"]
                          ] = action["values"][0]
          if turn["speaker"] == "USER":
              user_utterance = turn["utterance"]
              system_utterance = (
                  dialog["turns"][turn_idx - 1]["utterance"]
                  if turn_idx
                  else ""
              )
              system_user_utterance = (
                  system_utterance + " " + user_utterance
              )
              turn_id = "{:02d}".format(turn_idx)
              for frame in turn["frames"]:
                  predictions = all_predictions[
                      (dialog_id, turn_id, frame["service"])
                  ]
                  slot_values = all_slot_values[frame["service"]]
                  service_schema = schemas.get_service_schema(
                      frame["service"]
                  )
                  # Remove the slot spans and state if present.
                  frame.pop("slots", None)
                  frame.pop("state", None)
  
                  # The baseline model doesn't predict slot spans. Only state predictions
                  # are added.
                  state = {}
  
                  # Add prediction for active intent. No Offset is subtracted since schema has now NONE intent at index 0
                  state["active_intent"] = get_predicted_intent(
                      predictions=predictions[0],
                      intents=service_schema.intents,
                  )
                  # Add prediction for requested slots.
                  state["requested_slots"] = get_requested_slot(
                      predictions=predictions[1],
                      slots=service_schema.slots,
                  )
  
                  # Add prediction for user goal (slot values).
                  # Categorical slots.
                  cat_out_dict = set_cat_slot(
                      predictions_status=predictions[2],
                      predictions_value=predictions[3],
                      cat_slot_values=service_schema.categorical_slot_values,
                  )
                  for k, v in cat_out_dict.items():
                      slot_values[k] = v
  
                  # Non-categorical slots.
                  noncat_out_dict = set_noncat_slot(
                      predictions_status=predictions[4],
                      predictions_value=predictions[5],
                      non_cat_slots=service_schema.non_categorical_slots,
                      user_utterance=system_user_utterance,
                      sys_slots_agg=sys_slots_agg.get(
                          frame["service"], None
                      ),
                  )
                  for k, v in noncat_out_dict.items():
                      slot_values[k] = v
                  # Create a new dict to avoid overwriting the state in previous turns
                  # because of use of same objects.
                  state["slot_values"] = {
                      s: [v] for s, v in slot_values.items()
                  }
                  frame["state"] = state
      return dialog
  
file_path: NeMo/nemo/collections/nlp/data/dialogue/sgd/prediction_utils.py
imports: import json
  import os
  from collections import OrderedDict, defaultdict
  from typing import Dict, List, Optional
  from nemo.collections.nlp.data.dialogue.input_example.sgd_input_example import STATUS_ACTIVE, STATUS_DONTCARE, STR_DONTCARE
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling a global function with example usage: get_predicted_dialog(dialog, all_predictions, schemas, state_tracker) and returns: dialog