The reparameterization trick lets a model learn through a random sampling step. Instead of sampling directly from a distribution predicted by the model, it combines the distribution’s parameters with independent random noise in a differentiable calculation. section 10.5 section 10.4.3
In a molecular variational autoencoder (VAE), the encoder maps a molecule to a Gaussian probability cloud rather than a single point. For mean μ and standard deviation σ, draw noise ε from a standard normal distribution and calculate z = μ + σ × ε. The decoder reconstructs the molecule from z, while gradients can flow through μ and σ during training. section 10.3 section 10.4.3
Sampling a latent vector in PyTorch
A molecular encoder can output a mean and log-variance. Convert the log-variance to standard deviation, then combine it with independent noise: import torch def reparameterize(mu, logvar): std = torch.exp(0.5 * logvar) eps = torch.randn_like(std) return mu + std * eps The resulting z can be passed to the decoder. The mean and log-variance remain available for the KL-divergence term that regularizes the latent space. section 10.4.5 section 10.4.3 section 10.3
For SMILES molecular strings, a bidirectional GRU encoder summarizes the sequence and projects it to latent distribution parameters. Reparameterization produces z; a decoder then uses z to reconstruct the sequence. The training objective combines reconstruction loss with KL divergence, which pulls the predicted clouds toward a shared prior. section 10.4.3 section 10.3
Figure 10.8 Bidirectional RNN Encoder Architecture for VAE-CYC. The encoder processes input molecules by first converting them from chemical structure to SMILES representation, then through an embedding layer that converts text to numerical vectors. A multi-layer bidirectional RNN encoder processes the sequence in both forward and backward directions. The final hidden states from both directions are concatenated and passed through a linear projection layer to generate latent distribution parameters. These parameters, combined with random noise through the reparameterization trick, produce the final latent vector representation of the input molecule.

Follow the path from a SMILES string through the encoder and distribution parameters to the sampled latent vector. section 10.4.3



