项目文件夹

文件
Lingfan Yu b98dc92c59 [Model] Relational GCN (#55)
* data preprocessing for rgcn

* edge subgraph

* WIP: RGCN

* use edge feature in spmv

* fix bugs

* match AIFB accuracy

* match mutag accuracy

* avoid materializing in featureless case

* remove untouched nodes and relabel nodes

* fix python list concatenate overhead

* sparsely store edge types

* refactor entity classify code for clean link prediction implementation

* further refactor code

* refactoring

* rgcn block decompose layers

* link predict dataset

* link predict model and eval code

* dropout, self-loop, regularization, etc, plus bug fixes

* update to new api

* dataset update

* bugs, WIP, need to impl early stopping and filtered metrics

* instruction to run, and minor

* group conv and early stop

* clean slow code

* some code comments

* use new api in model code

* change data preprocessing

* entity classify model

* WIP

* move dgl graph out of model

* hot fix for extract zip

* fix link predict model

* use latest dgl apis

* still have memory issue...

* bug fix and move inference to cpu

* move rgcn data processing to contrib

* th.allclose -> U.allclose

* minor change in readme

* fix memory issue in entity classify

* fix and testing code for link predict

* fix entity classify

* clean up

* fix comments

* revert erroneous git merge changes

* code clean up and more comments

* minor

* dependent package version
2018-12-03 13:01:27 -05:00

57 行
1.5 KiB
Python

import torch.nn as nn
class BaseRGCN(nn.Module):
def __init__(self, num_nodes, h_dim, out_dim, num_rels, num_bases=-1,
num_hidden_layers=1, dropout=0, use_cuda=False):
super(BaseRGCN, self).__init__()
self.num_nodes = num_nodes
self.h_dim = h_dim
self.out_dim = out_dim
self.num_rels = num_rels
self.num_bases = num_bases
self.num_hidden_layers = num_hidden_layers
self.dropout = dropout
self.use_cuda = use_cuda
# create rgcn layers
self.build_model()
# create initial features
self.features = self.create_features()
def build_model(self):
self.layers = nn.ModuleList()
# i2h
i2h = self.build_input_layer()
if i2h is not None:
self.layers.append(i2h)
# h2h
for idx in range(self.num_hidden_layers):
h2h = self.build_hidden_layer(idx)
self.layers.append(h2h)
# h2o
h2o = self.build_output_layer()
if h2o is not None:
self.layers.append(h2o)
# initialize feature for each node
def create_features(self):
return None
def build_input_layer(self):
return None
def build_hidden_layer(self):
raise NotImplementedError
def build_output_layer(self):
return None
def forward(self, g):
if self.features is not None:
g.ndata['id'] = self.features
for layer in self.layers:
layer(g)
return g.ndata.pop('h')