code: def _preprocess_embedding_data(
      self, res, train_split: Union[float, int] = 0.8
  ) -> Plottable:
      # _, torch, _, _, _, _, _, _ = lazy_embed_import_dep()
      import torch
  
      log("Preprocessing embedding data")
      src, dst = res._source, res._destination
      relation = res._relation
  
      if res._node is not None and res._nodes is not None:
          nodes = res._nodes[self._node]
      elif res._node is None and res._nodes is not None:
          nodes = res._nodes.reset_index(drop=True).reset_index()[
              "index"
          ]
      else:
          res = res.materialize_nodes()
          nodes = res._nodes[res._node]
  
      edges = res._edges
      edges = edges[edges[src].isin(nodes) & edges[dst].isin(nodes)]
      relations = edges[relation].unique()
  
      # type2id
      res._node2id = {n: idx for idx, n in enumerate(nodes)}
      res._relation2id = {r: idx for idx, r in enumerate(relations)}
  
      res._id2node = {idx: n for idx, n in enumerate(nodes)}
      res._id2relation = {idx: r for idx, r in enumerate(relations)}
  
      s, r, t = (
          edges[src].map(res._node2id),
          edges[relation].map(res._relation2id),
          edges[dst].map(res._node2id),
      )
      triplets = torch.from_numpy(
          pd.concat([s, r, t], axis=1).to_numpy()
      )
  
      # split idx
      if res._train_idx is None or res._train_split != train_split:
          log(msg="--Splitting data")
          train_size = int(train_split * len(triplets))
          test_size = len(triplets) - train_size
          train_dataset, test_dataset = torch.utils.data.random_split(triplets, [train_size, test_size])  # type: ignore
          res._train_idx = train_dataset.indices
          res._test_idx = test_dataset.indices
  
      res._triplets = triplets
      res._num_nodes, res._num_rels = (
          len(res._node2id),
          len(res._relation2id),
      )
      log(
          f"--num_nodes: {res._num_nodes}, num_relationships: {res._num_rels}"
      )
      return res
  
imports: import logging
  import numpy
  import pandas
  from typing import Optional, Union, Callable, List, TYPE_CHECKING, Any, Tuple
  from .PlotterBase import Plottable
  from .compute.ComputeMixin import ComputeMixin
label_desc: Use image node_id 2 for calling the HeterographEmbedModuleMixin obj's underlying member method code with example usage: obj._preprocess_embedding_data(res, train_split) and returns: res