A decoder turns a latent representation into the output a model is trained to produce. In an autoencoder, an encoder compresses an input and the decoder reconstructs it; training reduces the gap between the input and reconstruction. For graph data, the output might be predicted edges, an entire graph, or future node states rather than an image. section 5.5 section 6.5.3
Choose the decoder to match the prediction target:
- For link prediction, give an inner-product decoder node embeddings and an edge list. It scores each candidate node pair by multiplying its embeddings elementwise, summing, and applying a sigmoid. The scores represent predicted edges in the reconstructed adjacency matrix. section 5.2.2
- For small-graph generation, use a decoder with output layers for both the adjacency structure and node features. Molecular graphs also require attention to different bond types; a property-prediction layer can use the latent representation alongside reconstruction. section 5.4.3 section 5.4.2
- For trajectories, use edge-type probabilities and previous timesteps to predict future node states. A GRU-based decoder combines messages associated with edges, updates hidden states, and produces future predictions. section 6.4.2 section 6.5.3
Listing 5.5 Graph decoder
class InnerProductDecoder(torch.nn.Module): #1
def __init__(self):
super().__init__()
def forward(self, z, edge_index): #2
value = (z[edge_index[0]] * \
z[edge_index[1]]).sum(dim=1) #3
return torch.sigmoid(value)
The inner-product implementation shows the compact link-prediction case: select the two embeddings named by each candidate edge, multiply them, sum their dimensions, and return a score. section 5.2.2
Training a link-prediction decoder
On the Amazon Products graph, split edges into training, validation, and test sets. Encode the training graph, draw nonexistent edges as negative samples, and ask the decoder to score both observed and sampled edges. Compare its outputs with binary edge labels, then evaluate held-out predictions with ROC AUC. Keep the decoder’s output convention aligned with the loss: the illustrated inner-product decoder applies a sigmoid, while the illustrated training setup specifies BCEWithLogitsLoss. section 5.2.3 section 5.2.2
A variational graph autoencoder keeps the decoding role but draws its latent input from a learned distribution and adds KL divergence to its training loss. Decoder design remains task-dependent: scoring selected edges is simpler than producing an entire graph, while temporal predictions require a recurrent model to account for change over time. section 5.3.1 section 5.4.3 section 6.4.2




