2Department of Computer Science, Aalto University, Finland
3Department of Computer Science, University of Helsinki, Finland
4Department of Computer Science, University of Manchester, UK
Knowledge supplied at deployment becomes part of the design process.
IMBUE encodes priors and previous experiments as context, then checks that context
against the observations collected so far.
The challenge: using knowledge at deployment
A new experiment rarely starts from zero. An expert may have a useful prior, or
previous participants may already provide relevant observations. How can a trained
policy use that knowledge to choose its next measurement?
Existing amortized Bayesian experimental design policies are tied to their training
prior, with no input pathway for this extra knowledge at deployment. Simply adding
previous observations can also hurt when they come from a different population.
IMBUE accepts both priors and previous experiments in context, without
retraining, and checks their reliability as new observations arrive.
Read the paper abstract
Amortized Bayesian experimental design (BED) enables real-time design strategies by
shifting acquisition cost offline, but existing methods remain tied to the prior and
task distribution they were trained on and cannot exploit additional information
available at deployment. We introduce in-context amortized BED with unified knowledge
encoding (IMBUE), a BED framework that admits external knowledge at deployment through a
unified in-context interface. IMBUE accepts two forms of such knowledge without
retraining, namely user-specified prior knowledge and observations from previous
instances of the experiment. Both are encoded as additional input tokens and processed
in-context with the accumulated observations by a shared Transformer, and a learned
reliability filter scores each external token against the observations and excludes
inconsistent ones. Across four benchmarks, IMBUE accelerates early-stage information
acquisition when the external knowledge is reliable, and remains close to the
no-external baseline when it is not.
Method: knowledge as in-context
IMBUE builds on the shared Transformer and design–inference heads of
ALINE. Its new interface represents
two kinds of external knowledge as tokens. A learned filter compares each token
with the current experimental history before the policy selects the next design.
A shared Transformer with two additional input channels. Prior and instance
tokens pass through a reliability filter before joining the experimental history,
candidate designs, and inference targets.
Problem setup
Let \(\theta \in \Theta \subseteq \mathbb{R}^L\) be the latent parameters of the system
under study. A design \(x\) returns an outcome \(y \sim p(y \mid \theta, x)\). Over
\(T\) rounds, starting from an empty history \(\mathcal{D}_0 = \emptyset\), a design
policy \(\pi_\psi\) proposes \(x_t\), the experiment returns \(y_t\), and the history
grows to \(\mathcal{D}_t = \mathcal{D}_{t-1} \cup \{(x_t, y_t)\}\). The inference target
\(Z\) is either the parameters, \(Z = \theta\), or outcomes \(Z = y^\star\) at test
inputs \(x^\star\).
IMBUE adds in-context knowledge available at deployment,
\(C = (C_{\text{prior}}, C_{\text{obs}})\), and the policy proposes
\(x_t \sim \pi_\psi(\cdot \mid \mathcal{D}_{t-1}, C)\):
Prior channel \(C_{\text{prior}}\): a user's marginal beliefs
\(\rho_l(\theta_l)\) over the individual parameters \(\theta_1, \ldots, \theta_L\).
Previous-instance channel \(C_{\text{obs}} = \{\mathcal{A}_k\}_{k=1}^{K}\):
\(K\) earlier runs of the same experiment, each with \(T\) design–outcome pairs
\(\mathcal{A}_k = \{(x_i^{(k)}, y_i^{(k)})\}_{i=1}^{T}\).
Either channel may be empty, which recovers standard amortized BED. The policy is
judged by the information the experiment gathers about \(Z\), given \(C\):
\[ \begin{aligned} \mathcal{U}(\psi; C) &= I_{p_\psi}(Z; \mathcal{D}_T \mid C) \\ &= H(Z \mid C) - H_{p_\psi}(Z \mid \mathcal{D}_T, C). \end{aligned} \]
Training maximizes its expectation over a distribution \(p_{\text{train}}(C)\) that mixes
reliable and unreliable knowledge.
In-context token interface
IMBUE represents each piece of in-context knowledge as a token, so a single trained
Transformer accepts either channel at deployment without retraining. Priors and
previous observations differ in form, length and meaning, so each channel has its own
token type.
Prior tokens
Each marginal belief \(\rho_l\) is discretized into a normalized histogram
\(\boldsymbol{\rho}_l = (\rho_l^{(1)}, \ldots, \rho_l^{(N_B)})\) over \(N_B\) uniform bins
\(B_1, \ldots, B_{N_B}\) covering the support of \(\theta_l\):
This non-parametric form accepts multimodal, skewed or truncated beliefs without
committing to a parametric family. An MLP \(f_{\text{prior}}\) maps the histogram to the
model dimension \(D\), and a learnable parameter-specific embedding
\(\boldsymbol{\zeta}_l\) ties the token to its parameter:
The same \(\boldsymbol{\zeta}_l\) serves as the target token for \(\theta_l\) in the
backbone, which aligns each prior with the parameter it describes. Parameters without a
user-specified prior get a uniform histogram.
Instance tokens
Feeding all \(K \cdot T\) raw design–outcome pairs into the main encoder would make
self-attention scale quadratically in \(K \cdot T\) and tie the encoder's input length to
the previous instances' horizon. Instead, a per-instance encoder \(g_{\text{aux}}\), a
separate Transformer shared across all \(K\) instances, compresses each instance into a
single token:
Inside \(g_{\text{aux}}\), \(n_s\) learnable summary slots are prepended to the embedded
pairs of instance \(k\) and attend to them through self-attention; \(\mathbf{h}_s^{(k)}\)
is the output at slot \(s\). Averaging over the slots gives the main encoder one token
per instance.
Joining the backbone
Prior and instance tokens are the in-context tokens. Those kept by the
reliability filter join ALINE's three token groups in the shared encoder: context tokens
for the history \(\mathcal{D}_t\), query tokens for the candidate designs, and target
tokens, one per parameter when \(Z = \theta\) or one per test input when
\(Z = y^\star\). A structured attention mask lets every token attend to the in-context
and context tokens, and lets query tokens also attend to the target tokens. The design
head reads the query positions to give \(\pi_\psi\), and the inference head reads the
target positions to give \(q_\phi\), a Gaussian mixture over the components of \(Z\).
Show the attention masks
Attention masks of the shared Transformer layers for the previous-instance
channel (left, in-context tokens \(\mathbf{r}_1, \ldots, \mathbf{r}_K\)) and the prior
channel (right, in-context tokens
\(\mathbf{e}^{\text{prior}}_1, \ldots, \mathbf{e}^{\text{prior}}_L\)). Rows index
queries and columns index keys, ordered as in-context tokens, context tokens
\((x_i, y_i)\), query tokens \(x^{\text{q}}_m\) and target tokens
\(\boldsymbol{\zeta}_l\). Shaded squares indicate allowed attention.
Reliability filter
External knowledge is not always reliable: a prior may concentrate its mass in the
wrong region of parameter space, and a previous instance may come from a different
population. Conditioning on such tokens without scrutiny can pull the policy away from
what the observations support. The filter \(f_\omega\) therefore scores every in-context
token \(\mathbf{e}_j\) against the embeddings \(\mathbf{E}_t\) of the history
\(\mathcal{D}_t\):
where \(f_\omega\) is a cross-attention block that uses the token as the query and the
history as keys and values, followed by a small scoring MLP, and \(\sigma\) is the
logistic sigmoid.
Keep or discard. Tokens with \(\alpha_j^{(t)} \le \tau = 0.5\) are
excluded from self-attention in the backbone through a key-padding mask.
Re-scored every round. Reliability is judged by consistency with the
observations, so the same token can receive different scores as \(\mathcal{D}_t\)
grows. Before the first observation there is nothing to compare against, and all
in-context tokens are excluded.
Falls back to the history. When every in-context token is excluded,
the forward pass reduces to a history-only amortized BED policy.
Training
IMBUE keeps ALINE's backbone, output heads, per-step reward and variational training
scheme unchanged. What is new is trained alongside them: the token interface, on a
mixture of reliable and unreliable inputs, and the reliability filter, supervised with
labels computed from the simulated ground truth.
Simulated rollouts with reliable and unreliable knowledge
Each training rollout draws a ground-truth parameter \(\theta^\star\) and in-context
knowledge \(C\) for the task's channel, deliberately including knowledge that is wrong:
Previous instances. A random number \(K\) of instances is drawn. Each
is relevant with probability 0.7, generated from \(\theta^{(k)} = \theta^\star + \eta_k\)
with a small Gaussian perturbation \(\eta_k\), or irrelevant with probability 0.3,
generated from a \(\theta^{(k)}\) drawn independently of \(\theta^\star\). Its designs
are drawn uniformly and its outcomes simulated from \(p(y \mid \theta^{(k)}, x)\).
Priors. The prior is uniform (probability 0.2) or Gaussian with a
random location and width. Each parameter is then calibrated, with
\(\theta_l^\star\) drawn from its histogram, or miscalibrated, with that draw shifted
toward the far side of the support.
The policy then runs a \(T\)-round rollout, \(x_t \sim \pi_\psi(\cdot \mid \mathcal{D}_{t-1}, C)\)
and \(y_t \sim p(y \mid \theta^\star, x_t)\). After every round the inference head
evaluates \(\log q_\phi^{(t)} = \log q_\phi(Z^\star \mid \mathcal{D}_t, C)\) at the
realized target \(Z^\star\), and the filter re-scores the in-context tokens.
Reliability labels from the simulator
Because \(\theta^\star\) is known in simulation, every in-context token gets an oracle
reliability label. A prior token is scored by how much more mass its histogram puts on
the bin \(b^\star\) containing \(\theta_l^\star\) than a uniform histogram would,
where \([r_l^{\min}, r_l^{\max}]\) is the support of \(\theta_l\) (or a fixed range if it
is unbounded) and \(\beta, \kappa > 0\) set the sharpness. Thresholding at \(1/2\) gives
binary targets \(c_j = \mathbb{I}[r_j > 1/2]\). On GP active learning, where the target
is \(y^\star\), the label is binary and tied to the regime that generated the instance.
The labels use only quantities the simulator already draws; they are neither observed
nor needed at deployment.
A lower bound on information gain
The posterior inside \(\mathcal{U}\) is intractable for general likelihoods, so IMBUE,
like ALINE, trains against the Barber–Agakov variational lower bound, with the inference
head \(q_\phi\) as the variational distribution:
\[ \begin{aligned} \mathcal{U}(\psi; C) \;\ge\;& H(Z \mid C) \\ &+ \mathbb{E}_{p_\psi(Z, \mathcal{D}_T \mid C)}\bigl[\log q_\phi(Z \mid \mathcal{D}_T, C)\bigr]. \end{aligned} \]
\(H(Z \mid C)\) depends on neither network, so training maximizes, jointly in the policy
\(\psi\) and the inference head \(\phi\), the expected log-density that \(q_\phi\) assigns
to the true target at the end of the rollout.
Three losses
Averaged over a minibatch of rollouts, these quantities enter three losses, combined
with equal weights \(\lambda_1 = \lambda_2 = \lambda_3 = 1\):
Its final-round term optimizes the bound above with respect to \(\phi\) and, for a fixed
policy, tightens it; the earlier rounds keep \(q_\phi\) accurate enough to reward the
policy.
Policy loss. The design head is trained by policy gradient with ALINE's
dense per-step reward \(R_t = \log q_\phi^{(t)} - \log q_\phi^{(t-1)}\), the gain in
log-density after each new observation:
with \(\gamma = 1\). Gradients stop at \(q_\phi\), so the policy cannot raise its reward by
changing the inference head. The rewards telescope to the final log-density minus a term
the policy cannot affect, which favors designs that raise the bound.
Filter loss. The filter is trained as a classifier against the oracle
labels, with binary cross-entropy over all rounds and all \(|C|\) in-context tokens:
It is zero when \(C\) is empty, is not derived from the bound, and is detached from the
embedders shared with the rest of the network.
Two-stage schedule
The reward \(R_t\) is informative only once \(q_\phi\) is accurate. For the first
\(E_{\text{warm}}\) epochs, designs are therefore drawn uniformly at random from the
candidate pool and only \(\mathcal{L}_{\text{inf}}\) and \(\mathcal{L}_{\text{filter}}\)
are optimized. Afterwards the policy selects the designs and all three losses are
optimized jointly, with AdamW and a cosine learning-rate schedule.
At deployment no labels, gradient steps or retraining are needed: a user supplies a
prior, previous instances, or nothing, and each design takes one forward pass in which
the filter decides, from the observations alone, which tokens to keep. The
paper gives the full algorithm,
architecture and hyperparameters.
Experiments and results
Four benchmarks test useful priors, previous experiments, and mixtures of relevant and
irrelevant inputs. Across these settings, reliable knowledge accelerates acquisition,
while unreliable knowledge leaves IMBUE close to its no-external-input baseline.
Benchmarks, metrics, and baseline notation
The four benchmarks. ↑ higher is better, ↓ lower is better.
Benchmark
In-context knowledge
Inference target
Steps \(T\)
Metric
Location Finding
Prior over each source coordinate
Locations of two hidden sources in \([0, 1]^2\)
20
sPCE ↑
CES
\(K\) previous respondents
Preference parameter \(\theta \in \mathbb{R}^5\)
10
sPCE ↑
GP active learning (1D)
\(K = 5\) previous instances, 0–5 of them irrelevant
Predictions at held-out test inputs
15
RMSE ↓
Psychometric
\(K = 5\) previous participants
The four parameters of a psychometric function, \(\theta \in \mathbb{R}^4\)
30
Joint RMSE (threshold, slope) ↓
sPCE
Sequential Prior Contrastive Estimation, a lower bound on the total EIG.
Relevant / irrelevant
A relevant previous instance comes from parameters that are a small Gaussian
perturbation of the current ones; an irrelevant one is drawn independently of them. On
GP active learning: perturbations of the target function versus unrelated functions.
Strong / miscalibrated prior
Concentrated near the true parameters, or shifted away from them.
Method*
In-context knowledge supplied by naive concatenation to the experimental history.
± and bands
95% confidence intervals, unless a caption says otherwise.
01 / Location finding
Expert priors accelerate acquisition
The task is to locate two hidden sources from 20 noisy measurements. IMBUE
receives a prior histogram for each source coordinate, supplied at deployment.
With a strong prior, it reaches ALINE's final information level several
measurements earlier. With a prior shifted away from the true locations, it
stays close to the ALINE baseline. The same trained policy handles both cases.
A useful prior reaches the baseline's final information level earlier.
Location Finding over 20 measurements. sPCE (↑), a lower bound on the total expected
information gain; mean ± 95% CI across 2,000 rollouts. The miscalibrated-prior policy
stays close to the ALINE reference.
02 / Preference elicitation (CES)
Past experiments help when they are relevant
CES (Constant Elasticity of Substitution) infers a person's preferences from
sequential choices. Data from previous respondents can be useful context, but only
when their preferences are related.
With five relevant instances, IMBUE's sPCE rises from 13.46 to 13.93;
with five irrelevant ones, it remains close to its no-input score at 13.14.
Simply concatenating these observations into existing policies is less reliable.
ALINE*'s score falls to 10.16 with five irrelevant instances, while DAD and RL-BOED
degrade even with relevant ones. An asterisk marks this concatenation baseline.
Useful previous instances improve IMBUE; irrelevant ones leave it close to its
no-input score. CES, sPCE (↑), mean ± 95% CI across 2,000 rollouts.
\(K\) is the number of previous instances. At \(K = 0\),
starred methods are their standard versions without concatenated inputs.
\(K = 0\)
\(K = 1\)
\(K = 5\)
Method
—no previous instances
Relevant
Irrelevant
Relevant
Irrelevant
Random
9.05 ± 0.26
—not reported
—not reported
—not reported
—not reported
DAD*
11.52 ± 0.17
7.38 ± 0.21
7.37 ± 0.21
5.16 ± 0.21
5.40 ± 0.21
RL-BOED*
14.34 ± 0.13
4.54 ± 0.20
4.74 ± 0.21
2.56 ± 0.15
2.84 ± 0.17
ALINE*
13.37 ± 0.15
13.27 ± 0.15
11.10 ± 0.22
13.07 ± 0.15
10.16 ± 0.24
IMBUE ours
13.46 ± 0.15
13.63 ± 0.14
13.42 ± 0.15
13.93 ± 0.12
13.14 ± 0.16
03 / GP active learning
Useful and misleading inputs can arrive together
Here the policy learns an unknown function by choosing where to observe it next.
Five previous instances mix related and unrelated functions. As more instances
become irrelevant, GP*, ALINE*, and multi-task GP baselines lose accuracy;
IMBUE's prediction error stays essentially flat on all four benchmarks.
Synthetic functions test the training distribution, while Forrester, Higdon,
and Gramacy & Lee probe generalization beyond it.
IMBUE stays stable as the proportion of irrelevant inputs grows.
Final prediction RMSE (↓) on four 1D functions, mean ± 95% CI across 100 rollouts.
Of the five previous instances, the number that are irrelevant varies from zero to five.
04 / Psychometric model
Transfer knowledge between participants
A psychometric experiment estimates a participant's response threshold and
slope from binary responses to stimulus intensities. IMBUE can use five previous
participants as context for the new experiment.
Relevant participants reduce estimation error throughout the 30-measurement
experiment, especially early on. With irrelevant participants, IMBUE tracks
the no-external-input references ALINE, QUEST+, and Psi-marginal closely.
Relevant participants accelerate learning; irrelevant participants have little
effect. Joint RMSE on threshold and slope (↓), mean ± 95% CI across 500 rollouts.
Each experiment has 30 measurements and five previous participants.
The paper and its appendix include
further comparisons, deployment shifts, sensitivity studies, and computational costs.
Scope and limitations
IMBUE accepts structured inputs within the trained task family: prior histograms and
sequences of previous observations. Priors describe individual parameters, without
modeling dependencies between them. The filter is less reliable in the earliest rounds,
when little evidence is available. Richer knowledge formats and continuous design
policies that avoid enumerating large candidate pools remain directions for future work.
Citation
BibTeX
@inproceedings{zhao2026amortized,
title = {Amortized {Bayesian} Experimental Design with In-Context Knowledge Conditioning},
author = {Zhao, Zhanghu and Huang, Daolang and Wen, Xinyi and Kaski, Samuel},
booktitle = {Advances in Neural Information Processing Systems},
year = {2026}
}
Acknowledgments
This work was supported by the ERC (grant ODD-ML 101201120) and the Research Council of
Finland (Flagship programme: Finnish Center for Artificial Intelligence FCAI, decision
359207). The authors acknowledge the research environment provided by ELLIS Institute
Finland. SK was also supported by the UKRI Turing AI World-Leading Researcher Fellowship,
[EP/W002973/1]. The authors wish to thank the Aalto Science–IT project and CSC–IT Center
for Science, Finland, for the computational and data storage resources provided. Views
and opinions expressed are however those of the author(s) only and do not necessarily
reflect those of the European Union or the European Research Council Executive Agency.
Neither the European Union nor the granting authority can be held responsible for them.