Train a concise LSTM
Build a batch first native LSTM, train an immutable snapshot and inspect its bounded architecture diagram.
// Requires the recurrent-enabled development runtime and matching editor.
// Synthetic data demonstrates API mechanics, not predictive quality.
import aner.nn
import aner.tensor
import aner.dev
let x = tensor.reshape(nn.random(8, 6, seed: 2026, scale: 0.5), List(8, 6, 1))
let y = nn.zeros(8, 1)
let model = nn.lstm(inputs: 1, hidden: 8, seed: 42).on("auto")
dev.capture("LSTM architecture", model)
let fitted = model.fit(x, y, epochs: 3, batch: 4, clip_norm: 1.0)
print(fitted.last_loss())
print(fitted.updates())
print(fitted.predict(x).rows())
// New checkpoint paths are required; a saved snapshot retains optimizer state.
// fitted.save("sequence.anerrnn")
// let resumed = nn.load_recurrent("sequence.anerrnn").fit(x, y, epochs: 2)
Make it your experiment.
Use Aner 0.0.3 or newer. Save this program as examples/recurrent_basics.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/recurrent_basics.aner
aner run examples/recurrent_basics.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires Aner 0.0.4 or newer and matching editor integration. Uses synthetic tensors with no external dataset, credentials or network connection. Supported Mac packages include Metal/MPS; current Linux and Windows packages do not include CUDA or MPI/NCCL. Optional source backends require a compatible runtime and hardware.
aner check examples/recurrent_basics.aner
aner examples/recurrent_basics.anerBundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution