Typed Data Loaders #
Typed collation for low-level manual loops. Application code should usually construct a
Trainer.Dataset and use trainer.train.
Shape-typed loader for supervised samples.
The batch size batch appears in the type. Every emitted sample therefore contains collated tensors
whose leading dimension is batch. Partial final batches are omitted because they have a different
shape.
- samples : SampleStream (Sample.Supervised α input target)
Uncollated supervised samples.
- shuffle : Bool
Whether to shuffle before each epoch.
- seed : ℕ
Seed threaded through deterministic epoch shuffles.
Instances For
Collate a statically bounded sample function without an intermediate array.
Instances For
Collate n supervised samples into one sample with a leading batch axis.
For samples with shapes input and target, the result contains:
input : Tensor α (input.prependDim n);target : Tensor α (target.prependDim n).
Example:
-- Three samples in, one batched sample out, with the batch size checked against the array length.
def batched (samples : Array (Sample.Supervised Float [2] [1])) :
Except String (Sample.Batch Float 3 [2] [1]) :=
Data.collateSupervised 3 samples
Instances For
Turn a per-sample supervised stream into a stream of fixed-size minibatches.
This is useful for metrics and manual loops when a model expects a leading batch axis.
Notes:
- This drops the final partial batch (PyTorch
drop_last=Truebehavior). - Batches are formed in dataset order (shuffling is the loader's job).
- Samples are read and collated only when the corresponding batch is requested.
Instances For
Run one epoch and require at least one full typed minibatch.
This is the shared checked boundary for examples that need a nonempty array of full batches. It keeps the "drop partial batches, but fail if nothing remains" policy with the loader API rather than repeating it in each dataset-specific helper.
Instances For
Build a fixed-size supervised loader for a manual training loop.
The underlying stream stores individual samples. Each epoch emits tensors with a leading batch axis, omitting any final partial batch.