Weighted data batcher with deterministic resume

0
Sign in

Build a sampler that draws weighted batches from a dataset registry and can resume deterministically from a saved offset, including the edge case where the batch size does not divide the data evenly.

class WeightedBatcher:
    def __init__(self, datasets, weights, batch_size, seed=0, max_samples=None, drop_last=False, state=None): ...

    def next_batch(self):
        """A list of (dataset name, item), or None when the run is over."""

    def state(self):
        """Something JSON-friendly that resumes the exact same stream."""
AnthropicMicrosoftCodingMediumLast asked May 2026

Sign in to see the worked answer

The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.