class
ConstantPad1d
extends
_ConstantPadNdConstantPad1d(padding: _Size2d, value: float)Pad a 3-D tensor (N, C, L) along the last dimension with a constant.
Adds padding[0] values on the left and padding[1] values on the
right of the sequence dimension, filling each new position with
value.
Parameters
paddingint or tuple[int, int](left, right) padding sizes. A single int applies the same
amount on both sides.valuefloatConstant fill value.
Attributes
paddingtuple[int, int]Normalised
(left, right) padding.valuefloatFill value.
Notes
- Input: .
- Output: .
Examples
**Causal temporal padding (left-only) for a 1-D causal convolution:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> # Pad 2 timesteps on the left so no future context leaks
>>> causal_pad = nn.ConstantPad1d(padding=(2, 0), value=0.0)
>>> x = lucid.zeros(4, 16, 100) # (N, C, T)
>>> causal_pad(x).shape
(4, 16, 102)
**Symmetric padding with a non-zero fill value:**
>>> pad = nn.ConstantPad1d(padding=3, value=-1.0)
>>> x = lucid.zeros(2, 8, 50)
>>> pad(x).shape
(2, 8, 56)Methods (1)
dunder
__init__
→None__init__(padding: _Size2d, value: float)Initialise the ConstantPad1d module. See the class docstring for parameter semantics.