Abstract: At present, people usually use some methods based on convolutional neural networks (CNNs) for Electroencephalograph (EEG) decoding. However, CNNs have limitations in perceiving global dependencies, which is not adequate for common EEG paradigms with a strong overall relationship. Regarding this issue, we propose a novel EEG decoding method that mainly relies on the attention mechanism. The EEG data is firstly preprocessed and spatially filtered. And then, we apply attention transforming on the feature-channel dimension so that the model can enhance more relevant spatial features. The most crucial step is to slice the data in the time dimension for attention transforming, and finally obtain a highly distinguishable representation. At this time, global averaging pooling and a simple fully-connected layer are used to classify different categories of EEG data. Experiments on two public datasets indicate that the strategy of attention transforming effectively utilizes spatial and temporal features. And we have reached the level of the state-of-the-art in multi-classification of EEG, with fewer parameters. As far as we know, it is the first time that a detailed and complete method based on the transformer idea has been proposed in this field. It has good potential to promote the practicality of brain-computer interface (BCI).
Introduction
Decoding EEG signals is a cornerstone of Brain-Computer Interfaces (BCIs), enabling the translation of electrical brain activity into commands for external devices. However, EEG data is notoriously difficult to process due to its low signal-to-noise ratio and non-stationary nature. While Convolutional Neural Networks (CNNs) have become the standard for this task, they are inherently limited by their local receptive fields, which struggle to capture the global dependencies essential for holistic EEG paradigms. Recurrent architectures like LSTMs address sequence modeling but are often slow to train and prone to forgetting long-term information. This paper introduces the Spatial-Temporal Tiny Transformer (S3T), a lightweight model designed to leverage the attention mechanism to capture these critical global relationships.
Methods
The S3T architecture processes EEG data through a specialized four-stage pipeline designed for efficiency and feature enhancement:
- Preprocessing & Spatial Filtering: Raw EEG signals are preprocessed and filtered using techniques like Common Spatial Pattern (CSP) to maximize class discriminability.
- Spatial Transforming: A feature-channel attention block is applied to the spatially filtered data. This allows the model to dynamically weight relevant brain regions while suppressing noise.
- Temporal Transforming: The core of the model involves slicing the continuous signal into temporal "patches." A convolutional layer provides position encoding, and a temporal attention module captures global dependencies across these slices.
- Classification: The resulting representation is passed through Global Average Pooling (GAP) and a simple fully-connected layer for final classification.
Results and Discussion
The model was evaluated on two benchmarks from BCI Competition IV: Dataset 2a (4-class Motor Imagery) and Dataset 2b (2-class Motor Imagery).
Performance and Efficiency
S3T achieved state-of-the-art (SOTA) performance, reaching an average accuracy of 82.59% on Dataset 2a, significantly outperforming established models like EEGNet (74.50%). Remarkably, S3T achieves this with only 8.68k parameters, compared to the 295k parameters required by traditional deep ConvNets. This efficiency makes it highly suitable for real-time BCI applications on portable hardware.
Ablation Study
A key finding of this research is the critical role of temporal attention. In ablation studies, removing the temporal attention module caused accuracy to drop by nearly 36%, confirming that global temporal relationships are the primary driver of the model's success.
Conclusion
The S3T model demonstrates that a "tiny" Transformer can outperform much larger CNN-based models in EEG decoding by effectively capturing spatial and temporal dependencies. While current training is subject-specific, future work will focus on cross-subject decoding and data augmentation to further enhance the model's generalizability and robustness for practical BCI systems.
Source Code: github.com/anranknight/EEG-Transformer
Summary updated