Manuscript Offprint
arXiv:2610.22294Multi-Target Few-Shot Prompting with Diffusion Language Models
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Few-shot prompting is useful when instructions and rewards are hard to specify. One such application is editing by example, where a demonstrated formatting change or API migration may need to be applied across multiple sites. However, such edits often depend on both left and right context, making generation with causal autoregressive models awkward. We therefore introduce multi-target few-shot prompting with diffusion language models, where examples guide the infilling of multiple masked regions within a shared canvas. To address the known challenge of reliably following demonstrations in few-shot prompting, we further leverage selective masking of the canvas to derive a likelihood-ratio reward that favors example-supported infills. Across few-shot prompting benchmarks and software refactoring case studies, we find that demonstrations improve infilling accuracy, with example guidance yielding further gains in several settings.
Initial canvas
Follow the examples:
Meeting January 5: M 5 Jan
Review March 3: R 3 Mar
Workshop April 7: [M] [M] [M]
Deadline June 30: [M] [M] [M]
After round 1
Follow the examples:
Meeting January 5: M 5 Jan
Review March 3: R 3 Mar
Workshop April 7: [M] 7 Apr
Deadline June 30: D [M] Jun
After round 2
Follow the examples:
Meeting January 5: M 5 Jan
Review March 3: R 3 Mar
Workshop April 7: W 7 Apr
Deadline June 30: D 30 Jun
Figure 1: Multi-target few-shot prompting with a DLM. Demonstrations map event names and dates to initials, days, and abbreviated months. The DLM progressively fills two masked outputs within a shared canvas; tokens revealed at one site can inform subsequent predictions at the other.
1 Introduction
Few-shot prompting lets users specify model behavior through demonstrations, without updating model parameters (Brown et al., 2020; Garg et al., 2022). This is useful for test-time guidance, especially when instructions or rewards are difficult to specify (Kwon et al., 2023; Zamfirescu-Pereira et al., 2023; Zhou et al., 2023). For instance, in editing by example, a demonstrated formatting change or API migration can illustrate a transformation to apply elsewhere (Gupta et al., 2023; Wei et al., 2024). When a demonstrated edit must be applied at multiple sites, a natural approach is to generate the tokens in place within a shared canvas containing all demonstrations and relevant context. We call this multi-target few-shot prompting.
However, causal autoregressive models generate outputs as continuations, making it awkward to infill a target site using right-hand-side context. Incorporating such context requires rearranging the prompt or using specialized infilling formats (Bavarian et al., 2022; Fried et al., 2022), a process that becomes more cumbersome when editing multiple sites. Moreover, pretrained associations and sensitivity to prompt design can interfere with the model's adherence to demonstrations (Min et al., 2022; Wei et al., 2023; Zhao et al., 2021). Although guidance methods have been developed to mitigate these issues, they are primarily designed for autoregressive models and do not directly apply to in-place editing (Peng et al., 2025; Shi et al., 2024b).
Diffusion language models (DLMs) offer a natural interface for these tasks because they are not restricted to next-token prediction and can generate tokens anywhere on the shared canvas (Austin et al., 2021; Sahoo et al., 2024; Shi et al., 2024a). As illustrated in Figure 1, the missing output regions are initially masked and progressively filled, while demonstrations and surrounding context remain visible. Each generated token can therefore condition on both left and right context, avoiding the specialized prompting harnesses often needed in causal autoregressive generation (Ou et al., 2025). Moreover, jointly infilling multiple sites allows tokens revealed at one site to inform subsequent predictions at others, helping maintain consistency (Kim et al., 2026).
Yet several challenges remain in using DLMs for multi-target few-shot prompting. First, infilling requires allocating masked positions before generation, even though the required output lengths are generally unknown (Xu et al., 2026a; Zhang et al., 2025). Second, although DLMs condition on demonstrations, they may still fail to follow them reliably. Context-aware decoding suggests that contrasting predictions across contexts could strengthen adherence to demonstrations (Shi et al., 2024b; Whitammer et al., 2022), but extending such guidance to complete DLM infills requires joint likelihoods that are often intractable or decoder-specific (Turok et al., 2026).
In this work, we study how to overcome such challenges. We state our contributions next.
Example-guided sampling. We construct a tractable distribution over complete multi-site infills by revealing one token at a time, allowing us to compare candidate likelihoods with and without demonstrations. The resulting likelihood-ratio reward enables inference-time importance resampling to favor example-supported completions, offering an additional way to encourage adherence to demonstrations without retraining the generator.
Empirical evaluation. We evaluate the effects of demonstrations, target counts, example guidance, and learned length prediction across repurposed few-shot prompting benchmarks and software refactoring case studies. We find that demonstrations generally improve infilling accuracy and guidance provides additional gains in some settings, but accurate length prediction remains a challenge.
1.2 Related Work
Few-shot prompting. Few-shot prompting specifies tasks through demonstrations (Brown et al., 2020), but mappings and placement can affect model behavior (Li et al., 2026; Min et al., 2022; Wei et al., 2023). Applications include information extraction and semantic parsing (Pang et al., 2023; Shin and Van Durme, 2022), as well as programming by example and code editing, where demonstrations or prior edits guide subsequent transformations (Gulwani, 2011; Gupta et al., 2023; Meng et al., 2011; Wei et al., 2024). Prior work also explores batching multiple inputs into a single prompt, allowing their answers to be generated in one model call (Cheng et al., 2023; Lin et al., 2024). We instead study joint infilling of multiple unresolved regions in place within a shared canvas containing demonstrations and surrounding context.
Test-time guidance. Beyond few-shot prompting, various test-time guidance methods have been developed to steer model generation. Contrastive decoding compares predictions from different models (Li et al., 2023; O'Brien and Lewis, 2023), while context-aware methods compare predictions under different conditioning contexts to strengthen the influence of supplied evidence or demonstrations (Peng et al., 2025; Shi et al., 2024b; Song et al., 2025; Whitammer et al., 2022). In diffusion models, classifier-free guidance adjusts the influence of conditioning information (Ho and Salimans, 2021), while KL-regularized reward tilting (Korbak et al., 2022; Rafailov et al., 2023) and inference-time resampling (Singhal et al., 2025) provide mechanisms for reweighting candidate generations. However, extending likelihood-based comparisons to complete DLM infills requires tractable sequence-level likelihoods under a specified decoding procedure.
Diffusion language models. Masked diffusion language models iteratively unmask positions within a shared canvas, supporting flexible generation orders and parallel decoding (Austin et al., 2021; Sahoo et al., 2024; Shi et al., 2024a). Recent models include LLaDA (Nie et al., 2025), Dream (Ye et al., 2025), Nemotron-Labs-Diffusion (Fu et al., 2026), and dQwen3.5 (Xue et al., 2026), alongside diffusion-augmented autoregressive approaches such as Uno (Sahoo et al., 2026). Standard masked infilling also requires allocating output lengths in advance, motivating work on flexible-length generation and length prediction (Ding et al., 2026; Xu et al., 2026a; Zhang et al., 2025). Prior work shows that decoding strategies affect generation quality and efficiency (Arriola et al., 2025; Kim et al., 2026; Wu et al., 2026), while the tractability of complete-sequence likelihoods depends on the decoding procedure (Turok et al., 2026).

Figure 2: Further examples of multi-target few-shot prompting. Two input–output demonstrations illustrate alphabetical sorting of word lists, which a DLM applies to two missing outputs.
2 Background
2.1 Few-Shot Prompting on a Shared Canvas
We consider a partially observed canvas containing demonstrations, target sites, and relevant surrounding context. Let denote this canvas, where is the vocabulary, is a mask token, and is the canvas length. The original target positions are , where ; these positions form masked output regions. The task is to fill these regions while preserving the visible content of the canvas.
In Figure 2, demonstrations illustrate alphabetical sorting, while missing outputs occupy six masked positions in total ( in the schematic). At the target sites, the original word lists remain visible, while their sorted versions must be generated. More generally, demonstrations and targets may be interleaved with surrounding context; conventional few-shot prompting is recovered when a single target follows the demonstrations. For now, we assume the target sites are specified and their output lengths are given by an oracle, fixing the mask allocation before generation.
2.2 Masked Diffusion Language Models
Like BERT-style masked language modeling (Devlin et al., 2019), masked DLMs predict missing tokens using visible context on both sides of each masked position (Austin et al., 2021; Sahoo et al., 2024; Shi et al., 2024a). At each masked position , the model predicts a distribution over candidate tokens . Turning these predictions into complete infills requires a decoding algorithm that determines which masked positions to reveal and when. Common strategies select positions by prediction confidence or a prescribed order, potentially revealing multiple tokens in parallel (Fruytier et al., 2026; Kim et al., 2026; Wu et al., 2026). As illustrated in Figure 2, newly revealed tokens become visible context for subsequent predictions, including those at other target sites. Different decoding procedures can induce different distributions over complete infills, so we seek a decoder that permits exact sampling and scoring.
3 Multi-Target Few-Shot Prompting and Reward Guidance
While Section 2 assumes known output lengths, practical multi-target few-shot prompting must generally determine both the lengths and contents of missing outputs. We formulate this joint generation problem using a shared canvas with one placeholder per target site. To characterize the complete infills produced by a DLM, we construct tractable likelihoods under one-token-at-a-time decoding. These likelihoods additionally enable reward guidance to encourage adherence to the demonstrations.
3.1 Length Allocation and Joint Infilling
We begin with a compact canvas in which each missing output is represented by a single placeholder. Let denote this canvas, containing target placeholders together with the visible demonstrations and surrounding context. For a proposed length vector , where each specifies the token length of target , we expand each placeholder into mask tokens. This produces an expanded canvas with target positions , on which the DLM can generate the missing contents.
We model joint generation of output lengths and contents by first allocating lengths and then infilling the resulting canvas. Let be a distribution over length allocations, with each ranging over a prescribed finite set of positive integers. For a given allocation, let denote a complete infill, assigning a vocabulary token to each target position. We define the joint distribution
The allocator may be a point mass at oracle lengths or a learned predictor, as investigated in Section 4. To complete this formulation, we next characterize the distribution induced by DLM decoding.
3.2 Tractable DLM Infilling
A DLM provides predictions at individual masked positions, but different decoding procedures can induce different distributions over complete infills (Section 2). To obtain tractable likelihoods, we focus on decoders that reveal one token at a time, including prescribed orders and deterministic confidence-based selection.
Fix an expanded canvas with target positions , and let be a candidate completion. At step , the decoder selects an unrevealed target position based on the current canvas, then samples its token from the DLM. Let denote the canvas after revealing the first tokens of , with . For deterministic position selection, replaying the policy on determines the reveal order and yields the complete-infill likelihood
The following lemma establishes the properties of this construction.
Lemma 3.1 (One-token-at-a-time decoding). For any deterministic one-token-at-a-time position-selection policy, Equation (2) defines a normalized distribution that can be sampled and scored exactly. If the DLM predicts exact data conditionals, then recovers the conditional data distribution wherever defined, independently of the reveal policy (Ou et al., 2025).

Figure 3: Example guidance strengthens a demonstrated naming convention. With the demonstration output masked , the model favors item_count; revealing it increases support for itemCount, but does not change the ranking. At an illustrative , example guidance amplifies this shift and favors itemCount. Probabilities are schematic and normalized over the two completions of the blue mask; [M] denotes a masked span.
Exact sampling and scoring hold for the induced distribution regardless of whether the DLM matches the data conditionals. Recovery of the data distribution requires exact conditional predictions; learned DLMs need not satisfy this assumption, and their induced distributions may depend on the decoding policy. While our construction excludes parallel token revelation, it permits generating and scoring only the designated targets T while other masked positions remain unresolved.
3.3 Reward Guidance
Even with demonstrations visible, a DLM may favor completions that do not follow their demonstrated patterns, as illustrated in Figure 3. The tractable likelihoods above allow us to measure how strongly the demonstrations support each candidate and use this signal for additional reward guidance. Let denote selected demonstration-output positions, and write for the canvas with these positions additionally masked. We compare the likelihood of the same candidate with and without these demonstration outputs visible:
Both distributions use the same decoding policy over the original target positions T, leaving the additional masks in E unresolved. Their log-likelihood ratio defines the reward
A higher reward indicates greater relative support from the demonstrations, rather than necessarily greater correctness. We incorporate this reward into generation by defining the guided distribution
where controls guidance strength and is the normalizing constant . At , we recover unguided sampling from , which already conditions on the demonstrations. Increasing favors candidates with higher rewards, potentially counteracting a pretrained model's preference for familiar but demonstration-inconsistent completions.
This form of reward guidance is also known as exponential tilting (Korbak et al., 2022)

Figure 4: Inference with unknown target lengths. A length predictor runs once on the compact canvas; each sample then draws a length allocation and generates a DLM infill over the expanded masks. Samples receive reward-guidance weights , comparing their likelihoods with demonstration outputs visible and masked . Resampling according to these weights approximates . Bars aggregate normalized weights over identical completions; tokens, samples, and weights are schematic.
However, direct sampling from is generally intractable because its sequence-level reward does not yield tractable token-level conditionals. Instead, we approximate reward-guided generation using importance resampling from . We draw independent candidates , evaluate their likelihoods under , and resample an index according to
These weights are proportional to , allowing finite-pool resampling to approximate the guided distribution without modifying the DLM. The following proposition formalizes the KL-regularized interpretation of reward guidance and the consistency of its approximation.
Proposition 3.2 (Reward guidance and importance sampling). Let and be positive distributions on a common finite candidate space, and let . The distribution defined by Equation (4) uniquely solves
Moreover, the weighted empirical distribution obtained from independent samples of using Equation (5) converges almost surely to in total variation as .
Extension to unknown lengths. Reward guidance also applies to joint assignments of output lengths and contents. Let denote the selected demonstration-output positions in the expanded canvas . Using the factorization from Equation (1), we define
Since both contexts use the same allocator, its contribution cancels from the reward , although resampling joint candidates can still change the marginal distribution over lengths. The same guidance procedure and Theorem 3.2 apply to these joint candidates (see Section A.3). Figure 4 summarizes the complete procedure, from length allocation and DLM infilling to optional reward-guided resampling.

LLaDA-1.5 Nemotron causal dQwen3.5 Qwen3-8B no gain (0 pp)
Figure 5: Single-target prompting as the number of demonstrations grows. The top row shows unguided answer accuracy ( ), while the bottom row shows the accuracy gain from example guidance ( ), obtained by reweighting the same K = 64 samples per canvas. Four benchmarks and four model interfaces, with 64 prompt families per benchmark; DLMs use oracle target lengths, while Qwen3 generates freely.
4 Few-Shot Prompting Experiments with Standard Benchmarks
We first quantify the effects of demonstrations and example guidance in single-target infilling (Section 4.1). We then investigate how these effects change when multiple targets are infilled jointly (Section 4.2). Finally, we evaluate the impact of predicting target lengths rather than supplying them through an oracle (Section 4.3). We defer additional experiments to Section B, such as on guidance strength (Section B.5) and likelihood sharpening (Section B.6).
Experimental setup. We evaluate four benchmarks spanning different few-shot transformations: SST-2 (Socher et al., 2013; Wang et al., 2018) with demonstration-defined sentiment codes, List Functions–Easy (BIG-bench authors, 2023; Rule, 2020) for list transformations, SALT repetition (Zheng et al., 2025a,b) for artificial-language transformations, and Movie Director (Liu et al., 2012; Zhao et al., 2021) for information extraction. We use three DLMs: LLaDA-1.5 (Zhu et al., 2026), Nemotron-Labs-Diffusion-8B (Fu et al., 2026), and dQwen3.5-9B-Base (Xue et al., 2026), together with Qwen3-8B (Yang et al., 2025) as an autoregressive single-target comparison.
Throughout, D and J denote the numbers of demonstrations and targets, respectively. We refer to generation without additional guidance ( ) as standard infilling for DLMs, or equivalently unguided sampling, and compare this with example guidance at by default. Outputs are graded by task-specific exact or parsed matching, and the DLM experiments reveal one target token at a time in ascending canvas order. Further experimental details appear in Section B.1.
4.1 Single-Target Few-Shot Prompting
We begin with single-target infilling, which closely resembles conventional autoregressive few-shot prompting, except that DLMs generate a masked output rather than a continuation. Since few-shot prompting is sensitive to demonstration selection and ordering (Zhao et al., 2021), we hold the target fixed when comparing different demonstration counts. We first randomly draw a sequence of 16 demonstrations from the benchmark, followed by one target. For each , we construct a prompt by retaining only the first D demonstrations while keeping the target unchanged. These five related prompts form a prompt family, allowing us to vary the demonstration count without changing the target or previously included demonstrations. We evaluate 64 families per benchmark across four tasks and four model interfaces, drawing K = 64 samples for each prompt. Figure 5 reports standard infilling accuracy and the gain from guidance.
Increasing the demonstration count from D = 1 to D = 16 improves accuracy without additional guidance in all 16 model-task series (Figure 5, top). For LLaDA, unguided accuracy rises from 14.0% to 76.5% on SST-2, from 33.3% to 74.7% on List Functions-Easy, from 0.0% to 98.8% on SALT repetition, and from 64.1% to 94.9% on Movie Director. This shows that demonstrations provide useful conditioning information even before applying reward guidance. Consistent with this observation, the reference answer's example reward generally increases with D, indicating stronger relative likelihood support from the demonstrations (Section B.2).
Beyond these improvements from demonstration conditioning, example guidance yields further accuracy gains in several settings, particularly SST-2 at intermediate demonstration counts (Figure 5, bottom). At D = 4, guidance improves LLaDA's accuracy by 14.4 percentage points on SST-2, 6.6 on List Functions–Easy, 3.6 on SALT repetition, and 2.9 on Movie Director, where unguided accuracy already exceeds 94%. These gains tend to shrink as standard infilling accuracy saturates, and depend on whether the reward favors correct samples.
4.2 Multi-Target Few-Shot Prompting
We next examine how demonstration conditioning and example guidance behave when multiple targets are infilled jointly. For each prompt family, we randomly draw 16 demonstrations and 8 targets from List Functions–Easy, then interleave them into a shared sequence. For each configuration and , we construct a canvas by removing all but the first D demonstrations and first J targets from this sequence. The retained items preserve their relative order, allowing us to vary demonstration and target counts without independently reshuffling the canvas. For each resulting canvas, the DLM draws K = 16 joint samples using oracle target lengths, which we evaluate under standard infilling and additional example guidance.
With multiple targets, we distinguish between completing every target correctly and maintaining accuracy at individual sites. Let indicate whether target is correct in sample , and let denote its normalized resampling weight. We define all-target accuracy and average per-target accuracy by
For each sample pool, is the probability that resampling selects an infill with every target correct, whereas is the expected fraction of correct targets. We average these quantities

Figure 6: Demonstrations and target count on List Functions–Easy. Each column fixes the number of jointly infilled targets J, while the horizontal axis varies the number of demonstrations D. The rows show all-target accuracy and average per-target accuracy under unguided sampling ( ), followed by the gain in from example guidance ( ) using the same samples. Three DLMs, oracle target lengths, and K = 16 samples per canvas.
across prompt families; they coincide when . Figure 6 reports both under standard infilling and the guidance gain in at (Section B.1).
Demonstrations continue to improve joint infilling, with standard all-target accuracy increasing at every successive demonstration count (Figure 6, top). For LLaDA with J = 8, rises from 24.3% at D = 2 to 44.5% at D = 16. Increasing the number of targets, however, affects all-target and per-target accuracy differently. At D = 16, LLaDA maintains nearly the same as J grows from 1 to 8 (73.6% versus 72.3%), despite a decline in all-target accuracy (Figure 6, top and middle). Thus, lower joint success need not imply a comparable decline in accuracy at individual target sites.
The benefits of additional example guidance, however, are less consistent as the number of targets grows. On List Functions–Easy, guidance at yields positive gains with confidence intervals above zero in every J = 1 condition, but in none of the J = 8 conditions (Figure 6, bottom). This pattern is not universal across tasks: a separate cross-benchmark study at D = 4, K = 64, and J = 8 finds guidance gains on SST-2 but losses on Movie Director (Section B.3). Together, these results indicate that guidance effectiveness depends on both the task and the number of jointly infilled targets.

Figure 7: Length allocation and downstream infilling accuracy. On List Functions–Easy ( , ), the top row compares per-target accuracy under oracle and sampled learned lengths as the number of targets increases. The bottom row measures sensitivity to length errors, setting each target length to for , where is the reference length and recovers oracle allocation. These forced offsets are distinct from the predictor's own error distribution. Results cover three DLMs; additional length-prediction diagnostics appear in Section B.4.
4.3 Predicting Target Lengths
The preceding experiments assume oracle target lengths, whereas infilling in practice generally requires predicting them. To evaluate the learned-allocation setting of Section 3.1, we train length predictors on structured few-shot tasks and Java edits (Section B.4). On List Functions–Easy, we fix and vary across three DLMs, comparing oracle lengths against sampled predictions with the same content generator and standard infilling (). Figure 7 reports downstream accuracy and sensitivity to length errors.
The learned predictors capture useful information about the required output lengths. They assign 40–46% probability mass to the reference length, compared with approximately 27% for a prior constructed from visible demonstration lengths (Section B.4). This indicates that the compact canvas contains useful predictive information about the missing output lengths.
Despite this improvement over the length prior, learned allocation remains a gap for reliable downstream infilling. Sampling predicted lengths retains only 35–48% of oracle-length per-target accuracy (Figure 7, top). To examine this sensitivity directly, we impose offsets , where is the reference token length. One-token underallocation harms LLaDA and Nemotron more than overallocation, while dQwen3.5 is sensitive to errors in either direction (Figure 7, bottom). These findings identify accurate length allocation as a remaining challenge for practical multi-target infilling.

reference replacement length (LLaDA tokens)
(D demonstrations, J targets)
Figure 8: Java helper refactoring with LLaDA-1.5 (K = 16). Left: mass of the Java length predictor within two tokens of the reference length versus a training-label prior, by reference length. Right: joint LLM-judged success by , oracle or learned lengths, and unguided or example-guided evaluation of the same sample pools. Pooled contrasts are in Table 1.
5 Case Studies in Software Refactoring
Software refactoring often requires applying a demonstrated transformation at multiple sites. For example, updating callers after extracting a helper requires adapting receivers, arguments, and surrounding code rather than copying an accepted edit.
5.1 Helper Refactoring Experiments
We construct multi-site editing tasks from Extract Method commits in SWE-Refactor (Xu et al., 2026b). Each task includes the extracted helper, accepted <old>/<new> demonstrations, and masked replacement sites. We evaluate 127 tasks from 50 commits across 14 repositories, with ; different configurations have different eligible commits (Section C.1). Frozen LLaDA-1.5 (Zhu et al., 2026) generates rewrites per task using either oracle lengths or lengths sampled from a separately trained Java predictor. We compare unguided sampling () with example guidance () on the same samples. We assess joint correctness using Claude Sonnet 5.5, without executing the generated code.
A separate post-hoc ablation on 80 tasks compares generation with and without one visible accepted edit, holding the other prompt components and oracle lengths fixed. Adding the demonstration improves joint LLM-judged success by 14.7 and 17.5 percentage points for J = 1 and J = 2, respectively (Section C.2). These gains indicate that the DLM can use a demonstrated refactoring to guide edits at other sites. Under unguided sampling, pooled joint success reaches 74.4% with oracle lengths but only 15.8% with predicted lengths (Table 1). This gap identifies length allocation as a major opportunity for improvement, even though the predictor outperforms a simple length prior (Figure 8, left). Example guidance at reduces success to 71.5% and 14.5%, respectively (Table 1). Thus, demonstrations help the DLM generate appropriate rewrites, but the additional likelihood-ratio reward does not improve their selection in this experiment.
5.2 Qualitative Analysis
The limited benefits of guidance may arise because the sampled rewrites offer little room for improvement, or because the reward fails to identify correct candidates. With oracle lengths, only 23 of 127 sample pools contain both judged-correct and judged-incorrect rewrites, so even a perfect selector could improve pooled success by at most 8.3 percentage points. With learned lengths, 72 of 127 pools contain both outcomes, and the corresponding upper bound rises to 45.2 points (Section C.3). Thus, limited selection opportunities help explain the oracle-length results, whereas learned-length sampling leaves substantial room for better selection.
A post-hoc Checkstyle example illustrates how the reward can favor an incorrect rewrite. An incorrect edit to logMessage changes the logged line number and message type, yet receives a higher example reward than the developer-consistent rewrite (8.69 versus 2.05 nats). At , this gives the incorrect rewrite approximately 28 times the resampling weight of each correct occurrence. Despite appearing only once among K = 16 samples, compared with seven occurrences of the correct rewrite, it receives 61.8% of the total weight, reducing expected LLM-judged success from 43.8% to 15.7%. Here, correct rewrites are available, but the reward disproportionately favors an incorrect one (Section C.3).
6 Conclusion
We introduce and study multi-target few-shot prompting with masked DLMs, where demonstrations guide the infilling of multiple regions within a shared canvas. One-token-at-a-time decoding with deterministic position selection defines a normalized distribution over complete infills, enabling exact sampling, scoring, and likelihood-based example guidance. Across few-shot prompting benchmarks and Java refactoring, we find that demonstrations improve infilling accuracy, with example guidance providing further gains in several settings. Our experiments further investigate the benefits of example guidance relative to likelihood sharpening, while identifying opportunities to improve target-length allocation for practical editing. Together, these findings provide a foundation for more effective example-guided multi-site infilling.
Limitations. Our framework assumes that target sites and demonstration-output positions E are specified in advance, leaving their automatic identification for future work. The deterministic, one-token-at-a-time decoding used for exact sampling and scoring does not exploit parallel generation, while the induced distribution may depend on the reveal order and model interface for learned DLMs. Moreover, target lengths must be allocated before infilling, making improved length prediction an important direction for practical use. Example guidance measures relative support from demonstrations rather than correctness, so its effectiveness depends on how the reward ranks sampled infills. Increasing guidance strength can also concentrate resampling weights without necessarily improving accuracy (Section B.5). Our experiments include an autoregressive comparison for single-target prompting, while systematic comparison for multi-target infilling remains future work. Finally, the Java refactoring study uses an LLM judge rather than code execution, includes commits examined during development, and contains some prompts in which reference text appears elsewhere in the context.
References
Marianne Arriola, Aaron Gokaslan, Justin T. Chiu, Zhihan Yang, Zhixuan Qi, Jiaqi Han, Subham Sekhar Sahoo, and Volodymyr Kuleshov. Block diffusion: Interpolating between autoregressive and diffusion language models. In International Conference on Learning Representations (ICLR), 2025.
Jacob Austin, Daniel D. Johnson, Jonathan Ho, Daniel Tarlow, and Rianne van den Berg. Structured denoising diffusion models in discrete state-spaces. In Advances in Neural Information Processing Systems (NeurIPS), 2021.
Mohammad Bavarian, Heewoo Jun, Nikolas Tezak, John Schulman, Christine McLeavey, Jerry Tworek, and Mark Chen. Efficient training of language models to fill in the middle. arXiv preprint arXiv:2207.14255, 2022.
BIG-bench authors. Beyond the imitation game: Quantifying and extrapolating the capabilities of language models. Transactions on Machine Learning Research, 2023.
Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In Advances in Neural Information Processing Systems (NeurIPS), 2020.
Zhoujun Cheng, Jungo Kasai, and Tao Yu. Batch prompting: Efficient inference with large language model APIs. In Conference on Empirical Methods in Natural Language Processing (EMNLP), Industry Track, 2023.
Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 conference of the North American chapter of the association for computational linguistics: human language technologies, volume 1 (long and short papers), pages 4171–4186, 2019.
Fangyu Ding, Ding Ding, Sijin Chen, Kaibo Wang, Peng Xu, Zijin Feng, Haoli Bai, Kai Han, Youliang Yan, Binhang Yuan, and Jiacheng Sun. Beyond masks: Efficient, flexible diffusion language models via deletion-insertion processes. In International Conference on Learning Representations (ICLR), 2026.
Daniel Fried, Armen Aghajanyan, Jessy Lin, Sida Wang, Eric Wallace, Freda Shi, Ruiqi Zhong, Wen-tau Yih, Luke Zettlemoyer, and Mike Lewis. InCoder: A generative model for code infilling and synthesis. arXiv preprint arXiv:2204.05999, 2022.
Quentin Fruytier, Anton Xue, Sanjay Shakkottai, and Sujay Sanghavi. PIG: Parallel inconsistency guidance for accelerating diffusion language models. arXiv preprint arXiv:2610.17375, 2026.
Yonggan Fu, Lexington Whalen, Abhinav Garg, Chengyue Wu, Maksim Khadkevich, Nicolai Oswald, Enze Xie, Daniel Egert, Sharath Turuvekere Sreenivas, Shizhe Diao, Chenhan Yu, Ye Yu, Weijia Chen, Sajad Norouzi, Jingyu Liu, Shiyi Lan, Ligeng Zhu, Jin Wang, Jindong
Jiang, Morteza Mardani, Mehran Maghoumi, Song Han, Ante Jukić, Nima Tajbakhsh, Jan Kautz, and Pavlo Molchanov. Nemotron-Labs-Diffusion: A tri-mode language model unifying autoregressive, diffusion, and self-speculation decoding. arXiv preprint arXiv:2607.05722, 2026.
Shivam Garg, Dimitris Tsipras, Percy Liang, and Gregory Valiant. What can transformers learn in-context? a case study of simple function classes. In Advances in Neural Information Processing Systems (NeurIPS), 2022.
Sumit Gulwani. Automating string processing in spreadsheets using input-output examples. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), 2011.
Priyanshu Gupta, Avishree Khare, Yasharth Bajpai, Saikat Chakraborty, Sumit Gulwani, Aditya Kanade, Arjun Radhakrishna, Gustavo Soares, and Ashish Tiwari. Grace: Language models meet code edits. In Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering, pages 1483–1495, 2023.
Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. In NeurIPS 2021 Workshop on Deep Generative Models and Downstream Applications, 2021.
Bumjun Kim, Dongjae Jeon, Moongyu Jeon, and Albert No. DAPD: Dependency-aware parallel decoding via attention for diffusion LLMs. In International Conference on Machine Learning (ICML), 2026.
Tomasz Korbak, Ethan Perez, and Christopher Buckley. RL with KL penalties is better viewed as Bayesian inference. In Findings of the Association for Computational Linguistics: EMNLP 2022, 2022.
Minae Kwon, Sang Michael Xie, Kalesha Bullard, and Dorsa Sadigh. Reward design with language models. In International Conference on Learning Representations (ICLR), 2023.
Xiang Lisa Li, Ari Holtzman, Daniel Fried, Percy Liang, Jason Eisner, Tatsunori Hashimoto, Luke Zettlemoyer, and Mike Lewis. Contrastive decoding: Open-ended text generation as optimization. In Annual Meeting of the Association for Computational Linguistics (ACL), 2023.
Zhengheng Li, Panrui Li, Xuyang Liu, and Puzhi Xia. Where to place the query? unveiling and mitigating positional bias in in-context learning for diffusion LLMs via decoding dynamics. arXiv preprint arXiv:2606.19349, 2026.
Jianzhe Lin, Maurice Diesendruck, Liang Du, and Robin Abraham. Batchprompt: Accomplish more with less. In International Conference on Learning Representations, volume 2024, pages 21590–21612, 2024.
Jingjing Liu, Scott Cyphers, Panupong Pasupat, Ian McGraw, and Jim Glass. A conversational movie search system based on conditional random fields. In Proceedings of INTERSPEECH, 2012.
Na Meng, Miryung Kim, and Kathryn S. McKinley. Systematic editing: Generating program transformations from an example. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), 2011.
Sewon Min, Xinxi Lyu, Ari Holtzman, Mikel Artetxe, Mike Lewis, Hannaneh Hajishirzi, and Luke Zettlemoyer. Rethinking the role of demonstrations: What makes in-context learning work? In Conference on Empirical Methods in Natural Language Processing (EMNLP), 2022.
Shen Nie, Fengqi Zhu, Zebin You, Xiaolu Zhang, Jingyang Ou, Jun Hu, Jun Zhou, Yankai Lin, Ji-Rong Wen, and Chongxuan Li. Large language diffusion models. In Advances in Neural Information Processing Systems (NeurIPS), 2025.
Sean O'Brien and Mike Lewis. Contrastive decoding improves reasoning in large language models. arXiv preprint arXiv:2309.09117, 2023.
Jingyang Ou, Shen Nie, Kaiwen Xue, Fengqi Zhu, Jiacheng Sun, Zhenguo Li, and Chongxuan Li. Your absorbing discrete diffusion secretly models the conditional distributions of clean data. In International Conference on Learning Representations (ICLR), 2025.
Chaoxu Pang, Yixuan Cao, Qiang Ding, and Ping Luo. Guideline learning for in-context information extraction. In Conference on Empirical Methods in Natural Language Processing (EMNLP), 2023.
Keqin Peng, Liang Ding, Yuanxin Ouyang, Meng Fang, Yancheng Yuan, and Dacheng Tao. Enhancing input-label mapping in in-context learning with contrastive decoding. In Annual Meeting of the Association for Computational Linguistics (ACL), 2025.
Rafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D Manning, Stefano Ermon, and Chelsea Finn. Direct preference optimization: Your language model is secretly a reward model. Advances in neural information processing systems, 36:53728–53741, 2023.
Joshua S. Rule. The child as hacker: Building more human-like models of learning. PhD thesis, Massachusetts Institute of Technology, 2020.
Subham Sekhar Sahoo, Marianne Arriola, Yair Schiff, Aaron Gokaslan, Edgar Marroquin, Justin T Chiu, Alexander Rush, and Volodymyr Kuleshov. Simple and effective masked diffusion language models. In Advances in Neural Information Processing Systems (NeurIPS), 2024.
Subham Sekhar Sahoo, Lingjie Chen, Khiem Pham, Jonathan Geuter, Chaitanya Dwivedi, Varad Pimpalkhute, Yash Akhauri, Alexander Moreno, Mikhail Yurochkin, Zhenting Wang, Mostafa Elhoushi, Nolan Dey, Shane Bergsma, Joel Hestness, John Thickstun, Eric Xing, and Zhengzhong Liu. Unlocking lossless speedups in LLMs via discrete diffusion. arXiv preprint arXiv:2609.04010, 2026.
Jiaxin Shi, Kehang Han, Zhe Wang, Arnaud Doucet, and Michalis K. Titsias. Simplified and generalized masked diffusion for discrete data. In Advances in Neural Information Processing Systems (NeurIPS), 2024a.
Weijia Shi, Xiaochuang Han, Mike Lewis, Yulia Tsvetkov, Luke Zettlemoyer, and Wen-tau Yih.
Trusting your evidence: Hallucinate less with context-aware decoding. In Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), 2024b.
Richard Shin and Benjamin Van Durme. Few-shot semantic parsing with language models trained on code. In Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), 2022.
Raghav Singhal, Zachary Horvitz, Ryan Teehan, Mengye Ren, Zhou Yu, Kathleen McKeown, and Rajesh Ranganath. A general framework for inference-time scaling and steering of diffusion models. In International Conference on Machine Learning (ICML), 2025.
Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D. Manning, Andrew Ng, and Christopher Potts. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 1631–1642, 2013.
Feifan Song, Yuxuan Fan, Xin Zhang, Peiyi Wang, and Houfeng Wang. Instantly learning preference alignment via in-context DPO. In Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), 2025.
Gilad Turok, Chris De Sa, and Volodymyr Kuleshov. DUEL: Exact likelihood for masked diffusion via deterministic unmasking. arXiv preprint arXiv:2603.01367, 2026.
Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. GLUE: A multi-task benchmark and analysis platform for natural language understanding. In Proceedings of the 2018 EMNLP Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP, pages 353–355, 2018.
Jerry Wei, Jason Wei, Yi Tay, Dustin Tran, Albert Webson, Yifeng Lu, Xinyun Chen, Hanxiao Liu, Da Huang, Denny Zhou, and Tengyu Ma. Larger language models do in-context learning differently. arXiv preprint arXiv:2303.03846, 2023.
Jiayi Wei, Greg Durrett, and Isil Dillig. Coeditor: Leveraging repo-level diffs for code auto-editing. In International Conference on Learning Representations, volume 2024, pages 28103–28125, 2024.
Esmeralda S. Whitammer, Zhen Wang, and Nebojsa Jojic. Coherence boosting: When your pretrained language model is not paying enough attention. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 8214–8236, 2022.
Chengyue Wu, Hao Zhang, Shuchen Xue, Zhijian Liu, Shizhe Diao, Ligeng Zhu, Ping Luo, Song Han, and Enze Xie. Fast-dLLM: Training-free acceleration of diffusion LLM by enabling KV cache and parallel decoding. In International Conference on Learning Representations (ICLR), 2026.
Haobo Xu, Sirui Chen, Yuanchen Bei, Lingjie Chen, Yuchen Yan, Dongqi Fu, Jingrui He, and Hanghang Tong. Predict, don't iterate: Efficient adaptive-length infilling for diffusion language models. arXiv preprint arXiv:2609.02108, 2026a.
Yisen Xu, Jinqiu Yang, and Tse-Hsun Chen. SWE-Refactor: A repository-level benchmark for real-world LLM-based code refactoring. arXiv preprint arXiv:2602.03712, 2026b.
Anton Xue, Litu Rout, Aditya Akella, Adam Klivans, Sujay Sanghavi, and Sanjay Shakkottai. dQwen3.5: Hybrid-attention diffusion language models. arXiv preprint arXiv:2609.20751, 2026.
An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, Chujie Zheng, Dayiheng Liu, Fan Zhou, Fei Huang, Feng Hu, Hao Ge, Haoran Wei, Huan Lin, Jialong Tang, Jian Yang, Jianhong Tu, Jianwei Zhang, Jianxin Yang, Jiaxi Yang, Jing Zhou, Jingren Zhou, Junyang Lin, Kai Dang, Keqin Bao, Kexin Yang, Le Yu, Lianghao Deng, Mei Li, Mingfeng Xue, Mingze Li, Pei Zhang, Peng Wang, Qin Zhu, Rui Men, Ruize Gao, Shixuan Liu, Shuang Luo, Tianhao Li, Tianyi Tang, Wenbiao Yin, Xingzhang Ren, Xinyu Wang, Xinyu Zhang, Xuancheng Ren, Yang Fan, Yang Su, Yichang Zhang, Yinger Zhang, Yu Wan, Yuqiong Liu, Zekun Wang, Zeyu Cui, Zhenru Zhang, Zhipeng Zhou, and Zihan Qiu. Qwen3 technical report. arXiv preprint arXiv:2505.09388, 2025.
Jiacheng Ye, Zhihui Xie, Lin Zheng, Jiahui Gao, Zirui Wu, Xin Jiang, Zhenguo Li, and Lingpeng Kong. Dream 7B: Diffusion large language models. arXiv preprint arXiv:2508.15487, 2025.
J.D. Zamfirescu-Pereira, Richmond Y. Wong, Bjoern Hartmann, and Qian Yang. Why Johnny can't prompt: How non-AI experts try (and fail) to design LLM prompts. In ACM CHI Conference on Human Factors in Computing Systems (CHI), 2023.
Andrew Zhang, Anushka Sivakumar, Chia-Wei Tang, and Chris Thomas. Flexible-length text infilling for discrete diffusion models. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 31344–31359, 2025.
Zihao Zhao, Eric Wallace, Shi Feng, Dan Klein, and Sameer Singh. Calibrate before use: Improving few-shot performance of language models. In International Conference on Machine Learning (ICML), 2021.
Tianshi Zheng, Yixiang Chen, Chengxi Li, Chunyang Li, Qing Zong, Haochen Shi, Baixuan Xu, Yangqiu Song, Ginny Y. Wong, and Simon See. The curse of CoT: On the limitations of chain-of-thought in in-context learning. Transactions on Machine Learning Research, 2025a.
Tianshi Zheng, Jiayang Cheng, Chunyang Li, Haochen Shi, Zihao Wang, Jiaxin Bai, Yangqiu Song, Ginny Y. Wong, and Simon See. LogiDynamics: Unraveling the dynamics of inductive, abductive and deductive logical inferences in LLM reasoning. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2025b.
Yongchao Zhou, Andrei Ioan Muresanu, Ziwen Han, Keiran Paster, Silviu Pitis, Harris Chan, and Jimmy Ba. Large language models are human-level prompt engineers. In International Conference on Learning Representations (ICLR), 2023.
Fengqi Zhu, Rongzhen Wang, Shen Nie, Xiaolu Zhang, Chunwei Wu, Jun Zhou, Yankai Lin, Ji-Rong Wen, and Chongxuan Li. LLaDA 1.5: Variance-reduced preference optimization for large language diffusion models. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 11425–11460, 2026.
A Proofs
We prove the one-token-at-a-time decoding and reward-guidance results of Section 3, then extend the construction to unknown target lengths.
A.1 One-Token-at-a-Time Decoding
Lemma A.1 (One-token-at-a-time decoding). For any deterministic one-token-at-a-time position-selection policy, Equation (2) defines a normalized distribution that can be sampled and scored exactly. If the DLM predicts exact data conditionals, then recovers the conditional data distribution wherever defined, independently of the reveal policy (Ou et al., 2025).
Proof of Theorem 3.1. Fix a canvas and a designated set of masked target positions. Let denote the initially visible positions, so that any masked positions outside remain unresolved. We consider a deterministic decoding policy that selects one unrevealed target position based on the current canvas, then samples its token from the DLM. For any complete assignment , replaying this policy determines a unique sequence of selected positions , which may depend on previously revealed tokens.
Normalization and exact sampling. Consider a decision tree representing all possible decoding trajectories. Each node corresponds to a partially revealed canvas, and the decoding policy selects the next target position to reveal. The outgoing edges correspond to the possible tokens at that position, with probabilities given by the DLM that sum to one. Since the policy is deterministic and eventually reveals every target position, each complete assignment corresponds to exactly one leaf. The probability of reaching that leaf is the product of its edge probabilities, precisely in Equation (2). Summing the probabilities of all leaves therefore gives
Thus, is a normalized distribution, and sequential decoding samples exactly from it. Moreover, replaying the policy on any candidate recovers its reveal trajectory and permits exact evaluation of .
Recovery of the data conditional distribution. Now suppose the DLM predicts exact data conditionals, and let be a clean sequence. We assume that the initially visible context has positive probability, . For a fixed candidate , define the agreement events as follows:
Thus, is the event that a clean data sample agrees with the visible context and the first s revealed tokens of u. Because the reveal policy selects using only previously revealed information, the exact-conditional assumption implies
whenever .
If , multiplying these conditional probabilities yields a telescoping product:
The final equality holds because specifies every target token in addition to the initially visible context.
If instead , let be the first step at which . The preceding event has positive probability, so the corresponding DLM conditional assigns probability zero to . Consequently, , matching the data conditional. Thus, the equality holds for every complete assignment , independently of the reveal policy.
The argument covers prescribed orders and deterministic adaptive policies, including confidence-based position selection performed before sampling each token. It also allows masked positions outside the designated targets T to remain unresolved, as in the demonstration-masked likelihood . Randomized position selection may require marginalizing over multiple reveal trajectories, while parallel token revelation is outside the present construction.
A.2 Reward Guidance and Importance Resampling
Proposition A.2 (Reward guidance and importance sampling). Let and be positive distributions on a common finite candidate space, and let . The distribution defined by Equation (4) uniquely solves
Moreover, the weighted empirical distribution obtained from independent samples of using Equation (5) converges almost surely to in total variation as .
Proof of Theorem 3.2. Variational characterization. Since and are positive distributions on the finite candidate space , the reward is finite and the normalizing constant satisfies
For any distribution Q on U, substituting into the definition of KL divergence gives
Since KL divergence is nonnegative and vanishes only when its arguments agree, the objective in Equation (6) is uniquely maximized by . In particular, setting recovers .
Importance-resampling consistency. Let be independent candidates sampled from . Given this proposal pool, the resampling procedure in Equation (5) induces a weighted empirical distribution . For any completion , its probability of being selected is
The numerator accumulates the weights of all proposals equal to v, including repeated occurrences, while the denominator normalizes the weights across the pool.
By the strong law of large numbers, the numerator converges almost surely to , while the denominator converges almost surely to . Their ratio therefore converges to
Since the candidate space U is finite, this convergence holds simultaneously for every completion. Consequently,
which establishes convergence in total variation.
This guarantee is asymptotic and provides no finite-K error bound. It also does not imply that higher example reward corresponds to greater correctness.
A.3 Extension to Unknown Lengths
With unknown target lengths, each complete candidate consists of a length allocation and an assignment to its expanded target positions. Let denote the finite support of the length allocator . For every , Theorem 3.1 ensures that the conditional infill distributions and are normalized over . Since the length allocator is also normalized, both joint distributions in Equation (7) are normalized. Assuming their conditional infill probabilities are positive, the joint distributions satisfy the assumptions of Theorem 3.2 on their common support. Moreover, the shared allocator cancels from the likelihood ratio, giving
Thus, reward guidance and importance resampling extend directly to joint length-content candidates.
Although the allocator cancels from each candidate’s reward, guidance can still change the distribution over selected lengths. To see this, define the length-specific normalizing constant
The overall normalizer and the marginal guided length distribution then satisfy
Hence, length allocations with larger receive greater relative probability under guidance, even though the allocator itself is unchanged. The argument does not require to match the data length distribution or to factorize across target sites; oracle lengths correspond to a single supported allocation.
B Few-Shot Prompting Experiments
This appendix documents the experiments of Section 4 and provides additional analyses of demonstration conditioning, example guidance, and length allocation.
B.1 Experimental Setup
Benchmarks. We study four types of few-shot transformations: classification, list transformation, artificial-language transformation, and information extraction. For SST-2 (Socher et al., 2013; Wang et al., 2018), sentiment labels are replaced by two resampled single-token capital-letter codes; the first two demonstrations cover both classes, and answers are graded by exact code match. List Functions–Easy (BIG-bench authors, 2023; Rule, 2020) uses 85 unconditional functions adapted from BIG-bench List Functions; the transformation rule is hidden, and parsed integer lists are matched exactly. SALT repetition (Zheng et al., 2025a,b) uses categories 5–6 with a separate dictionary for each example to translate words and repeat each verb or adjective; generated pairs pass an executable-rule check, and outputs are matched exactly. Movie Director (Liu et al., 2012; Zhao et al., 2021) extracts the Director field from audited MIT Movie queries without naming the field in the instruction; labels are fixed, and outputs are graded by exact string match.
Experimental studies. We use three separately sampled studies with frozen models: a single-target demonstration sweep across four benchmarks and four model interfaces (J = 1, K = 64); a List Functions–Easy grid across three DLMs (K = 16); and a cross-benchmark target-count sweep across four benchmarks and three DLMs (D = 4, K = 64). Each K specifies the number of samples per canvas, and the studies are analyzed separately.
Prompt families. For single-target prompting, we draw 16 demonstrations followed by one target, then retain the first demonstrations to construct five canvases with the same target. For multi-target prompting, we draw 16 demonstrations and eight targets. We first randomly interleave four demonstrations and eight targets (12 items), then extend this sequence with the remaining 12 demonstrations (24 items), preserving the relative order of the original items. Each canvas retains the first demonstrations and first targets in that order. The canvases from one draw form a prompt family; all evaluation examples come from sources disjoint from development.
Model interfaces and decoding. LLaDA-1.5 (Zhu et al., 2026) and dQwen3.5-9B-Base (Xue et al., 2026) directly infill masked canvases. Nemotron-Labs-Diffusion-8B (Fu et al., 2026) was trained with limited bidirectional diffusion blocks, so we use a fixed-length causal suffix for the single-target sweep and a causal prefix with a bidirectional tail for both target-count studies, including J = 1. Qwen3-8B (Yang et al., 2025) provides a free-length causal-continuation comparison for single targets only. DLMs reveal one target token at a time in ascending canvas order for both generation and likelihood scoring, using oracle lengths except in Section 4.3.
Sampling, scoring, and statistics. We sample at token temperature one, retain duplicate infills, and reuse each sample pool for unguided and guidance-weighted evaluation. The scores keep demonstration outputs visible, while masks them for DLMs or removes them from causal prompts; sampled contents, target lengths, and reveal orders are unchanged. Malformed outputs count as incorrect, and we average and across prompt families with unadjusted 95% paired family-bootstrap intervals from 10,000 resamples. Main guidance comparisons use , while length-allocation experiments use .
Example prompts. The following show one , logical prompt per benchmark, omitting model-specific chat tokens. [MASKED TARGET] denotes an oracle-length mask span for DLMs, while causal generation starts after the target's Output:: reference answers are shown only to the reader.
| SST-2 with demonstration-defined codes | |
|---|---|
| User:Each input is followed by its output code. Produce the output code for the final input. | |
| Assistant:Input: an uninspired preachy and clichéd warOutput: F | |
| Input: miraculous as its dreamworks makersOutput: E | |
| Input: a skillful filmmaker can impart a message without bludgeoning the audience over the headOutput: [MASKED TARGET] | |
| E | Reference (hidden from model) |
| List Functions—Easy | |
|---|---|
| User:Apply the transformation illustrated by the examples. | |
| Assistant:Input: [7, 8, 4, 9, 6, 0, 5]Output: [5, 0, 6, 9, 4, 8, 7] | |
| Input: [9, 3, 5, 1, 6, 2, 4]Output: [4, 2, 6, 1, 5, 3, 9] | |
| Input: [2, 7, 8]Output: [MASKED TARGET] | |
| [8, 7, 2] | Reference (hidden from model) |
| SALT repetition: repeat every verb | |
|---|---|
| User:Below are several examples that convert english sentence into an output sequence based on specific rules.Each word in the input sequence either corresponds to a translated word in the output, or indicates a syntactic rule (e.g., repeating or reordering semantic units) for forming the output sequence. | |
| Assistant:Input: flower bloom bee | |
Output: ngq mqh mqh owx
Input: bee pollinate seed colorful Output: owx zkl zkl qqn yil
Input: pollinate colorful seed Output: [MASKED TARGET]
zkl zkl yil qqn
Reference (hidden from model)
Movie Director extraction
User: Extract the same kind of information as in the examples. Copy the answer exactly from the input. Return only the answer.
Assistant: Input: barbara stanwyck played a wicked scheming woman duping an insurance company in cahoots with ↔ fred macmurray in this classic 1944 film noir directed by billy wilder Output: billy wilder
Input: what s the woody allen movie where owen wilson finds himself going back in time and meeting ↔ famous people Output: woody allen
Input: what 2005 ron howard biopic tells the story of james braddock a washed up boxer who came ↔ back to become a champion Output: [MASKED TARGET]
ron howard
Reference (hidden from model)
B.2 Single-Target Experiments
To examine why additional demonstrations improve unguided accuracy in Section 4.1, we measure how their presence changes the likelihood of the reference answer. For each prompt family, we retain the same target as grows and evaluate the reference completion under both demonstration contexts. We report its example reward per target token:
This is equivalently the reduction in reference-answer negative log likelihood per token when demonstration outputs become visible. The reward generally increases with , indicating that additional demonstrations provide greater relative support for the reference answer. Because masks demonstration outputs for DLMs but removes them from causal prompts, reward magnitudes are not directly comparable across these interfaces.
Greater support for a reference answer does not, however, guarantee a larger gain from guidance. At , SST-2 exposes only one class code, while a single List Functions or SALT demonstration may be compatible with several rules. At larger , unguided accuracy can approach saturation, leaving less room for additional improvement. Moreover, guidance depends on how the reward ranks the sampled alternatives, not only on its value for the reference answer.

Figure 9: Reference-token NLL under and by reveal position (cross-benchmark study, J = 8). Previously revealed reference targets are visible in both contexts, and the gap between their subsequent reference-token scores generally narrows. This diagnostic follows reference assignments, not sampled decoding trajectories.
B.3 Multi-Target Experiments
Section 4.2 shows that the effects of example guidance vary with the number of jointly infilled targets. We investigate this behavior with two additional analyses: a reference-likelihood diagnostic that follows successive targets, and a separate cross-benchmark target-count study. The latter uses D = 4 and K = 64 samples per canvas, rather than the K = 16 pools of the main List Functions–Easy grid.
Reference-likelihood diagnostic. Previously revealed targets may supply information that would otherwise come from the demonstrations. To examine this possibility, we evaluate the reference tokens in reveal order with D = 4 and J = 8, making each preceding reference target visible under both and while keeping demonstration outputs masked under . In Figure 9, the gap between subsequent reference-token negative log likelihoods generally narrows as more targets are revealed.
Cross-benchmark target-count study. The main study uses only List Functions-Easy, so we also examine whether its guidance trends hold across other tasks. In this separate experiment, three DLMs are evaluated on four benchmarks at , , and (Figure 10). At , guidance at improves on SST-2, decreases it on Movie Director, is nearly neutral on List Functions-Easy, and varies by model on SALT. Thus, the reduced guidance benefits observed on List Functions-Easy do not hold uniformly across tasks.
B.4 Length Allocation
Predictor architecture. To evaluate infilling without oracle target lengths, we train length predictors using frozen DLM representations, following Xu et al. (2026a). Each compact prompt contains one placeholder per target, whose hidden state before the final transformer block is passed through a trainable copy of that block and its final normalization. For LLaDA-1.5

Figure 10: Cross-benchmark target-count study at the common guidance strength. Top: unguided all-target accuracy ; bottom: its change under example guidance at , which varies by task at J = 8. D = 4, K = 64 samples per canvas, oracle lengths, three DLMs, and 64 prompt families per cell; bands are unadjusted 95% family-bootstrap intervals.
this is block 31 of 32 with ; for Nemotron it is layer 33 of 34 with encoder.norm; and for dQwen3.5 it is layer 31 of 32 with model.norm. A categorical head predicts lengths in independently across sites, conditional on the compact prompt. Only the length predictor is trained, using prompt-normalized cross-entropy on the reference token lengths under each backbone's tokenizer; the original DLM remains frozen and jointly infills the allocated targets.
Training protocol. Training draws from a 70/30 mixture of structured few-shot prompts (100,000 from MIT-Movie, ATIS, List Functions, and SALT) and Java editing episodes (22,128 from 28 repositories, split 21/4/3 by repository). We exclude evaluation source units, all 85 List Functions–Easy rules, SALT categories 5–6, the MIT-Movie Director field, and all 18 SWE-Refactor repositories. The Java predictor used in Section 5 is trained separately (Section C.2). For optimization, we use AdamW with weight decay 0.01, learning rates for the copied block and normalization and for the categorical head. We train for 1,563 steps with 64 draws per update, 5% warm-up, cosine decay, evaluating the final checkpoint.
Length fidelity. For a target with reference length , we measure the predictor's probability mass within tokens of that length:
We average over evaluation targets and prompt families; measures probability assigned to the reference length, not the accuracy of the most likely prediction. Across backbones and target

LLaDA-1.5 Nemotron prefix/tail dQwen3.5 95 % family bootstrap
Figure 11: Guidance-strength sensitivity on List Functions–Easy (cross-benchmark study). Change in from at J = 1 and J = 4 (left), and mean , the entropy-based effective fraction of sampled draws (right). Each strength reweights the same D = 4, K = 64 sample pools, with duplicates retained and oracle lengths; Nemotron uses a causal prefix and bidirectional tail even at J = 1. Bands are unadjusted 95% paired family-bootstrap intervals from 10,000 resamples.
counts, and , versus approximately 27% exact-length mass from a prior based on four demonstration-output lengths.
Downstream evaluation. On List Functions–Easy, we fix , vary , and compare oracle lengths with sampled predictor lengths using the same content decoder and samples per canvas at . Predicted lengths retain 35–48% of oracle-length per-target accuracy (Figure 7, top). To assess sensitivity separately from the predictor's own errors, we impose for (Figure 7, bottom), skipping a prompt family at any for which some ; these forced offsets do not represent lengths sampled from the predictor.
B.5 Guidance-Strength Sensitivity
We examine whether increasing the guidance strength improves accuracy or instead concentrates resampling weights on fewer samples. Using stored cross-benchmark List Functions–Easy pools with , we compare at over 64 prompt families per cell, reweighting the same samples for . To describe weight concentration, define the entropy and entropy-based effective fraction of the normalized sample weights :
The fraction measures concentration over sampled draws, counting duplicates separately, rather than diversity among distinct completions. Figure 11 compares its mean against gains in relative to .
For a single target, every tested improves mean for all three DLMs (intervals exclude zero except for LLaDA at ). Gains peak near for LLaDA and dQwen3.5 (+5.2 and +10.3 percentage points), while Nemotron reaches +18.0 points at . With four targets,

Figure 12: Likelihood sharpening with the same total exponent in the grid. Top: gain in from sharpening alone (sample weights , resulting distribution ); bottom: example guidance minus sharpening (negative values favor sharpening). Both reweight the sample pools of Figure 6; bands are unadjusted 95% family-bootstrap intervals.
however, gains reach at most +3.3 points at and then diminish or reverse, reaching -2.6 to -9.6 points at (intervals exclude zero for Nemotron and dQwen3.5).
Weight concentration alone does not appear to explain these accuracy trends. When accuracy deteriorates at , remains 0.48–0.71, whereas single-target accuracy still improves at comparable fractions (0.62–0.73 at ). Four-target rewards also span roughly four times as many tokens and are more dispersed, so this comparison does not isolate target count as the cause.
B.6 Likelihood Sharpening
Some gains from example guidance could reflect sharpening of the demonstration-conditioned likelihood , rather than the additional information in the reward. To separate these effects, we compare example guidance with likelihood sharpening that uses the same total exponent on . At , the guided distribution, the sharpening distribution, and the sample weights for sharpening are
Both methods reweight the same samples without additional sampling or tuning. The comparison matches the exponent, but not necessarily weight concentration or a separately tuned decoding temperature.
Likelihood sharpening explains much of the improvement from guidance, although the example-dependent reward provides an additional gain in one setting. For LLaDA with a single target at , guidance improves over sharpening by +3.6 percentage points ([+0.4, +6.9]) on SST-2; no other single-target task shows a positive residual. In the List Functions–Easy grid, sharpening improves for every and outperforms guidance in every cell with (Figure 12). These comparisons distinguish the gains attributable to likelihood sharpening from the additional contribution of the example-dependent reward.
C Software Editing Experiments
We describe the Java refactoring benchmark and evaluation, then analyze demonstration conditioning, length allocation, and example guidance.
C.1 Benchmark Construction and Evaluation Setup
We derive multi-site editing tasks from Extract Method commits in SWE-Refactor (Xu et al., 2026b), which provide before-and-after snapshots and extracted helpers. For each (repository, commit, file, helper) group, we identify updated callers and represent each minimal changed region as a <old>/<new> pair. A seeded file-order rule assigns accepted edits as demonstrations and remaining sites as targets. Eligibility rules fixed before inspecting outcomes exclude edits requiring identifiers or literals absent from the prompt or changing asserted values. We also limit replacements to 80 LLaDA tokens and enclosing methods to 200 lines, retain one helper per commit and file, and collapse mirrored commits. The resulting benchmark contains 127 tasks from 50 commits across 14 repositories, with and at most one task per group and configuration. Because eligible commits differ across configurations, comparisons across in Table 1 do not isolate the effect of demonstration or target count; results are aggregated and bootstrapped by commit.
The figure is an excerpt: actual prompts include instructions, chat framing, and additional context from the accepted after-file, with target edits reverted and context cropped to the helper and enclosing methods. For , only changed-line tokens of demonstration outputs are masked.
Evaluation procedure. Frozen LLaDA-1.5 (Zhu et al., 2026) generates K = 16 rewrites per task under each length setting; unguided sampling and example guidance use the same stored samples. We use Claude Sonnet 5.5 (claude-sonnet-5-5) as a Claude Code sub-agent, with a fixed judging rubric and fresh context per call. Each judging packet contains the helper and its Javadoc, accepted demonstrations, and target methods with candidate rewrites inserted, but excludes developer references, generation settings, length allocations, and model scores. The judge assesses whether the edits adapt receivers, arguments, and control flow while plausibly preserving behavior; equivalent rewrites may pass, while incomplete or erroneous edits fail. Joint success requires every target to be judged correct; uncertain judgments count as failures, and ill-posed packets remain in the evaluation. Duplicate candidate texts are judged once per task, but duplicate draws remain in the sample pools; we report unadjusted 95% paired commit-bootstrap intervals. We do not compile or execute the generated code.
Judge checks and limitations. The 4,064 generated draws yielded 2,089 distinct judging packets after deduplication within tasks, including across length settings. The judge classified
One editing canvas Checkstyle 21c8e04bc9, D=1, J=2
Provided context Helper definition private static boolean isChildNodeTextMatches( DetailNode ast, Pattern pattern) { return getFirstChildOfType(ast, JavadocTokenTypes.TEXT, 0) .map(DetailNode::getText) .map(pattern::matcher) .map(Matcher::matches) .orElse(false); }
Accepted edit (demonstration) private static boolean isExamplesText( DetailNode ast) { <old> final Optional<DetailNode> resultNode = getFirstChildOfType(ast, JavadocTokenTypes.TEXT, 0); return resultNode.isPresent() && EXAMPLES_TAG.Matcher( resultNode.get().getText().matches(); </old> <new> return isChildNodeTextMatches( ast, EXAMPLES_TAG); </new> }
Sites to complete Target 1 private static boolean isPropertyList( DetailNode nodeLi) { <old> final Optional<DetailNode> firstTextChildToken = → getFirstChildOfType(nodeLi, JavadocTokenTypes.TEXT, 0); return firstTextChildToken.isPresent() && PROPERTY_TAG.Matcher( firstTextChildToken.get() .getText().matches(); </old> <new>[MASKED TARGET]</new> }
Target 2 private static boolean isViolationMessagesText( DetailNode nodeParagraph) { <old> final Optional<DetailNode> resultNode = getFirstChildOfType(nodeParagraph, JavadocTokenTypes.TEXT, 0); return resultNode.isPresent() && VIOLATION_MESSAGES_TAG.Matcher( resultNode.get().getText().matches(); </old> <new>[MASKED TARGET]</new> }
Target 1: return isChildNodeTextMatches(nodeLi, PROPERTY_TAG); Reference (hidden from model) Target 2: return isChildNodeTextMatches(nodeParagraph, VIOLATION_MESSAGES_TAG);
Figure 13: One editing canvas from a Checkstyle refactoring. An accepted edit introduces a helper call, and two masked targets must adapt it to their local arguments. Both columns belong to the same prompt; hook arrows indicate visual line wraps.
all 46 blinded validation cases as expected, and ten repeated judgments agreed, although these checks do not replace execution-based evaluation. Its inherited agent context contained brief summaries of earlier Section 5 results, but no packet-specific labels; judge sampling parameters were not explicitly set or recorded. All 50 source commits were examined during development, and some prompts contain target-reference text elsewhere in the helper or demonstrations, so this study is not a held-out evaluation.
C.2 Demonstration Conditioning and Length Allocation
Demonstration ablation. To measure the effect of demonstration conditioning, we compare and on the same 80 editing tasks (52 with , 28 with ) in a post-hoc ablation. Both conditions share the helper, target sites, oracle lengths, chat framing, , and unguided sampling (). They use the instruction: “Complete each target <new> span by applying the intended refactoring using the helper shown in the source context; use any accepted before/after edits if provided." Only demonstration visibility changes during generation; the judge sees the accepted edit in both conditions.
Adding one demonstration improves joint LLM-judged success by 14.7 percentage points for ([+5.8, +24.5]) and 17.5 points for ([+4.7, +32.5]). The estimated gain is smaller on commits outside the narrower LLaDA development subset (+5.3 points, [-1.0, +13.9]). The ablation was designed after inspecting the main results but fixed before collecting its own outcomes; its instruction differs from the main experiment, so absolute success rates are not directly comparable.
Java length predictor. We train a Java-specific length predictor using the LLaDA-1.5 architecture and objective of Section B.4, with edits from 21 training and four development repositories in the 28-repository corpus; the remaining three repositories and all SWE-Refactor repositories are excluded. Training prompts contain an optional helper declaration, D accepted <old>/<new> demonstrations, and J targets with visible <old> spans and one placeholder per missing <new> span. We use seeded, disjoint site assignments, retain up to 20 context lines before and 12 after each edit, and exclude empty replacements, lengths above 256 tokens, and prompts exceeding 2,048 tokens. Reference lengths are withheld from the inputs, with prompt-invariance checks to detect leakage. This yields helper-only and all-multi-site corpora with 1,887/370 and 13,543/3,598 training/development prompts, respectively, where the latter includes the former. Training alternates between the corpora equally for 313 updates (batch size 64, 16 warm-up updates, cosine decay), with other settings following Section B.4. We also train an alternative on the all-multi-site corpus alone and select by exact-length probability mass on 488 helper-only development targets (0.0664 versus 0.0660), although within-two-token mass would favor the alternative (0.317 versus 0.328); SWE-Refactor outcomes are not used for selection.
Length evaluation. At evaluation, the selected predictor runs once per task and independently samples target lengths for each of K = 16 rewrites, without temperature adjustment or truncation. Oracle lengths equal the developer-reference token counts; 3.3% of predicted per-target lengths exceed the benchmark's 80-token reference-length eligibility limit. We compare length fidelity against the empirical distribution of 2,467 replacement lengths in the helper-only training corpus, distinct from the demonstration-length prior in Section 4.3. Across 80 unique target sites, the predictor assigns 26.7% probability mass within two tokens of the reference length ([20.1, 33.8]), compared with 15.2% for this prior; exact-length mass is 6.8% versus 3.1%. However, only 6.2% of learned-length joint samples allocate every target exactly. Among learned-length samples, 95% with exact joint allocations are judged correct, compared with 13% for near-but-incorrect allocations and 8% otherwise. These descriptive associations help explain the large oracle-versus-learned accuracy gap in Table 1, while highlighting the importance of accurate joint length allocation.
C.3 Example Guidance and Failure Analysis
Example guidance at reduces pooled LLM-judged joint success by 2.9 percentage points with oracle lengths ( ) and 1.3 points with learned lengths ( ); Table 1 reports the configuration-specific results. The oracle-length decline also persists in the prespecified
Table 1: Joint LLM-judged success (%) by configuration, with samples per editing task and length setting and learned lengths sampled from the Java predictor. Differences are in percentage points, with unadjusted 95% paired commit-bootstrap intervals. The pooled row weights 50 commits equally and is not the mean of the four configuration rows.
| Commits/tasks | Oracle lengths | Learned lengths | Learned-oracle at | |||||
|---|---|---|---|---|---|---|---|---|
| Difference | Difference | |||||||
| (1,1) | 50/52 | 76.1 | 72.9 | -3.2 [-5.9, -0.8] | 17.3 | 17.1 | -0.2 [-3.4, +3.9] | -58.9 [-68.1, -49.5] |
| (1,2) | 26/28 | 74.9 | 72.7 | -2.2 [-4.7, -0.2] | 9.4 | 4.7 | -4.6 [-8.9, -1.3] | -65.5 [-79.8, -50.5] |
| (2,1) | 26/28 | 92.7 | 90.4 | -2.2 [-6.9, +0.9] | 21.2 | 18.6 | -2.5 [-9.3, +5.9] | -71.5 [-82.6, -59.1] |
| (2,2) | 17/19 | 82.7 | 84.5 | +1.8 [0.0, +5.2] | 9.2 | 9.6 | +0.4 [-5.2, +8.0] | -73.5 [-88.4, -56.6] |
| Pooled | 50/127 | 74.4 | 71.5 | -2.9 [-5.4, -0.6] | 15.8 | 14.5 | -1.3 [-3.8, +1.6] | -58.6 [-67.4, -49.6] |
sensitivity population (-3.3 points, [-6.1, -1.1]) and among 30 commits outside the narrower LLaDA development subset (-3.1 points, [-6.7, -0.1]).
Selection helps only when a sample pool contains both correct and incorrect rewrites. Among 127 oracle-length pools, 87 contain only judged-correct samples, 17 only incorrect samples, and 23 both; the corresponding counts with learned lengths are 0, 55, and 72. Selecting a correct rewrite whenever one is available could therefore improve pooled success by at most 8.3 points with oracle lengths, versus 45.2 points with learned lengths. Even within the 23 mixed oracle-length pools, guidance lowers expected success from 62.0% to 50.5% (-11.5 points, [-19.7, -3.1]); this is a post-hoc comparison on an outcome-selected subset.
A post-hoc Checkstyle example (commit b142dda472, distinct from Figure 13) illustrates how the reward can favor an incorrect rewrite. The developer-consistent rewrite of logMessage preserves the logged line number and MSG_DUPLICATE_REGEXP, whereas an incorrect rewrite changes both, yet receives a higher reward (8.69 versus 2.05 nats). The following code excerpts omit the enclosing method's closing braces.
Developer's rewrite
7 of 16 draws
final String msg = getMessage(); if (illegalPattern) { log(lineNumber, MSG_ILLEGAL_REGEXP, msg); } else { log(lineNumber, MSG_DUPLICATE_REGEXP, msg); }
Incorrect rewrite
1 of 16 draws
final String msg = getMessage(); if (illegalPattern) { log(lineNumber - 1, MSG_ILLEGAL_REGEXP, msg); } else { log(lineNumber, MSG_REQUIRED_REGEXP, msg); }
At , the reward difference gives each occurrence of approximately 28 times the resampling weight of an occurrence of . The single incorrect draw consequently receives 61.8% of the total weight, compared with 15.7% across the seven correct draws, lowering expected LLM-judged success from 43.8% to 15.7%. Nevertheless, the ideal guided distribution favors over in their pairwise comparison:
The original sampling distribution favors by a much larger margin than the observed七十-to-one draw count; finite-pool resampling therefore reverses this pairwise preference. These ratios compare only the two displayed rewrites, not the total probability of a correct edit.
D Additional Discussion
Broader impacts. Multi-target few-shot prompting could enable example-guided document and code editing across multiple sites. Practical use will require more reliable adherence to demonstrations and better prediction of output lengths. With these improvements, users could specify transformations through a few examples rather than editing each site manually.
Potential risks. Incorrect transformations can propagate across sites, altering document meaning or introducing software defects. Our Checkstyle case study shows that example guidance can favor an incorrect edit even when demonstrations support the intended transformation. Practical use requires review, including compilation and testing for code; our evaluation instead relies on an LLM judge without execution.
Artifacts and licensing. The models are released under MIT (LLaDA 1.5), Apache 2.0 (dQwen3.5 and Qwen3), and the NVIDIA Open Model License (Nemotron-Labs-Diffusion). The BIG-bench and SALT repositories use Apache 2.0 and MIT, respectively; SWE-Refactor is marked CC BY 4.0, but its underlying Java files retain their upstream licenses. We could not verify uniform redistribution terms for SST-2 or MIT Movie, so we do not assume unrestricted redistribution rights.
Compute. All experiments use 8–9B-parameter models on NVIDIA H100 NVL (96 GB) GPUs, one model per GPU; only the length predictors are trained. Run logs suggest fewer than 100 H100 GPU-hours, although cumulative GPU time was not tracked separately.
AI usage. We used generative AI assistants for literature exploration, manuscript drafting and revision, and code and figure preparation. The authors remain responsible for the methods, citations, results, and final text. Separately, Claude Sonnet 5.5 was used to judge software edits under the experimental protocol of Section 5.1.