Skip to content

Commit 035b569

Browse files
aferludintensorflower-gardener
authored andcommitted
Docstrings made compatible with API Docs
PiperOrigin-RevId: 549624329
1 parent 6d8d3e7 commit 035b569

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

tensorflow_gnn/graph/graph_tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ def get_aux_type_prefix(set_name: const.SetName) -> Optional[str]:
15901590
def get_homogeneous_node_and_edge_set_name(
15911591
graph: Union[GraphTensor, GraphTensorSpec],
15921592
name: str = 'This operation') -> tuple[str, str]:
1593-
"""Returns the sole `node_set_name, edge_set_name` or raises ValueError.
1593+
"""Returns the sole `node_set_name, edge_set_name` or raises `ValueError`.
15941594
15951595
By default, this function ignores auxiliary node sets and edge sets for which
15961596
`tfgnn.get_aux_type_prefix(set_name) is not None` (e.g., those needed for

tensorflow_gnn/sampler/sampling_spec_builder.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
1717
Output `SamplingSpec` will contain topologically-sorted `SamplingOp`s.
1818
19-
# Usage examples.
2019
21-
## Homogeneous Graphs.
20+
21+
Example: Homogeneous Graphs.
2222
2323
If your graph is *homogeneous* and your node set is named "nodes" and edge set
2424
is named "edges", then you can create the sampling spec proto as:
2525
2626
27-
```
27+
```python
2828
# Assume homogeneous schema with edge-set name "edges" connecting "nodes".
2929
schema = schema_pb2.GraphSchema()
3030
schema.edge_sets['edges'].source = s.edge_sets['edges'].target = 'nodes'
@@ -52,11 +52,11 @@
5252
- for each of those neighbors, sample (up to) 5 neighbors (from same edgeset).
5353
5454
55-
## Heterogeneous Graphs.
55+
Example: Heterogeneous Graphs.
5656
5757
E.g., if you consider citation datasets, you can make a SamplingSpec proto as:
5858
59-
```
59+
```python
6060
proto = (SamplingSpecBuilder(schema)
6161
.seed('author').sample('writes', 10).sample('cited_by', 5)
6262
.build())
@@ -66,12 +66,12 @@
6666
each paper, 10 papers citing it.
6767
6868
69-
## DAG Sampling.
69+
Example: DAG Sampling.
7070
7171
Finally, your sampling might consist of a DAG. For this, you need to cache
7272
some returns of `.sample()` calls. For example:
7373
74-
```
74+
```python
7575
# Store builder at level of "author written papers":
7676
builder = tfgnn.SamplingSpecBuilder(schema).seed('author').sample('writes', 10)
7777
path1 = builder.sample('cited_by', 5)
@@ -158,10 +158,10 @@ def make_sampling_spec_tree(
158158
graph_schema: contains node-sets & edge-sets.
159159
seed_nodeset: name of node-set that the sampler will be instructed to use as
160160
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.
165165
sampling_strategy: one of the supported sampling strategies, the same for
166166
each depth.
167167
@@ -197,36 +197,44 @@ def _recursively_sample_all_edge_sets(
197197
class SamplingSpecBuilder(object):
198198
"""Mimics builder pattern that eases creation of `tfgnn.SamplingSpec`.
199199
200-
# Usage examples.
201-
## Homogeneous Graphs.
200+
201+
Example: Homogeneous Graphs.
202+
202203
If your graph is *homogeneous* and your node set is named "nodes" and edge set
203204
is named "edges", then you can create the sampling spec proto as:
204205
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
207209
schema = schema_pb2.GraphSchema()
208210
schema.edge_sets['edges'].source = s.edge_sets['edges'].target = 'nodes'
209211
210212
proto = (SamplingSpecBuilder(schema)
211213
.seed('nodes').sample('edges', 10).sample('edges', 5)
212214
.build())
213215
```
216+
214217
The above spec is instructing to start at:
215218
- Nodes of type set name "nodes", then,
216219
- for each seed node, sample 10 of its neighbors (from edge set "edges").
217220
- for each of those neighbors, sample 5 neighbors (from same edge set).
218221
219-
## Heterogeneous Graphs.
222+
Example: Heterogeneous Graphs.
223+
220224
E.g., if you consider citation datasets, you can make a SamplingSpec proto as:
221-
```
225+
226+
```python
222227
proto = (SamplingSpecBuilder(schema)
223228
.seed('author').sample('writes', 10).sample('cited_by', 5)
224229
.build())
225230
```
231+
226232
This samples, starting from author node, 10 papers written by author, and for
227233
each paper, 10 papers citing it.
228234
229-
## DAG Sampling.
235+
236+
Example: DAG Sampling.
237+
230238
Finally, your sampling might consist of a DAG. For this, you need to cache
231239
some returns of `.sample()` calls.
232240
"""

0 commit comments

Comments
 (0)