pytensor_ml.layers.Linear#
- class pytensor_ml.layers.Linear(name=None, *, n_in, n_out, bias=True, weight_initializer=None, bias_initializer=None)#
Affine map \(y = x W + b\).
- Parameters:
- name
strorNone Name prefix for the layer’s parameters. Defaults to “Linear” when None.
- n_in
int Size of the input feature axis.
- n_out
int Size of the output feature axis.
- biasbool, optional
Add the learned shift \(b\), which starts at zero and is redrawn there. Default is True.
- weight_initializer
Initializer, optional How \(W\) is drawn, at construction and on every redraw. Xavier normal when omitted.
- bias_initializer
Initializer, optional How \(b\) is drawn. Zeros when omitted, following Keras and flax rather than torch, which draws the bias from \(\mathcal{U}(\pm 1/\sqrt{\text{fan\_in}})\).
- name
Notes
Both parameters are drawn when the layer is built, so a network trains without any further call.
initialize()redraws them from a single seed, which is what makes a run reproducible.Examples
The dense layer: multiply by a learned matrix and add a learned bias. Pass
bias=Falsewhere a normalization layer follows and would subtract the bias away again:from pytensor_ml.layers import BatchNorm, Input, Linear, Sequential X = Input("X", shape=(None, 64)) network = Sequential( Linear("fc", n_in=64, n_out=32, bias=False), BatchNorm("bn", n_in=32), ) activations = network(X)
Methods
Linear.__init__([name, bias, ...])