lisbet.modeling.backbones.tcn#

TCN Backbone for LISBET.

Implements a Temporal Convolutional Network (TCN) with dilated convolutions and residual connections.

Reference:

Bai, S., Kolter, J. Z., & Koltun, V. (2018). An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling. arXiv:1803.01271.

Classes

Chomp1d(chomp_size)

Removes padding from the end of the sequence to ensure causality.

TCNBackbone(feature_dim, embedding_dim, ...)

Temporal Convolutional Network (TCN) backbone for sequence modeling.

TemporalBlock(in_channels, out_channels, ...)

A single TCN block with dilated convolutions and residual connection.

class lisbet.modeling.backbones.tcn.Chomp1d(chomp_size)[source]#

Removes padding from the end of the sequence to ensure causality.

__init__(chomp_size)[source]#

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class lisbet.modeling.backbones.tcn.TemporalBlock(in_channels, out_channels, kernel_size, stride, dilation, padding, dropout=0.0)[source]#

A single TCN block with dilated convolutions and residual connection.

__init__(in_channels, out_channels, kernel_size, stride, dilation, padding, dropout=0.0)[source]#

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class lisbet.modeling.backbones.tcn.TCNBackbone(feature_dim, embedding_dim, hidden_dim, num_layers, kernel_size=3, dilation_base=2, dropout=0.0)[source]#

Temporal Convolutional Network (TCN) backbone for sequence modeling.

Parameters:
  • feature_dim (int) – Dimension of the input features.

  • embedding_dim (int) – Dimension of the output embeddings.

  • hidden_dim (int) – Number of channels in the hidden layers.

  • num_layers (int) – Number of temporal blocks (layers).

  • kernel_size (int) – Size of the convolutional kernel. Default: 3

  • dilation_base (int) – Base for the dilation factor. Default: 2

  • dropout (float) – Dropout rate. Default: 0.0

__init__(feature_dim, embedding_dim, hidden_dim, num_layers, kernel_size=3, dilation_base=2, dropout=0.0)[source]#

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

forward(x)[source]#

Forward pass through the TCN backbone.

Parameters:

x (Tensor) – Input tensor of shape (batch_size, sequence_length, feature_dim).

Returns:

Output tensor of shape (batch_size, sequence_length, embedding_dim).

Return type:

Tensor

get_config()[source]#

Get the configuration dictionary for this backbone.

Return type:

dict[str, Any]

classmethod from_config(config)[source]#

Create a TCNBackbone instance from a configuration dictionary.

Return type:

TCNBackbone