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.
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.
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