TL;DR
This paper introduces a self-attention framework for multivariate sequence data by upgrading the Neural Bag-of-Features (NBoF) architecture. Instead of learning attention weights directly, the proposed method projects data into latent spaces to calculate feature and temporal relevance via dot-product similarity, including a novel joint "codeword-temporal" attention mechanism. The approach yields consistent performance gains across audio and biosignal classification tasks.
What Problem Does This Paper Address?
Modeling sequence data (like audio or medical biosignals) requires capturing both what features are present and when they occur. The Neural Bag-of-Features (NBoF) model is a popular choice for this; it passes data through a quantization layer to map features to a dictionary of representative expressions called "codewords," which are then averaged over time to create a histogram.
However, standard NBoF treats all codewords and time steps as equally important during this averaging step. While prior work introduced "2D-Attention" (2DA) to weight these dimensions, it suffered from two core flaws:
- It learned attention weights directly from scratch without structural guidance.
- It treated the codeword (feature) dimension and the temporal dimension as completely independent, ignoring the reality that certain features are only important at specific moments in time.
Methods
The authors reformulate 2D-Attention by leveraging dot-product self-attention principles, shifting the model's job from learning raw weights to learning a meaningful latent space projection. They propose three distinct attention formulations:
- Codeword-Temporal Self-Attention (CTSA): The flagship contribution. It projects the feature representation into a joint latent space using two learnable matrices ($W_q$ and $W_k$). It then computes a scaled dot-product similarity between the temporal and codeword dimensions, applying a sigmoid activation to generate a joint 2D attention mask. This allows the model to co-attend to features and time simultaneously.
- Codeword Self-Attention (CSA): Explicitly determines the relevance of codewords by calculating their dot-product similarity in a learned latent space, using a softmax activation to encourage competition among features.
- Temporal Self-Attention (TSA): Applies the same latent space similarity principle to the transpose of the feature representation to evaluate the relative importance of each timestamp.
These attention mechanisms can also be scaled up to multi-head variants, allowing parallel tracking of different representation subspaces.
Datasets
The authors evaluated their approaches on two primary domains:
- TUT-UAS2018: An acoustic scene classification dataset containing 10 urban environment classes (e.g., airport, park, metro station).
- AF Dataset (PhysioNet Challenge 2017): An Electrocardiogram (ECG) dataset for classifying atrial fibrillation and other cardiac abnormalities.
- PCG Dataset (PhysioNet Challenge 2016): Phonocardiogram (heart sound) recordings split into two tasks: abnormal heart sound detection (PCG-1) and recording quality evaluation (PCG-2).
Key Insights and Ideas
- Guided vs. Unguided Learning: Directly learning an attention matrix from scratch gives the model too much freedom and no structural guidance. By forcing the model to compute attention via dot-product similarity in a latent space, the architecture inherently exploits the relationships between features.
- Features and Time are Intertwined: The success of CTSA proves that feature relevance is highly contextual. A specific codeword might be vital during second 2 of an audio clip but completely irrelevant noise by second 5. Joint modeling captures this dependency.
Key Results
The self-attention variants consistently outperformed standard 2D-Attention baselines across all datasets.
As shown in the single-head audio classification results, the proposed temporal self-attention variant ($\text{2DA-TSA}_{256}$) achieved the highest accuracy on the TUT-UAS2018 dataset at 57.55%, outperforming the standard temporal baseline ($\text{2DA-TA}$) at 56.09%.
For biosignal analysis, the proposed methods demonstrated notable improvements in F1 scores. On the PCG heart sound dataset, Codeword Self-Attention ($\text{2DA-CSA}_{256}$) reached an F1 score of 88.38%, a clear step up from the standard codeword attention baseline ($\text{2DA-CA}$) at 86.93%.
When expanding to multi-head attention, the authors observed that using 4 heads provided an additional performance gain of up to 2.5% on the acoustic scene dataset.
Limitations and Future Work
While multi-head attention boosted performance for the standard logistic NBoF formulation, the authors noted a limitation when applying it to Temporal NBoF (TNBoF)—a variant that utilizes separate long-term and short-term codebooks. For TNBoF, single-head variants actually performed best, and adding more heads degraded performance.
The authors suggest that because these attention mechanisms are generic, future work should focus on moving beyond NBoF modules to test their compatibility with entirely different multivariate sequence architectures.
Summary updated