Maps to: UC Berkeley CS294-158 Deep Unsupervised Learning (Spring 2024), Lecture 13a · Thu 4/18/2024 · Generative Modeling for Science (guest lecture: John Ingraham; 99 slides, mostly figures). The talk frames three problems for generative modeling in three areas of science:
- likelihood estimation (statistical genetics);
- amortizing intractable inference (molecular physics);
- controllable generation (molecular engineering).
It discusses sequence likelihoods as predictors, Boltzmann generators, diffusion models of 3-D structures with subquadratic architectures and polymer-shaped noise, low-temperature sampling, and “programmable” conditioning. Scope of these notes: as announced in the syllabus, only the general modeling methods are covered: likelihood ratios as zero-shot predictors, flows as amortized samplers with importance weights, symmetry and equivariance, chain-correlated noise, and conditioning as composable state and energy transformations. Everything is done on abstract toys with known ground truth: strings from a known random field, a 2-D double-well energy, 2-D chains of points. Application-specific content (biological sequences, molecular design targets, experimental results) is deliberately not reproduced. Code:
code/lecture24/(4 scripts +science_toys.py; PyTorch on CPU; reuses Lecture 4’s Transformer; the first run of script 03 trains six diffusion models) Reading time: 2.5 hours including running the code
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Likelihood ratios. Explain why the likelihood ratio of a generative model fitted to a family of related sequences can predict the effect of a change without labels. Explain when pairwise models, deep models and regularization matter.
- Amortized sampling. Explain why sampling a Boltzmann distribution is hard. Describe how a flow trained by reverse KL, maximum likelihood or both becomes an amortized sampler, and what importance weights can and cannot fix.
- Symmetry. Explain why generative models of structures in space must respect rotations and translations. Describe an equivariant network, and what correlated (“polymer”) noise does for a diffusion model of chains.
- Programmable conditioning. Describe conditioning as composable state transformations and energy adjustments, and the trade-offs of guidance strength and temperature.
0.2 Prerequisites and scope
| Assumed | Introduced here |
|---|---|
| Lectures 3–4 (autoregressive models), 5–6 (flows), 11–12 (diffusion, guidance) | likelihood ratios as zero-shot predictors; Potts models and pseudo-likelihood |
| Lecture 14–15 (self-supervision; “the distribution reflects the process that made the data”) | Boltzmann generators; reverse vs forward KL; importance weights and effective sample size |
| E(n)-equivariant networks; chain-correlated noise; composable conditioning; low temperature |
0.3 Map
§1 three problems for generative modeling in science
§2 likelihood estimation: likelihood ratios as zero-shot predictors ← code 01
§3 amortizing intractable inference: Boltzmann generators ← code 02
§4 structures in space: symmetry, equivariance, chain-shaped noise ← code 03
§5 controllable generation: conditioners as state and energy transforms ← code 04
§6 summary §7 pitfalls §8 exercises §9 further reading §10 next lecture
1. Three problems for generative modeling in science
The talk opens with a map of where generative models meet science (slides 3–7):
- uncertainty propagation in physical systems;
- scientific imaging and inverse problems (“NeRF for molecules”);
- inference machinery for simulations;
- language models for science.
It then focuses on three problems (slide 8):
| problem | the generative-modeling question | why it is hard |
|---|---|---|
| Likelihood estimation | how probable is a sequence, compared with a reference? | data are few and related, models must generalize from them |
| Amortizing intractable inference | draw samples from a distribution known only up to a constant (an energy) | dynamics mix slowly across barriers |
| Controllable generation | sample structures that satisfy many constraints at once | constraints are diverse; retraining per constraint is impossible |
Each section below takes one problem and reproduces its central method on a toy whose truth is known.
2. Likelihood estimation: likelihood ratios as zero-shot predictors
2.1 The idea (slides 10–22)
A family of related sequences that arose under selection carries, in its distribution, a record of which variations were tolerated (slide 11). The recipe:
- Collect related sequences.
- Learn a distribution .
- Score a variant of a reference sequence by .
No measurement of any variant is needed. The slides compare model classes:
- Site-independent models: one distribution per position.
- Pairwise Markov random fields (“Potts models”): .
- VAEs, including Bayesian ones: regularization mattered because “the data can be weak”.
- Language models trained across many families: the one-family-at-a-time models “can still be hard to beat”.
A Potts model’s partition function is intractable, but likelihood ratios do not need it. It is fitted by pseudo-likelihood, , a product of small softmaxes, plus an L2 penalty on and .
2.2 The toy (script 01)
| element | setting |
|---|---|
| data | strings of length 12 over 6 symbols, from a known Potts model (random fields, 18 coupled position pairs), drawn by Gibbs sampling |
| reference | the most probable sample |
| ground truth | the exact ratios of all 60 single and 500 random double variants |
| models fitted | site-independent frequencies; Potts by pseudo-likelihood at four regularization strengths; an autoregressive Transformer (Lecture 4’s) |
| training sets | sequences, from 30 to 10,000 |
Spearman correlation with the exact effects (singles / doubles; for , the mean of 5 random training sets):
| model | = 30 | 100 | 1,000 | 10,000 |
|---|---|---|---|---|
| independent sites | 0.526 / 0.400 | 0.551 / 0.446 | 0.552 / 0.477 | 0.554 / 0.486 |
| Potts, | 0.440 / 0.321 | 0.639 / 0.540 | 0.951 / 0.903 | 0.989 / 0.982 |
| Potts, | 0.577 / 0.439 | 0.730 / 0.627 | 0.951 / 0.895 | 0.982 / 0.952 |
| Potts, | 0.664 / 0.563 | 0.801 / 0.703 | 0.927 / 0.858 | 0.949 / 0.891 |
| Potts, | 0.715 / 0.622 | 0.795 / 0.708 | 0.835 / 0.767 | 0.857 / 0.772 |
| autoregressive Transformer | 0.194 / 0.201 | 0.402 / 0.330 | 0.711 / 0.564 | 0.945 / 0.882 |
The ± over 5 draws at is 0.05–0.12.
- Likelihood ratios predict effects without a single label. At = 10,000 the fitted Potts model ranks the exact effects with Spearman 0.99 (singles) / 0.98 (doubles). Independent sites stop at 0.55 / 0.49 whatever : in this family the couplings carry most of the information.
- With few sequences, regularization decides. At = 30 the strongest penalty is best (0.72), and the weakest is worse than independent sites (0.44 vs 0.53). With 10,000 sequences the order reverses (0.99 vs 0.86). This is the slides’ “the data can be weak, so simple and/or regularized models have been favorable”.
- The flexible model is the most data-hungry. The Transformer has no pairwise structure built in and no regularization beyond weight decay. It is the worst at 30 sequences (0.19, below independent sites) and nearly as good as the best Potts model at 10,000 (0.95). The slides’ observation that one-family models “can still be hard to beat” is, at heart, about how much data a family offers.
Epistasis. A double variant’s effect minus the two single effects. It is identically zero for the site-independent model. At :
| model | correlation with the exact epistasis | mean |predicted| | mean |exact| |
|---|---|---|---|
| independent sites | 0 (predicts none) | 0.00 | 0.81 |
| Potts, | 0.927 | 0.93 | 0.81 |
| Potts, | 0.773 | 0.48 | 0.81 |
| Potts, | 0.618 | 0.30 | 0.81 |
| autoregressive Transformer | 0.642 | 0.67 | 0.81 |
Pairwise models predict epistasis, the non-additivity of two changes, and the weakly regularized Potts model predicts it well. Regularization shrinks it: the predicted magnitude falls from 0.93 to 0.30 nats as grows. The Transformer captures part of it (0.64).
3. Amortizing intractable inference: Boltzmann generators
3.1 The problem (slides 24–28)
Physics gives an energy (here in units of ), hence a distribution . It is well defined, but sampling it is hard (“sampling is hard”, slide 25).
Molecular dynamics integrates Langevin-like equations with time steps of femtoseconds: about 400 million steps for a microsecond (slide 26). Crossing an energy barrier of height happens at a rate .
Idea 1: Boltzmann generators (Noé et al., 2019; slides 27–28).
- Train a normalizing flow to imitate . Use reverse KL, , which needs only the energy; in practice, combine it with maximum likelihood on samples from short simulations.
- Correct the remaining mismatch with importance weights .
The slides add that these remain tricky to train and are used mostly for fluctuations around a known structure.
Idea 2 (slides 29–30): fine-tune a point-estimate predictor into a generative model with diffusion or flow matching, adding diversity at little cost in precision. The notes do not reproduce it.
3.2 Measured (script 02)
The energy is : two wells at , a barrier of about 6 , and the right well favoured. By grid integration, and .
Langevin dynamics (step , 200 chains started in the left well):
| steps | 1,000 | 5,000 | 10,000 | 20,000 | 30,000 | 40,000 |
|---|---|---|---|---|---|---|
| chains in the right well | 1.5% | 13.0% | 21.5% | 42.5% | 59.0% | 66.5% |
After 40,000 steps the chains are still short of the exact 87%. A short simulation (the first 2,000 steps of 50 chains) is 96.8% left-well data. Every crossing must climb the barrier.
Flows (RealNVP, 2,000 steps; 20,000 samples reweighted; 3 seeds):
| training | (right): raw samples | reweighted | ESS of 20,000 | estimate |
|---|---|---|---|---|
| reverse KL (energy only) | 0.999 – 1.000 | 0.988 – 1.000 | 8,016 – 19,842 | 0.915 – 0.928 |
| maximum likelihood on short simulations (left well only) | 0.031 – 0.035 | 0.852 – 0.864 | 138 – 407 | 0.898 – 0.988 |
| both | 0.435 – 0.512 | 0.872 – 0.873 | 8,248 – 11,600 | 1.047 – 1.053 |
| exact | 0.872 | 0.872 | 1.053 |
What the table shows:
- Reverse KL is mode-seeking. Trained from the energy alone, every seed put all its samples into one well, the deeper one. Importance weights cannot restore mass the flow never proposes. Worse, the ESS looks excellent (up to 19,842 of 20,000) because the weights are uniform within the well the flow knows. The failure is invisible to the sampler’s own diagnostics, and is biased low by 0.13.
- Maximum likelihood on biased simulations learns the left well. The flow’s thin tails reach the right well, so reweighting gives roughly the right population (0.85–0.86), but from only 138–407 effective samples.
- Both losses together cover both wells. Reweighting gives the exact population (0.872) and (1.047–1.053) with thousands of effective samples. This is why the slides call the method finicky and why practice combines simulation data with the energy.
4. Structures in space: symmetry, equivariance, chain-shaped noise
4.1 Why symmetry
A structure in space has no preferred frame. Rotating or translating it gives the same structure, so its distribution is invariant: . Its score and a diffusion model’s noise prediction are then equivariant: .
A generic network can only learn this from data, approximately. An equivariant network has it by construction. An example is the E(n)-equivariant graph network (EGNN, Satorras et al., 2021):
- messages are computed from invariant quantities (distances, node features);
- coordinates move only along relative vectors , scaled by invariant weights.
The talk’s 3-D models add two architectural points (slides 51–57):
- Subquadratic cost. Sparse long-range connections preserve global context without interactions.
- Distance-preserving diffusion. The noise is correlated along the chain, so that neighbours stay neighbours during the forward process.
4.2 Measured (script 03)
The toy is 2-D chains of 10 points with unit bonds and persistent turning angles, centered and randomly rotated.
Equivariance. Rotating a chain by 1 radian moves coordinates by up to 4.26; pairwise distances change by . Relative equivariance error at noise level 0.5:
| denoiser | 0.5 rad | 1 rad | 2 rad | π | translation by (3, −2) |
|---|---|---|---|---|---|
| MLP | 0.097 | 0.13 | 0.14 | 0.13 | 1.8 |
| EGNN | 3.5e-7 | 3.7e-7 | 3.3e-7 | 0 | 4.5e-7 |
Orientations never seen in training. Denoising loss on test chains:
| denoiser | test chains pointing right | randomly rotated test chains |
|---|---|---|
| MLP, trained on chains pointing right | 0.177 | 0.277 |
| EGNN, trained on chains pointing right | 0.190 | 0.186 |
| MLP, trained on rotated chains | 0.197 | 0.193 |
| EGNN, trained on rotated chains | 0.190 | 0.186 |
The MLP’s loss rises 56% on orientations it never saw. The EGNN does not care: equivariance is generalization to every orientation, for free.
Samples (500 chains, 100 ancestral steps). “Valid” means every bond within 0.1 of length 1:
| model | parameters | valid | mean |bond − 1| | turning-angle W1 | radius-of-gyration W1 |
|---|---|---|---|---|---|
| data (fresh chains) | — | 100% | 0.000 | 0.035 | 0.031 |
| MLP, isotropic noise on coordinates | 212K | 46.6% | 0.057 | 0.045 | 0.042 |
| MLP, noise on bond vectors (chain noise) | 211K | 78.8% | 0.035 | 0.021 | 0.021 |
| EGNN, isotropic noise on coordinates | 121K | 90.2% | 0.022 | 0.026 | 0.043 |
| same, 1,000 training chains | 121K | 88.8% | 0.022 | 0.029 | 0.041 |
Why chain noise helps: the forward process. Mean distance between consecutive points, and the share above 2:
| isotropic noise | chain noise | |
|---|---|---|
| 0.3 | 1.15 (7.1% > 2) | 1.01 (1.1%) |
| 0.5 | 1.42 (20.6%) | 1.10 (6.5%) |
| 0.9 | 1.75 (35.5%) | 1.24 (12.7%) |
Isotropic noise tears neighbours apart early, and the reverse process must reconnect a scattered cloud. Noise on the bond vectors, i.e. a random-walk covariance in coordinates, keeps the chain a chain at every noise level.
- Same architecture: chain noise nearly doubles the share of valid samples, 46.6% → 78.8%.
- The equivariant network does best with fewer parameters, and is still 88.8% valid from 1,000 training chains.
5. Controllable generation: conditioners as state and energy transformations
5.1 The idea (slides 49–74)
The talk asks for three properties of a generative model of structures:
- programmable generation;
- a subquadratic architecture;
- a likelihood that is useful and controllable, via low-temperature sampling.
The central idea for programmability is to write every conditioner as a transformation of the reverse diffusion with matching inputs and outputs:
- a state transformation, a change of variables, e.g. building a symmetric structure from one asymmetric unit;
- and/or an energy adjustment, a guidance term as in classifier guidance (Lecture 12).
Because inputs and outputs match, conditioners compose: symmetry + shape + substructure, all on one unconditional model, with no retraining.
Low temperature sharpens the distribution toward high likelihood. The slides’ hybrid SDE adds Langevin dynamics at inverse temperature to the reverse SDE. We use the cruder knob of scaling the fresh noise of every reverse step.
5.2 Measured (script 04)
The model is script 03’s EGNN, unchanged. The conditioners:
| conditioner | type | definition | satisfied by unconditional samples |
|---|---|---|---|
| C2 symmetry | state transformation | project every clean estimate onto point-symmetric chains, | — |
| End-to-end distance 1.5 | energy | 6% | |
| Compactness | energy | radius of gyration at most 1.6 | 18% |
Energies only use relative positions, so they agree with the model’s symmetry.
One conditioner at a time (400 chains each). “Within 0.3” is the share whose end-to-end distance is within 0.3 of 1.5; “compact” is the share with radius of gyration at most 1.6:
| conditioning | symmetry error | end-to-end within 0.3 | compact | valid | diversity |
|---|---|---|---|---|---|
| data (reference) | 1.327 | 6% | 19% | 100% | 1.12 |
| unconditional samples | 1.457 | 6% | 18% | 89.2% | 1.18 |
| C2 symmetry (state projection) | 0.003 | 4% | 23% | 88.5% | 1.16 |
| end-to-end distance (energy, scale 0.3) | 1.852 | 100% | 59% | 60.0% | 0.78 |
| compactness (energy, scale 0.3) | 1.722 | 15% | 98% | 55.5% | 0.92 |
Composed on the same model:
| conditioning | symmetry error | end-to-end within 0.3 | compact | valid | diversity |
|---|---|---|---|---|---|
| symmetry + compact | 0.003 | 8% | 100% | 54.0% | 0.69 |
| distance + compact | 1.842 | 100% | 98% | 56.2% | 0.81 |
| symmetry + distance + compact | 0.003 | 100% | 100% | 41.2% | 0.60 |
Guidance scale for the end-to-end distance:
| scale | 0 | 0.05 | 0.1 | 0.3 | 1.0 | 3.0 |
|---|---|---|---|---|---|---|
| within 0.3 of the target | 6% | 19% | 65% | 100% | 76% | 0% |
| valid | 89.2% | 17.8% | 22.2% | 60.0% | 48.5% | 0% |
| diversity | 1.18 | 0.95 | 0.86 | 0.78 | 0.79 | 2.00 (broken) |
Temperature (fresh noise scaled in every reverse step):
| noise × | 1.0 | 0.8 | 0.6 | 0.3 |
|---|---|---|---|---|
| valid | 89.2% | 92.0% | 91.8% | 84.0% |
| compact | 18% | 23% | 36% | 85% |
| diversity | 1.18 | 1.23 | 1.27 | 0.87 |
What these tables show:
- A state transformation is exact and nearly free. Projecting every clean estimate onto point-symmetric chains made every sample symmetric (error 0.003) at no cost in validity (88.5% vs 89.2%).
- Energy conditioners turn rare samples into common ones. Only 6% of unconditional samples have the requested end-to-end distance, and 18% are compact; rejection sampling would keep that few. Guidance satisfies the distance in 100% of samples and compactness in 98%. The price is validity, 89% → 55–60%: the constraint pulls the chain toward conformations the model finds unlikely.
- Conditioners compose. All three on one unconditional model with no retraining satisfied everything (symmetry error 0.003, distance 100%, compact 100%), with 41% valid chains. Costs add up: each extra constraint removes validity and diversity (1.18 → 0.60).
- Guidance strength has a sweet spot, and a weak setting is the worst of both worlds.
- At scale 0.05 only 19% of samples meet the target, yet validity falls to 18%: the nudge disturbs the chains without committing them to a conformation that satisfies it.
- At 0.3 both the constraint (100%) and validity (60%) peak.
- At 3.0 the sampler breaks (0% valid).
- (The compactness energy needed a weight of 50 for the same reason; with 10, it half-acted: 22% compact, 35% valid.)
- Lower temperature (less fresh noise) moves samples toward high-likelihood conformations, as the slides’ low-temperature sampler does. Validity rises slightly at × 0.8 (92.0%), and at × 0.3 the chains curl up (85% compact) and lose diversity. With this crude knob, very low temperature also lowers validity (84%). The slides’ hybrid sampler re-equilibrates with Langevin steps for that reason.
6. Summary
- Likelihood estimation. A generative model fitted to a family of related sequences predicts the effects of changes with no labels.
- On the toy, the Potts model’s likelihood ratios ranked exact effects with Spearman 0.99, vs 0.55 for independent sites.
- With 30 sequences, the strongest regularization was best (0.72) and the weakest worse than independent sites (0.44). The Transformer needed thousands of sequences (0.19 → 0.95).
- Pairwise models also predicted epistasis (0.93).
- Amortizing intractable inference. Dynamics cross barriers slowly (66% of the way to equilibrium after 40,000 steps).
- A flow trained by reverse KL alone collapsed onto one well, with a misleadingly high ESS and low by 0.13.
- Trained on biased simulations alone it needed reweighting from ~200 effective samples.
- Trained on both, it gave the exact population (0.872) and (1.05) after reweighting.
- Symmetry. An equivariant network respects rotations to and generalizes to orientations it never saw; an MLP’s loss rose 56% on unseen ones. For chains, noise correlated along the chain kept neighbours together during the forward process and raised valid samples from 47% to 79% for the same MLP. The EGNN reached 90% (89% from 1,000 chains).
- Programmable generation. Conditioners as state transformations (a symmetry projection: exact, free) and energy adjustments (distance, compactness: rare → 98–100%) composed on one unconditional model without retraining. Each costs validity and diversity; guidance has a sweet spot, and lower temperature trades diversity for likelihood.
7. Common pitfalls
- Reading a likelihood ratio as a measured effect. It predicts rankings inherited from the data’s history. Our toy’s “effects” are defined as exact log-probability ratios, which real effects are not.
- Unregularized pairwise models on few sequences. With 30 sequences the weakest penalty ranked worse than independent sites.
- Trusting the ESS of a reverse-KL sampler. A flow that misses a mode has uniform weights on the mode it found: a high ESS and a wrong answer. Check against simulations, or train with data from every known state.
- A non-equivariant network on structures. It must learn every orientation from data and fails on unseen ones. Centering data also hides translations from it (error 1.8 for a shifted input).
- Frame-dependent conditioners. An energy written in absolute coordinates breaks the symmetry the model respects. Use distances, the center of mass, and similar quantities.
- Over-strong guidance. Constraints are met at the cost of validity, and large scales diverge. Composing many constraints compounds the cost.
8. Exercises
Exercise 1 (likelihood ratios without the partition function — derivation). For a Potts model, show that for a single change at position (from to ) is , so cancels. Why does a double change at add the term , the epistasis?
Answer
Single change. . Changing alters only and the pairs that contain ; is the same for every sequence.
Double change. Changing (a → b) and (a’ → b’) changes all terms with or . Subtracting the two single effects (each computed with the other position at its reference value) leaves exactly the pair term between and : the non-additivity. A site-independent model has no , hence no epistasis.
Exercise 2 (reverse KL is mode-seeking — derivation). Show that . Explain why placing all of ‘s mass in the deeper of two wells costs only nats of KL.
Answer
The identity. , so .
One well. If exactly, then For the right well, nats, a small price. The flow’s reported was 0.915–0.928 instead of 1.053: low by about 0.13.
KL punishes for putting mass where has none, not for missing mass where has some. Covering both wells requires transporting mass through the low-density barrier, which the optimization rarely discovers.
Exercise 3 (EGNN equivariance — derivation). Show that the update , with a function of and invariant features, satisfies .
Answer
Distances are unchanged by and , so the messages and the weights are unchanged. Relative vectors transform as Hence The predicted noise is then rotated by and unaffected by . Script 03 measured .
Exercise 4 (chain noise — derivation). In 2-D, with a unit bond scaled by and noise of standard deviation per coordinate, show that the mean squared distance between neighbours is with isotropic noise on the points and with noise on the bond vectors. Compare with script 03’s table.
Answer
Isotropic noise. The neighbour difference is . The noise difference has variance per coordinate, so the mean squared distance is in 2-D.
Bond noise. The bond vector is , so the mean squared distance is .
Comparison at (): the root-mean-square values are and . The measured means, 1.42 and 1.10, are a little lower, because the mean of a distance is below its root mean square (and centering the isotropic noise lowers its variance slightly). Chain noise halves the extra spread.
Exercise 5 (coding). In script 04, condition on end-to-end distance 1.5 at guidance scale 0.3 with noise × 0.6. Does lower temperature recover the validity lost to guidance?
Answer
(Run it.) Part 4 showed that lower temperature raises validity slightly (89% → 92% at × 0.6–0.8) and Part 3 that this guidance costs about 30 points. Expect a partial recovery, at a further cost in diversity.
9. Further reading
From the slides
- T. Hopf, J. Ingraham et al. Mutation Effects Predicted from Sequence Co-variation, Nature Biotechnology 2017; A. Riesselman, J. Ingraham, D. Marks. Deep generative models of genetic variation capture the effects of mutations, Nature Methods 2018.
- F. Noé, S. Olsson, J. Köhler, H. Wu. Boltzmann generators: Sampling equilibrium states of many-body systems with deep learning, Science 2019.
- J. Ingraham et al. Illuminating protein space with a programmable generative model (Chroma), Nature 2023 — the source of composable conditioners, polymer-structured noise and low-temperature hybrid SDEs. (These notes reproduce only the general methods.)
Added by these notes
- M. Ekeberg et al. Improved contact prediction in proteins: using pseudolikelihoods to infer Potts models, Physical Review E 2013 (pseudo-likelihood with L2 penalties).
- V. G. Satorras, E. Hoogeboom, M. Welling. E(n) Equivariant Graph Neural Networks, ICML 2021; E. Hoogeboom et al. Equivariant Diffusion for Molecule Generation in 3D, ICML 2022.
- M. Bronstein, J. Bruna, T. Cohen, P. Veličković. Geometric Deep Learning, 2021 (symmetry as a design principle).
- Y. Du et al. Reduce, Reuse, Recycle: Compositional Generation with Energy-Based Diffusion Models and MCMC, ICML 2023 (composing conditioners as energies).
10. Next lecture
Lecture 25, the second guest lecture and the last of the course, is on neural radiance fields: differentiable volume rendering, positional encoding, NeRF itself, and how 2-D generative models can make 3-D objects (score distillation).