-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path_model.py
50 lines (44 loc) · 1.58 KB
/
_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from kgcnn.layers.mlp import GraphMLP, MLP
from kgcnn.layers.modules import Embedding
from keras.layers import Dense, Dropout, Add
from kgcnn.layers.pooling import PoolingNodes
from ._layers import rGIN
def model_disjoint(
inputs,
use_node_embedding,
input_node_embedding,
gin_mlp,
depth,
rgin_args,
last_mlp,
output_mlp,
output_embedding,
dropout
):
n, edi, batch_id_node, count_nodes = inputs
# Embedding, if no feature dimension
if use_node_embedding:
n = Embedding(**input_node_embedding)(n)
# Model
# Map to the required number of units.
n_units = gin_mlp["units"][-1] if isinstance(gin_mlp["units"], list) else int(gin_mlp["units"])
n = Dense(n_units, use_bias=True, activation='linear')(n)
list_embeddings = [n]
for i in range(0, depth):
n = rGIN(**rgin_args)([n, edi])
n = GraphMLP(**gin_mlp)([n, batch_id_node, count_nodes])
list_embeddings.append(n)
# Output embedding choice
if output_embedding == "graph":
out = [PoolingNodes()([count_nodes, x, batch_id_node]) for x in list_embeddings] # will return tensor
out = [MLP(**last_mlp)(x) for x in out]
out = [Dropout(dropout)(x) for x in out]
out = Add()(out)
out = MLP(**output_mlp)(out)
elif output_embedding == "node": # Node labeling
out = n
out = GraphMLP(**last_mlp)([out, batch_id_node, count_nodes])
out = GraphMLP(**output_mlp)([out, batch_id_node, count_nodes])
else:
raise ValueError("Unsupported output embedding for mode `rGIN`")
return out