TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/itsubaki/autograd/llms.txt
Use this file to discover all available pages before exploring further.
model package provides composable neural network models — MLP and LSTM — built from layer primitives. Each model embeds Model, which manages a slice of layers and exposes a unified parameter and gradient interface consumed by optimizers.
Layer interface
Every element inModel.Layers must satisfy the Layer interface. The built-in layer types (LinearT, RNNT, LSTMT) all implement it.
Runs the layer forward and returns the first output variable. Convenience wrapper around
Forward.Runs the layer forward and returns all output variables.
Returns the learnable parameters (
layer.Parameters) for this layer.Sets all parameter gradients to
nil, preparing for the next forward/backward pass.Model
Model is the base struct embedded by MLP and LSTM. It aggregates parameters and gradient clearing across all its layers.
The ordered list of layers that make up the model. You can inspect or replace layers directly.
Methods
Params
layer.Parameters map from every layer. Keys are prefixed with the layer index ("0.W", "1.b", etc.) so parameter names remain unique across layers.
Cleargrads
Cleargrads() on every layer, zeroing all gradient tensors. Call this before each backward pass to prevent gradient accumulation.
Activation
Activation is the function type used for inter-layer activations in MLP.
F.Sigmoid, F.ReLU, F.Tanh, F.Softmax(axis)) all satisfy this type.
MLP
MLP is a multi-layer perceptron with a configurable number of hidden layers and a shared activation function applied between each layer. The final layer has no activation.
The activation function applied after every layer except the last. Defaults to
F.Sigmoid.NewMLP
outSize defines the output size of a Linear layer.
Output sizes for each layer.
len(outSize) determines the depth of the network.Option functions that customize the MLP before the layers are initialized.
Layer weights are initialized with the default random source. Use
WithMLPSource to set a deterministic source for reproducible experiments.Option functions
WithMLPActivation
F.Sigmoid activation with any Activation-compatible function.
WithMLPSource
math/rand/v2.Source) used to initialize layer weights. Pass a seeded source for reproducible results.
Forward
x through every hidden layer with the configured activation, then through the final layer with no activation.
The input variable. Shape must be compatible with the first layer’s weight matrix.
LSTM
LSTM wraps a single layer.LSTMT followed by a layer.LinearT projection. It exposes a stateful forward pass and a method to reset the hidden and cell states between sequences.
NewLSTM
The dimensionality of the LSTM hidden state.
The output size of the projection
Linear layer that follows the LSTM.Option functions applied before the layers are constructed.
Option functions
WithLSTMSource
math/rand/v2.Source) for initializing both the LSTM and projection layer weights.
Forward
x through the LSTM layer, then through the projection layer. The LSTM hidden and cell states are carried forward across calls — reset them with ResetState between sequences.
ResetState
h) and cell state (c). Call this at the start of each new sequence during training or inference.
Examples
Training an MLP
Using ReLU activation
Training an LSTM on a sequence
See also
- layer package — the underlying layer primitives (
Linear,LSTM, etc.) - optimizer package — update model parameters after each backward pass
- Guides: deep learning — end-to-end training walkthrough