linmult.core.tcn

Temporal Convolutional Network (TCN) for local temporal smoothing.

Provides dilated causal 1-D convolution layers that capture short-range temporal dynamics (e.g. micro-expressions, motion patterns) without leaking future information. Designed to sit after the projection Conv1d and before cross-modal attention in the LinMulT pipeline.

Classes

TCNLayer

Single dilated causal Conv1d layer with residual connection.

TCN

Stack of TCNLayer with exponentially increasing dilation.

Module Contents

class linmult.core.tcn.TCNLayer(d_model: int, kernel_size: int = 3, dilation: int = 1, dropout: float = 0.1)[source]

Bases: torch.nn.Module

Single dilated causal Conv1d layer with residual connection.

Computes:

x + dropout(relu(bn(causal_conv1d(x))))

Causal padding is applied on the left so that output at time t depends only on inputs at times <= t.

Parameters:
  • d_model (int) – Number of input and output channels.

  • kernel_size (int) – Convolution kernel size. Defaults to 3.

  • dilation (int) – Dilation factor. Defaults to 1.

  • dropout (float) – Dropout probability after activation. Defaults to 0.1.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: torch.Tensor) torch.Tensor[source]

Apply causal convolution with residual.

Parameters:

x (torch.Tensor) – Input (B, T, d_model).

Returns:

Output (B, T, d_model), same shape as input.

Return type:

torch.Tensor

class linmult.core.tcn.TCN(d_model: int, num_layers: int = 3, kernel_size: int = 3, dropout: float = 0.1)[source]

Bases: torch.nn.Module

Stack of TCNLayer with exponentially increasing dilation.

Dilations are [1, 2, 4, ..., 2^(num_layers-1)], giving a receptive field of 1 + sum((kernel_size - 1) * 2^i for i in range(num_layers)) frames. With the defaults (num_layers=3, kernel_size=3) the receptive field is 15 frames (~0.5 s at 30 fps).

Parameters:
  • d_model (int) – Channel dimension (preserved through all layers).

  • num_layers (int) – Number of dilated convolution layers. Defaults to 3.

  • kernel_size (int) – Kernel size for every layer. Defaults to 3.

  • dropout (float) – Dropout probability in each layer. Defaults to 0.1.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: torch.Tensor) torch.Tensor[source]

Apply all TCN layers sequentially.

Parameters:

x (torch.Tensor) – Input (B, T, d_model).

Returns:

Output (B, T, d_model), temporally smoothed.

Return type:

torch.Tensor