Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sktime Pytorch forecasting sLSTMNetwork

From Leeroopedia
Revision as of 16:43, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Sktime_Pytorch_forecasting_sLSTMNetwork.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Time_Series, Forecasting, Deep_Learning
Last Updated 2026-02-08 08:00 GMT

Overview

sLSTMNetwork is a complete stabilized LSTM network combining stacked sLSTM layers with a fully connected output layer for prediction.

Description

sLSTMNetwork extends nn.Module and composes an sLSTMLayer (stacked stabilized LSTM layers) with a final nn.Linear fully connected layer. The sLSTM layers process the input sequence recurrently with exponential gating, and the FC layer maps the last time step's hidden output to the desired output dimension. This provides an end-to-end trainable network architecture based on the sLSTM cell with stabilized gating.

Usage

Use sLSTMNetwork as a standalone recurrent forecasting model when you want a complete stabilized LSTM-based architecture. It is suitable for time series prediction tasks where training stability from exponential gating is beneficial.

Code Reference

Source Location

Signature

class sLSTMNetwork(nn.Module):
    def __init__(
        self,
        input_size,
        hidden_size,
        num_layers,
        output_size,
        dropout=0.0,
        use_layer_norm=True,
    ):
    def forward(self, x, h=None, c=None):
    def init_hidden(self, batch_size, device=None):

Import

from pytorch_forecasting.layers._recurrent._slstm.network import sLSTMNetwork

I/O Contract

Inputs

__init__

Name Type Required Description
input_size int Yes Number of features in the input.
hidden_size int Yes Number of features in the hidden state of each sLSTM layer.
num_layers int Yes Number of stacked sLSTM layers in the network.
output_size int Yes Number of features in the output prediction.
dropout float No Dropout probability for the input of each sLSTM layer. Defaults to 0.0.
use_layer_norm bool No Whether to use layer normalization in each sLSTM layer. Defaults to True.

forward

Name Type Required Description
x torch.Tensor Yes Input sequence tensor of shape (seq_len, batch_size, input_size).
h list of torch.Tensor or None No Initial hidden states for each layer. If None, initialized to zeros.
c list of torch.Tensor or None No Initial cell states for each layer. If None, initialized to zeros.

Outputs

forward

Name Type Description
output torch.Tensor Final output tensor from the fully connected layer, produced from the last time step. Shape is (batch_size, output_size).
(h, c) tuple of lists Final hidden and cell states for each layer.

Usage Examples

import torch
from pytorch_forecasting.layers._recurrent._slstm.network import sLSTMNetwork

model = sLSTMNetwork(
    input_size=32,
    hidden_size=64,
    num_layers=2,
    output_size=10,
    dropout=0.1,
    use_layer_norm=True,
)

seq_len, batch_size = 20, 16
x = torch.randn(seq_len, batch_size, 32)
output, (h, c) = model(x)
# output shape: (16, 10)  -- last time step projected to output_size

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment