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. For command-line model training, use the
torchlean executable examples in NN/Examples/Models.
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.fromNpy(metadata)Data.supervisedDatasetData.batchDatasetTrainer.newTrainer.RunConfigTrainer.TrainOptionstrainer.train
def
NN.Examples.Data.Loaders.Npy.mkModel
{batch : ℕ}
:
TorchLean.nn.M (TorchLean.nn.Sequential (TorchLean.Shape.mat batch inDim) (TorchLean.Shape.mat batch outDim))
A small 2-layer batched MLP 2 -> 8 -> 1.
Instances For
Command-line help for the NPY loader tutorial.