FB15kDatasetο
- class dgl.data.FB15kDataset(reverse=True, raw_dir=None, force_reload=False, verbose=True, transform=None)[source]ο
Bases:
KnowledgeGraphDataset
FB15k link prediction dataset.
The FB15K dataset was introduced in Translating Embeddings for Modeling Multi-relational Data. It is a subset of Freebase which contains about 14,951 entities with 1,345 different relations. When creating the dataset, a reverse edge with reversed relation types are created for each edge by default.
FB15k dataset statistics:
Nodes: 14,951
Number of relation types: 1,345
Number of reversed relation types: 1,345
Label Split:
Train: 483142
Valid: 50000
Test: 59071
- Parameters:
reverse (bool) β Whether to add reverse edge. Default True.
raw_dir (str) β Raw file directory to download/contains the input data directory. Default: ~/.dgl/
force_reload (bool) β Whether to reload the dataset. Default: False
verbose (bool) β Whether to print out progress information. Default: True.
transform (callable, optional) β A transform that takes in a
DGLGraph
object and returns a transformed version. TheDGLGraph
object will be transformed before every access.
Examples
>>> dataset = FB15kDataset() >>> g = dataset.graph >>> e_type = g.edata['e_type'] >>> >>> # get data split >>> train_mask = g.edata['train_mask'] >>> val_mask = g.edata['val_mask'] >>> >>> train_set = th.arange(g.num_edges())[train_mask] >>> val_set = th.arange(g.num_edges())[val_mask] >>> >>> # build train_g >>> train_edges = train_set >>> train_g = g.edge_subgraph(train_edges, relabel_nodes=False) >>> train_g.edata['e_type'] = e_type[train_edges]; >>> >>> # build val_g >>> val_edges = th.cat([train_edges, val_edges]) >>> val_g = g.edge_subgraph(val_edges, relabel_nodes=False) >>> val_g.edata['e_type'] = e_type[val_edges]; >>> >>> # Train, Validation and Test >>>
- __getitem__(idx)[source]ο
Gets the graph object
- Parameters:
idx (int) β Item index, FB15kDataset has only one graph object
- Returns:
The graph contains
edata['e_type']
: edge relation typeedata['train_edge_mask']
: positive training edge maskedata['val_edge_mask']
: positive validation edge maskedata['test_edge_mask']
: positive testing edge maskedata['train_mask']
: training edge set mask (include reversed training edges)edata['val_mask']
: validation edge set mask (include reversed validation edges)edata['test_mask']
: testing edge set mask (include reversed testing edges)ndata['ntype']
: node type. All 0 in this dataset
- Return type: