Welcome to CogDLβs Documentation!ο

CogDL is a graph representation learning toolkit that allows researchers and developers to easily train and compare baseline or customized models for node classification, graph classification, and other important tasks in the graph domain.
We summarize the contributions of CogDL as follows:
High Efficiency: CogDL utilizes well-optimized operators to speed up training and save GPU memory of GNN models.
Easy-to-Use: CogDL provides easy-to-use APIs for running experiments with the given models and datasets using hyper-parameter search.
Extensibility: The design of CogDL makes it easy to apply GNN models to new scenarios based on our framework.
Reproducibility: CogDL provides reproducible leaderboards for state-of-the-art models on most of important tasks in the graph domain.
β Newsο
The new v0.5.1 release adds fast operators including SpMM (cpu version) and scatter_max (cuda version). It also adds lots of datasets for node classification. π
The new v0.5.0 release designs and implements a unified training loop for GNN. It introduces DataWrapper to help prepare the training/validation/test data and ModelWrapper to define the training/validation/test steps.
The new v0.4.1 release adds the implementation of Deep GNNs and the recommendation task. It also supports new pipelines for generating embeddings and recommendation. Welcome to join our tutorial on KDD 2021 at 10:30 am - 12:00 am, Aug. 14th (Singapore Time). More details can be found in https://kdd2021graph.github.io/. π
The new v0.4.0 release refactors the data storage (from
Data
toGraph
) and provides more fast operators to speed up GNN training. It also includes many self-supervised learning methods on graphs. BTW, we are glad to announce that we will give a tutorial on KDD 2021 in August. Please see this link for more details. πThe new v0.3.0 release provides a fast spmm operator to speed up GNN training. We also release the first version of CogDL paper in arXiv. You can join our slack for discussion. πππ
The new v0.2.0 release includes easy-to-use
experiment
andpipeline
APIs for all experiments and applications. Theexperiment
API supports automl features of searching hyper-parameters. This release also providesOAGBert
API for model inference (OAGBert
is trained on large-scale academic corpus by our lab). Some features and models are added by the open source community (thanks to all the contributors π).The new v0.1.2 release includes a pre-training task, many examples, OGB datasets, some knowledge graph embedding methods, and some graph neural network models. The coverage of CogDL is increased to 80%. Some new APIs, such as
Trainer
andSampler
, are developed and being tested.The new v0.1.1 release includes the knowledge link prediction task, many state-of-the-art models, and
optuna
support. We also have a Chinese WeChat post about the CogDL release.
Citing CogDLο
Please cite our paper if you find our code or results useful for your research:
@article{cen2021cogdl,
title={CogDL: An Extensive Toolkit for Deep Learning on Graphs},
author={Yukuo Cen and Zhenyu Hou and Yan Wang and Qibin Chen and Yizhen Luo and Xingcheng Yao and Aohan Zeng and Shiguang Guo and Peng Zhang and Guohao Dai and Yu Wang and Chang Zhou and Hongxia Yang and Jie Tang},
journal={arXiv preprint arXiv:2103.00959},
year={2021}
}
Installο
Python version >= 3.7
PyTorch version >= 1.7.1
Please follow the instructions here to install PyTorch (https://github.com/pytorch/pytorch#installation).
When PyTorch has been installed, cogdl can be installed using pip as follows:
pip install cogdl
Install from source via:
pip install git+https://github.com/thudm/cogdl.git
Or clone the repository and install with the following commands:
git clone git@github.com:THUDM/cogdl.git
cd cogdl
pip install -e .
If you want to use the modules from PyTorch Geometric (PyG), you can follow the instructions to install PyTorch Geometric (https://github.com/rusty1s/pytorch_geometric/#installation).
Quick Startο
API Usageο
You can run all kinds of experiments through CogDL APIs, especially experiment()
. You can also use your own datasets and models for experiments. A quickstart example can be found in the quick_start.py. More examples are provided in the examples/.
from cogdl import experiment
# basic usage
experiment(dataset="cora", model="gcn")
# set other hyper-parameters
experiment(dataset="cora", model="gcn", hidden_size=32, epochs=200)
# run over multiple models on different seeds
experiment(dataset="cora", model=["gcn", "gat"], seed=[1, 2])
# automl usage
def search_space(trial):
return {
"lr": trial.suggest_categorical("lr", [1e-3, 5e-3, 1e-2]),
"hidden_size": trial.suggest_categorical("hidden_size", [32, 64, 128]),
"dropout": trial.suggest_uniform("dropout", 0.5, 0.8),
}
experiment(dataset="cora", model="gcn", seed=[1, 2], search_space=search_space)
Command-Line Usageο
You can also use python scripts/train.py --dataset example_dataset --model example_model
to run example_model on example_data.
--dataset
, dataset name to run, can be a list of datasets with space likecora citeseer
. Supported datasets includecora
,citeseer
,pumbed
,ppi
,flickr
. More datasets can be found in the cogdl/datasets.--model
, model name to run, can be a list of models likegcn gat
. Supported models includegcn
,gat
,graphsage
. More models can be found in the cogdl/models.
For example, if you want to run GCN and GAT on the Cora dataset, with 5 different seeds:
`bash
python scripts/train.py --dataset cora --model gcn gat --seed 0 1 2 3 4
`
Expected output:
Variant |
test_acc |
val_acc |
---|---|---|
(βcoraβ, βgcnβ) |
0.8050Β±0.0047 |
0.7940Β±0.0063 |
(βcoraβ, βgatβ) |
0.8234Β±0.0042 |
0.8088Β±0.0016 |
If you want to run parallel experiments on your server with multiple GPUs on multiple models/datasets:
python scripts/parallel_train.py --dataset cora citeseer --model gcn gat --devices 0 1 --seed 0 1 2 3 4
Expected output:
Variant |
test_acc |
val_acc |
---|---|---|
(βcoraβ, βgcnβ) |
0.8050Β±0.0047 |
0.7940Β±0.0063 |
(βcoraβ, βgatβ) |
0.8234Β±0.0042 |
0.8088Β±0.0016 |
(βciteseerβ, βgcnβ) |
0.6938Β±0.0133 |
0.7108Β±0.0148 |
(βciteseerβ, βgatβ) |
0.7098Β±0.0053 |
0.7244Β±0.0039 |
Node Classificationο
Graph neural networks(GNN) have great power in tackling graph-related tasks. In this chapter, we take node classification as an example and show how to use CogDL to finish a workflow using GNN. In supervised setting, node classification aims to predict the ground truth label for each node.
Quick Startο
CogDL provides abundant of common benchmark datasets and GNN models. On the one hand, you can simply start a running using models and datasets in CogDL. This is convenient when you want to test the reproducibility of proposed GNN or get baseline results in different datasets.
from cogdl import experiment
experiment(model="gcn", dataset="cora")
Or you can create each component separately and manually run the process using build_dataset
, build_model
in CogDL.
from cogdl import experiment
from cogdl.datasets import build_dataset
from cogdl.models import build_model
from cogdl.options import get_default_args
args = get_default_args(model="gcn", dataset="cora")
dataset = build_dataset(args)
model = build_model(args)
experiment(model=model, dataset=dataset)
As show above, model/dataset/task are 3 key components in establishing a training process. In fact, CogDL also supports customized model and datasets. This will be introduced in next chapter. In the following we will briefly show the details of each component.
Save trained modelο
CogDL supports saving the trained model with checkpoint_path
in command line or API usage. For example:
experiment(model="gcn", dataset="cora", checkpoint_path="gcn_cora.pt")
When the training stops, the model will be saved in gcn_cora.py. If you want to continue the training from previous checkpoint with different parameters(such as learning rate, weight decay and etc.), keep the same model parameters (such as hidden size, model layers) and do it as follows:
experiment(model="gcn", dataset="cora", checkpoint_path="gcn_cora.pt", resume_training=True)
In command line usage, the same results can be achieved with --checkpoint-path {path}
and --resume-training
.
Save embeddingsο
Graph representation learning (network embedding and unsupervised GNNs) aims to get node representation. The embeddings
can be used in various downstream applications. CogDL will save node embeddings in the given path specified by --save-emb-path {path}
.
experiment(model="prone", dataset="blogcatalog", save_emb_path="./embeddings/prone_blog.npy")
Evaluation on node classification will run as the end of training. We follow the same experimental settings used in DeepWalk, Node2Vec and ProNE.
We randomly sample different percentages of labeled nodes for training a liblinear classifier and use the remaining for testing
We repeat the training for several times and report the average Micro-F1. By default, CogDL samples 90% labeled nodes for training
for one time. You are expected to change the setting with --num-shuffle
and --training-percents
to your needs.
In addition, CogDL supports evaluating node embeddings without training in different evaluation settings. The following code snippet evaluates the embedding we get above:
experiment(
model="prone",
dataset="blogcatalog",
load_emb_path="./embeddings/prone_blog.npy",
num_shuffle=5,
training_percents=[0.1, 0.5, 0.9]
)
You can also use command line to achieve the same results
# Get embedding
python script/train.py --model prone --dataset blogcatalog
# Evaluate only
python script/train.py --model prone --dataset blogcatalog --load-emb-path ./embeddings/prone_blog.npy --num-shuffle 5 --training-percents 0.1 0.5 0.9
Graph Storageο
A graph is used to store information of structured data. CogDL represents a graph with a cogdl.data.Graph
object.
Briefly, a Graph
holds the following attributes:
x
: Node feature matrix with shape[num_nodes, num_features]
, torch.Tensoredge_index
: COO format sparse matrix, Tupleedge_weight
: Edge weight with shape[num_edges,]
, torch.Tensoredge_attr
: Edge attribute matrix with shape[num_edges, num_attr]
y
: Target labels of each node, with shape[num_nodes,]
for single label case and [num_nodes, num_labels] for mult-label caserow_indptr
: Row index pointer for CSR sparse matrix, torch.Tensor.col_indices
: Column indices for CSR sparse matrix, torch.Tensor.num_nodes
: The number of nodes in graph.num_edges
: The number of edges in graph.
The above are the basic attributes but are not necessary. You may define a graph with g = Graph(edge_index=edges) and omit the others.
Besides, Graph
is not restricted to these attributes and other self-defined attributes, e.x. graph.mask = mask, are also supported.
Graph
stores sparse matrix with COO or CSR format. COO format is easier to add or remove edges, e.x. add_self_loops, and CSR is stored for fast message-passing.
Graph
automatically convert between two formats and you can use both on demands without worrying. You can create a Graph with edges or assign edges
to a created graph. edge_weight will be automatically initialized as all ones, and you can modify it to fit your need.
import torch
from cogdl.data import Graph
edges = torch.tensor([[0,1],[1,3],[2,1],[4,2],[0,3]]).t()
g = Graph()
g.edge_index = edges
g = Graph(edge_index=edges) # equivalent to that above
print(g.edge_weight)
>> tensor([1., 1., 1., 1., 1.])
g.num_nodes
>> 5
g.num_edges
>> 5
g.edge_weight = torch.rand(5)
print(g.edge_weight)
>> tensor([0.8399, 0.6341, 0.3028, 0.0602, 0.7190])
We also implement commonly used operations in Graph
:
add_self_loops
: add self loops for nodes in graph,
add_remaining_self_loops
: add self-loops for nodes without it.sym_norm
: symmetric normalization of edge_weight used GCN:
row_norm
: row-wise normalization of edge_weight:
degrees
: get degrees for each node. For directed graph, this function returns in-degrees of each node.
import torch
from cogdl.data import Graph
edge_index = torch.tensor([[0,1],[1,3],[2,1],[4,2],[0,3]]).t()
g = Graph(edge_index=edge_index)
>> Graph(edge_index=[2, 5])
g.add_remaining_self_loops()
>> Graph(edge_index=[2, 10], edge_weight=[10])
>> print(edge_weight) # tensor([1., 1., ..., 1.])
g.row_norm()
>> print(edge_weight) # tensor([0.3333, ..., 0.50])
subgraph
: get a subgraph containing given nodes and edges between them.edge_subgraph
: get a subgraph containing given edges and corresponding nodes.sample_adj
: sample a fixed number of neighbors for each given node.
from cogdl.datasets import build_dataset_from_name
g = build_dataset_from_name("cora")[0]
g.num_nodes
>> 2707
g.num_edges
>> 10184
# Get a subgraph contaning nodes [0, .., 99]
sub_g = g.subgraph(torch.arange(100))
>> Graph(x=[100, 1433], edge_index=[2, 18], y=[100])
# Sample 3 neighbors for each nodes in [0, .., 99]
nodes, adj_g = g.sample_adj(torch.arange(100), size=3)
>> Graph(edge_index=[2, 300]) # adj_g
train/eval
: In inductive settings, some nodes and edges are unseen during training,train/eval
provides access to switching backend graph for training/evaluation. In transductive setting, you may ignore this.
# train_step
model.train()
graph.train()
# inference_step
model.eval()
graph.eval()
Mini-batch Graphsο
In node classification, all operations are in one single graph. But in tasks like graph classification, we need to deal with
many graphs with mini-batch. Datasets for graph classification contains graphs which can be accessed with index, e.x. data[2]
.
To support mini-batch training/inference, CogDL combines graphs in a batch into one whole graph, where adjacency matrices form sparse block diagnal matrices
and others(node features, labels) are concatenated in node dimension. cogdl.data.Dataloader
handles the process.
from cogdl.data import DataLoader
from cogdl.datasets import build_dataset_from_name
dataset = build_dataset_from_name("mutag")
>> MUTAGDataset(188)
dataswet[0]
>> Graph(x=[17, 7], y=[1], edge_index=[2, 38])
loader = DataLoader(dataset, batch_size=8)
for batch in loader:
model(batch)
>> Batch(x=[154, 7], y=[8], batch=[154], edge_index=[2, 338])
batch
is an additional attributes that indicate the respective graph the node belongs to. It is mainly used to do global
pooling, or called readout to generate graph-level representation. Concretely, batch
is a tensor like:
The following code snippet shows how to do global pooling to sum over features of nodes in each graph:
def batch_sum_pooling(x, batch):
batch_size = int(torch.max(batch.cpu())) + 1
res = torch.zeros(batch_size, x.size(1)).to(x.device)
out = res.scatter_add_(
dim=0,
index=batch.unsqueeze(-1).expand_as(x),
src=x
)
return out
Editing Graphsο
Mutation or changes can be applied to edges in some settings. In such cases, we need to generate a graph for calculation while keep the original graph. CogDL provides graph.local_graph to set up a local scape and any out-of-place operation will not reflect to the original graph. However, in-place operation will affect the original graph.
graph = build_dataset_from_name("cora")[0]
graph.num_edges
>> 10184
with graph.local_graph():
mask = torch.arange(100)
row, col = graph.edge_index
graph.edge_index = (row[mask], col[mask])
graph.num_edges
>> 100
graph.num_edges
>> 10184
graph.edge_weight
>> tensor([1.,...,1.])
with graph.local_graph():
graph.edge_weight += 1
graph.edge_weight
>> tensor([2.,...,2.])
Common benchmarksο
CogDL provides a bunch of commonly used datasets for graph tasks like node classification, graph classification and many others. You can access them conveniently shown as follows. Statistics of datasets are on this page .
from cogdl.datasets import build_dataset_from_name, build_dataset
dataset = build_dataset_from_name("cora")
dataset = build_dataset(args) # args.dataet = "cora"
For all datasets for node classification, we use train_mask, val_mask, test_mask to denote train/validation/test split for nodes.
Using customized GNNο
Sometimes you would like to design your own GNN module or use GNN for other purposes. In this chapter, we introduce how to use GNN layer in CogDL to write your own GNN model and how to write a GNN layer from scratch.
GNN layers in CogDL to Define modelο
CogDL has implemented popular GNN layers in cogdl.layers
, and they can serve as modules to help design new GNNs.
Here is how we implement Jumping Knowledge Network (JKNet) with GCNLayer
in CogDL.
JKNet collects the output of all layers and concatenate them together to get the result:
import torch
from cogdl.layers import GCNLayer
from cogdl.models import BaseModel
class JKNet(BaseModel):
def __init__(self, in_feats, out_feats, hidden_size, num_layers):
super(JKNet, self).__init__()
shapes = [in_feats] + [hidden_size] * num_layers
self.layers = nn.ModuleList([
GCNLayer(shape[i], shape[i+1])
for i in range(num_layers)
])
self.fc = nn.Linear(hidden_size * num_layers, out_feats)
def forward(self, graph):
# symmetric normalization of adjacency matrix
graph.sym_norm()
h = graph.x
out = []
for layer in self.layers:
h = layer(x)
out.append(h)
out = torch.cat(out, dim=1)
return self.fc(out)
Define your GNN Moduleο
In most cases, you may build a layer module with new message propagation and aggragation scheme. Here the code snippet
shows how to implement a GCNLayer using Graph
and efficient sparse matrix operators in CogDL.
import torch
from cogdl.utils import spmm
class GCNLayer(torch.nn.Module):
"""
Args:
in_feats: int
Input feature size
out_feats: int
Output feature size
"""
def __init__(self, in_feats, out_feats):
super(GCNLayer, self).__init__()
self.fc = torch.nn.Linear(in_feats, out_feats)
def forward(self, graph, x):
h = self.fc(x)
h = spmm(graph, h)
return h
spmm
is sparse matrix multiplication operation frequently used in GNNs.
Sparse matrix is stored in Graph
and will be called automatically. Message-passing in spatial space is equivalent to
matrix operations. CogDL also supports other efficient operators like edge_softmax
and multi_head_spmm
, you can refer
to this page for usage.
Use Custom models with CogDLο
Now that you have defined your own GNN, you can use dataset/task in CogDL to immediately train and evaluate the performance of your model.
data = dataset.data
# Use the JKNet model as defined above
model = JKNet(data.num_features, data.num_classes, 32, 4)
experiment(model=model, dataset="cora", mw="node_classification_mw", dw="node_classification_dw")
Using customized Datasetο
CogDL has provided lots of common datasets. But you may wish to apply GNN to new datasets for different applications. CogDL provides an interface for customized datasets. You take care of reading in the dataset and the rest is to CogDL
We provide NodeDataset
and GraphDataset
as abstract classes and implement necessary basic operations.
Dataset for node_classificationο
To create a dataset for node_classification, you need to inherit NodeDataset
. NodeDataset
is for node-level prediction. Then you need to implement process
method.
In this method, you are expected to read in your data and preprocess raw data to the format available to CogDL with Graph
.
Afterwards, we suggest you to save the processed data (we will also help you do it as you return the data) to avoid doing
the preprocessing again. Next time you run the code, CogDL will directly load it.
The running process of the module is as follows:
Specify the path to save processed data with self.path
2. Function process is called to load and preprocess data and your data is saved as Graph in self.path. This step will be implemented the first time you use your dataset. And then every time you use your dataset, the dataset will be loaded from self.path for convenience. 3. For dataset, for example, named MyNodeDataset in node-level tasks, You can access the data/Graph via MyNodeDataset.data or MyDataset[0].
In addition, evaluation metric for your dataset should be specified. CogDL provides accuracy
and multiclass_f1
for multi-class classification, multilabel_f1
for multi-label classification.
If scale_feat
is set to be True, CogDL will normalize node features with mean u and variance s:
Here is an example:
from cogdl.data import Graph
from cogdl.datasets import NodeDataset, generate_random_graph
class MyNodeDataset(NodeDataset):
def __init__(self, path="data.pt"):
self.path = path
super(MyNodeDataset, self).__init__(path, scale_feat=False, metric="accuracy")
def process(self):
"""You need to load your dataset and transform to `Graph`"""
num_nodes, num_edges, feat_dim = 100, 300, 30
# load or generate your dataset
edge_index = torch.randint(0, num_nodes, (2, num_edges))
x = torch.randn(num_nodes, feat_dim)
y = torch.randint(0, 2, (num_nodes,))
# set train/val/test mask in node_classification task
train_mask = torch.zeros(num_nodes).bool()
train_mask[0 : int(0.3 * num_nodes)] = True
val_mask = torch.zeros(num_nodes).bool()
val_mask[int(0.3 * num_nodes) : int(0.7 * num_nodes)] = True
test_mask = torch.zeros(num_nodes).bool()
test_mask[int(0.7 * num_nodes) :] = True
data = Graph(x=x, edge_index=edge_index, y=y, train_mask=train_mask, val_mask=val_mask, test_mask=test_mask)
return data
if __name__ == "__main__":
# Train customized dataset via defining a new class
dataset = MyNodeDataset()
experiment(dataset=dataset, model="gcn")
# Train customized dataset via feeding the graph data to NodeDataset
data = generate_random_graph(num_nodes=100, num_edges=300, num_feats=30)
dataset = NodeDataset(data=data)
experiment(dataset=dataset, model="gcn")
Dataset for graph_classificationο
Similarly, you need to inherit GraphDataset
when you want to build a dataset for graph-level tasks such as graph_classification.
The overall implementation is similar while the difference is in process
. As GraphDataset
contains a lot of graphs,
you need to transform your data to Graph
for each graph separately to form a list of Graph
.
An example is shown as follows:
from cogdl.data import Graph
from cogdl.datasets import GraphDataset
class MyGraphDataset(GraphDataset):
def __init__(self, path="data.pt"):
self.path = path
super(MyGraphDataset, self).__init__(path, metric="accuracy")
def process(self):
# Load and preprocess data
# Here we randomly generate several graphs for simplicity as an example
graphs = []
for i in range(10):
edges = torch.randint(0, 20, (2, 30))
label = torch.randint(0, 7, (1,))
graphs.append(Graph(edge_index=edges, y=label))
return graphs
if __name__ == "__main__":
dataset = MyGraphDataset()
experiment(model="gin", dataset=dataset)
dataο
- class cogdl.data.Adjacency(row=None, col=None, row_ptr=None, weight=None, attr=None, num_nodes=None, types=None, **kwargs)[source]ο
Bases:
cogdl.data.data.BaseGraph
- property deviceο
- property edge_indexο
- get_weight(indicator=None)[source]ο
If indicator is not None, the normalization will not be implemented
- property keysο
Returns all names of graph attributes.
- property num_edgesο
- property num_nodesο
- property row_indptrο
- property row_ptr_vο
- class cogdl.data.Batch(batch=None, **kwargs)[source]ο
Bases:
cogdl.data.data.Graph
A plain old python object modeling a batch of graphs as one big (dicconnected) graph. With
cogdl.data.Data
being the base class, all its methods can also be used here. In addition, single graphs can be reconstructed via the assignment vectorbatch
, which maps each node to its respective graph identifier.- cumsum(key, item)[source]ο
If
True
, the attributekey
with contentitem
should be added up cumulatively before concatenated together.Note
This method is for internal use only, and should only be overridden if the batch concatenation process is corrupted for a specific data attribute.
- static from_data_list(data_list, class_type=None)[source]ο
Constructs a batch object from a python list holding
cogdl.data.Data
objects. The assignment vectorbatch
is created on the fly. Additionally, creates assignment batch vectors for each key infollow_batch
.
- property num_graphsο
Returns the number of graphs in the batch.
- class cogdl.data.DataLoader(*args, **kwargs)[source]ο
Bases:
Generic
[torch.utils.data.dataloader.T_co
]Data loader which merges data objects from a
cogdl.data.dataset
to a mini-batch.- Parameters
- dataset: torch.utils.data.dataset.Dataset[torch.utils.data.dataloader.T_co]ο
- sampler: torch.utils.data.sampler.Samplerο
- class cogdl.data.Dataset(root, transform=None, pre_transform=None, pre_filter=None)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]Dataset base class for creating graph datasets. See here for the accompanying tutorial.
- Parameters
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
)
- property edge_attr_sizeο
- property max_degreeο
- property max_graph_sizeο
- property num_classesο
The number of classes in the dataset.
- property num_featuresο
Returns the number of features per node in the graph.
- property num_graphsο
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property processed_pathsο
The filepaths to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- property raw_pathsο
The filepaths to find in order to skip the download.
- class cogdl.data.Graph(x=None, y=None, **kwargs)[source]ο
Bases:
cogdl.data.data.BaseGraph
- property col_indicesο
- property deviceο
- property edge_attrο
- property edge_indexο
- property edge_typesο
- property edge_weightο
Return actual edge_weight
- property in_normο
- property keysο
Returns all names of graph attributes.
- property num_classesο
- property num_edgesο
Returns the number of edges in the graph.
- property num_featuresο
Returns the number of features per node in the graph.
- property num_nodesο
- property out_normο
- property raw_edge_weightο
Return edge_weight without __in_norm__ and __out_norm__, only used for SpMM
- property row_indptrο
- property test_nidο
- property train_nidο
- property val_nidο
- class cogdl.data.MultiGraphDataset(root=None, transform=None, pre_transform=None, pre_filter=None)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property max_degreeο
- property max_graph_sizeο
- property num_classesο
The number of classes in the dataset.
- property num_featuresο
Returns the number of features per node in the graph.
- property num_graphsο
datasetsο
GATNE datasetο
- class cogdl.datasets.gatne.AmazonDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.gatne.GatneDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]The network datasets βAmazonβ, βTwitterβ and βYouTubeβ from the βRepresentation Learning for Attributed Multiplex Heterogeneous Networkβ paper.
- Parameters
root (string) β Root directory where the dataset should be saved.
name (string) β The name of the dataset (
"Amazon"
,"Twitter"
,"YouTube"
).
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- url = 'https://github.com/THUDM/GATNE/raw/master/data'ο
- class cogdl.datasets.gatne.TwitterDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
GCC datasetο
- class cogdl.datasets.gcc_data.Edgelist(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property num_classesο
The number of classes in the dataset.
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- url = 'https://github.com/cenyk1230/gcc-data/raw/master'ο
- class cogdl.datasets.gcc_data.GCCDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- url = 'https://github.com/cenyk1230/gcc-data/raw/master'ο
- class cogdl.datasets.gcc_data.KDD_ICDM_GCCDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.gcc_data.SIGIR_CIKM_GCCDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
GTN datasetο
- class cogdl.datasets.gtn_data.ACM_GTNDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.gtn_data.DBLP_GTNDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.gtn_data.GTNDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]The network datasets βACMβ, βDBLPβ and βIMDBβ from the βGraph Transformer Networksβ paper.
- Parameters
root (string) β Root directory where the dataset should be saved.
name (string) β The name of the dataset (
"gtn-acm"
,"gtn-dblp"
,"gtn-imdb"
).
- property num_classesο
The number of classes in the dataset.
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
HAN datasetο
- class cogdl.datasets.han_data.ACM_HANDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.han_data.DBLP_HANDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.han_data.HANDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]The network datasets βACMβ, βDBLPβ and βIMDBβ from the βHeterogeneous Graph Attention Networkβ paper.
- Parameters
root (string) β Root directory where the dataset should be saved.
name (string) β The name of the dataset (
"han-acm"
,"han-dblp"
,"han-imdb"
).
- property num_classesο
The number of classes in the dataset.
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
KG datasetο
- class cogdl.datasets.kg_data.FB13Datset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.kg_data.FB13SDatset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.kg_data.FB15k237Datset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.kg_data.FB15kDatset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.kg_data.KnowledgeGraphDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property num_entitiesο
- property num_relationsο
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- property test_start_idxο
- property train_start_idxο
- url = 'https://cloud.tsinghua.edu.cn/d/b567292338f2488699b7/files/?p=%2F{}%2F{}&dl=1'ο
- property valid_start_idxο
- class cogdl.datasets.kg_data.WN18Datset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
Matlab matrix datasetο
- class cogdl.datasets.matlab_matrix.BlogcatalogDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.matlab_matrix.DblpNEDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.matlab_matrix.FlickrDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.matlab_matrix.MatlabMatrix(root, name, url)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]networks from the http://leitang.net/code/social-dimension/data/ or http://snap.stanford.edu/node2vec/
- Parameters
root (string) β Root directory where the dataset should be saved.
name (string) β The name of the dataset (
"Blogcatalog"
).
- property num_classesο
The number of classes in the dataset.
- property num_nodesο
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- class cogdl.datasets.matlab_matrix.NetworkEmbeddingCMTYDataset(root, name, url)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property num_classesο
The number of classes in the dataset.
- property num_nodesο
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- class cogdl.datasets.matlab_matrix.PPIDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
OGB datasetο
- class cogdl.datasets.ogb.OGBArxivDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.ogb.OGBCodeDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.ogb.OGBGDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property num_classesο
The number of classes in the dataset.
- class cogdl.datasets.ogb.OGBMolbaceDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.ogb.OGBMolhivDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.ogb.OGBMolpcbaDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.ogb.OGBNDataset(root, name, transform=None)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- class cogdl.datasets.ogb.OGBPapers100MDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
TU datasetο
- class cogdl.datasets.tu_data.CollabDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.ENZYMES(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.ImdbBinaryDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.ImdbMultiDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.MUTAGDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.NCI109Dataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.NCI1Dataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.PTCMRDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.ProteinsDataset(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.RedditBinary(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.RedditMulti12K(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.RedditMulti5K(data_path='data')[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]
- class cogdl.datasets.tu_data.TUDataset(root, name)[source]ο
Bases:
Generic
[torch.utils.data.dataset.T_co
]- property num_classesο
The number of classes in the dataset.
- property processed_file_namesο
The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
- property raw_file_namesο
The name of the files to find in the
self.raw_dir
folder in order to skip the download.
- url = 'https://www.chrsmrrs.com/graphkerneldatasets'ο
- cogdl.datasets.tu_data.parse_txt_array(src, sep=None, start=0, end=None, dtype=None, device=None)[source]ο
Module contentsο
- cogdl.datasets.register_dataset(name)[source]ο
New dataset types can be added to cogdl with the
register_dataset()
function decorator.For example:
@register_dataset('my_dataset') class MyDataset(): (...)
- Parameters
name (str) β the name of the dataset
modelsο
BaseModelο
- class cogdl.models.base_model.BaseModel[source]ο
Bases:
torch.nn.modules.module.Module
- property deviceο
- forward(*args)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
Embedding Modelο
- class cogdl.models.emb.hope.HOPE(dimension, beta)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The HOPE model from the βGrarep: Asymmetric transitivity preserving graph embeddingβ paper.
- Parameters
- class cogdl.models.emb.spectral.Spectral(hidden_size)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Spectral clustering model from the βLeveraging social media networks for classiο¬cationβ paper
- Parameters
hidden_size (int) β The dimension of node representation.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.hin2vec.Hin2vec(hidden_dim, walk_length, walk_num, batch_size, hop, negative, epochs, lr, cpu=True)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Hin2vec model from the βHIN2Vec: Explore Meta-paths in Heterogeneous Information Networks for Representation Learningβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
batch_size (int) β The batch size of training in Hin2vec.
hop (int) β The number of hop to construct training samples in Hin2vec.
negative (int) β The number of nagative samples for each meta2path pair.
epochs (int) β The number of training iteration.
lr (float) β The initial learning rate of SGD.
cpu (bool) β Use CPU or GPU to train hin2vec.
- forward(data)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.netmf.NetMF(dimension, window_size, rank, negative, is_large=False)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The NetMF model from the βNetwork Embedding as Matrix Factorization: Unifying DeepWalk, LINE, PTE, and node2vecβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
window_size (int) β The actual context size which is considered in language model.
rank (int) β The rank in approximate normalized laplacian.
negative (int) β The number of nagative samples in negative sampling.
is-large (bool) β When window size is large, use approximated deepwalk matrix to decompose.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.deepwalk.DeepWalk(dimension, walk_length, walk_num, window_size, worker, iteration)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The DeepWalk model from the βDeepWalk: Online Learning of Social Representationsβ paper
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
window_size (int) β The actual context size which is considered in language model.
worker (int) β The number of workers for word2vec.
iteration (int) β The number of training iteration in word2vec.
- static add_args(parser: argparse.ArgumentParser)[source]ο
Add model-specific arguments to the parser.
- classmethod build_model_from_args(args) cogdl.models.emb.deepwalk.DeepWalk [source]ο
- forward(graph, embedding_model_creator=<class 'gensim.models.word2vec.Word2Vec'>, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.gatne.GATNE(dimension, walk_length, walk_num, window_size, worker, epochs, batch_size, edge_dim, att_dim, negative_samples, neighbor_samples, schema)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The GATNE model from the βRepresentation Learning for Attributed Multiplex Heterogeneous Networkβ paper
- Parameters
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
window_size (int) β The actual context size which is considered in language model.
worker (int) β The number of workers for word2vec.
epochs (int) β The number of training epochs.
batch_size (int) β The size of each training batch.
edge_dim (int) β Number of edge embedding dimensions.
att_dim (int) β Number of attention dimensions.
negative_samples (int) β Negative samples for optimization.
neighbor_samples (int) β Neighbor samples for aggregation
schema (str) β The metapath schema used in model. Metapaths are splited with β,β,
example (while each node type are connected with "-" in each metapath. For) β β0-1-0,0-1-2-1-0β
- forward(network_data)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.dgk.DeepGraphKernel(hidden_dim, min_count, window_size, sampling_rate, rounds, epochs, alpha, n_workers=4)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Hin2vec model from the βDeep Graph Kernelsβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
min_count (int) β Parameter in word2vec.
window (int) β The actual context size which is considered in language model.
sampling_rate (float) β Parameter in word2vec.
iteration (int) β The number of iteration in WL method.
epochs (int) β The number of training iteration.
alpha (float) β The learning rate of word2vec.
- forward(graphs, **kwargs)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.grarep.GraRep(dimension, step)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The GraRep model from the βGrarep: Learning graph representations with global structural informationβ paper.
- Parameters
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.dngr.DNGR(hidden_size1, hidden_size2, noise, alpha, step, epochs, lr, cpu)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The DNGR model from the βDeep Neural Networks for Learning Graph Representationsβ paper
- Parameters
hidden_size1 (int) β The size of the first hidden layer.
hidden_size2 (int) β The size of the second hidden layer.
noise (float) β Denoise rate of DAE.
alpha (float) β Parameter in DNGR.
step (int) β The max step in random surfing.
epochs (int) β The max epoches in training step.
lr (float) β Learning rate in DNGR.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.pronepp.ProNEPP(filter_types, svd, search, max_evals=None, loss_type=None, n_workers=None)[source]ο
- class cogdl.models.emb.graph2vec.Graph2Vec(dimension, min_count, window_size, dm, sampling_rate, rounds, epochs, lr, worker=4)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Graph2Vec model from the βgraph2vec: Learning Distributed Representations of Graphsβ paper
- Parameters
hidden_size (int) β The dimension of node representation.
min_count (int) β Parameter in doc2vec.
window_size (int) β The actual context size which is considered in language model.
sampling_rate (float) β Parameter in doc2vec.
dm (int) β Parameter in doc2vec.
iteration (int) β The number of iteration in WL method.
lr (float) β Learning rate in doc2vec.
- forward(graphs, **kwargs)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.metapath2vec.Metapath2vec(dimension, walk_length, walk_num, window_size, worker, iteration, schema)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Metapath2vec model from the βmetapath2vec: Scalable Representation Learning for Heterogeneous Networksβ paper
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
window_size (int) β The actual context size which is considered in language model.
worker (int) β The number of workers for word2vec.
iteration (int) β The number of training iteration in word2vec.
schema (str) β The metapath schema used in model. Metapaths are splited with β,β,
example (while each node type are connected with "-" in each metapath. For) β β0-1-0,0-2-0,1-0-2-0-1β.
- forward(data)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.node2vec.Node2vec(dimension, walk_length, walk_num, window_size, worker, iteration, p, q)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The node2vec model from the βnode2vec: Scalable feature learning for networksβ paper
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
window_size (int) β The actual context size which is considered in language model.
worker (int) β The number of workers for word2vec.
iteration (int) β The number of training iteration in word2vec.
p (float) β Parameter in node2vec.
q (float) β Parameter in node2vec.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.pte.PTE(dimension, walk_length, walk_num, negative, batch_size, alpha)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The PTE model from the βPTE: Predictive Text Embedding through Large-scale Heterogeneous Text Networksβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
negative (int) β The number of nagative samples for each edge.
batch_size (int) β The batch size of training in PTE.
alpha (float) β The initial learning rate of SGD.
- forward(data)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.netsmf.NetSMF(dimension, window_size, negative, num_round, worker)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The NetSMF model from the βNetSMF: Large-Scale Network Embedding as Sparse Matrix Factorizationβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
window_size (int) β The actual context size which is considered in language model.
negative (int) β The number of nagative samples in negative sampling.
num_round (int) β The number of round in NetSMF.
worker (int) β The number of workers for NetSMF.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.line.LINE(dimension, walk_length, walk_num, negative, batch_size, alpha, order)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The LINE model from the βLine: Large-scale information network embeddingβ paper.
- Parameters
hidden_size (int) β The dimension of node representation.
walk_length (int) β The walk length.
walk_num (int) β The number of walks to sample for each node.
negative (int) β The number of nagative samples for each edge.
batch_size (int) β The batch size of training in LINE.
alpha (float) β The initial learning rate of SGD.
order (int) β 1 represents perserving 1-st order proximity, 2 represents 2-nd,
them (while 3 means both of) β
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.sdne.SDNE(hidden_size1, hidden_size2, droput, alpha, beta, nu1, nu2, epochs, lr, cpu)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The SDNE model from the βStructural Deep Network Embeddingβ paper
- Parameters
hidden_size1 (int) β The size of the first hidden layer.
hidden_size2 (int) β The size of the second hidden layer.
droput (float) β Droput rate.
alpha (float) β Trade-off parameter between 1-st and 2-nd order objective function in SDNE.
beta (float) β Parameter of 2-nd order objective function in SDNE.
nu1 (float) β Parameter of l1 normlization in SDNE.
nu2 (float) β Parameter of l2 normlization in SDNE.
epochs (int) β The max epoches in training step.
lr (float) β Learning rate in SDNE.
cpu (bool) β Use CPU or GPU to train hin2vec.
- forward(graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.emb.prone.ProNE(dimension, step, mu, theta)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The ProNE model from the βProNE: Fast and Scalable Network Representation Learningβ paper.
- Parameters
- forward(graph: cogdl.data.data.Graph, return_dict=False)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
GNN Modelο
- class cogdl.models.nn.dgi.DGIModel(in_feats, hidden_size, activation)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.mvgrl.MVGRL(in_feats, hidden_size, sample_size=2000, batch_size=4, alpha=0.2, dataset='cora')[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.patchy_san.PatchySAN(num_features, num_classes, num_sample, num_neighbor, iteration)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The Patchy-SAN model from the βLearning Convolutional Neural Networks for Graphsβ paper.
- Parameters
- forward(batch)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gcn.GCN(in_feats, hidden_size, out_feats, num_layers, dropout, activation='relu', residual=False, norm=None)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The GCN model from the βSemi-Supervised Classification with Graph Convolutional Networksβ paper
- Parameters
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gdc_gcn.GDC_GCN(nfeat, nhid, nclass, dropout, alpha, t, k, eps, gdctype)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The GDC model from the βDiffusion Improves Graph Learningβ paper, with the PPR and heat matrix variants combined with GCN
- Parameters
num_features (int) β Number of input features in ppr-preprocessed dataset.
num_classes (int) β Number of classes.
hidden_size (int) β The dimension of node representation.
dropout (float) β Dropout rate for model training.
alpha (float) β PPR polynomial filter param, 0 to 1.
t (float) β Heat polynomial filter param
k (int) β Top k nodes retained during sparsification.
eps (float) β Threshold for clipping.
gdc_type (str) β βnoneβ, βpprβ, βheatβ
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.graphsage.Graphsage(num_features, num_classes, hidden_size, num_layers, sample_size, dropout, aggr)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(*args)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.compgcn.LinkPredictCompGCN(num_entities, num_rels, hidden_size, num_bases=0, layers=1, sampling_rate=0.01, penalty=0.001, dropout=0.0, lbl_smooth=0.1, opn='sub')[source]ο
Bases:
cogdl.utils.link_prediction_utils.GNNLinkPredict
,cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- loss(data: cogdl.data.data.Graph, scoring)[source]ο
- class cogdl.models.nn.drgcn.DrGCN(num_features, num_classes, hidden_size, num_layers, dropout, norm=None, activation='relu')[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.graph_unet.GraphUnet(in_feats: int, hidden_size: int, out_feats: int, pooling_layer: int, pooling_rates: List[float], n_dropout: float = 0.5, adj_dropout: float = 0.3, activation: str = 'elu', improved: bool = False, aug_adj: bool = False)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph: cogdl.data.data.Graph) torch.Tensor [source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gcnmix.GCNMix(in_feat, hidden_size, num_classes, k, temperature, alpha, dropout)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.diffpool.DiffPool(in_feats, hidden_dim, embed_dim, num_classes, num_layers, num_pool_layers, assign_dim, pooling_ratio, batch_size, dropout=0.5, no_link_pred=True, concat=False, use_bn=False)[source]ο
Bases:
cogdl.models.base_model.BaseModel
DIFFPOOL from paper Hierarchical Graph Representation Learning with Differentiable Pooling.
- Parameters
in_feats (int) β Size of each input sample.
hidden_dim (int) β Size of hidden layer dimension of GNN.
embed_dim (int) β Size of embeded node feature, output size of GNN.
num_classes (int) β Number of target classes.
num_layers (int) β Number of GNN layers.
num_pool_layers (int) β Number of pooling.
assign_dim (int) β Embedding size after the first pooling.
pooling_ratio (float) β Size of each poolling ratio.
batch_size (int) β Size of each mini-batch.
dropout (float, optional) β Size of dropout, default: 0.5.
no_link_pred (bool, optional) β If True, use link prediction loss, default: True.
- forward(batch)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gcnii.GCNII(in_feats, hidden_size, out_feats, num_layers, dropout=0.5, alpha=0.1, lmbda=1, wd1=0.0, wd2=0.0, residual=False, actnn=False)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Implementation of GCNII in paper βSimple and Deep Graph Convolutional Networksβ.
- Parameters
in_feats (int) β Size of each input sample
hidden_size (int) β Size of each hidden unit
out_feats (int) β Size of each out sample
num_layers (int) β
dropout (float) β
alpha (float) β Parameter of initial residual connection
lmbda (float) β Parameter of identity mapping
wd1 (float) β Weight-decay for Fully-connected layers
wd2 (float) β Weight-decay for convolutional layers
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.sign.MLP(in_feats, out_feats, hidden_size, num_layers, dropout=0.0, activation='relu', norm=None, act_first=False, bias=True)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.mixhop.MixHop(num_features, num_classes, dropout, layer1_pows, layer2_pows)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gat.GAT(in_feats, hidden_size, out_features, num_layers, dropout, attn_drop, alpha, nhead, residual, last_nhead, norm=None)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The GAT model from the βGraph Attention Networksβ paper
- Parameters
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.han.HAN(num_edge, w_in, w_out, num_class, num_nodes, num_layers)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.ppnp.PPNP(nfeat, nhid, nclass, num_layers, dropout, propagation, alpha, niter, cache=True)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.grace.GRACE(in_feats: int, hidden_size: int, proj_hidden_size: int, num_layers: int, drop_feature_rates: List[float], drop_edge_rates: List[float], tau: float = 0.5, activation: str = 'relu', batch_size: int = - 1)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- drop_adj(graph: cogdl.data.data.Graph, drop_rate: float = 0.5)[source]ο
- forward(graph: cogdl.data.data.Graph, x: Optional[torch.Tensor] = None)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- prop(graph: cogdl.data.data.Graph, x: torch.Tensor, drop_feature_rate: float = 0.0, drop_edge_rate: float = 0.0)[source]ο
- class cogdl.models.nn.pprgo.PPRGo(in_feats, hidden_size, out_feats, num_layers, alpha, dropout, activation='relu', nprop=2, norm='sym')[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(x, targets, ppr_scores)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gin.GIN(num_layers, in_feats, out_feats, hidden_dim, num_mlp_layers, eps=0, pooling='sum', train_eps=False, dropout=0.5)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Graph Isomorphism Network from paper βHow Powerful are Graph Neural Networks?β.
- Parameters
num_layers β int Number of GIN layers
in_feats β int Size of each input sample
out_feats β int Size of each output sample
hidden_dim β int Size of each hidden layer dimension
num_mlp_layers β int Number of MLP layers
eps β float32, optional Initial epsilon value, default:
0
pooling β str, optional Aggregator type to use, default:γ
sum
train_eps β bool, optional If True, epsilon will be a learnable parameter, default:
True
- forward(batch)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.grand.Grand(nfeat, nhid, nclass, input_droprate, hidden_droprate, use_bn, dropnode_rate, order, alpha)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Implementation of GRAND in paper βGraph Random Neural Networks for Semi-Supervised Learning on Graphsβ <https://arxiv.org/abs/2005.11079>
- Parameters
nfeat (int) β Size of each input features.
nhid (int) β Size of hidden features.
nclass (int) β Number of output classes.
input_droprate (float) β Dropout rate of input features.
hidden_droprate (float) β Dropout rate of hidden features.
use_bn (bool) β Using batch normalization.
dropnode_rate (float) β Rate of dropping elements of input features
tem (float) β Temperature to sharpen predictions.
lam (float) β Proportion of consistency loss of unlabelled data
order (int) β Order of adjacency matrix
sample (int) β Number of augmentations for consistency loss
alpha (float) β
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.gtn.GTN(num_edge, num_channels, w_in, w_out, num_class, num_nodes, num_layers)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.rgcn.LinkPredictRGCN(num_entities, num_rels, hidden_size, num_layers, regularizer='basis', num_bases=None, self_loop=True, sampling_rate=0.01, penalty=0, dropout=0.0, self_dropout=0.0)[source]ο
Bases:
cogdl.utils.link_prediction_utils.GNNLinkPredict
,cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.deepergcn.DeeperGCN(in_feat, hidden_size, out_feat, num_layers, activation='relu', dropout=0.0, aggr='max', beta=1.0, p=1.0, learn_beta=False, learn_p=False, learn_msg_scale=True, use_msg_norm=False, edge_attr_size=None)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Implementation of DeeperGCN in paper βDeeperGCN: All You Need to Train Deeper GCNsβ
- Parameters
in_feat (int) β the dimension of input features
hidden_size (int) β the dimension of hidden representation
out_feat (int) β the dimension of output features
num_layers (int) β the number of layers
activation (str, optional) β activation function. Defaults to βreluβ.
dropout (float, optional) β dropout rate. Defaults to 0.0.
aggr (str, optional) β aggregation function. Defaults to βmaxβ.
beta (float, optional) β a coefficient for aggregation function. Defaults to 1.0.
p (float, optional) β a coefficient for aggregation function. Defaults to 1.0.
learn_beta (bool, optional) β whether beta is learnable. Defaults to False.
learn_p (bool, optional) β whether p is learnable. Defaults to False.
learn_msg_scale (bool, optional) β whether message scale is learnable. Defaults to True.
use_msg_norm (bool, optional) β use message norm or not. Defaults to False.
edge_attr_size (int, optional) β the dimension of edge features. Defaults to None.
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.drgat.DrGAT(num_features, num_classes, hidden_size, num_heads, dropout)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.infograph.InfoGraph(in_feats, hidden_dim, out_feats, num_layers=3, sup=False)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- Implimentation of Infograph in paper `βInfoGraph: Unsupervised and Semi-supervised Graph-Level Representation
Learning via Mutual Information Maximizationβ <https://openreview.net/forum?id=r1lfF2NYvH>__. `
- in_featsint
Size of each input sample.
- out_featsint
Size of each output sample.
- num_layersint, optional
Number of MLP layers in encoder, default:
3
.- unsupbool, optional
Use unsupervised model if True, default:
True
.
- forward(batch)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.dropedge_gcn.DropEdge_GCN(nfeat, nhid, nclass, nhidlayer, dropout, baseblock, inputlayer, outputlayer, nbaselayer, activation, withbn, withloop, aggrmethod)[source]ο
Bases:
cogdl.models.base_model.BaseModel
DropEdge: Towards Deep Graph Convolutional Networks on Node Classification Applying DropEdge to GCN @ https://arxiv.org/pdf/1907.10903.pdf
The model for the single kind of deepgcn blocks. The model architecture likes: inputlayer(nfeat)βblock(nbaselayer, nhid)ββ¦βoutputlayer(nclass)βsoftmax(nclass)
The total layer is nhidlayer*nbaselayer + 2. All options are configurable.
- Args:
Initial function. :param nfeat: the input feature dimension. :param nhid: the hidden feature dimension. :param nclass: the output feature dimension. :param nhidlayer: the number of hidden blocks. :param dropout: the dropout ratio. :param baseblock: the baseblock type, can be βmutigcnβ, βresgcnβ, βdensegcnβ and βinceptiongcnβ. :param inputlayer: the input layer type, can be βgcnβ, βdenseβ, βnoneβ. :param outputlayer: the input layer type, can be βgcnβ, βdenseβ. :param nbaselayer: the number of layers in one hidden block. :param activation: the activation function, default is ReLu. :param withbn: using batch normalization in graph convolution. :param withloop: using self feature modeling in graph convolution. :param aggrmethod: the aggregation function for baseblock, can be βconcatβ and βaddβ. For βresgcnβ, the default
is βaddβ, for others the default is βconcatβ.
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.disengcn.DisenGCN(in_feats, hidden_size, num_classes, K, iterations, tau, dropout, activation)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.mlp.MLP(in_feats, out_feats, hidden_size, num_layers, dropout=0.0, activation='relu', norm=None, act_first=False, bias=True)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.sgc.sgc(in_feats, out_feats)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.sortpool.SortPool(in_feats, hidden_dim, num_classes, num_layers, out_channel, kernel_size, k=30, dropout=0.5)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Implimentation of sortpooling in paper βAn End-to-End Deep Learning Architecture for Graph Classificationβ <https://www.cse.wustl.edu/~muhan/papers/AAAI_2018_DGCNN.pdf>__.
- Parameters
in_feats (int) β Size of each input sample.
out_feats (int) β Size of each output sample.
hidden_dim (int) β Dimension of hidden layer embedding.
num_classes (int) β Number of target classes.
num_layers (int) β Number of graph neural network layers before pooling.
k (int, optional) β Number of selected features to sort, default:
30
.out_channel (int) β Number of the first convolutionβs output channels.
kernel_size (int) β Size of the first convolutionβs kernel.
dropout (float, optional) β Size of dropout, default:
0.5
.
- forward(batch)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.srgcn.SRGCN(in_feats, hidden_size, out_feats, attention, activation, nhop, normalization, dropout, node_dropout, alpha, nhead, subheads)[source]ο
Bases:
cogdl.models.base_model.BaseModel
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.unsup_graphsage.SAGE(num_features, hidden_size, num_layers, sample_size, dropout)[source]ο
Bases:
cogdl.models.base_model.BaseModel
Implementation of unsupervised GraphSAGE in paper βInductive Representation Learning on Large Graphsβ <https://cs.stanford.edu/people/jure/pubs/graphsage-nips17.pdf>
- Parameters
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.daegc.DAEGC(num_features, hidden_size, embedding_size, num_heads, dropout, num_clusters)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The DAEGC model from the βAttributed Graph Clustering: A Deep Attentional Embedding Approachβ paper
- Parameters
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.models.nn.agc.AGC(num_clusters, max_iter, cpu)[source]ο
Bases:
cogdl.models.base_model.BaseModel
The AGC model from the βAttributed Graph Clustering via Adaptive Graph Convolutionβ paper
- Parameters
- forward(data)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
Model Moduleο
- cogdl.models.register_model(name)[source]ο
New model types can be added to cogdl with the
register_model()
function decorator. For example:@register_model('gat') class GAT(BaseModel): (...)
- Parameters
name (str) β the name of the model
data wrappersο
Node Classificationο
- class cogdl.wrappers.data_wrapper.node_classification.ClusterWrapper(dataset, method='metis', batch_size=20, n_cluster=100)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- get_train_dataset()[source]ο
Return the wrapped dataset for specific usage. For example, return ClusteredDataset in cluster_dw for DDP training.
- class cogdl.wrappers.data_wrapper.node_classification.GraphSAGEDataWrapper(dataset, batch_size: int, sample_size: list)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- get_train_dataset()[source]ο
Return the wrapped dataset for specific usage. For example, return ClusteredDataset in cluster_dw for DDP training.
- class cogdl.wrappers.data_wrapper.node_classification.M3SDataWrapper(dataset, label_rate, approximate, alpha)[source]ο
Bases:
cogdl.wrappers.data_wrapper.node_classification.node_classification_dw.FullBatchNodeClfDataWrapper
- class cogdl.wrappers.data_wrapper.node_classification.NetworkEmbeddingDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.node_classification.FullBatchNodeClfDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- train_wrapper() cogdl.data.data.Graph [source]ο
- Returns
DataLoader
cogdl.Graph
list of DataLoader or Graph
Any other data formats other than DataLoader will not be traversed
- class cogdl.wrappers.data_wrapper.node_classification.PPRGoDataWrapper(dataset, topk, alpha=0.2, norm='sym', batch_size=512, eps=0.0001, test_batch_size=- 1)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.node_classification.SAGNDataWrapper(dataset, batch_size, label_nhop, threshold, nhop)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
Graph Classificationο
- class cogdl.wrappers.data_wrapper.graph_classification.GraphClassificationDataWrapper(dataset, degree_node_features=False, batch_size=32, train_ratio=0.5, test_ratio=0.3)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.graph_classification.GraphEmbeddingDataWrapper(dataset, degree_node_features=False)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.graph_classification.InfoGraphDataWrapper(dataset, degree_node_features=False, batch_size=32, train_ratio=0.5, test_ratio=0.3)[source]ο
Pretrainingο
Link Predictionο
- class cogdl.wrappers.data_wrapper.link_prediction.EmbeddingLinkPredictionDataWrapper(dataset, negative_ratio)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.link_prediction.GNNKGLinkPredictionDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.link_prediction.GNNLinkPredictionDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
Heterogeneousο
- class cogdl.wrappers.data_wrapper.heterogeneous.HeterogeneousEmbeddingDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
- class cogdl.wrappers.data_wrapper.heterogeneous.HeterogeneousGNNDataWrapper(dataset)[source]ο
Bases:
cogdl.wrappers.data_wrapper.base_data_wrapper.DataWrapper
model wrappersο
Node Classificationο
- class cogdl.wrappers.model_wrapper.node_classification.DGIModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.GCNMixModelWrapper(model, optimizer_cfg, temperature, rampup_starts, rampup_ends, mixup_consistency, ema_decay, tau, k)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
GCNMixModelWrapper calls forward_aux in model forward_aux is similar to forward but ignores spmm operation.
- class cogdl.wrappers.model_wrapper.node_classification.GRACEModelWrapper(model, optimizer_cfg, tau, drop_feature_rates, drop_edge_rates, batch_fwd, proj_hidden_size)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- prop(graph: cogdl.data.data.Graph, x: torch.Tensor, drop_feature_rate: float = 0.0, drop_edge_rate: float = 0.0)[source]ο
- class cogdl.wrappers.model_wrapper.node_classification.GrandModelWrapper(model, optimizer_cfg, sample=2, temperature=0.5, lmbda=0.5)[source]ο
Bases:
cogdl.wrappers.model_wrapper.node_classification.node_classification_mw.NodeClfModelWrapper
- sampleint
Number of augmentations for consistency loss
- temperaturefloat
Temperature to sharpen predictions.
- lmbdafloat
Proportion of consistency loss of unlabelled data
- class cogdl.wrappers.model_wrapper.node_classification.MVGRLModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.SelfAuxiliaryModelWrapper(model, optimizer_cfg, auxiliary_task, dropedge_rate, mask_ratio, sampling)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.GraphSAGEModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.UnsupGraphSAGEModelWrapper(model, optimizer_cfg, walk_length, negative_samples)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.M3SModelWrapper(model, optimizer_cfg, n_cluster, num_new_labels)[source]ο
Bases:
cogdl.wrappers.model_wrapper.node_classification.node_classification_mw.NodeClfModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.NetworkEmbeddingModelWrapper(model, num_shuffle=1, training_percents=[0.1], enhance=None, max_evals=10, num_workers=1)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.NodeClfModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.CorrectSmoothModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.node_classification.node_classification_mw.NodeClfModelWrapper
- class cogdl.wrappers.model_wrapper.node_classification.PPRGoModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
Graph Classificationο
- class cogdl.wrappers.model_wrapper.graph_classification.GraphClassificationModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.graph_classification.GraphEmbeddingModelWrapper(model)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
Pretrainingο
Link Predictionο
- class cogdl.wrappers.model_wrapper.link_prediction.EmbeddingLinkPredictionModelWrapper(model)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
- class cogdl.wrappers.model_wrapper.link_prediction.GNNKGLinkPredictionModelWrapper(model, optimizer_cfg, score_func)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.link_prediction.GNNLinkPredictionModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
Heterogeneousο
- class cogdl.wrappers.model_wrapper.heterogeneous.HeterogeneousEmbeddingModelWrapper(model, hidden_size=200)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
- static add_args(parser: argparse.ArgumentParser)[source]ο
Add task-specific arguments to the parser.
- class cogdl.wrappers.model_wrapper.heterogeneous.HeterogeneousGNNModelWrapper(model, optimizer_cfg)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
- class cogdl.wrappers.model_wrapper.heterogeneous.MultiplexEmbeddingModelWrapper(model, hidden_size=200, eval_type='all')[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
- static add_args(parser: argparse.ArgumentParser)[source]ο
Add task-specific arguments to the parser.
Clusteringο
- class cogdl.wrappers.model_wrapper.clustering.AGCModelWrapper(model, optimizer_cfg, num_clusters, cluster_method='kmeans', evaluation='full', max_iter=5)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.EmbeddingModelWrapper
- class cogdl.wrappers.model_wrapper.clustering.DAEGCModelWrapper(model, optimizer_cfg, num_clusters, cluster_method='kmeans', evaluation='full', T=5)[source]ο
Bases:
cogdl.wrappers.model_wrapper.base_model_wrapper.ModelWrapper
layersο
- class cogdl.layers.gcn_layer.GCNLayer(in_features, out_features, dropout=0.0, activation=None, residual=False, norm=None, bias=True, **kwargs)[source]ο
Bases:
torch.nn.modules.module.Module
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.gat_layer.GATLayer(in_feats, out_feats, nhead=1, alpha=0.2, attn_drop=0.5, activation=None, residual=False, norm=None)[source]ο
Bases:
torch.nn.modules.module.Module
Sparse version GAT layer, similar to https://arxiv.org/abs/1710.10903
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.sage_layer.SAGELayer(in_feats, out_feats, normalize=False, aggr='mean', dropout=0.0, norm=None, activation=None, residual=False)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.gin_layer.GINLayer(apply_func=None, eps=0, train_eps=True)[source]ο
Bases:
torch.nn.modules.module.Module
Graph Isomorphism Network layer from paper βHow Powerful are Graph Neural Networks?β.
\[h_i^{(l+1)} = f_\Theta \left((1 + \epsilon) h_i^{l} + \mathrm{sum}\left(\left\{h_j^{l}, j\in\mathcal{N}(i) \right\}\right)\right)\]- Parameters
apply_func (callable layer function)) β layer or function applied to update node feature
eps (float32, optional) β Initial epsilon value.
train_eps (bool, optional) β If True, epsilon will be a learnable parameter.
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.gcnii_layer.GCNIILayer(n_channels, alpha=0.1, beta=1, residual=False)[source]ο
Bases:
torch.nn.modules.module.Module
- class cogdl.layers.deepergcn_layer.BondEncoder(bond_dim_list, emb_size)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.deepergcn_layer.EdgeEncoder(in_feats, out_feats, bias=False)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.deepergcn_layer.GENConv(in_feats: int, out_feats: int, aggr: str = 'softmax_sg', beta: float = 1.0, p: float = 1.0, learn_beta: bool = False, learn_p: bool = False, use_msg_norm: bool = False, learn_msg_scale: bool = True, norm: Optional[str] = None, residual: bool = False, activation: Optional[str] = None, num_mlp_layers: int = 2, edge_attr_size: Optional[list] = None)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.deepergcn_layer.ResGNNLayer(conv, in_channels, activation='relu', norm='batchnorm', dropout=0.0, out_norm=None, out_channels=- 1, residual=True, checkpoint_grad=False)[source]ο
Bases:
torch.nn.modules.module.Module
Implementation of DeeperGCN in paper βDeeperGCN: All You Need to Train Deeper GCNsβ
- Parameters
- forward(graph, x, dropout=None, *args, **kwargs)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.disengcn_layer.DisenGCNLayer(in_feats, out_feats, K, iterations, tau=1.0, activation='leaky_relu')[source]ο
Bases:
torch.nn.modules.module.Module
Implementation of βDisentangled Graph Convolutional Networksβ.
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.han_layer.AttentionLayer(num_features)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.han_layer.HANLayer(num_edge, w_in, w_out)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.mlp_layer.MLP(in_feats, out_feats, hidden_size, num_layers, dropout=0.0, activation='relu', norm=None, act_first=False, bias=True)[source]ο
Bases:
torch.nn.modules.module.Module
Multilayer perception with normalization
\[x^{(i+1)} = \sigma(W^{i}x^{(i)})\]- Parameters
- forward(x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.pprgo_layer.LinearLayer(in_features, out_features, bias=True)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(input)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.pprgo_layer.PPRGoLayer(in_feats, hidden_size, out_feats, num_layers, dropout, activation='relu')[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.rgcn_layer.RGCNLayer(in_feats, out_feats, num_edge_types, regularizer='basis', num_bases=None, self_loop=True, dropout=0.0, self_dropout=0.0, layer_norm=True, bias=True)[source]ο
Bases:
torch.nn.modules.module.Module
Implementation of Relational-GCN in paper βModeling Relational Data with Graph Convolutional Networksβ
- Parameters
in_feats (int) β Size of each input embedding.
out_feats (int) β Size of each output embedding.
num_edge_type (int) β The number of edge type in knowledge graph.
regularizer (str, optional) β Regularizer used to avoid overfitting,
basis
orbdd
, default :basis
.num_bases (int, optional) β The number of basis, only used when regularizer is basis, default :
None
.self_loop (bool, optional) β Add self loop embedding if True, default :
True
.dropout (float) β
self_dropout (float, optional) β Dropout rate of self loop embedding, default :
0.0
layer_norm (bool, optional) β Use layer normalization if True, default :
True
bias (bool) β
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
Modified from https://github.com/GraphSAINT/GraphSAINT
- class cogdl.layers.saint_layer.SAINTLayer(dim_in, dim_out, dropout=0.0, act='relu', order=1, aggr='mean', bias='norm-nn', **kwargs)[source]ο
Bases:
torch.nn.modules.module.Module
- class cogdl.layers.sgc_layer.SGCLayer(in_features, out_features, order=3)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.layers.mixhop_layer.MixHopLayer(num_features, adj_pows, dim_per_pow)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph, x)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
optionsο
utilsο
- cogdl.utils.utils.alias_draw(J, q)[source]ο
Draw sample from a non-uniform discrete distribution using alias sampling.
- cogdl.utils.utils.alias_setup(probs)[source]ο
Compute utility lists for non-uniform sampling from discrete distributions. Refer to https://hips.seas.harvard.edu/blog/2013/03/03/the-alias-method-efficient-sampling-with-many-discrete-outcomes/ for details
- cogdl.utils.utils.download_url(url, folder, name=None, log=True)[source]ο
Downloads the content of an URL to a specific folder.
- cogdl.utils.utils.get_memory_usage(print_info=False)[source]ο
Get accurate gpu memory usage by querying torch runtime
- cogdl.utils.utils.get_norm_layer(norm: str, channels: int)[source]ο
- Parameters
norm β str type of normalization: layernorm, batchnorm, instancenorm
channels β int size of features for normalization
- cogdl.utils.utils.untar(path, fname, deleteTar=True)[source]ο
Unpacks the given archive file to the same directory, then (by default) deletes the archive file.
- cogdl.utils.sampling.random_walk(start, length, indptr, indices, p=0.0)[source]ο
- Parameters
start β np.array(dtype=np.int32)
length β int
indptr β np.array(dtype=np.int32)
indices β np.array(dtype=np.int32)
p β float
- Returns
list(np.array(dtype=np.int32))
- cogdl.utils.graph_utils.add_remaining_self_loops(edge_index, edge_weight=None, fill_value=1, num_nodes=None)[source]ο
- cogdl.utils.graph_utils.add_self_loops(edge_index, edge_weight=None, fill_value=1, num_nodes=None)[source]ο
- cogdl.utils.graph_utils.negative_edge_sampling(edge_index: Union[Tuple, torch.Tensor], num_nodes: Optional[int] = None, num_neg_samples: Optional[int] = None, undirected: bool = False)[source]ο
- cogdl.utils.graph_utils.sorted_coo2csr(row, col, data, num_nodes=None, return_index=False)[source]ο
- cogdl.utils.graph_utils.to_undirected(edge_index, num_nodes=None)[source]ο
Converts the graph given by
edge_index
to an undirected graph, so that \((j,i) \in \mathcal{E}\) for every edge \((i,j) \in \mathcal{E}\).
- class cogdl.utils.link_prediction_utils.ConvELayer(dim, num_filter=20, kernel_size=7, k_w=10, dropout=0.3)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(sub_emb, obj_emb, rel_emb)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.link_prediction_utils.DistMultLayer[source]ο
Bases:
torch.nn.modules.module.Module
- forward(sub_emb, obj_emb, rel_emb)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.link_prediction_utils.GNNLinkPredict[source]ο
Bases:
torch.nn.modules.module.Module
- forward(graph)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- cogdl.utils.link_prediction_utils.cal_mrr(embedding, rel_embedding, edge_index, edge_type, scoring, protocol='raw', batch_size=1000, hits=[])[source]ο
- cogdl.utils.link_prediction_utils.get_filtered_rank(heads, tails, rels, embedding, rel_embedding, batch_size, seen_data)[source]ο
- cogdl.utils.link_prediction_utils.get_raw_rank(heads, tails, rels, embedding, rel_embedding, batch_size, scoring)[source]ο
- cogdl.utils.link_prediction_utils.sampling_edge_uniform(edge_index, edge_types, edge_set, sampling_rate, num_rels, label_smoothing=0.0, num_entities=1)[source]ο
- Parameters
edge_index β edge index of graph
edge_types β
edge_set β set of all edges of the graph, (h, t, r)
sampling_rate β
num_rels β
label_smoothing (Optional) β
num_entities (Optional) β
- Returns
sampled existing edges rels: types of smapled existing edges sampled_edges_all: existing edges with corrupted edges sampled_types_all: types of existing and corrupted edges labels: 0/1
- Return type
sampled_edges
- cogdl.utils.ppr_utils.calc_ppr_topk_parallel(indptr, indices, deg, alpha, epsilon, nodes, topk)[source]ο
- cogdl.utils.ppr_utils.ppr_topk(adj_matrix, alpha, epsilon, nodes, topk)[source]ο
Calculate the PPR matrix approximately using Anderson.
- cogdl.utils.ppr_utils.topk_ppr_matrix(adj_matrix, alpha, eps, idx, topk, normalization='row')[source]ο
Create a sparse matrix where each node has up to the topk PPR neighbors and their weights.
- class cogdl.utils.prone_utils.Gaussian(mu=0.5, theta=1, rescale=False, k=3)[source]ο
Bases:
object
- class cogdl.utils.prone_utils.NodeAdaptiveEncoder[source]ο
Bases:
object
shrink negative values in signal/feature matrix
no learning
- class cogdl.utils.prone_utils.PPR(alpha=0.5, k=10)[source]ο
Bases:
object
applying sparsification to accelerate computation
- class cogdl.utils.prone_utils.SignalRescaling[source]ο
Bases:
object
- rescale signal of each node according to the degree of the node:
sigmoid(degree)
sigmoid(1/degree)
- class cogdl.utils.srgcn_utils.ColumnUniform[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_index, edge_attr, N)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.EdgeAttention(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.Gaussian(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.HeatKernel(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.Identity(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.NodeAttention(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.NormIdentity[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_index, edge_attr, N)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.PPR(in_feat)[source]ο
Bases:
torch.nn.modules.module.Module
- forward(x, edge_index, edge_attr)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.RowSoftmax[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_index, edge_attr, N)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.RowUniform[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_index, edge_attr, N)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class cogdl.utils.srgcn_utils.SymmetryNorm[source]ο
Bases:
torch.nn.modules.module.Module
- forward(edge_index, edge_attr, N)[source]ο
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
experimentsο
pipelinesο
- class cogdl.pipelines.DatasetPipeline(app: str, **kwargs)[source]ο
Bases:
cogdl.pipelines.Pipeline
- class cogdl.pipelines.GenerateEmbeddingPipeline(app: str, model: str, **kwargs)[source]ο
Bases:
cogdl.pipelines.Pipeline
- class cogdl.pipelines.OAGBertInferencePipepline(app: str, model: str, **kwargs)[source]ο
Bases:
cogdl.pipelines.Pipeline
- class cogdl.pipelines.RecommendationPipepline(app: str, model: str, **kwargs)[source]ο
Bases:
cogdl.pipelines.Pipeline
- cogdl.pipelines.pipeline(app: str, **kwargs) cogdl.pipelines.Pipeline [source]ο