liveBook · Manning

Latent space

As explained in Graph Neural Networks in Action

The space of lower-dimensional representations produced by an encoder, with each point representing encoded information about an input.

A latent space is the low-dimensional representation an encoder makes from input data. A decoder uses that representation to reconstruct the input. For a graph autoencoder, the representation can help reconstruct edges, making it useful for predicting missing links. section 5.5 section 5.2

The practical pipeline is:

  • Prepare node features and an edge list, then encode the graph into latent representations. section 5.2
  • Decode candidate edges from those representations and train against observed and sampled negative edges. section 5.2.3
  • For a variational graph autoencoder, output a mean and log variance instead of one fixed encoding; sample a representation and add KL divergence to the reconstruction loss. section 5.3.1

Fixed-point encodings can leave sharp gaps between training examples, making interpolation unreliable. A more regular latent space aims for continuity—nearby representations decode to similar results—and compactness, so sampled points decode meaningfully. Regularization brings a trade-off: improving sampling and interpolation can come at the expense of reconstruction. section 5.3

Listing 5.13 VariationalGCNEncoder
class VariationalGCNEncoder(torch.nn.Module):            #1
  def __init__(self, input_size, layers, latent_dims):
    super().__init__()
    self.layer0 = GCNConv(input_size, layers[0])
    self.layer1 = GCNConv(layers[0], layers[1])
    self.mu = GCNConv(layers[1], latent_dims)           
    self.logvar = GCNConv(layers[1], latent_dims)       

  def forward(self, x, edge_index):
    x = self.layer0(x, edge_index).relu()
    x = self.layer1(x, edge_index).relu()
    mu = self.mu(x, edge_index)
    logvar = self.logvar(x, edge_index)
    return mu, logvar                      #2

The variational GCN encoder makes the change concrete: separate GCNConv outputs produce mu and logvar for each latent dimension. section 5.3.1

Search for candidate molecules

Encode molecules into a latent space and predict their QED property there. If high-QED molecules cluster in one region, sample nearby representations to propose molecules for testing. The generated candidates still need verification. section 5.4.2 section 5.4.4

Latent representations need not describe whole inputs or nodes. In a dynamic graph model, an encoder represents probabilities of different edge types; a decoder uses sampled interactions and previous timesteps to predict future node trajectories. section 6.5.3

How Graph Neural Networks in Action covers it

How deep it goes
Defines encoder–decoder compression, then works through fixed versus sampled representations, regularization, and graph-model training.
Examples
Uses product-graph edge prediction, QED-guided molecule generation, and latent edge-type probabilities for trajectory prediction.
What it assumes
Starts with encoder–decoder compression and shows how node features and edge lists enter a graph workflow.
What you can do after
Apply it via PyTorch Geometric to encode graphs, decode candidate edges, and train a variational model with KL loss.
How it connects
Connects autoencoders, graph autoencoders, variational autoencoders, KL divergence, link prediction, and property prediction.

Also explained in

Compare how 18 books explain latent space →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.