Exploring Length Generalization For Transformer-based Speech Enhancement

Qiquan Zhang, Hongxu Zhu, Xinyuan Qian, Eliathamby Ambikairajah, Haizhou Li · DOI

Abstract: Transformer network architecture has proven effective in speech enhancement. However, as its core module, self-attention suffers from quadratic complexity, making it infeasible for training on long speech utterances. In practical scenarios, speech enhancement models are often required to perform on noisy speech at run-time that is substantially longer than the training utterances. It remains a challenge how a Transformer-based speech enhancement model can generalize to long speech utterances. In this paper, extensive empirical studies are conducted to explore the model's length generalization ability. In particular, we conduct speech enhancement experiments on four training objectives and evaluate with five metrics. Our studies establish that positional encoding is an effective instrument to dampen the effect of utterance length on speech enhancement. We first explore several existing positional encoding methods, and the results show that relative positional encoding methods exhibit a better length generalization property than absolute positional encoding methods. Additionally, we also explore a simpler and more effective positional encoding scheme, i.e. LearnLin, that uses only one trainable parameter for each attention head to scale the real relative position between time frames, which learns the different preferences on short- or long-term dependencies of these heads. The results demonstrate that our proposal exhibits excellent length generalization ability with comparable or superior performance than other state-of-the-art positional encoding strategies.

The Challenge of Long-Form Speech

Transformers have revolutionized speech enhancement (SE) by capturing long-range dependencies across time frames. However, their self-attention mechanism's quadratic complexity often limits training to short audio segments, typically 1–2 seconds. A critical gap exists when these models encounter much longer utterances in real-world applications—a phenomenon known as the "length generalization" problem.

The goal of length generalization: training on short samples and successfully processing long ones at inference.

When a model trained on short clips meets a 20-second recording, performance often degrades significantly. This research investigates how different positional encoding (PE) schemes affect a Transformer's ability to maintain speech quality and intelligibility across varying utterance lengths.

Positional Encoding: Absolute vs. Relative

The study identifies Positional Encoding as the primary factor in length generalization.

  • Absolute Positional Encoding (APE): Methods like sinusoidal or learned embeddings assign unique identifiers to specific time steps (e.g., "this is frame 50"). While effective for fixed-length sequences, APE fails to extrapolate to unseen positions, causing models to fail when processing audio longer than the training data.
  • Relative Positional Encoding (RPE): These methods focus on the distance between frames ($i-j$) rather than their absolute indices. Because the relationship between two frames ten steps apart is consistent regardless of their position in the sequence, RPE is inherently more robust to length variations.

LearnLin: A Minimalist Innovation

The authors propose LearnLin, a streamlined RPE scheme designed for maximum efficiency. Unlike complex methods that use logarithmic binning or multiple kernels, LearnLin introduces only one trainable scalar parameter ($\beta$) per attention head.

The LearnLin mechanism: adding a scaled relative distance bias to the attention score matrix.

As shown in the figure above, the attention score is modified by a bias matrix where each entry $(i, j)$ is the product of $\beta$ and the absolute relative distance $|i - j|$. A positive $\beta$ allows a head to prioritize long-term dependencies, while a negative $\beta$ focuses the head on local context. This simple linear scaling proves remarkably effective for speech tasks.

Key Results and Insights

The researchers evaluated various PE methods across multiple training objectives and metrics. Models were trained on 1s or 2s clips and tested on utterances up to 20s, representing a 10x-20x jump in length.

  • APE Failure: Sinusoidal and BERT-style encodings showed catastrophic performance drops on 20s samples, sometimes performing worse than unprocessed noisy audio.
  • RPE Superiority: All RPE methods (Gauss-Bias, T5-Bias, TISA, KERPLE) maintained stable performance across lengths.
  • Efficiency Wins: Despite having only 8 parameters (one per head), LearnLin matched or outperformed state-of-the-art methods like TISA and KERPLE. On 20s test samples, LearnLin achieved a PESQ gain of 0.81 over noisy speech, providing the most stable performance as audio length increased.

Conclusion

Length generalization is a vital requirement for practical speech enhancement. This work demonstrates that Relative Positional Encoding is essential for Transformers to handle long-form audio. By introducing LearnLin, the authors show that a simple, single-parameter linear bias is sufficient to achieve state-of-the-art generalization, paving the way for more robust and efficient speech processing models.

Summary updated

BibTeX
@article{zhang2025exploring,
  author = {Qiquan Zhang and Hongxu Zhu and Xinyuan Qian and Eliathamby Ambikairajah and Haizhou Li},
  title = {{Exploring Length Generalization For Transformer-based Speech Enhancement}},
  journal = {IEEE Transactions on Audio, Speech and Language Processing},
  year = {2025},
  url = {https://openreview.net/forum?id=mSRXGhsPNe},
}
Figure