Skip to content

Neural processes: learning to predict a whole function from a few points

A neural process learns, across many related curves, how to predict a new curve from a handful of observed points, with no refitting. Conditional, latent and attentive versions, what each fixes, and how to evaluate them on unseen tasks.

Advanced ~13 min9 steps

What runs in CodeSplash

You will be able to

  • Explain amortization across tasks and why the context set must be order-free
  • Contrast the conditional neural process with the latent version's coherent samples
  • Explain the bottleneck that attentive neural processes remove
  • Design an evaluation that splits by task, not by point

Read first

01

A GP that learned its prior from data

Read

A GP predicts a curve from a few observed points using a kernel you choose. A neural processNeural processA network trained across many related curves to predict a new curve from a few observed points in one pass, with uncertainty. learns that skill instead, from many example curves of the same kind: daily temperature profiles, growth curves, sensor traces.

Training shows it thousands of tasks, each split into context points (seen) and target points (to predict). At use, you hand it a new context set of any size and it predicts the rest of the curve in one pass, with no refitting. That is amortization: the cost of inference was paid up front, across tasks.

02

Conditional neural process

Read

The CNP encodes each context pair and averages: rC=1nC∑ihθ(xi,yi)r_C=\frac{1}{n_C}\sum_i h_\theta(x_i,y_i). Averaging makes the summary ignore the order of the context points, as it should. A decoder then predicts each target independently: p(yT∣xT,C)=∏jp(yj∣xj,rC)p(y_T\mid x_T,C)=\prod_j p(y_j\mid x_j,r_C).

In the reference's small example, two context points give a two-number summary and target means of −0.393 and 0.407, each with SD 0.836. Because targets are predicted independently, drawing from a CNP gives a jagged set of points, not a plausible curve.

03

Latent neural process

Read

The latent NP adds a random variable zz shared by all targets. One draw of zz gives one whole, coherent function; another draw gives another. It's trained with a variational objective,

Eq(z∣C∪T)[∑j∈Tlog⁡p(yj∣xj,z,C)]−KL(q(z∣C∪T)∥q(z∣C)),\mathbb E_{q(z\mid C\cup T)}\Big[\sum_{j\in T}\log p(y_j\mid x_j,z,C)\Big]-\mathrm{KL}\big(q(z\mid C\cup T)\Vert q(z\mid C)\big),

where the posterior sees the targets only during training. At use, sample zz from q(z∣C)q(z\mid C) and reuse it for every target of that function. Watch for a latent the decoder ignores (the KL falls to zero) and for target labels leaking into q(z∣C)q(z\mid C) at evaluation.

04

One summary for every target

Predict

Predict first

A CNP sees forty context points, three of them tracing a sharp bump near one target location. What does a single averaged summary do to the prediction at that location?

It predicts the bump wellIt blurs the bump into the average
Reveal

It blurs the bump. One mean vector serves every target, so local detail is averaged away and CNPs underfit dense context. Attentive neural processes let each target look up the context points relevant to it.

05

Attentive neural process

Read

The ANP keeps a latent path for coherence and adds cross-attention: each target query QQ compares itself with context keys KK and reads a weighted mix of values, RT=softmax⁡(QK⊤/dk)VR_T=\operatorname{softmax}(QK^\top/\sqrt{d_k})V. Nearby, relevant context points get the most weight. In the reference's example, one target puts weight 0.480 on its first context point.

Attention costs one score per context–target pair, and good interpolation doesn't promise good extrapolation. Attention weights are a retrieval diagnostic, not proof of what caused a prediction.

06

Evaluating by task

Read

The unit of a neural process is the task, so split by task: whole curves in training, other whole curves in evaluation. Holding out points from training curves only tests memory.

Then plot target log likelihood against context size and distance from the nearest context point, separate interpolation from extrapolation, check that shuffling the context leaves predictions unchanged, and compare CNP, NP and ANP on identical splits and context budgets.

07

Where each idea stands in CodeSplash

Read
08

Check your understanding

Checkpoint

Check yourself

What does a conditional neural process do with a new context set?

Show the answer

Answer: b

Training across many tasks taught it how to condition. New contexts only need a forward pass.

Check yourself

Why do samples from a CNP look jagged rather than like smooth curves?

Show the answer

Answer: a

The factorized likelihood gives good pointwise predictions but no joint structure. A shared latent fixes that.

Check yourself

What does the latent NP's shared variable z give you?

Show the answer

Answer: b

Reusing one draw of z for every target ties the predictions together. The context encoder remains an approximation.

Check yourself

In evaluation, your latent NP samples z from a posterior that saw the target points. What's wrong?

Show the answer

Answer: b

The posterior with targets is a training device. At evaluation, condition on the context alone.

Check yourself

What problem do attentive neural processes address?

Show the answer

Answer: b

Cross-attention lets each target read the context points most relevant to it.

Check yourself

An ANP puts most attention on one context point for a target. What can you conclude?

Show the answer

Answer: a

Attention weights show retrieval. The decoder and the latent path also shape the output.

Check yourself

How should you split data to evaluate a neural process?

Show the answer

Answer: b

Neural processes promise transfer to new tasks. Point-level holdouts from training curves only test memory.

09

What comes next

Recap

The next unit moves from uncertainty about numbers to structure among labels: predicting a whole sequence of labels at once with conditional random fields.

Concepts in this lesson