|
16 | 16 |
|
17 | 17 | Output `SamplingSpec` will contain topologically-sorted `SamplingOp`s. |
18 | 18 |
|
19 | | -# Usage examples. |
20 | 19 |
|
21 | | -## Homogeneous Graphs. |
| 20 | +
|
| 21 | +Example: Homogeneous Graphs. |
22 | 22 |
|
23 | 23 | If your graph is *homogeneous* and your node set is named "nodes" and edge set |
24 | 24 | is named "edges", then you can create the sampling spec proto as: |
25 | 25 |
|
26 | 26 |
|
27 | | -``` |
| 27 | +```python |
28 | 28 | # Assume homogeneous schema with edge-set name "edges" connecting "nodes". |
29 | 29 | schema = schema_pb2.GraphSchema() |
30 | 30 | schema.edge_sets['edges'].source = s.edge_sets['edges'].target = 'nodes' |
|
52 | 52 | - for each of those neighbors, sample (up to) 5 neighbors (from same edgeset). |
53 | 53 |
|
54 | 54 |
|
55 | | -## Heterogeneous Graphs. |
| 55 | +Example: Heterogeneous Graphs. |
56 | 56 |
|
57 | 57 | E.g., if you consider citation datasets, you can make a SamplingSpec proto as: |
58 | 58 |
|
59 | | -``` |
| 59 | +```python |
60 | 60 | proto = (SamplingSpecBuilder(schema) |
61 | 61 | .seed('author').sample('writes', 10).sample('cited_by', 5) |
62 | 62 | .build()) |
|
66 | 66 | each paper, 10 papers citing it. |
67 | 67 |
|
68 | 68 |
|
69 | | -## DAG Sampling. |
| 69 | +Example: DAG Sampling. |
70 | 70 |
|
71 | 71 | Finally, your sampling might consist of a DAG. For this, you need to cache |
72 | 72 | some returns of `.sample()` calls. For example: |
73 | 73 |
|
74 | | -``` |
| 74 | +```python |
75 | 75 | # Store builder at level of "author written papers": |
76 | 76 | builder = tfgnn.SamplingSpecBuilder(schema).seed('author').sample('writes', 10) |
77 | 77 | path1 = builder.sample('cited_by', 5) |
@@ -158,10 +158,10 @@ def make_sampling_spec_tree( |
158 | 158 | graph_schema: contains node-sets & edge-sets. |
159 | 159 | seed_nodeset: name of node-set that the sampler will be instructed to use as |
160 | 160 | seed nodes. |
161 | | - sample_sizes: list of number of nodes to sample. E.g. if `== [5, 2, 2]`, |
162 | | - then for every sampled node, up-to 5 of its neighbors will be sampled, and |
163 | | - for each, up to 2 of its neighbors will be sampled, etc, totalling sampled |
164 | | - nodes up to `5 * 2 * 2 = 20` for each seed node. |
| 161 | + sample_sizes: list of number of nodes to sample. E.g. if `sample_sizes` are |
| 162 | + `[5, 2, 2]`, then for every sampled node, up-to `5` of its neighbors will |
| 163 | + be sampled, and for each, up to `2` of its neighbors will be sampled, etc, |
| 164 | + totalling sampled nodes up to `5 * 2 * 2 = 20` for each seed node. |
165 | 165 | sampling_strategy: one of the supported sampling strategies, the same for |
166 | 166 | each depth. |
167 | 167 |
|
@@ -197,36 +197,44 @@ def _recursively_sample_all_edge_sets( |
197 | 197 | class SamplingSpecBuilder(object): |
198 | 198 | """Mimics builder pattern that eases creation of `tfgnn.SamplingSpec`. |
199 | 199 |
|
200 | | - # Usage examples. |
201 | | - ## Homogeneous Graphs. |
| 200 | +
|
| 201 | + Example: Homogeneous Graphs. |
| 202 | +
|
202 | 203 | If your graph is *homogeneous* and your node set is named "nodes" and edge set |
203 | 204 | is named "edges", then you can create the sampling spec proto as: |
204 | 205 |
|
205 | | - ### NOTE: This should come from the outside, e.g., `graph_tensor.schema`. |
206 | | - ``` |
| 206 | + NOTE: This should come from the outside, e.g., `graph_tensor.schema`. |
| 207 | + |
| 208 | + ```python |
207 | 209 | schema = schema_pb2.GraphSchema() |
208 | 210 | schema.edge_sets['edges'].source = s.edge_sets['edges'].target = 'nodes' |
209 | 211 |
|
210 | 212 | proto = (SamplingSpecBuilder(schema) |
211 | 213 | .seed('nodes').sample('edges', 10).sample('edges', 5) |
212 | 214 | .build()) |
213 | 215 | ``` |
| 216 | +
|
214 | 217 | The above spec is instructing to start at: |
215 | 218 | - Nodes of type set name "nodes", then, |
216 | 219 | - for each seed node, sample 10 of its neighbors (from edge set "edges"). |
217 | 220 | - for each of those neighbors, sample 5 neighbors (from same edge set). |
218 | 221 |
|
219 | | - ## Heterogeneous Graphs. |
| 222 | + Example: Heterogeneous Graphs. |
| 223 | +
|
220 | 224 | E.g., if you consider citation datasets, you can make a SamplingSpec proto as: |
221 | | - ``` |
| 225 | +
|
| 226 | + ```python |
222 | 227 | proto = (SamplingSpecBuilder(schema) |
223 | 228 | .seed('author').sample('writes', 10).sample('cited_by', 5) |
224 | 229 | .build()) |
225 | 230 | ``` |
| 231 | +
|
226 | 232 | This samples, starting from author node, 10 papers written by author, and for |
227 | 233 | each paper, 10 papers citing it. |
228 | 234 |
|
229 | | - ## DAG Sampling. |
| 235 | +
|
| 236 | + Example: DAG Sampling. |
| 237 | +
|
230 | 238 | Finally, your sampling might consist of a DAG. For this, you need to cache |
231 | 239 | some returns of `.sample()` calls. |
232 | 240 | """ |
|
0 commit comments