NPY loader tutorial (NumPy/PyTorch interop) #
This tutorial shows how to train from .npy files (NumPy arrays), similar to a common PyTorch
workflow where you:
- prepare
X.npy/y.npyin Python (NumPy / PyTorch), - then train a model in TorchLean by loading those files.
Generate small deterministic .npy files with
python3 NN/Examples/Data/generate_small_data.py:
NN/Examples/Data/small_regression_X.npy(shape 25×2, dtype float32)NN/Examples/Data/small_regression_y.npy(shape 25×1, dtype float32)
Build:
lake build NN.Examples.Data.Loaders.Npy
The tutorial code is compiled with the rest of TorchLean and is directly runnable as
lake exe torchlean data_npy. It checks the array metadata before constructing the typed dataset,
then trains through the same public trainer used by the model examples.
Optional flags (tutorial-specific):
--data-dir PATH(default:NN/Examples/Data)--x PATH,--y PATH(override the.npyfiles)--seed S(controls shuffling and model initialization)--batch N--steps N
Public API used here:
Data.readNpy(metadata)Data.fromSupervisedSourceData.batchTrainer.newTrainer.RunConfigTrainer.TrainOptionstrainer.train
Command name used in diagnostics and by the top-level example runner.
Instances For
Two input features, matching the generated .npy arrays.
Instances For
def
NN.Examples.Data.Loaders.Npy.model
{batchSize : ℕ}
:
TorchLean.nn.Builder (TorchLean.nn.Sequential [batchSize, inputWidth] [batchSize, outputWidth])
A small 2-layer batched MLP 2 -> 8 -> 1.
Instances For
Command-line help for the NPY loader tutorial.