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_toy_data.py:
NN/Examples/Data/toy_regression_X.npy(shape 25×2, dtype float32)NN/Examples/Data/toy_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--epochs E
Public API used here:
Data.fromNpy(metadata)Data.fromNpySupervised(typed dataset from disk)Data.Transforms.ComposeData.batchLoadertrain.fitLoaderWith
def
NN.Examples.Data.Loaders.Npy.loadDataset
(xPath yPath : System.FilePath)
{α : Type}
[API.Semantics.Scalar α]
[API.Runtime.Scalar α]
:
Load the .npy tensors, print their metadata, then apply a small input transform.
This file is intentionally interop-first: it shows the path from NumPy/PyTorch exports on disk to TorchLean's normal training API.