VirtualNode
gtrick.dgl.VirtualNode(in_feats, out_feats, dropout=0.5, residual=False)
¶
Bases: nn.Module
Virtual Node from OGB Graph Property Prediction Examples.
It adds an virtual node to all nodes in the graph. This trick is helpful for Graph Level Task.
Note
To use this trick, call update_node_emb
at first, then call update_vn_emb
.
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_feats |
int
|
Feature size before conv layer. |
required |
out_feats |
int
|
Feature size after conv layer. |
required |
dropout |
float
|
Dropout rate on virtual node embedding. Default: 0.5. |
0.5
|
residual |
bool
|
If True, use residual connection. Default: False. |
False
|
update_node_emb(graph, x, vx=None)
¶
Add message from virtual nodes to graph nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
dgl.DGLGraph
|
The graph. |
required |
x |
torch.Tensor
|
The input node feature. |
required |
vx |
torch.Tensor
|
Optional virtual node embedding. Default: None. |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
The output node feature. |
torch.Tensor
|
The output virtual node embedding. |
update_vn_emb(graph, x, vx)
¶
Add message from graph nodes to virtual node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
dgl.DGLGraph
|
The graph. |
required |
x |
torch.Tensor
|
The input node feature. |
required |
vx |
torch.Tensor
|
Optional virtual node embedding. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
The output virtual node embedding. |