class

ConstantPad1d

extends_ConstantPadNd
ConstantPad1d(padding: _Size2d, value: float)
source

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.

output[n,c,i]={valuei<pleft or iL+pleftx[n,c,  ipleft]otherwise\text{output}[n, c, i] = \begin{cases} \text{value} & i < p_{\text{left}} \text{ or } i \geq L + p_{\text{left}} \\ x[n, c,\; i - p_{\text{left}}] & \text{otherwise} \end{cases}

Parameters

paddingint or tuple[int, int]
(left, right) padding sizes. A single int applies the same amount on both sides.
valuefloat
Constant fill value.

Attributes

paddingtuple[int, int]
Normalised (left, right) padding.
valuefloat
Fill value.

Notes

  • Input: (N,C,L)(N, C, L).
  • Output: (N,C,L+pleft+pright)(N, C, L + p_{\text{left}} + p_{\text{right}}).

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)
source

Initialise the ConstantPad1d module. See the class docstring for parameter semantics.