Datasets:
updated ## Working with Graph Topology part
Browse files
README.md
CHANGED
|
@@ -104,14 +104,23 @@ print(ds["train"][0])
|
|
| 104 |
|
| 105 |
### Working with Graph Topology
|
| 106 |
```python
|
| 107 |
-
import
|
|
|
|
|
|
|
| 108 |
|
| 109 |
example = ds["train"][0]
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|