Attention-based Neural Bag-of-Features Learning for Sequence Data

Dat Thanh Tran, Nikolaos Passalis, Anastasios Tefas, Moncef Gabbouj, Alexandros IosifidisarXiv 2020

TL;DR

This paper introduces 2D-Attention (2DA), a flexible attention mechanism designed for matrix-structured data. By integrating 2DA into Neural Bag-of-Features (NBoF) models, the authors create specialized architectures that can selectively focus on relevant time steps, specific codewords, or clean input channels, significantly boosting performance and noise resilience in financial, audio, and medical sequence analysis.

What Problem Does This Paper Address?

Sequence data—like stock market fluctuations, heart sounds, or audio clips—is often "noisy" and "non-stationary," meaning its statistical properties change over time and it contains irrelevant information.

The Neural Bag-of-Features (NBoF) model is a powerful tool for these sequences because it can handle variable-length inputs by quantizing features into "codewords" and then aggregating them into a fixed-size histogram. However, standard NBoF has a major flaw: it treats every time step and every codeword as equally important by simply averaging them. This "democratic" approach is suboptimal when a sequence contains bursts of noise or when only a few specific patterns (codewords) are actually relevant to the task at hand.

Methods

The authors propose 2D-Attention (2DA), a generic computation block that learns to "mask" a matrix. It calculates an attention mask $A$ that highlights important columns (or rows) while suppressing others. A key innovation is a learnable parameter $\tau$ that allows the model to automatically decide how much attention is needed; if the data is clean and every part is useful, the model can learn to disable the attention effect entirely.

They propose three ways to "plug" 2DA into the NBoF pipeline:

  1. Codeword Attention (NBoF-CA): Applies attention to the codewords themselves, allowing the model to focus on a specialized subset of features for a specific input.
  2. Temporal Attention (NBoF-TA): Applies attention across time steps, performing a weighted average during aggregation rather than a simple mean.
  3. Input Attention (NBoF-IA): Applies attention directly to the raw input features, acting as a filter to block out noisy channels or irrelevant series in multivariate data.
Fig. 1. Illustration of the proposed attention formulation (2DA) and different attention-based NBoF models

Datasets

The models were benchmarked across three distinct domains:

  • Financial Forecasting: The FI2010 dataset, the largest publicly available Limit Order Book (LOB) dataset, used for predicting stock price movements.
  • Audio Analysis: The FMA (Free Music Archive) dataset for music genre recognition and the TUT-UAS2018 dataset for acoustic scene classification.
  • Medical Diagnosis: The AF dataset (Physionet 2017) for detecting atrial fibrillation from ECGs and the PCG dataset (Physionet 2016) for heart sound anomaly detection.

Key Insights and Ideas

  • The Power of Selective Focus: The simple act of replacing a global average with a weighted average (Temporal Attention) consistently improved results, proving that not all moments in a sequence are created equal.
  • Noise Resilience via Input Attention: One of the most striking findings was NBoF-IA's ability to handle "contaminated" data. By learning to mask noisy frequency bands in audio, it maintained high accuracy where standard models (and even GRUs) saw significant performance drops.
  • Synergy with CNNs: While NBoF models are not inherently designed to capture local spatial patterns, the authors found that using a Convolutional Neural Network (CNN) as a "preprocessing" layer to extract local features before the NBoF stage yielded the best overall results, outperforming standard Recurrent Neural Networks (GRUs).
  • Attention vs. Adaptive Scaling: The authors noted that a previously proposed "adaptive scaling" technique for NBoF actually conflicted with the attention mechanism. The extra degrees of freedom from scaling negated the "competition" effect that attention relies on, suggesting that for NBoF, attention is a superior way to handle feature importance.

Key Results

  • Financials: On the FI2010 dataset (Horizon H=50), the baseline NBoF achieved a 68.84% F1 score. The attention-enhanced NBoF-CA pushed this to 73.25%, outperforming the GRU baseline (65.93%).
  • Audio: In music genre recognition (FMA), adding 2DA to the temporal variant (TNBoF) improved accuracy from 39.13% to 42.67%.
  • Noise Robustness: In a simulated noisy audio test, the baseline NBoF's accuracy dropped to 31.54%. The NBoF-IA variant, however, achieved 36.21%, showing it could effectively "ignore" the synthetic noise bands.
  • Medical: For heart sound anomaly detection (PCG), the baseline NBoF was quite poor (50.31% accuracy). Adding Temporal Attention (NBoF-TA) skyrocketed this to 89.32%, nearly matching the much more complex GRU model.

Limitations and Future Work

  • Architecture Specificity: While 2DA is "generic," this paper focuses almost entirely on its application within NBoF. Its efficacy in other architectures (like standard Transformers or pure CNNs) remains to be fully explored.
  • Computational Overhead: The weight matrix $W$ in the 2DA block is $N \times N$ (where $N$ is the number of columns/time steps). For very long sequences, this could lead to a significant increase in parameters and memory usage.
  • Future Directions: The authors suggest investigating 2DA's efficacy in other neural network models as a promising research path.

Summary updated

Abstract

In this paper, we propose 2D-Attention (2DA), a generic attention formulation for sequence data, which acts as a complementary computation block that can detect and focus on relevant sources of information for the given learning objective. The proposed attention module is incorporated into the recently proposed Neural Bag of Feature (NBoF) model to enhance its learning capacity. Since 2DA acts as a plug-in layer, injecting it into different computation stages of the NBoF model results in different 2DA-NBoF architectures, each of which possesses a unique interpretation. We conducted extensive experiments in financial forecasting, audio analysis as well as medical diagnosis problems to benchmark the proposed formulations in comparison with existing methods, including the widely used Gated Recurrent Units. Our empirical analysis shows that the proposed attention formulations can not only improve performances of NBoF models but also make them resilient to noisy data.
BibTeX
@misc{tran2020attention,
  author = {Dat Thanh Tran and Nikolaos Passalis and Anastasios Tefas and Moncef Gabbouj and Alexandros Iosifidis},
  title = {{Attention-based Neural Bag-of-Features Learning for Sequence Data}},
  year = {2020},
  eprint = {2005.12250},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2005.12250},
}

Loading related content...

Figure