BucketBatchSampler

Models & Types ยท AiDotNet.Data.Sampling

Groups sequences by length into buckets, then batches within each bucket to minimize padding.

Inheritance: DataSamplerBase โ†’ BucketBatchSampler

Implements: IBatchSampler

How It Works

Bucket batching is essential for efficient NLP training. By grouping sequences of similar lengths together, padding waste is minimized and GPU utilization is maximized.

The sampler sorts samples by their length, divides them into buckets of roughly equal size, shuffles within each bucket, and yields batches from each bucket.

Constructors

Constructor Summary
BucketBatchSampler(int[] sampleLengths, int batchSize, int numBuckets, bool dropLast, int? seed) Creates a new bucket batch sampler.

Properties

Property Summary
bool DropLast { get; set; }
int BatchSize { get; set; }
int Length { get; }

Methods

Method Summary
IEnumerable<int[]> GetBatchIndices()