ElasticAST: An Audio Spectrogram Transformer for All Length and Resolutions

Jiu Feng, Mehmet Hamza Erol, Joon Son Chung, Arda Senocak

Abstract

Standard Audio Spectrogram Transformers (ASTs) are constrained by fixed-size inputs, leading to information loss through trimming or computational waste through padding. We present ElasticAST, a novel architecture designed to handle audio of arbitrary length and temporal resolution without retraining. By employing sequence packing and masked attention mechanisms, ElasticAST achieves superior performance on variable-length datasets and maintains high accuracy across diverse inference-time computational budgets.

Introduction

The Audio Spectrogram Transformer (AST) has become a cornerstone of modern audio classification. However, its reliance on fixed-size inputs—a legacy of convolutional neural network architectures—presents significant challenges in real-world applications where audio clips vary naturally in duration. Conventional approaches involve trimming longer clips, which discards potentially vital data, or padding shorter clips, which introduces redundant computation. Furthermore, standard ASTs exhibit poor generalization when the test-time resolution differs from the training resolution. ElasticAST addresses these limitations by creating a single, flexible model capable of processing "native-length" audio with varying temporal resolutions.

Methodology

ElasticAST introduces three key architectural innovations to overcome the fixed-length barrier:

Sequence Packing and Masked Self-Attention

To optimize training and inference, ElasticAST "packs" multiple audio samples of varying lengths into a single sequence up to a predefined token limit. To prevent information leakage between unrelated samples within the same pack, a boolean mask is applied during self-attention. This ensures that tokens from a specific audio clip only interact with other tokens from the same clip.

The ElasticAST architecture utilizes sequence packing and masked attention pooling to handle multiple audio clips of varying lengths within a single forward pass.

Masked Attention Pooling

Unlike standard ASTs that rely on a single [CLS] token, ElasticAST employs a learnable query vector and a masking mechanism to pool information. This allows the model to generate distinct representations for each individual sample in a packed sequence, facilitating accurate classification regardless of the sample's position or length.

Variable Resolution Training

The model is trained using spectrograms with randomly adjusted frame shifts (Fshift). This exposure to diverse temporal resolutions teaches the model to be invariant to the "stretching" or "compression" of audio features, enhancing its robustness to varying inference-time constraints.

Experimental Results

ElasticAST was evaluated on benchmarks including AudioSet, VGGSound, VoxCeleb, and Epic-Sounds.

Performance on Variable-Length Data

On datasets with naturally varying lengths like VoxCeleb and Epic-Sounds, ElasticAST outperformed standard AST baselines. By leveraging the full native length of the audio rather than trimming to a fixed window, the model effectively captured more semantic information, supporting the "Semantic Volume" hypothesis where performance scales with input volume.

Robustness to Resolution Changes

A critical advantage of ElasticAST is its stability across different temporal resolutions. While standard AST performance collapses when the test resolution deviates from training, ElasticAST maintains high accuracy across a wide range of compression rates.

Comparison of accuracy across different compression rates. ElasticAST (solid lines) maintains stable performance compared to the sharp decline of standard AST (dotted lines).

Discussion and Conclusion

ElasticAST demonstrates that a single model can match or exceed the performance of multiple specialized models trained for specific lengths. This "elasticity" allows for seamless adjustment to varying computational budgets at inference time. While the current implementation uses a simple packing algorithm and maintains a practical upper limit on sequence length for memory management, future work could explore more sophisticated packing strategies and applications in multimodal tasks requiring precise temporal synchronization.

Summary updated

BibTeX
@inproceedings{feng2024elasticast,
  author = {Jiu Feng and Mehmet Hamza Erol and Joon Son Chung and Arda Senocak},
  title = {{ElasticAST: An Audio Spectrogram Transformer for All Length and Resolutions}},
  booktitle = {Interspeech},
  year = {2024},
  doi = {10.21437/interspeech.2024-1890},
}
Figure