nerva_torch.layers
Neural network layers used by the MultilayerPerceptron class.
Layers in this module operate on matrices with row layout (each row is a sample). They expose a minimal interface with feedforward, backpropagate and optimize.
Functions
|
Parse a textual layer spec and create a configured Layer instance. |
Classes
|
Linear layer followed by a pointwise activation function. |
Batch normalization layer with per-feature gamma and beta. |
|
|
Base class for layers of a neural network with data in row layout (each row is a sample: shape (N, D)). |
|
Linear layer: Y = X W^T + b. |
|
Linear layer followed by log_softmax over the last dimension. |
|
Activation layer with SReLU and trainable activation parameters. |
|
Linear layer followed by softmax over the last dimension. |
- class nerva_torch.layers.Layer[source]
Bases:
object
Base class for layers of a neural network with data in row layout (each row is a sample: shape (N, D)).
- class nerva_torch.layers.LinearLayer(D: int, K: int)[source]
Bases:
Layer
Linear layer: Y = X W^T + b.
Shapes: X (N, D) -> Y (N, K), W (K, D), b (K,).
- class nerva_torch.layers.ActivationLayer(D: int, K: int, act: ActivationFunction)[source]
Bases:
LinearLayer
Linear layer followed by a pointwise activation function.
- class nerva_torch.layers.SReLULayer(D: int, K: int, act: SReLUActivation)[source]
Bases:
ActivationLayer
Activation layer with SReLU and trainable activation parameters.
In addition to W and b, this layer optimizes SReLU’s (al, tl, ar, tr).
- class nerva_torch.layers.SoftmaxLayer(D: int, K: int)[source]
Bases:
LinearLayer
Linear layer followed by softmax over the last dimension.
- class nerva_torch.layers.LogSoftmaxLayer(D: int, K: int)[source]
Bases:
LinearLayer
Linear layer followed by log_softmax over the last dimension.
- class nerva_torch.layers.BatchNormalizationLayer(D: int)[source]
Bases:
Layer
Batch normalization layer with per-feature gamma and beta.
Normalizes inputs across the batch using per-feature statistics. Shapes: X (N, D) -> Y (N, D), gamma/beta (D,).
- nerva_torch.layers.parse_linear_layer(text: str, D: int, K: int, optimizer: str, weight_initializer: str) Layer [source]
Parse a textual layer spec and create a configured Layer instance.
Supports Linear, Softmax, LogSoftmax, activation names (e.g. ReLU), and SReLU(…). The optimizer and weight initializer are applied.