code: def parse_semantics_str2dict(
      semantics_str: Union[List[str], str, Dict]
  ) -> Tuple[Dict, bool]:
      """
      This function parse the input string to a valid python dictionary for later evaluation.
      Part of this function is adapted from
      https://github.com/speechbrain/speechbrain/blob/develop/recipes/SLURP/direct/train_with_wav2vec2.py#L110-L127
      """
      invalid = False
      if isinstance(semantics_str, dict):
          return semantics_str, invalid
      if isinstance(semantics_str, list):
          semantics_str = " ".join(semantics_str)
  
      try:
          if "|" in semantics_str:
              semantics_str = semantics_str.replace("|", ",")
          _dict = ast.literal_eval(semantics_str)
          if not isinstance(_dict, dict):
              _dict = {
                  "scenario": "none",
                  "action": "none",
                  "entities": [],
              }
              invalid = True
      except Exception:  # need this if the output is not a valid dict
          _dict = {
              "scenario": "none",
              "action": "none",
              "entities": [],
          }
          invalid = True
  
      if "scenario" not in _dict or not isinstance(
          _dict["scenario"], str
      ):
          _dict["scenario"] = "none"
          invalid = True
      if "action" not in _dict or not isinstance(_dict["action"], str):
          _dict["action"] = "none"
          invalid = True
      if "entities" not in _dict:
          _dict["entities"] = []
          invalid = True
      else:
  
          def _parse_entity(item: Dict):
              error = False
              for key in ["type", "filler"]:
                  if key not in item or not isinstance(item[key], str):
                      item[key] = "none"
                      error = True
              return item, error
  
          for i, x in enumerate(_dict["entities"]):
              item, entity_error = _parse_entity(x)
              invalid = invalid or entity_error
              _dict["entities"][i] = item
  
      return _dict, invalid
  
file_path: NeMo/examples/slu/speech_intent_slot/eval_utils/evaluator.py
imports: import ast
  from typing import Dict, List, Tuple, Union
  from .evaluation.metrics.metrics import ErrorMetric
label_desc: Use image node_id 1 for calling a global function with example usage: parse_semantics_str2dict(semantics_str) and returns: _dict,  invalid, semantics_str,  invalid, item,  error