cogdl.layers.gpt_gnn_module

Module Contents

Classes

Graph

HGTConv

RelTemporalEncoding

Implement the Temporal Encoding (Sinusoid) function.

GeneralConv

GNN

GPT_GNN

Classifier

Matcher

Matching between a pair of nodes to conduct link prediction.

RNNModel

Container module with an encoder, a recurrent module, and a decoder.

Functions

args_print(args)

dcg_at_k(r, k)

ndcg_at_k(r, k)

mean_reciprocal_rank(rs)

normalize(mx)

Row-normalize sparse matrix

sparse_mx_to_torch_sparse_tensor(sparse_mx)

Convert a scipy sparse matrix to a torch sparse tensor.

randint()

feature_OAG(layer_data, graph)

feature_reddit(layer_data, graph)

load_gnn(_dict)

defaultDictDict()

defaultDictList()

defaultDictInt()

defaultDictDictInt()

defaultDictDictDictInt()

defaultDictDictDictDictInt()

defaultDictDictDictDictDictInt()

sample_subgraph(graph, time_range, sampled_depth=2, sampled_number=8, inp=None, feature_extractor=feature_OAG)

Sample Sub-Graph based on the connection of other nodes with currently sampled nodes

to_torch(feature, time, edge_list, graph)

Transform a sampled sub-graph into pytorch Tensor

preprocess_dataset(dataset) → cogdl.layers.gpt_gnn_module.Graph

cogdl.layers.gpt_gnn_module.args_print(args)[source]
cogdl.layers.gpt_gnn_module.dcg_at_k(r, k)[source]
cogdl.layers.gpt_gnn_module.ndcg_at_k(r, k)[source]
cogdl.layers.gpt_gnn_module.mean_reciprocal_rank(rs)[source]
cogdl.layers.gpt_gnn_module.normalize(mx)[source]

Row-normalize sparse matrix

cogdl.layers.gpt_gnn_module.sparse_mx_to_torch_sparse_tensor(sparse_mx)[source]

Convert a scipy sparse matrix to a torch sparse tensor.

cogdl.layers.gpt_gnn_module.randint()[source]
cogdl.layers.gpt_gnn_module.feature_OAG(layer_data, graph)[source]
cogdl.layers.gpt_gnn_module.feature_reddit(layer_data, graph)[source]
cogdl.layers.gpt_gnn_module.load_gnn(_dict)[source]
cogdl.layers.gpt_gnn_module.defaultDictDict()[source]
cogdl.layers.gpt_gnn_module.defaultDictList()[source]
cogdl.layers.gpt_gnn_module.defaultDictInt()[source]
cogdl.layers.gpt_gnn_module.defaultDictDictInt()[source]
cogdl.layers.gpt_gnn_module.defaultDictDictDictInt()[source]
cogdl.layers.gpt_gnn_module.defaultDictDictDictDictInt()[source]
cogdl.layers.gpt_gnn_module.defaultDictDictDictDictDictInt()[source]
class cogdl.layers.gpt_gnn_module.Graph[source]
node_feature[source]

edge_list: index the adjacancy matrix (time) by <target_type, source_type, relation_type, target_id, source_id>

add_node(self, node)[source]
add_edge(self, source_node, target_node, time=None, relation_type=None, directed=True)[source]
update_node(self, node)[source]
get_meta_graph(self)[source]
get_types(self)[source]
cogdl.layers.gpt_gnn_module.sample_subgraph(graph, time_range, sampled_depth=2, sampled_number=8, inp=None, feature_extractor=feature_OAG)[source]

Sample Sub-Graph based on the connection of other nodes with currently sampled nodes We maintain budgets for each node type, indexed by <node_id, time>. Currently sampled nodes are stored in layer_data. After nodes are sampled, we construct the sampled adjacancy matrix.

cogdl.layers.gpt_gnn_module.to_torch(feature, time, edge_list, graph)[source]

Transform a sampled sub-graph into pytorch Tensor node_dict: {node_type: <node_number, node_type_ID>} node_number is used to trace back the nodes in original graph. edge_dict: {edge_type: edge_type_ID}

class cogdl.layers.gpt_gnn_module.HGTConv(in_dim, out_dim, num_types, num_relations, n_heads, dropout=0.2, use_norm=True, use_RTE=True, **kwargs)[source]

Bases: torch_geometric.nn.conv.MessagePassing

forward(self, node_inp, node_type, edge_index, edge_type, edge_time)[source]
message(self, edge_index_i, node_inp_i, node_inp_j, node_type_i, node_type_j, edge_type, edge_time)[source]

j: source, i: target; <j, i>

update(self, aggr_out, node_inp, node_type)[source]

Step 3: Target-specific Aggregation x = W[node_type] * gelu(Agg(x)) + x

__repr__(self)[source]
class cogdl.layers.gpt_gnn_module.RelTemporalEncoding(n_hid, max_len=240, dropout=0.2)[source]

Bases: torch.nn.Module

Implement the Temporal Encoding (Sinusoid) function.

forward(self, x, t)[source]
class cogdl.layers.gpt_gnn_module.GeneralConv(conv_name, in_hid, out_hid, num_types, num_relations, n_heads, dropout, use_norm=True, use_RTE=True)[source]

Bases: torch.nn.Module

forward(self, meta_xs, node_type, edge_index, edge_type, edge_time)[source]
class cogdl.layers.gpt_gnn_module.GNN(in_dim, n_hid, num_types, num_relations, n_heads, n_layers, dropout=0.2, conv_name='hgt', prev_norm=False, last_norm=False, use_RTE=True)[source]

Bases: torch.nn.Module

forward(self, node_feature, node_type, edge_time, edge_index, edge_type)[source]
class cogdl.layers.gpt_gnn_module.GPT_GNN(gnn, rem_edge_list, attr_decoder, types, neg_samp_num, device, neg_queue_size=0)[source]

Bases: torch.nn.Module

neg_sample(self, souce_node_list, pos_node_list)[source]
forward(self, node_feature, node_type, edge_time, edge_index, edge_type)[source]
text_loss(self, reps, texts, w2v_model, device)[source]
feat_loss(self, reps, out)[source]
class cogdl.layers.gpt_gnn_module.Classifier(n_hid, n_out)[source]

Bases: torch.nn.Module

forward(self, x)[source]
__repr__(self)[source]
class cogdl.layers.gpt_gnn_module.Matcher(n_hid, n_out, temperature=0.1)[source]

Bases: torch.nn.Module

Matching between a pair of nodes to conduct link prediction. Use multi-head attention as matching model.

forward(self, x, ty, use_norm=True)[source]
__repr__(self)[source]
class cogdl.layers.gpt_gnn_module.RNNModel(n_word, ninp, nhid, nlayers, dropout=0.2)[source]

Bases: torch.nn.Module

Container module with an encoder, a recurrent module, and a decoder.

forward(self, inp, hidden=None)[source]
from_w2v(self, w2v)[source]
cogdl.layers.gpt_gnn_module.preprocess_dataset(dataset)cogdl.layers.gpt_gnn_module.Graph[source]