Manuscript Offprint

arXiv:2610.22294

Multi-Target Few-Shot Prompting with Diffusion Language Models

Anton Xue, Alan Li, Rahul Saha

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.

References (92)

  • Block diffusion: Interpolating between autoregressive and diffusion language models
  • Structured denoising diffusion models in discrete state-spaces
  • Efficient training of language models to fill in the middle (opens arXiv in a new tab)
  • Language models are few-shot learners
  • Batch prompting: Efficient inference with large language model APIs
  • BERT: Pre-training of deep bidirectional transformers for language understanding
  • Beyond masks: Efficient, flexible diffusion language models via deletion-insertion processes
  • InCoder: A generative model for code infilling and synthesis (opens arXiv in a new tab)
  • PIG: Parallel Inconsistency Guidance for Accelerating Diffusion Language Models
  • Nemotron-Labs-Diffusion: A tri-mode language model unifying autoregressive, diffusion, and self-speculation decoding (opens arXiv in a new tab)
  • What can transformers learn in-context? a case study of simple function classes
  • Grace: Language models meet code edits
  • Classifier-free diffusion guidance
  • Dependency-aware parallel decoding via attention for diffusion LLMs
  • RL with KL penalties is better viewed as Bayesian inference
  • Reward design with language models
  • Contrastive decoding: Open-ended text generation as optimization
  • Where to place the query? unveiling and mitigating positional bias in in-context learning for diffusion LLMs via decoding dynamics (opens arXiv in a new tab)
  • Batchprompt: Accomplish more with less
  • A conversational movie search system based on conditional random fields
  • Systematic editing: Generating program transformations from an example
  • Rethinking the role of demonstrations: What makes in-context learning work? In Conference on Empirical Methods in Natural Language Processing (EMNLP), 2022
  • Large language diffusion models
  • Contrastive decoding improves reasoning in large language models (opens arXiv in a new tab)
  • Your absorbing discrete diffusion secretly models the conditional distributions of clean data
  • Guideline learning for in-context information extraction
  • Enhancing input-label mapping in in-context learning with contrastive decoding
  • Direct preference optimization: Your language model is secretly a reward model
  • Simple and effective masked diffusion language models
  • Unlocking Lossless Speedups in LLMs via Discrete Diffusion
  • Simplified and generalized masked diffusion for discrete data
  • Few-shot semantic parsing with language models trained on code
  • A general framework for inference-time scaling and steering of diffusion models
  • Recursive deep models for semantic compositionality over a sentiment treebank
  • Instantly learning preference alignment via in-context DPO. In Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), 2025
  • DUEL: Exact likelihood for masked diffusion via deterministic unmasking (opens arXiv in a new tab)
  • GLUE: A multi-task benchmark and analysis platform for natural language understanding
  • Larger language models do in-context learning differently (opens arXiv in a new tab)
  • Coeditor: Leveraging repo-level diffs for code auto-editing
  • Coherence boosting: When your pretrained language model is not paying enough attention
  • Fast-dLLM: Training-free acceleration of diffusion LLM by enabling KV cache and parallel decoding
  • Predict, Don't Iterate: Efficient Adaptive-Length Infilling for Diffusion Language Models
  • SWE-Refactor: A repository-level benchmark for real-world LLM-based code refactoring (opens arXiv in a new tab)
  • dQwen3.5: Hybrid-attention diffusion language models (opens arXiv in a new tab)
  • Qwen3 Technical Report
  • Dream 7B: Diffusion large language models (opens arXiv in a new tab)
  • Why Johnny can't prompt: How non-AI experts try (and fail) to design LLM prompts
  • Flexible-length text infilling for discrete diffusion models
  • Calibrate before use: Improving few-shot performance of language models
  • The curse of CoT: On the limitations of chain-of-thought in in-context learning
  • LogiDynamics: Unraveling the dynamics of inductive, abductive and deductive logical inferences in LLM reasoning
  • Large language models are human-level prompt engineers
  • LLaDA 1.5: Variance-reduced preference optimization for large language diffusion models
  • Consider a decision tree representing all possible decoding trajectories
  • Moreover, replaying the policy on any candidate $u$ recovers its reveal trajectory and permits exact evaluation of $P(u \mid z)$
  • Because the reveal policy selects $i_{s}$ using only previously revealed information, the exact-conditional assumption implies
  • It also allows masked positions outside the designated targets T to remain unresolved, as in the demonstration-masked likelihood $P_{0}$
  • Let $P_0$ and $P_1$ be positive distributions on a common finite candidate space, and let $\beta \geq 0$
  • Their ratio therefore converges to
  • Consequently
  • It also does not imply that higher example reward corresponds to greater correctness
  • Let $\mathcal{L}$ denote the finite support of the length allocator $\pi_{\psi}(\cdot \mid \tilde{z})$
  • To see this, define the length-specific normalizing constant
  • The argument does not require $\pi_{\psi}$ to match the data length distribution or to factorize across target sites; oracle lengths correspond to a single supported allocation
  • LLaDA-1.5 (Zhu et al., 2026) and dQwen3.5-9B-Base (Xue et al., 2026) directly infill masked canvases
  • We sample at token temperature one, retain duplicate infills, and reuse each sample pool for unguided and guidance-weighted evaluation
  • ><tr><td>SST-2 with demonstration-defined codes</td><td>$D=2, J=1$</td></tr><tr><td colspan=
  • ><tr><td>List Functions—Easy</td><td>$D=2, J=1$</td></tr><tr><td colspan=
  • ><tr><td>SALT repetition: repeat every verb</td><td>$D=2, J=1$</td></tr><tr><td colspan=
  • woody allen
  • For each prompt family, we retain the same target as $D$ grows and evaluate the reference completion $u^{\star}$ under both demonstration contexts
  • At $D = 1$, SST-2 exposes only one class code, while a single List Functions or SALT demonstration may be compatible with several rules
  • Previously revealed reference targets are visible in both contexts, and the gap between their subsequent reference-token scores generally narrows
  • A categorical head predicts lengths in $\{1,\ldots,256\}$ independently across sites, conditional on the compact prompt
  • Across backbones and target
  • Figure 11 compares its mean against gains in $A_{all}$ relative to $\beta = 0$
  • Gains peak near $\beta = 1$ for LLaDA and dQwen3.5 (+5.2 and +10.3 percentage points), while Nemotron reaches +18.0 points at $\beta = 2$
  • To separate these effects, we compare example guidance with likelihood sharpening that uses the same total exponent on $P_{1}$
  • For LLaDA with a single target at $D = 4$, 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
  • For each (repository, commit, file, helper) group, we identify updated callers and represent each minimal changed region as a <old>/<new> pair
  • For $P_{0}$, only changed-line tokens of demonstration outputs are masked
  • The 4,064 generated draws yielded 2,089 distinct judging packets after deduplication within tasks, including across length settings
  • 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
  • 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
  • The estimated gain is smaller on commits outside the narrower LLaDA development subset (+5.3 points, [-1.0, +13.9])
  • The oracle-length decline also persists in the prespecified
  • Differences are in percentage points, with unadjusted 95% paired commit-bootstrap intervals
  • ><tr><td rowspan=
  • 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
  • The developer-consistent rewrite $u_{+}$ of logMessage preserves the logged line number and MSG_DUPLICATE_REGEXP, whereas an incorrect rewrite $u_{-}$ changes both, yet receives a higher reward (8.69 versus 2.05 nats)
  • 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%
  • 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)