fn
constant_
→Tensorconstant_(tensor: Tensor, val: float)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
tensorTensorTensor to fill in place; any shape is accepted.
valfloatScalar to broadcast into every entry.
Returns
Tensortensor (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)