Tutorial 7

Few-Shot Learning

Reproduce Han & Choi's transfer-learning approach to 1H NMR chemical shift prediction: pretrain a GNN on computed (DFT) data, fine-tune on a handful of experimental molecules, and see why that beats training on experimental data alone.

Jules Schleinitz
105 min
Python · Google Colab
Back to schedule

Open in Google Colab

The notebook has most of the code pre-filled. Complete the exercises marked ### YOUR CODE HERE ###.

Open Notebook

Getting started

Open the Colab notebook using the button above. Run each cell in order; cells marked Exercise require you to fill in code.

  1. Build the architecture (a). Implement the edge-network + GRU message-passing GNN from Han & Choi (2021), and pretrain it on a small real subset of DFT-computed shielding constants (QM9NMR case-study molecules).

  2. More data, less error (b). Fine-tune the pretrained model on increasing fractions (1%, 4%, 7%, 10%, ...) of a real experimental 1H NMR dataset (NMRShiftDB2-derived). Plot MAE vs. fraction and compare its shape to Figure 1c of the paper.

  3. Fine-tuning hyperparameters (c). Use the interactive widget to vary learning rate, number of frozen layers, warm-up length, and epochs. Find a setting that clearly under- or over-adapts.

  4. Comparisons (d). Train an experimental-only model (no pretraining), a common-molecules-only model (H/C/N/O/F only), and a k-NN/HOSE-code baseline at the same data budget. Compare all four MAEs.

  5. Challenge. Predict delta(1H) for the fixed class test set, compute your MAE, and run the notebook's submit cell — it POSTs your score straight from Colab to appear on the live leaderboard below.


Answer these questions as you work through the notebook. Discuss with your neighbour — some have no single right answer.

    Warm-up

    Why does the pretrained model's MAE for σ(H) come out so much smaller than for σ(C), σ(N), σ(O), σ(F)? (Hint: look at the spread of each element's shielding-constant distribution, not just the model.)

    Easy
    Core

    At what fine-tuning fraction does the pretrained+fine-tuned model's test MAE stop improving noticeably? Compare that fraction's MAE to the experimental-only (no pretraining) model trained on the same fraction — how big is the gap, and does it shrink as the fraction grows?

    Medium
    Core

    The common-molecules-only model and the k-NN baseline both do well on "in-distribution" test molecules. Which one degrades more gracefully on molecules containing P, S, or Cl, and why might a learned 3D GNN generalize differently than a nearest-neighbor lookup on rare environments?

    Medium
    Challenge

    Re-run the frozen-layers sweep from part (c) with 0, 1, 2, and 3 frozen layers at a fixed 10% fine-tuning fraction. Is there a monotonic trend, and does the best choice change if you cut the fine-tuning fraction to 1%?

    Challenge

Class challenge results

Run the notebook's challenge section and submit cell — it computes your test MAE/RMSE on the fixed class test set and POSTs the score directly from Colab. It appears here within moments; only each team's best (lowest) MAE is shown. Resubmit as many times as you like.

Loading leaderboard…
Loading…

Notebook (Colab) GitHub repo (leaderboard setup) Paired lecture notes Han & Choi 2021 (paper)