cogdl.datasets.kg_data

Module Contents

Classes

BidirectionalOneShotIterator

TestDataset

TrainDataset

KnowledgeGraphDataset

Dataset base class for creating graph datasets.

FB13Datset

Dataset base class for creating graph datasets.

FB15kDatset

Dataset base class for creating graph datasets.

FB15k237Datset

Dataset base class for creating graph datasets.

WN18Datset

Dataset base class for creating graph datasets.

WN18RRDataset

Dataset base class for creating graph datasets.

FB13SDatset

Dataset base class for creating graph datasets.

Functions

read_triplet_data(folder)

class cogdl.datasets.kg_data.BidirectionalOneShotIterator(dataloader_head, dataloader_tail)[source]

Bases: object

__next__(self)[source]
static one_shot_iterator(dataloader)[source]

Transform a PyTorch Dataloader into python iterator

class cogdl.datasets.kg_data.TestDataset(triples, all_true_triples, nentity, nrelation, mode)[source]

Bases: torch.utils.data.Dataset

__len__(self)[source]
__getitem__(self, idx)[source]
static collate_fn(data)[source]
class cogdl.datasets.kg_data.TrainDataset(triples, nentity, nrelation, negative_sample_size, mode)[source]

Bases: torch.utils.data.Dataset

__len__(self)[source]
__getitem__(self, idx)[source]
static collate_fn(data)[source]
static count_frequency(triples, start=4)[source]

Get frequency of a partial triple like (head, relation) or (relation, tail) The frequency will be used for subsampling like word2vec

static get_true_head_and_tail(triples)[source]

Build a dictionary of true triples that will be used to filter these true triples for negative sampling

cogdl.datasets.kg_data.read_triplet_data(folder)[source]
class cogdl.datasets.kg_data.KnowledgeGraphDataset(root, name)[source]

Bases: cogdl.data.Dataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

url = https://raw.githubusercontent.com/thunlp/OpenKE/OpenKE-PyTorch/benchmarks[source]
property raw_file_names(self)[source]

The name of the files to find in the self.raw_dir folder in order to skip the download.

property processed_file_names(self)[source]

The name of the files to find in the self.processed_dir folder in order to skip the processing.

property train_start_idx(self)[source]
property valid_start_idx(self)[source]
property test_start_idx(self)[source]
property num_entities(self)[source]
property num_relations(self)[source]
get(self, idx)[source]

Gets the data object at index idx.

download(self)[source]

Downloads the dataset to the self.raw_dir folder.

process(self)[source]

Processes the dataset to the self.processed_dir folder.

class cogdl.datasets.kg_data.FB13Datset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

class cogdl.datasets.kg_data.FB15kDatset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

class cogdl.datasets.kg_data.FB15k237Datset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

class cogdl.datasets.kg_data.WN18Datset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

class cogdl.datasets.kg_data.WN18RRDataset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

class cogdl.datasets.kg_data.FB13SDatset[source]

Bases: cogdl.datasets.kg_data.KnowledgeGraphDataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Args:

root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an

cogdl.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

pre_transform (callable, optional): A function/transform that takes in

an cogdl.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

pre_filter (callable, optional): A function that takes in an

cogdl.data.Data object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default: None)

url = https://raw.githubusercontent.com/cenyk1230/test-data/main[source]