code: def _replace_edge_labels_with_nodes(
      graph: "networkx.MultiDiGraph",
      next_id: int,
      nlu_training_data: "TrainingData",
  ) -> None:
      """Replaces edge labels with nodes.
  
      User messages are created as edge labels. This removes the labels and
      creates nodes instead.
  
      The algorithms (e.g. merging) are simpler if the user messages are labels
      on the edges. But it sometimes
      looks better if in the final graphs the user messages are nodes instead
      of edge labels.
      """
      if nlu_training_data:
          message_generator = UserMessageGenerator(nlu_training_data)
      else:
          message_generator = None
  
      edges = list(graph.edges(keys=True, data=True))
      for s, e, k, d in edges:
          if k != EDGE_NONE_LABEL:
              label = d.get("label", k)
  
              if message_generator:
                  parsed_info = {TEXT: label}
                  if label.startswith(INTENT_MESSAGE_PREFIX):
                      parsed_info[INTENT] = {INTENT_NAME_KEY: label[1:]}
  
                  label = message_generator.message_for_data(
                      parsed_info
                  )
              next_id += 1
              graph.remove_edge(s, e, k)
              graph.add_node(
                  next_id,
                  label=label,
                  shape="rect",
                  style="filled",
                  fillcolor="lightblue",
                  **_transfer_style(d, {"class": "intent"}),
              )
              graph.add_edge(
                  s, next_id, **{"class": d.get("class", "")}
              )
              graph.add_edge(
                  next_id, e, **{"class": d.get("class", "")}
              )
  
imports: from collections import defaultdict, deque
  import random
  from typing import Any, Text, List, Deque, Dict, Optional, Set, TYPE_CHECKING, Union, cast
  import rasa.shared.utils.io
  from rasa.shared.constants import INTENT_MESSAGE_PREFIX
  from rasa.shared.core.constants import ACTION_LISTEN_NAME
  from rasa.shared.core.domain import Domain
  from rasa.shared.core.events import UserUttered, ActionExecuted, Event
  from rasa.shared.core.generator import TrainingDataGenerator
  from rasa.shared.core.training_data.structures import StoryGraph, StoryStep
  from rasa.shared.nlu.constants import ENTITY_ATTRIBUTE_VALUE, INTENT, TEXT, ENTITY_ATTRIBUTE_TYPE, INTENT_NAME_KEY
label_desc: Use image node_id 9 for calling a global function with example usage: _replace_edge_labels_with_nodes(graph, next_id, nlu_training_data) without return types