This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AI: GraphSAGE transductive model for heterogeneous graph (#1607)
- Loading branch information
1 parent
2598ffd
commit 35121db
Showing
8 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions
26
.../graph_modeling/graph_sage/modeling/model/heterogeneous/transductive/distributed/model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Chen Haifeng | ||
""" | ||
|
||
from cloudtik.runtime.ai.modeling.graph_modeling.graph_sage.modeling.model.\ | ||
heterogeneous.distributed.model import DistGraphSAGEModel | ||
from cloudtik.runtime.ai.modeling.graph_modeling.graph_sage.modeling.model.\ | ||
heterogeneous.transductive.model import TransductiveGraphSAGEModel | ||
|
||
|
||
class DistTransductiveGraphSAGEModel(DistGraphSAGEModel, TransductiveGraphSAGEModel): | ||
def __init__(self, vocab_size, hidden_size, num_layers, relations): | ||
TransductiveGraphSAGEModel.__init__( | ||
self, vocab_size, hidden_size, num_layers, relations) |
49 changes: 49 additions & 0 deletions
49
.../ai/modeling/graph_modeling/graph_sage/modeling/model/heterogeneous/transductive/model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Chen Haifeng | ||
""" | ||
|
||
import torch | ||
|
||
from cloudtik.runtime.ai.modeling.graph_modeling.graph_sage.modeling.model.\ | ||
heterogeneous.model import GraphSAGEModel | ||
|
||
|
||
class TransductiveGraphSAGEModel(GraphSAGEModel): | ||
def __init__(self, vocab_size, hidden_size, num_layers, relations): | ||
super().__init__(hidden_size, hidden_size, num_layers, relations) | ||
|
||
# node embedding | ||
# vocab_size is a dict of vocab_size of each node type in the relations | ||
self.emb = torch.nn.ModuleDict( | ||
{node_type: torch.nn.Embedding( | ||
node_vocab_size, hidden_size) for node_type, node_vocab_size in vocab_size.items()}) | ||
|
||
def forward(self, pair_graph, neg_pair_graph, blocks, x): | ||
h = {k: self.emb[k](v) for k, v in x.items()} | ||
return super().forward( | ||
pair_graph, neg_pair_graph, blocks, h) | ||
|
||
def get_input_embeddings(self): | ||
return {k: v.weight.data for k, v in self.emb} | ||
|
||
def get_inputs(self, input_nodes, blocks): | ||
return input_nodes | ||
|
||
def get_inference_inputs(self, g): | ||
return self.get_input_embeddings() | ||
|
||
def get_encoder_inputs(self, input_nodes, blocks): | ||
x = self.get_inputs(input_nodes, blocks) | ||
return {k: self.emb[k].weight.data[v] for k, v in x} |