code: def edge_index_from_dict(
      graph_dict: Dict[int, List[int]],
      num_nodes: Optional[int] = None,
  ) -> Tensor:
      rows: List[int] = []
      cols: List[int] = []
      for key, value in graph_dict.items():
          rows += repeat(key, len(value))
          cols += value
      row = torch.tensor(rows)
      col = torch.tensor(cols)
      edge_index = torch.stack([row, col], dim=0)
  
      # `torch.compile` is not yet ready for `EdgeIndex` :(
      # from torch_geometric import EdgeIndex
      # edge_index: Union[EdgeIndex, Tensor] = EdgeIndex(
      #     torch.stack([row, col], dim=0),
      #     is_undirected=True,
      #     sparse_size=(num_nodes, num_nodes),
      # )
  
      # NOTE: There are some duplicated edges and self loops in the datasets.
      #       Other implementations do not remove them!
      edge_index, _ = remove_self_loops(edge_index)
      edge_index = coalesce(
          edge_index, num_nodes=num_nodes, sort_by_row=False
      )
  
      return edge_index
  
file_path: pytorch_geometric/torch_geometric/io/planetoid.py
imports: import os.path
  import warnings
  from itertools import repeat
  from typing import Dict, List, Optional
  import fsspec
  import torch
  from torch import Tensor
  from torch_geometric.data import Data
  from torch_geometric.io import read_txt_array
  from torch_geometric.utils import coalesce, index_to_mask, remove_self_loops, to_torch_csr_tensor
label_desc: Use image node_id 3 for calling a global function with example usage: edge_index_from_dict(graph_dict, num_nodes) and returns: edge_index