Datasets, Loaders, and File Sources #
TorchLean datasets keep each sample's tensor shapes in its type. A file-backed workflow usually looks like this:
- Convert outside-world datasets to canonical
.npytensors or small numeric CSV files. - Describe those files with
TensorSource,SupervisedSource, orLabeledSource. - Load them into shape-typed TorchLean tensors and datasets.
- Train with
batchLoader,BatchLoader.epoch,trainer.train, or a manual trainer loop.
We keep the implementation small and predictable:
- datasets are in-memory and pure (often backed by
List) - loader shuffling is seed-driven and reproducible
.npyis the canonical numeric interchange format- CSV is supported for small tabular data
- MATLAB
.mat, PyTorch.pt/.pth, NumPy.npz, and image folders should be converted to.npywithscripts/datasets/torchlean_data_convert.py - there are no multiprocessing workers, memory maps, or pinned-memory support
PyTorch Mapping #
This is inspired by torch.utils.data:
- Dataset, DataLoader:
https://pytorch.org/docs/stable/data.html - TensorDataset:
https://pytorch.org/docs/stable/data.html#torch.utils.data.TensorDataset - DataLoader:
https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader
TorchLean’s key difference is that samples typically carry type-level shapes (via TensorPack),
so many helpers here are shape-aware by construction.
Main Types #
TensorSource: one file plus expected dimensions.SupervisedSource: two batched tensors,X : (N, xDims...)andY : (N, yDims...).LabeledSource: batched inputs plus integer class labels, one-hot encoded on load.TabularSupervisedSource: one CSV table with input columns followed by target columns.batchLoader: deterministic, typed minibatching.
For examples and conversion commands, see NN/Examples/Data/README.md.
Typed analogue of PyTorch's TensorDataset.
In TorchLean, a sample is usually a TensorPack α shapes, i.e. a shape-tracked tuple of tensors.
Instances For
Build a dataset from an explicit list of samples.
Instances For
Require that all paths exist, otherwise raise a user-facing error with a shared hint.
Instances For
Require one named data file to exist.
Instances For
Require paired supervised input/target files to exist.
Instances For
Write a small CSV file, creating the parent directory if needed.
Instances For
Write a one-dimensional prediction probe CSV.
Rows are i,x,input,target,prediction, where $x=i/(n-1)$ for $n>1$.
This writes the compact prediction table used by plotting examples such as 1D operator learning.
Instances For
Materialize a dataset as a list.
Instances For
Number of elements in the dataset.
Instances For
Whether the dataset is empty.
Instances For
Build a cycling index function for a nonempty dataset.
cycleDataset ds h i returns ds[i % ds.size].
This is the dataset analogue of cycleList. It avoids per-step Option handling in fixed-step
training loops.
Instances For
Like cycleDataset, but fail with a message if the dataset is empty.
This is the preferred helper for “PyTorch-style” fixed-step loops over in-memory datasets.
Instances For
Map a dataset elementwise (pure, deterministic).
Instances For
Append two datasets, preserving order: all samples from x followed by all samples from y.
Instances For
Untyped analogue of PyTorch's torch.utils.data.DataLoader.
This is the deterministic, purely-functional loader provided by the TorchLean runtime.
Instances For
Construct a RawDataLoader from a dataset.
If shuffle := true, shuffling is deterministic w.r.t. seed.
If dropLast := true, incomplete final batches are discarded.
Instances For
Run one epoch worth of minibatching and return:
- an updated loader (with the new seed), and
- the list of minibatches.
Instances For
Like epoch, but apply a user-provided collate function to each minibatch, matching the role of
PyTorch's collate_fn= option.
Instances For
Typed wrapper around RawDataLoader for supervised samples.
The batch size n is reflected in the type, and BatchLoader.epoch returns fully-collated
dim n minibatches (so dropLast=true is required).
- raw : RawDataLoader (Sample.Supervised α σ τ)
Raw underlying data.
Instances For
Existential wrapper for loaders when the batch size is chosen at runtime.
Instances For
Read the row count from an .npy file and check its trailing shape.
For a batched tensor with shape (N, d₁, ..., dₖ), this returns N when the trailing dimensions
match tailShape.
Instances For
Convert a list of (x, y) float tensors into a dataset of TorchLean supervised samples.
This casts float data into the selected scalar backend α and packs it into a
TensorPack α [σ, τ].
Instances For
Convert a list of (x, label) pairs into a dataset of one-hot classification samples.
Labels are given as Nat and converted to one-hot targets of shape Vec classes.