fn

constant_

Tensor
constant_(tensor: Tensor, val: float)
source

Fill tensor in-place with a single scalar value.

Every entry of tensor is overwritten with val. Most often used to initialise bias terms to zero or to a small positive value (e.g. 0.01 to keep ReLU units active at the start of training).

Parameters

tensorTensor
Tensor to fill in place; any shape is accepted.
valfloat
Scalar to broadcast into every entry.

Returns

Tensor

tensor (mutated) for chaining.

Notes

Constant-filling a weight matrix breaks the network's symmetry-breaking property — every output unit would compute the same function and learn identical gradients. Use this for biases only.

Examples

>>> import lucid
>>> from lucid.nn.init import constant_
>>> b = lucid.empty(128)
>>> constant_(b, 0.0)