A Lightweight Transformer for Pain Recognition from Brain Activity
Authors: Stefanos Gkikas, Christian Arzate Cruz, Yu Fang, Lu Cao, Muhammad Umar Khan, Thomas Kassiotis, Giorgos Giannakakis, Raul Fernandez Rojas, Randy Gomez
Organizations: Honda Research Institute Japan, Wako City, Japan · BioSIS (Biosensing & Intelligent Systems) Lab, Centre for Intelligent Computing and Systems, University of Canberra, Canberra, Australia · Department of Electronic Engineering, Hellenic Mediterranean University, Chania, Greece
Pain is a multifaceted and widespread phenomenon with substantial clinical and societal burden, making reliable automated assessment a critical objective. This paper presents a lightweight transformer architecture that fuses multiple fNIRS representations through a unified tokenization mechanism, enabling joint modeling of complementary signal views without requiring modality-specific adaptations or increasing architectural complexity. The proposed token-mixing strategy preserves spatial, temporal, and time-frequency characteristics by projecting heterogeneous inputs onto a shared latent representation, using a structured segmentation scheme to control the granularity of local aggregation and global interaction. The model is evaluated on the AI4Pain dataset using stacked raw waveform and power spectral density representations of fNIRS inputs. Experimental results demonstrate competitive pain recognition performance while remaining computationally compact, making the approach suitable for real-time inference on both GPU and CPU hardware.
Figures & tables
Fig. 1 : Overview of the proposed tokenization framework, using the two fNIRS representations.
Hyperparameter
Value
Depth ( L )
4
Number of latents ( M )
32
Latent dimension ( d )
128
Cross-attention heads
1
Latent self-attention heads
8
Cross-attention head dimension
64
TABLE I : Architectural details.
Optimizer
LR
LR decay
Weight decay
Total epochs
Warmup epochs
Cooldown epochs
Batch size
AdamW
2e-5
cosine
0.1
200
20
10
32
TABLE II : Training configuration.
Input
#Segm.
Computational Cost
Inference Cost
Performance
Params(M)
GFLOPs
Latency (ms) GPU ↓
Samples/s GPU ↑
Latency (ms) CPU ↓
Samples/s CPU ↑
Accuracy
Precision
F1
fNIRS-Wave
–
7.81
2.58
14.26
70.14
22.44
44.56
43.94
42.94
39.34
fNIRS-PSD
–
15.05
15.07
14.36
69.64
56.14
17.81
49.26
47.91
39.90
fNIRS-Wave
2
7.81
0.25
13.33
74.99
11.33
88.27
46.06
42.63
43.20
fNIRS-PSD
2
15.05
12.74
13.40
74.62
51.03
19.59
52.31
46.66
47.76
fNIRS-Wave
4
7.81
0.41
14.31
69.90
11.80
84.75
46.99
44.32
43.59
TABLE III : performance and computational/inference cost of fNIRS representations across latent segmentation settings.
Fig. 2 : Effect of latent segmentation on fNIRS accuracy (averaged across waveform and spectrogram representations) versus computational and inference cost.
Modality
Fusion
Computational Cost
Inference Cost
Performance
Params(M)
GFLOPs
Latency (ms) GPU ↓
Samples/s GPU ↑
Latency (ms) CPU ↓
Samples/s CPU ↑
Accuracy
Precision
F1
fNIRS-Wave
stack
15.15
15.20
13.79
72.54
49.00
20.41
48.52
45.62
44.62
fNIRS-PSD
TABLE IV : performance and computational/inference cost for the representation fusion.
Study
Modality
Method
Accuracy
Video
fNIRS
Features
Model
—
✓
43.30
✓
—
40.10
[ 49 ]
✓
✓
Handcrafted
SVM
41.70
[ 51 ]
✓
✓
Deep
Transformer
46.67
[ 52 ]
✓
—
Deep
2D CNN
49.00
TABLE V : Comparison of studies on the AI4Pain testing set.
Honda Research Institute Japan Wako City, Japan · BioSIS (Biosensing & Intelligent Systems) Lab Centre for Intelligent Computing and Systems University of Canberra Canberra, Australia