Recurrent Modeling of Variable Length Sequences

33 concepts28 papers1 proposal

Deep learning models often struggle when confronted with the messy variability of real-world data. Standard convolutional neural networks (CNNs) and vanilla Transformers typically require inputs of a fixed size. When dealing with video clips of different durations, text phrases of varying lengths, or biological sequences like proteins, traditional pipelines resort to padding (adding artificial zeros) or truncation (cutting off data). Both approaches introduce severe artifacts: padding injects meaningless noise that wastes computation, while truncation discards vital contextual information.

To overcome these constraints, a prominent research direction leverages recurrent mechanisms to process variable-length sequences natively. By maintaining a dynamically updating internal state, these architectures decouple the model's parameter footprint from the temporal or spatial length of the input.

The Core Mechanism: Shared Parameters and State Evolution

Why do recurrent mechanisms inherently handle variable lengths? The intuition lies in the mathematical formulation of a recurrent unit. Instead of allocating separate weights for every position in a sequence, a recurrent model applies the exact same transition function step-by-step.

As a sequence is read, the model maintains a hidden state $h_t$ that acts as an accumulating memory buffer. At each step $t$, the new hidden state is a function of the current input $x_t$ and the previous state $h_{t-1}$:

$$h_t = f(x_t, h_{t-1}; \theta)$$

Because the parameters $\theta$ of this function are shared across all time steps, the network can run for five steps or five hundred steps without changing its architecture or parameter count.

In their foundational work, Jeff Donahue et al. demonstrated this flexibility in Long-term recurrent convolutional networks for visual recognition and description by combining convolutional layers with Long Short-Term Memory (LSTM) networks. Their framework allowed a single architecture to process video clips of arbitrary durations and generate sentences of varying lengths by controlling information flow through input, output, and forget gates. Similarly, Reza Ghaeini et al. utilized forward-backward recurrent neural networks in Event Nugget Detection with Forward-Backward Recurrent Neural Networks to capture variable-length text segments for event nugget detection, bypassing the rigid windows of traditional CNNs.

Preserving Structural Integrity Without Padding

The primary advantage of this step-by-step processing is the elimination of destructive data manipulation. In domains where every single element carries precise meaning—such as bioinformatics or particle physics—avoiding padding and truncation is critical.

For instance, in predicting major histocompatibility complex (MHC) binding affinity, peptides naturally vary in length. Johanna Vielhaben et al. showed in USMPep: universal sequence models for major histocompatibility complex binding affinity prediction that standard RNNs can accumulate context sequentially, removing the need for complex, hand-engineered trimming heuristics. To capture context from both directions, Limin Jiang et al. employed bidirectional LSTMs in Prediction of Major Histocompatibility Complex Binding with Bilateral and Variable Long Short Term Memory Networks, demonstrating that directly processing variable-length peptide sequences significantly boosts prediction accuracy by avoiding artificial sequence manipulation.

In non-coding RNA family prediction, Linyu Wang et al. introduced a dynamic LSTM in ncDLRES: a novel method for non-coding RNAs family prediction based on dynamic LSTM and ResNet that preserves the original structural boundaries of RNA sequences, preventing the introduction of artificial noise. A similar structural preservation strategy is seen in DeeReCT-APA: Prediction of Alternative Polyadenylation Site Usage Through Deep Learning, where Zhongxiao Li et al. designed an interaction layer capable of processing a variable number of alternative polyadenylation sites per gene without input padding.

This principle extends to physical tracking systems. In particle physics experiments at the LHCb, J. Albrecht et al. utilized an LSTM in New approaches for track reconstruction in LHCb’s Vertex Locator to process particle tracks with varying numbers of detector hits. By processing these hits in reverse order—starting closest to the collision point—the model prioritizes the most spatially sensitive information without requiring rigid input padding.

Generalization Across Modalities and Structures

While sequence-to-sequence models are naturally suited for text and biological data, recent research adapts recurrent mechanisms to handle variable lengths across diverse modalities, including multi-frame imaging, dynamic graphs, and decision-making sets.

Burst Imaging and Trajectory Tracking

In computational photography, a "burst" consists of multiple short-exposure frames. Clément Godard et al. developed a recurrent architecture for multi-frame fusion in Deep Burst Denoising that processes low-light image sequences of arbitrary lengths using constant model parameters. To ensure the network remains stable regardless of the burst length, Renlong Wu et al. introduced an intermediate loss function in RBSR: Efficient and Flexible Recurrent Network for Burst Super-Resolution that evaluates outputs at each step, making the model highly robust to varying frame counts.

For motion prediction, Ruiqi Qiu et al. showed in Adapting to Observation Length of Trajectory Prediction via Contrastive Learning that recurrent trajectory encoders naturally accommodate "Observation Length Shifts"—scenarios where a pedestrian is tracked for fewer frames than expected—outperforming fixed-size convolutional or transformer models.

Hybrid and Graph Architectures

The core idea of recurrent state evolution has also been integrated into other paradigms. Guanyiman Fu et al. embedded recurrent gates inside a Transformer architecture in Hyperspectral Image Denoising via Spatial-Spectral Recurrent Transformer to denoise hyperspectral images, allowing the model to handle an arbitrary number of spectral bands.

For video-based behavioral assessment, Zijian Wu et al. modeled video frames as dynamic graphs in DepMGNN: Matrixial Graph Neural Network for Video-based Automatic Depression Assessment. Because the graph structure naturally scales with the number of frames, the architecture completely avoids temporal resampling or truncation, preserving long-term behavioral cues across videos of significantly different durations.

Choice Sets and Text Queries

Beyond physical or temporal sequences, recurrent processing can handle abstract sets of varying sizes. Ville Tanskanen et al. modeled human risky choices in Modeling Risky Choices in Unknown Environments by feeding a variable number of decision alternatives sequentially into an RNN, avoiding fixed-size input constraints. In information retrieval, Jiangui Chen et al. developed a generative retrieval model in CorpusBrain: Pre-train a Generative Retrieval Model for Knowledge-Intensive Language Tasks that processes queries of varying lengths and complexities within a single unified sequence-to-sequence architecture.

Inference-Time Adaptability and Robustness

A key reason this paradigm works so effectively is its zero-shot adaptability during inference. Because the underlying transition weights do not depend on sequence length, a model trained on short sequences can often generalize to longer sequences without structural modification or retraining.

For example, in quantitative medical imaging, Beomgu Kang et al. applied RNNs to process magnetic resonance fingerprinting signals in Only-Train-Once MR Fingerprinting for Magnetization Transfer Contrast Quantification. Their single trained network could perform accurate tissue quantification across entirely different acquisition lengths and scan protocols without needing to be retrained.

In computer vision, the Sequencer: Deep LSTM for Image Classification architecture replaced self-attention layers with a two-dimensional LSTM for spatial mixing. Because the recurrent weights are shared across the spatial sequence, the model inherently accommodates varying input resolutions during inference, demonstrating remarkable robustness compared to standard Vision Transformers.

Finally, to handle variable-length outputs dynamically, models can learn an explicit termination signal. As demonstrated by Marc Assens et al. in PathGAN: Visual Scanpath Prediction with Generative Adversarial Networks, modeling an end-of-sequence signal allows the network to determine both where a person looks and when they stop looking, capturing natural variations in human visual exploration.

Key Foundational Work

Long-term recurrent convolutional networks for visual recognition and description (2015) — contributed 2 concept elements to this direction.
Event Nugget Detection with Forward-Backward Recurrent Neural Networks (2016) — contributed 1 concept elements to this direction.
History & citationVersion 1 · 2026-10-04

Current · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_variable_length_sequence_processing_vari_a02a36ab,
  title = {variable-length sequence processing (variable-length sequence handling)},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/variable-length-sequence-processing-variable-length-sequence-handling/rdr_a02a36ab728c403db95a94efaaa91407},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-23},
}

This exact version (version 1, frozen text):

@misc{lacuna_variable_length_sequence_processing_vari_a02a36ab_v1,
  title = {variable-length sequence processing (variable-length sequence handling)},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/variable-length-sequence-processing-variable-length-sequence-handling/rdr_a02a36ab728c403db95a94efaaa91407/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-23},
}
About

These directions overlap with this one through shared papers.

See something wrong? Report a mistake