All examples
Neural networks

Save and resume an Iris classifier

Save a versioned fitted checkpoint, restore normalization and weights, then continue training from the immutable fitted snapshot.

Download .aner source
neural_model_state.aner
// Creates iris.anermodel in the current working directory. Use a fresh folder.
// Iris: Fisher (1936), UCI, CC BY 4.0. See THIRD_PARTY_DATA.md.
import aner.dataset
import aner.nn
import aner.ml
import aner.dev

let split = dataset.iris().split(test: 0.2, seed: 2026)
let network = nn.sequential(seed: 42)
    .dense(inputs: 4, outputs: 8).tanh()
    .dense(inputs: 8, outputs: 3)
let pipeline = ml.classifier(network, standardize: true,
                             loss: "cross_entropy", optimizer: "sgd")
let fitted = pipeline.fit(split.train(), epochs: 100, rate: 0.1)
fitted.save("iris.anermodel")
let restored = ml.load_classifier("iris.anermodel")
print(restored.evaluate(split.test()).summary())
// Zero-based Dense layer indices ignore activation stages. These are detached copies.
if dev.enabled() {
    dev.capture("Restored first Dense weights", restored.weights(layer: 0))
    dev.capture("Restored first Dense bias", restored.bias(layer: 0))
}
// New rows use the restored training scaler; the original fitted model is unchanged.
let continued = pipeline.warm_start(restored).fit(split.train(), epochs: 50, rate: 0.1)
print(continued.evaluate(split.test()).summary())

Make it your experiment.

With Aner installed, save this program as examples/neural_model_state.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/neural_model_state.aner
aner run examples/neural_model_state.aner

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

Run from a fresh working directory: this program creates iris.anermodel and refuses to overwrite an existing file. Its parent directory must already exist.

Iris and Wine are teaching datasets with their own attribution. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner