naos-ku commited on
Commit
5fa2808
·
1 Parent(s): 3851629

updated ## Working with Graph Topology part

Browse files
Files changed (1) hide show
  1. README.md +14 -5
README.md CHANGED
@@ -104,14 +104,23 @@ print(ds["train"][0])
104
 
105
  ### Working with Graph Topology
106
  ```python
107
- import networkx as nx
 
 
108
 
109
  example = ds["train"][0]
110
- G = nx.Graph()
111
- G.add_nodes_from(example["nodes"])
112
- G.add_edges_from({tuple(edge) for edge in example["edges"]})
113
- motif_nodes = set(example["motif_nodes"])
 
 
 
 
 
 
114
  ```
 
115
 
116
  ### Regenerating the Dataset Locally
117
  ```bash
 
104
 
105
  ### Working with Graph Topology
106
  ```python
107
+ import torch
108
+ from torch_geometric.data import Data
109
+ from src.utils import visualize_graph
110
 
111
  example = ds["train"][0]
112
+
113
+ # Build a PyG data object from the serialized edge list.
114
+ edge_index = torch.tensor(example["edges"], dtype=torch.long).t().contiguous()
115
+ graph = Data(edge_index=edge_index, num_nodes=example["nnodes"])
116
+
117
+ # Attach the motif mask expected by `visualize_graph`.
118
+ graph.node_mask = torch.zeros(example["nnodes"])
119
+ graph.node_mask[example["motif_nodes"]] = 1
120
+
121
+ visualize_graph(graph, "motif_example.png")
122
  ```
123
+ The script saves a PNG with motif nodes highlighted in orange. Use absolute imports (e.g., `from motif_qa.src.utils import visualize_graph`) if you install the project as a package.
124
 
125
  ### Regenerating the Dataset Locally
126
  ```bash