SAGEEncoder
- class graphstorm.model.SAGEEncoder(h_dim, out_dim, num_hidden_layers=1, dropout=0, aggregator_type='mean', activation=<function relu>, num_ffn_layers_in_gnn=0, norm=None)
Bases:
GraphConvEncoderGraphSage Conv Encoder.
The
SAGEEncoderemploys severalSAGEConvLayers as its encoding mechanism. TheSAGEEncodershould be designated as the model’s encoder within Graphstorm.Parameters
- h_dim: int
Hidden dimension size.
- out_dim: int
Output dimension size.
- num_hidden_layers: int
Number of hidden layers. Total GNN layers is equal to
num_hidden_layers + 1.- dropout: float
Dropout rate. Default: 0.
- aggregator_type: str
Message aggregation type. Options:
mean,gcn,pool,lstm.- activation: torch.nn.functional
Activation function. Default: relu.
- num_ffn_layers_in_gnn: int
Number of fnn layers between GNN layers. Default: 0.
- norm: str
Normalization methods. Options:
batch,layer, andNone. Default: None, meaning no normalization.
Examples:
# Build model and do full-graph inference on SAGEEncoder from graphstorm import get_node_feat_size from graphstorm.model import SAGEEncoder from graphstorm.model import EntityClassifier from graphstorm.model import GSgnnNodeModel, GSNodeEncoderInputLayer from graphstorm.dataloading import GSgnnData from graphstorm.model import do_full_graph_inference np_data = GSgnnData(...) model = GSgnnNodeModel(alpha_l2norm=0) feat_size = get_node_feat_size(np_data.g, "feat") encoder = GSNodeEncoderInputLayer(g, feat_size, 4, dropout=0, use_node_embeddings=True) model.set_node_input_encoder(encoder) gnn_encoder = SAGEEncoder(4, 4, num_hidden_layers=1, dropout=0, aggregator_type="mean", norm="batch") model.set_gnn_encoder(gnn_encoder) model.set_decoder(EntityClassifier(model.gnn_encoder.out_dims, 3, False)) h = do_full_graph_inference(model, np_data)
- forward(blocks, h)
GraphSage encoder forward computation.
Parameters
- blocks: list of DGL MFGs
Sampled subgraph in the list of DGL message flow graphs (MFGs) format. More detailed information about DGL MFG can be found in DGL Neighbor Sampling Overview.
- h: dict of Tensor
Node features for the default node type in the format of {
dgl.DEFAULT_NTYPE: tensor}. The definition ofdgl.DEFAULT_NTYPEcan be found at DGL official Github site.
Returns
- h: dict of Tensor
New node embeddings for the default node type in the format of {
dgl.DEFAULT_NTYPE: tensor}. The definition ofdgl.DEFAULT_NTYPEcan be found at DGL official Github site.