Source-linked AI summary

Multi-Target Few-Shot Prompting with Diffusion Language Models

Anton Xue, Alan Li, Rahul Saha

arXiv:2610.22294v1cs.CL

TL;DR

Few-shot prompting can guide edits when instructions or rewards are difficult to specify, but multi-site edits that depend on context on both sides are awkward for causal autoregressive generation. The paper uses diffusion language models to infill multiple masked regions in a shared canvas and adds likelihood-ratio reward guidance from demonstrations. Across few-shot prompting benchmarks and software refactoring, demonstrations improve infilling accuracy, with example guidance yielding further gains in several settings.

  • Problem

    Multi-site edits can depend on both left and right context, making their generation awkward for causal autoregressive models.

    Source: §1 · p. 2
  • Method

    The approach uses frozen DLMs to infill multiple masked regions in a shared canvas and likelihood-ratio rewards with inference-time resampling to favor example-supported completions.

    Source: §1.1 · pp. 2–3
  • Results

    Across few-shot prompting benchmarks and Java refactoring, demonstrations improve infilling accuracy, with example guidance providing further gains in several settings.

    Source: §6 · p. 13
  • Takeaways & Limitations

    The findings provide a foundation for more effective example-guided multi-site infilling.

    Source: §6 · p. 13

    Target sites and demonstration-output positions must be specified in advance, and target lengths must be allocated before infilling.

    Source: §6 · p. 13

Abstract

from arXiv · show

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.

1 Introduction

Multi-target few-shot prompting uses demonstrations to guide in-place generation at multiple sites in a shared canvas, addressing the awkwardness of applying causal generation across edits that need right context. The paper introduces a likelihood-based guidance method and evaluates it alongside prior work on few-shot prompting, test-time guidance, and diffusion language models.

1 Introduction

  • Diffusion language models can infill multiple sites using left and right context, while causal autoregressive generation makes right-context editing cumbersome across multiple sites.The paper frames this as multi-target few-shot prompting: demonstrations and context share a canvas with the target sites.Source: §1 · p. 2

1.1 Contributions

  • Multi-target few-shot prompting fills multiple regions in place on a shared canvas, and example-guided sampling uses likelihood-ratio rewards to favor example-supported completions without retraining.The approach constructs a tractable distribution over complete infills by revealing one token at a time, enabling likelihood comparisons with and without demonstrations.Source: §1.1 · pp. 2–3
  • Across repurposed few-shot benchmarks and software-refactoring case studies, demonstrations generally improve infilling accuracy, guidance adds gains in some settings, and accurate target-length prediction remains challenging.The evaluation examines demonstrations, target counts, example guidance, and learned length prediction.Source: §1.1 · p. 3

1.2 Related Work

  • Prior few-shot work includes demonstrations for programming and code editing, as well as batching multiple inputs; this paper instead jointly infills unresolved regions in a shared canvas.The related work also describes guidance methods that compare predictions across contexts and diffusion models that iteratively unmask positions; complete-infill likelihood comparisons require a specified decoding procedure.Source: §1.2 · p. 3

2 Background

The background formulates multi-target few-shot prompting as filling masked output regions in a shared canvas while preserving visible demonstrations and context. It then describes masked DLM prediction and the need for a decoding procedure that determines how masked positions are revealed.

2.1 Few-Shot Prompting on a Shared Canvas

  • The shared-canvas task fills multiple masked output regions while preserving visible demonstrations and surrounding context.Target sites are assumed specified, and output lengths are given by an oracle to fix the mask allocation before generation.Source: §2.1 · p. 4
  • Demonstrations and targets can be interleaved, and a single target after demonstrations recovers conventional few-shot prompting.The schematic uses two sorting demonstrations and two target sites, with six masked positions in total.Source: §2.1 · p. 4

2.2 Masked Diffusion Language Models

  • Masked DLMs predict missing tokens from visible context on both sides, but a decoder must choose which masked positions to reveal and when.Newly revealed tokens become context for later predictions, and different decoding procedures can induce different distributions over complete infills.Source: §2.2 · p. 4

3 Multi-Target Few-Shot Prompting and Reward Guidance

The section formulates multi-target infilling when output lengths are unknown and develops tractable likelihoods that support reward-guided generation. It applies the guidance to joint length-and-content candidates and describes how inference and evaluation are organized.

3 Multi-Target Few-Shot Prompting and Reward Guidance

  • Unknown-length multi-target prompting jointly generates missing-output lengths and contents on a shared canvas, using tractable infill likelihoods to support demonstration-aware reward guidance.The formulation addresses both length allocation and completion of the resulting canvas.Source: §3 · pp. 4–5

3.1 Length Allocation and Joint Infilling

  • A compact canvas gives each target a placeholder; a proposed length vector expands those placeholders into masks for DLM infilling, with oracle or learned length allocation.Each target length ranges over a prescribed finite set of positive integers.Source: §3.1 · p. 5

3.2 Tractable DLM Infilling

  • One-token-at-a-time decoding yields exactly scorable normalized infill distributions, but data-distribution recovery requires exact DLM conditionals and learned-model distributions may depend on reveal policy.The construction excludes parallel token revelation but can score designated targets while other masked positions remain unresolved.Source: §3.2 · pp. 5–6
  • Figure 3 illustrates that revealing a demonstrated naming convention raises support for itemCount without changing the model’s initial ranking, while guidance at β = 1 favors itemCount.The probabilities are schematic and normalized over two completions.Source: Figure 3 · p. 6

3.3 Reward Guidance

  • The reward compares a candidate’s likelihood with demonstration outputs visible versus masked; increasing β favors higher-reward candidates, potentially countering demonstration-inconsistent preferences.The same decoding policy is used over target positions in both contexts.Source: §3.3 · p. 6
  • Importance resampling from P1 candidates uses weights proportional to Qβ/P1 to approximate guided generation, and its weighted empirical distribution converges almost surely in total variation as K increases.Proposition 3.2 states the convergence for independent samples from P1.Source: §3.3 · p. 7
  • For unknown lengths, reward guidance compares joint length-and-content likelihoods; the shared allocator contribution cancels, though resampling can still change the marginal length distribution.Figure 4 summarizes allocation, infilling, and optional reward-guided resampling.Source: §3.3 · p. 7, Figure 4 · p. 7
  • Figure 5 organizes single-target prompting results by demonstration count, showing unguided accuracy and guidance gains across four benchmarks and four model interfaces.DLMs use oracle target lengths, whereas Qwen3 generates freely.Source: Figure 5 · p. 8

4 Few-Shot Prompting Experiments with Standard Benchmarks

Across standard few-shot benchmarks, the experiments test how demonstrations, example guidance, multiple jointly infilled targets, and predicted target lengths affect infilling accuracy. Demonstrations generally help, while guidance gains vary and learned length allocation remains a challenge.

4 Few-Shot Prompting Experiments with Standard Benchmarks

  • The benchmark experiments cover sentiment coding, list transformations, artificial-language transformations, and information extraction, using three DLMs and an autoregressive single-target comparison.Outputs are graded by task-specific exact or parsed matching; DLM experiments reveal one target token at a time in ascending canvas order.Source: §4 · p. 8

4.1 Single-Target Few-Shot Prompting

  • Increasing demonstrations from D = 1 to D = 16 improves unguided accuracy in all 16 model–task series.For LLaDA, 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.Source: §4.1 · p. 9
  • At D = 4, example guidance improves LLaDA 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.Gains tend to shrink as unguided accuracy saturates and depend on whether the reward favors correct samples.Source: §4.1 · p. 9

4.2 Multi-Target Few-Shot Prompting

  • With LLaDA and eight targets, standard all-target accuracy rises from 24.3% at D = 2 to 44.5% at D = 16, while demonstrations improve it at every successive count.Figure 6 reports all-target accuracy and average per-target accuracy under unguided sampling, plus the all-target accuracy gain from guidance.Source: §4.2 · p. 10, Figure 6 · p. 10
  • For LLaDA at D = 16, average per-target accuracy is 73.6% at J = 1 and 72.3% at J = 8, despite declining all-target accuracy as targets increase.Thus, lower joint success need not mean a comparable decline in accuracy at individual sites.Source: §4.2 · p. 10, Figure 6 · p. 10
  • On List Functions–Easy, guidance has positive gains with confidence intervals above zero for every J = 1 condition, but none of the J = 8 conditions.Across benchmarks at D = 4 and J = 8, guidance gains on SST-2 but produces losses on Movie Director.Source: §4.2 · p. 10

4.3 Predicting Target Lengths

  • Predicting target lengths retains only 35–48% of oracle-length per-target accuracy, leaving accurate length allocation a challenge for practical multi-target infilling.Learned predictors assign 40–46% probability mass to the reference length, versus approximately 27% for a prior based on visible demonstration lengths.Source: §4.3 · p. 11, Figure 7 · p. 11

5 Case Studies in Software Refactoring

The case studies evaluate multi-site Extract Method edits, finding that demonstrations help generate refactorings but the added likelihood-ratio guidance does not improve selection in the reported experiment.

5.1 Helper Refactoring Experiments

  • The study evaluates 127 tasks from 50 commits across 14 repositories, using LLM judgments rather than executing the generated code.Tasks are multi-site edits derived from Extract Method commits in SWE-Refactor.Source: §5.1 · p. 12
  • On an 80-task ablation, adding one accepted edit improves joint LLM-judged success by 14.7 percentage points for J = 1 and 17.5 for J = 2.In the broader evaluation, unguided pooled joint success is 74.4% with oracle lengths and 15.8% with predicted lengths; guidance reduces these to 71.5% and 14.5%.Source: §5.1 · p. 12

5.2 Qualitative Analysis

  • Across 127 sample pools, only 23 oracle-length pools contain both judged-correct and judged-incorrect rewrites, limiting possible selection gains to 8.3 percentage points.With learned lengths, 72 pools contain both outcomes and the upper bound rises to 45.2 points.Source: §5.2 · p. 13
  • In a Checkstyle example, an incorrect rewrite receives 61.8% of total resampling weight, reducing expected LLM-judged success from 43.8% to 15.7%.Its example reward is 8.69 nats versus 2.05 for the developer-consistent rewrite.Source: §5.2 · p. 13

6 Conclusion

The conclusion presents multi-target prompting with masked DLMs and example guidance as a foundation for example-guided multi-site infilling. The appendix proves that deterministic one-token-at-a-time decoding defines an exactly sampleable and scoreable distribution, and characterizes when it recovers the data conditional.

6 Conclusion

  • The conclusion frames multi-target prompting with masked DLMs as a setting where demonstrations guide infilling across multiple regions of a shared canvas.It also identifies improved target-length allocation as an opportunity for practical editing.Source: §6 · p. 13

A.1 One-Token-at-a-Time Decoding

  • When the DLM predicts exact data conditionals, the induced distribution recovers the conditional data distribution independently of the deterministic reveal policy.The proof handles both positive-probability complete assignments and zero-probability assignments.Source: §A.1 · pp. 19–20
  • Deterministic one-token-at-a-time decoding defines a normalized distribution over complete infills that can be sampled and scored exactly.The proof represents decoding as a decision tree: each completion has a unique leaf, and its probability is the product of the token probabilities along its path.Source: §A.1 · p. 19
  • The argument covers prescribed orders and deterministic adaptive selection, but randomized position selection may require marginalizing over reveal trajectories.Parallel token revelation is outside the construction.Source: §A.1 · p. 20

A.2 Reward Guidance and Importance Resampling

Reward guidance defines a distribution that trades off demonstration reward against divergence from the proposal distribution, and importance resampling converges to it as the sample pool grows. The construction extends to joint candidates containing both target lengths and infill content.

A.2 Reward Guidance and Importance Resampling

  • The guided distribution Qβ uniquely maximizes expected reward minus β-scaled KL divergence from P1.This variational characterization applies to positive P0 and P1 on a common finite candidate space, with β ≥ 0.Source: §A.2 · p. 20
  • As K → ∞, the weighted empirical distribution from independent P1 samples converges almost surely to Qβ in total variation.The proof establishes this by convergence of the weighted numerator and normalizing denominator.Source: §A.2 · pp. 20–21

A.3 Extension to Unknown Lengths

  • For unknown target lengths, reward guidance and importance resampling extend to joint candidates containing a length allocation and its infill.The shared length allocator cancels from the candidate-level likelihood ratio, while the joint distributions must have positive conditional infill probabilities on common support.Source: §A.3 · p. 21
  • Guidance changes the marginal distribution over lengths, favoring allocations with larger length-specific normalizing constants Zβ(L).This does not require the allocator to match the data length distribution or factorize across target sites.Source: §A.3 · p. 21

B Few-Shot Prompting Experiments

The appendix documents experiments on few-shot transformations, length allocation, guidance strength, and likelihood sharpening. It reports gains from demonstrations and guidance in some settings, alongside substantial sensitivity to target count and length prediction.

B.1 Experimental Setup

  • The experiments comprise a single-target sweep, a List Functions–Easy D × J grid, and a cross-benchmark target-count sweep, with frozen models and separately analyzed studies.The appendix describes four transformation types and uses oracle lengths except in the length-allocation experiment.Source: §B.1 · p. 22

B.4 Length Allocation

  • Length predictors use frozen DLM representations and a trained categorical head to predict each target length independently.The original DLM remains frozen and infills the allocated targets.Source: §B.4 · pp. 25–26
  • Predicted lengths retain 35–48% of oracle-length per-target accuracy on List Functions–Easy, while the predictor places F0 = 40–46% and F2 = 53–61% mass near reference lengths.F0 is probability mass on the exact reference length, not top-prediction accuracy; the comparison prior assigns approximately 27% exact-length mass.Source: §B.4 · pp. 26–27, Figure 10 · p. 26

B.5 Guidance-Strength Sensitivity

  • With one target, every tested β > 0 improves mean Aall for all three DLMs except that LLaDA’s interval includes zero at β = 2.Gains peak near β = 1 for LLaDA (+5.2 points) and dQwen3.5 (+10.3 points), while Nemotron reaches +18.0 points at β = 2.Source: §B.5 · p. 27, Figure 11 · p. 27
  • With four targets, guidance gains peak at +3.3 points at β = 0.25, then diminish or reverse to −2.6 to −9.6 points at β = 2.At β = 2, the intervals exclude zero for Nemotron and dQwen3.5.Source: Figure 11 · p. 27, §B.5 · p. 28
  • Accuracy deterioration at four targets is not explained by weight concentration alone: effective fractions remain 0.48–0.71, and the reward spans roughly four times as many tokens.The comparison does not isolate target count as the cause.Source: §B.5 · pp. 27–28

B.6 Likelihood Sharpening

  • Likelihood sharpening improves Aall for every J in the List Functions–Easy D × J grid and outperforms guidance in every cell with J ≥ 4.For LLaDA at D = 4 and J = 1, guidance exceeds sharpening by +3.6 percentage points ([+0.4, +6.9]) on SST-2; no other single-target task has a positive residual.Source: §B.6 · pp. 28–29, Figure 12 · p. 28

B.2 Single-Target Experiments

In the single-target sweep, additional demonstrations generally increase the reference answer’s relative likelihood support, but that support does not guarantee larger gains from guidance.

B.2 Single-Target Experiments

  • The reference-answer example reward generally increases as demonstrations are added, reflecting a reduction in its per-token negative log likelihood when demonstration outputs are visible.Reward magnitudes are not directly comparable across DLM and causal interfaces because P0 treats demonstration outputs differently.Source: §B.2 · p. 24
  • Greater reference-answer support does not guarantee a larger guidance gain: demonstrations may leave multiple rules compatible, and accuracy may approach saturation.Guidance also depends on how the reward ranks sampled alternatives, not only its value for the reference answer.Source: §B.2 · p. 24
  • After previously revealed reference targets become visible in both contexts, the subsequent reference-token NLL gap generally narrows.This diagnostic follows reference assignments rather than sampled decoding trajectories.Source: Figure 9 · p. 25

B.3 Multi-Target Experiments

The multi-target analyses examine whether guidance trends persist across target counts and benchmarks, alongside how revealed targets relate to demonstration information. Guidance effects vary across tasks rather than transferring uniformly.

B.3 Multi-Target Experiments

  • The reference-likelihood diagnostic and cross-benchmark target-count study extend the main List Functions–Easy D × J analysis using distinct setups.The cross-benchmark study uses K = 64 samples per canvas, compared with K = 16 in the main grid.Source: §B.3 · p. 25
  • With D = 4 and J = 8, the gap between subsequent reference-token negative log likelihoods generally narrows as more targets are revealed.The diagnostic makes preceding reference targets visible under both P1 and P0 while keeping demonstration outputs masked under P0.Source: §B.3 · p. 25
  • At J = 8, guidance at β = 0.5 improves Aall on SST-2, decreases it on Movie Director, is nearly neutral on List Functions–Easy, and varies by model on SALT.The cross-benchmark study uses three DLMs, four benchmarks, D = 4, and K = 64; reduced guidance benefits on List Functions–Easy do not hold uniformly across tasks.Source: §B.3 · p. 25

C Software Editing Experiments

  • The following software-editing experiments describe the Java refactoring benchmark and evaluation, then analyze demonstrations, length allocation, and example guidance.Source: C Software Editing Experiments · p. 29

C.1 Benchmark Construction and Evaluation Setup

The Java editing benchmark derives multi-site tasks from Extract Method commits and evaluates generated rewrites with an LLM judge. A post-hoc ablation finds gains from one visible demonstration, while learned length allocation remains a challenge.

C.1 Benchmark Construction and Evaluation Setup

  • The benchmark contains 127 tasks from 50 commits across 14 repositories, with configurations (D, J) ∈ {1, 2}² and differing eligible commits.Because eligible commits differ by configuration, comparisons across (D, J) do not isolate demonstration or target-count effects; outcomes are aggregated and bootstrapped by commit.Source: §C.1 · p. 29
  • The judge assesses whether edits adapt receivers, arguments, and control flow while plausibly preserving behavior, but generated code is not compiled or executed.Uncertain judgments count as failures, and ill-posed packets remain in the evaluation.Source: §C.1 · p. 29
  • Figure 13 illustrates a Checkstyle canvas where an accepted helper-call edit must be adapted to two masked targets with different local arguments.Actual prompts include instructions, chat framing, and additional after-file context; the figure is an excerpt.Source: §C.1 · p. 29, Figure 13 · p. 30

C.2 Demonstration Conditioning and Length Allocation

  • Adding one demonstration improved joint LLM-judged success by 14.7 percentage points for J = 1 ([+5.8, +24.5]) and 17.5 points for J = 2 ([+4.7, +32.5]).The ablation’s instruction differs from the main experiment, so absolute success rates are not directly comparable.Source: §C.2 · p. 31
  • Only 6.2% of learned-length joint samples allocate every target exactly, while 95% of samples with exact joint allocations are judged correct.Across 80 unique target sites, within-two-token length probability is 26.7% for the predictor versus 15.2% for the empirical training-corpus prior; exact-length mass is 6.8% versus 3.1%.Source: §C.2 · p. 31

C.3 Example Guidance and Failure Analysis

In the software case study, example guidance at β = 0.5 lowers pooled joint success, and finite-pool resampling can favor incorrect rewrites. The discussion identifies potential uses across sites while emphasizing review and execution-based checks for code.

C.3 Example Guidance and Failure Analysis

  • At β = 0.5, example guidance reduces pooled LLM-judged joint success by 2.9 percentage points with oracle lengths and 1.3 points with learned lengths.The oracle-length decline also persists in the sensitivity population and among commits outside the narrower LLaDA development subset.Source: §C.3 · pp. 31–32, Table 1 · p. 32
  • Selection could improve pooled success by at most 8.3 points with oracle lengths versus 45.2 points with learned lengths, because only mixed pools can benefit.Among 127 oracle-length pools, 23 contain both correct and incorrect samples; the corresponding learned-length count is 72.Source: §C.3 · p. 32
  • In a Checkstyle example, the incorrect rewrite receives a higher reward than the developer-consistent rewrite, and finite-pool resampling reverses the ideal pairwise preference.At β = 0.5, the incorrect rewrite receives 61.8% of total weight versus 15.7% across seven correct draws; the comparison concerns only the two displayed rewrites, not total probability of a correct edit.Source: §C.3 · pp. 32–33

D Additional Discussion

  • Multi-target prompting could support example-guided document and code editing, but practical use requires more reliable adherence to demonstrations and better output-length prediction.For code, the discussion calls for review, compilation, and testing; the evaluation instead relies on an LLM judge without execution.Source: D Additional Discussion · p. 33
Loading 2610.22294v1…