All examples
Neural networks

Train a concise LSTM

Build a batch first native LSTM, train an immutable snapshot and inspect its bounded architecture diagram.

recurrent_basics.aner
// 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.

With Aner 0.0.3 or newer installed, 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.

Terminal
aner check examples/recurrent_basics.aner
aner run examples/recurrent_basics.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Requires the matching neural development runtime and editor; published 0.0.3 packages predate these APIs. Uses synthetic tensors with no external dataset, credentials or network connection. Optional CUDA/MPS placement requires a compatible native build and hardware.

Credential setup
aner check examples/recurrent_basics.aner
aner examples/recurrent_basics.aner

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner