TGBNegativeEdgeSampler
¶
TGBNegativeEdgeSampler(dataset_name: str)
The precomputed negative edges of the validation and test events of a
TGB link property prediction dataset, as py-tgb's
tgb.linkproppred.negative_sampler.NegativeEdgeSampler.
Each positive event (src, dst, t) of the validation and test sets is
evaluated against a fixed list of negative destinations (one-vs-many),
which mixes historical and random destinations (TGB's "hist_rnd"
strategy). The sets are loaded with load_eval_set() (or the
load_val_ns / load_test_ns methods of the dataset) and queried
with query_batch(), or with query_batch_array() to get a
padded array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Name of the TGB dataset |
required |
Methods:
| Name | Description |
|---|---|
load_eval_set |
Loads the negative samples of a split. |
reset_eval_set |
Unloads the negative samples of a split. |
query_batch |
Negative destinations of each positive edge, as |
query_batch_array |
Negative destinations of each positive edge as a padded array. |
Source code in mlx_graphs/datasets/tgb.py
load_eval_set
¶
Loads the negative samples of a split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
A |
required |
split_mode
|
str
|
|
'val'
|
Source code in mlx_graphs/datasets/tgb.py
query_batch
¶
query_batch(
pos_src: Any,
pos_dst: Any,
pos_timestamp: Any,
edge_type: Any = None,
split_mode: str = "test",
) -> list[list[int]]
Negative destinations of each positive edge, as py-tgb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_src
|
Any
|
Sources of the positive edges, shape |
required |
pos_dst
|
Any
|
Destinations of the positive edges |
required |
pos_timestamp
|
Any
|
Timestamps of the positive edges |
required |
edge_type
|
Any
|
Edge types (only for datasets with typed edges) |
None
|
split_mode
|
str
|
|
'test'
|
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
A list with the list of negative destinations of every positive |
list[list[int]]
|
edge. |
Source code in mlx_graphs/datasets/tgb.py
query_batch_array
¶
query_batch_array(
pos_src: Any,
pos_dst: Any,
pos_timestamp: Any,
edge_type: Any = None,
split_mode: str = "test",
) -> tuple[array, array]
Negative destinations of each positive edge as a padded array.
Most positive edges of a split have the same number of negatives, a
few have less: their rows are padded with -1. Give the scores of
the padding entries the value -inf before passing them to the
TGBEvaluator, so that they never rank
above the positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_src
|
Any
|
Sources of the positive edges, shape |
required |
pos_dst
|
Any
|
Destinations of the positive edges |
required |
pos_timestamp
|
Any
|
Timestamps of the positive edges |
required |
edge_type
|
Any
|
Edge types (only for datasets with typed edges) |
None
|
split_mode
|
str
|
|
'test'
|
Returns:
| Type | Description |
|---|---|
array
|
The negative destinations, shape |
array
|
the boolean mask of the valid (non-padding) entries. |
Source code in mlx_graphs/datasets/tgb.py
from mlx_graphs.datasets import TGBNegativeEdgeSampler · mlx_graphs/datasets/tgb.py