Incremental Sampling Without Replacement for Sequence Models

Kensen Shi, David Bieber, Charles Sutton

Introduction

In sequence generation tasks—ranging from program synthesis to combinatorial optimization—models often need to produce a diverse set of high-quality candidates. Standard independent and identically distributed (i.i.d.) sampling frequently generates redundant outputs, wasting computational resources on high-probability sequences already seen. While Sampling Without Replacement (WOR) techniques exist, they often suffer from high latency (rejection sampling) or lack incrementality (Stochastic Beam Search), requiring a fixed sample size upfront.

This paper introduces UniqueRandomizer, an incremental sampling framework that allows sequence models to draw unique samples one-by-one. By maintaining an augmented trie of "unsampled probability mass," it provides a flexible, efficient, and statistically sound alternative to traditional sampling methods.

The UniqueRandomizer Framework

The core of the approach is the UniqueRandomizer data structure, which acts as a drop-in replacement for standard random choice operators. It manages the search space using an augmented trie that tracks the history of sampled sequences.

Augmented Trie and Probability Mass

Each node in the trie stores its unsampled probability mass—the total probability of all sequences in that branch that have not yet been sampled. When a sequence is fully generated, the algorithm performs an incremental update: it traverses back up the tree, subtracting the probability of the sampled sequence from each ancestor node. This ensures that subsequent samples are drawn exclusively from the remaining distribution.

The UniqueRandomizer updates the unsampled probability mass in the trie after each sample.

Hindsight Gumbel Estimator (HGE)

Beyond search efficiency, the authors address the challenge of statistical estimation. Standard WOR samples cannot be used directly to estimate expectations without bias. The authors derive the Hindsight Gumbel Estimator (HGE), which retroactively assigns Gumbel noise variables to unique samples. This allows for lower-variance estimation of expected values compared to i.i.d. sampling.

Experimental Results

The researchers evaluated UniqueRandomizer on two primary domains: program synthesis (SPoC dataset) and the Traveling Salesman Problem (TSP).

Program Synthesis (SPoC)

On the SPoC dataset, which involves translating human-authored pseudocode into C++ programs, UniqueRandomizer significantly accelerated the discovery of correct solutions. In one test split, the method reached the same success rate in just 47 samples that i.i.d. sampling required 100 samples to achieve. This efficiency stems from the elimination of redundant candidates and the ability to skip expensive neural network computations for fully explored branches.

Combinatorial Optimization (TSP)

In TSP benchmarks (n=20, 50, 100), sampling unique tours consistently yielded better results. Notably, applying UniqueRandomizer to a simple "Farthest Insertion" heuristic outperformed several complex, state-of-the-art deep learning models, demonstrating the power of diverse, unique sampling even with basic heuristics.

Computational Efficiency

A key advantage of UniqueRandomizer is its performance on modern hardware. While purely incremental sampling is sequential, the authors developed a "batched" version to improve GPU utilization.

Comparison of total sampling time on GPU for various methods. UniqueRandomizer (Batched) demonstrates superior scaling for large sample sizes.

As shown in the efficiency benchmarks, the batched UniqueRandomizer becomes the fastest method for generating 100 unique samples, significantly outperforming rejection sampling and standard Stochastic Beam Search (SBS).

Conclusion and Future Work

UniqueRandomizer provides a robust solution for incremental sampling without replacement. Its ability to handle dynamic stopping criteria—such as sampling until a program passes unit tests—makes it highly practical for real-world search tasks. While the trie structure introduces some memory overhead, the gains in search efficiency and statistical precision are substantial. Future work may explore its application in Reinforcement Learning to ensure diverse rollouts or integration into Monte Carlo Tree Search (MCTS).

Summary updated

BibTeX
@inproceedings{shi2020incremental,
  author = {Kensen Shi and David Bieber and Charles Sutton},
  title = {{Incremental Sampling Without Replacement for Sequence Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2020},
}
Figure