{'fraction_non_alphanumeric': 0.03330041694096993, 'fraction_numerical': 0.014483212639894667, 'mean_word_length': 4.947471451876019, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Monotonicity Constrained Attention Module for Emotion Classification with Limited EEG Data

In this work, a parameter-efficient attention module is presented for emotion classification using a limited, or relatively small, number of electroencephalogram (EEG) signals. This module is called the Monotonicity Constrained Attention Module (MCAM) due to its capability of incorporating priors on the monotonicity when converting features' Gram matrices into attention matrices for better feature refinement. Our experiments have shown that MCAM's effectiveness is comparable to state-of-the-art attention modules in boosting the backbone network's performance in prediction while requiring less parameters. Several accompanying sensitivity analyses on trained models' prediction concerning different attacks are also performed. These attacks include various frequency domain filtering levels and gradually morphing between samples associated with multiple labels. Our results can help better understand different modules' behaviour in prediction and can provide guidance in applications where data is limited and are with noises.


Introduction
Due to improved computational methodologies alongside affordable access to efficient and powerful computational and neuroimaging hardware, there has been significant enthusiasm for the development of techniques for analyzing, predicting, and understanding human behavior through brain signals recorded from neuroimaging devices. One of the most popular and widespread neuroimaging techniques is electroencephalography (EEG), which is appealing for a variety of reasons, including that electroencephalograms can capture excellent time resolution as far as neuroimaging techniques go while being recorded on pragmatic devices that are portable, available, and affordable.
As stated in [22], EEG classification algorithms can be roughly divided into the following five categories: i) conventional classifiers [28,18,19,20], ii) matrix and tensor based classifiers [6], iii) transfer learning based methods [3,8], iv) deep learning algorithms and advanced statistical approaches [5,23], and v) multi-label classifiers [21,3,31]. Although many effective classification methods exist, particularly those utilizing deep learning techniques, many potential concerns remain for developing practical algorithms which can be deployed for general contextual use. Three such problems include: 1) large open-sourced EEG data sets are limited, making deep neural networks with a lot of parameters challenging to train and generalize effectively; 2) brain signals such as scalp EEG are known to have a high signal-tonoise ratio, effectively polluting the training and generalizability of the models [17,2,25]; and 3) the result from large and deep networks -while accurately predictive -can be challenging to interpret [4,1].
One solution to the above three concerns (1)-(3) is to construct parameter-efficient models that can be trained on relatively small and potentially noisy data sets while being lightweight enough to allow for physically/medically/clinically interpretable solutions. We note that good candidates for such approaches are attention modules in neural networks such as in [10,33,32,7]. Thus this work, inspired by the self-attention mechanism and Gram feature matrix in the context of neural style transfer [9], presents the Monotonicity Constrained Attention Module (MCAM) that can dynamically construct the attention matrix from the feature Gram matrix. With MCAM, one can set constraints on different prior monotonic patterns to guide neural networks for selectively emphasizing informative features and suppressing unfavorable ones, leading to an efficient, accurate, and ultimately more easily interpretable framework.

Related Work
Attention Mechanism: Many attention mechanisms exist for refining deep features in the framework of neural network models. Among them, the Squeeze-and Excitation (SE) attention module [10] and Convolutional Block Attention Module (CBAM) [33] are two representatives. The former helped win the last ImageNet contest in 2017. The latter performed attention operations both spatially and channel-wise. Both the two attention modules can be applied to any existing network. More recently, starting from the research done in [7] with attention matrix computed from query-key-value (QKV) feature branches, various types of self-attention mechanism are growing fast in different fields such as computer vision (CV), e.g. [16,27] and speech processing,e.g. [24,13].
Our Work: With the setting of limited and noisy data, our primary contributions can be summarized as follows: 1) We have developed a Monotonicity Constrained Attention Module (MCAM) suitable for EEG-based emotion classification when data is limited. Our experiments show that MCAM can help achieve performance comparable to other SOTA modules requiring fewer trainable parameters. 2) MCAM opens a portal in the backbone network so that one can conveniently incorporate priors on the monotonicity of the learned function that can effectively convert feature-based Gram matrices into attention matrices for better feature refinement. 3) For better interpretation, extra sensitivity analysis on MCAM's prediction concerning different attacks is also performed to investigate the various influences caused by inserting attention modules.

Proposed Method
Gram Matrix Attention Figure 1: The Monotonicity Constrained Attention Module (MCAM). Here · 2 denotes the standard L 2 -norm.
The mechanism of our proposed attention module is summarized in Figure 1. First, the Gram matrix C [29] is computed using the deep channel features X.
Next, a function f : [−1, 1] → [0, 1] is constructed in the module, which is meant to 'learn' the mapping that effectively translates C element-wise to an attention matrix A for better classification. As the key component of MCAM, we use a 3-layer MLP for approximating f during training.
To understand the effect the trained function f has for incorporating prior information between feature correlation and attention, we test different constraints for regularizing the monotonicity of f . In this manuscript, three configurations of MCAM are considered: 1) M1, no constraint on f 's monotonicity at all; 2) M2, f should be non-decreasing on [−1, 0] and non-increasing on [0, 1], meaning the prior that less (positively or negatively) correlated features should contribute more to the corresponding value in A; and 3) M3, f should be non-increasing on [−1, 0] and non-decreasing on [0, 1] meaning the prior that the more correlation (positively or negatively) should result in more attention strength through A.
The monotonicity constraint is defined using a uniform grid {t i }, i = 0, · · · , N , on [−1, 1], where for for case M2 the loss becomes: and for case M3 becomes: Here f is estimated using a simple first order finite difference scheme. Finally, the resulting attention matrix A incorporates into the deep feature refinement via the expression X + XA as shown in Figure 1.

Experiments
EEGNet: EEGNet is a compact convolutional neural network for EEG-based brain-computer interfaces which was proposed by [15].We choose EEGNet as the backbone for benchmarking different attention modules for two main reasons: 1) It is one representative model that is parameter efficient, thus very suitable for small datasets; 2) Its simple design allows for accessible examinations and interpretations on the effects of attention modules considered in this paper.
Data Collection: DEAP dataset [12] is a well known database for benchmarking various emotion classification and analysis methods [11,30,14,26]. The dataset contains 32-channels EEG signals and 8-channels peripheral physiological signals from 32 volunteers who were asked to watch 40 1-min videos and report their emotion scores (varying from 1 to 9) in the four categories: valence, arousal, dominance, and liking. We will only be using the 32-channels EEG for experiments.
Data Preprocessing: We are interested in the within-subject classification task in this study. Setting the threshold at 5, we convert emotion scores from valence/arousal categories to form a 4-class classification family, comprised of {HVHA, HVLA, LVHA, LVLA} for each subject. The first three seconds of each trial are baseline data and are used to normalize the rest via Note that Subject 23 is excluded in the following experiments because this subject has only three emotion labels.
Experiment Setting: For each subject, the data is split into three parts. The first 5000 time points (from ∼0s to ∼39s) will be used in training, the following 5000 -6000 (from ∼40s to ∼47s) will be used for validation,and the remaining segments (from ∼47s to ∼63s) are used for testing.
Note that in order to mitigate the problems associated to limited data and imbalanced labeling, a data generator is used to randomly crop segments of 1s to provide batches for feeding the network during training and validation. Within each batch, the generator guarantees that each label is associated with about 25% of the total samples generated. For a valid and consistent comparison among different models, the test set will be cropped into nonoverlapping segments of 1s. For each subject and each attention module compared, training is repeated 10 times. During each training repetition, the best model in terms of validation accuracy is reloaded to make predictions on the testing set, and one instance of the performance under that configuration is stored. For all experiments, the following hyperparameters are used: the backbone EEGNet's dropout rate is set to 0.5, the batchsize is set to 256, and the optimization is performed with an Adam optimizer using a learning rate of 10 −3 . For training with the proposed MCAM, the weight for the extra loss constraining monotonicity is set at 0.1. These hyperparameters were selected from our pre-experiments with a small amount of data. Same hyperparamters were used for all experiments. The code used for our experiments will be made available at https://github.com/dykuang/BCI-Attention Benchmark: We summarize commonly used classification metrics in Table 2, using EEGNet as the backbone, and inserting all attention modules at the same location in our benchmark. Notice that the QKV type self-attention performs the worst, demonstrating no improvement. We hypothesize this is due to limited training data, as pointed out in [7]. For the remainder of this section, we focus only on the attention modules where performance is equivalent to, or higher than the backbone model. For a more quantitative comparison, we also perform paired T-tests and collect the resulting p-values in Table 1. At a significance level of α = 0.02 the alternative hypothesis H 1 is accepted, i.e. EEGNet+M3 has a higher F1-score than EEGNet alone. At significance level of α = 0.05, EEGNet+M3 has a higher F1-score than EEGNet+CBAM. Note that there is not enough evidence (at the significance level of 0.05) to reject the null hypothesis for the rest tests. That is, EEGNet+M3 performs similarly to EEGNet+SE and EEGNet+M1. Finally we can check the different monotonic patterns learned for different subjects during training. Figure 2 shows one example of the monotonic pattern mapping from C ij to A ij learned with different prior constraints. The insertion of different attention modules can potentially change the spatial attention pattern of the backbone EEGNet. For comparison, we can visualize the scalp map with EEGNet's kernel weights (normalized to [−1, 1]) for its spatial attention pattern, i.e., kernel weights in the first depthwise convolution layer. As one can observe from Figure 3, global patterns vary from model to model, though they share the same backbone network. Locally speaking, except for the case +M2, the value pair learned for channels T8 and T7 have different signs, while the case +CBAM learned the opposite pattern compared to the rest. With the exception of +M1, all other configurations show a locally isolated island in the Fp1 area. All three variations of MCAM considered here also show a similar attention pattern around the O2 area.

Models' scalp attention pattern
The standard deviation shown can be interpreted loosely as corresponding to each model's confidence in the value of its coincident kernel weights. Models compared here show high confidence in most areas, where areas of low confidence offer an interesting opportunity for deeper analysis and potentially clinical interpretation. It is also worth noting that, similar to the mean value patterns, the global patterns for standard deviation appear quite different across different models. Whether or not these patterns can be tied to clinical findings remains a question. On the other hand, robust algorithms that can help encode one's prior knowledge about clinical patterns into the models' weights is also an import research direction.

Models' sensitivity of prediction on inputs' frequency
Low pass filters are frequently used in applications to suppress noise as a preprocessing step. This section examines how frequency information in the input affects the trained model predictions with different modules inserted. With the same test data, first, a lowpass filter is used at different frequencies, and then the accuracy of different model predictions is tracked on this filtered input. Figure 4 demonstrates the result for subject 12 and subject 24. Of note is that different models show the same trend given the same data, but the trends vary across different subjects. For subject 12, a noticeable drop in performance is observed when inputs are lowpass filtered below 50Hz, while stable performance is recovered when the frequencies are set below 30Hz. For subject 24, a noticeable drop in performance is seen at 60Hz, while the performance trace decreases slowly as frequencies go lower. In the case of subject 24, suppressing high-frequency noise using lowpass filters seems to compromise model performance. While each model decreases in performance as higher frequencies are filtered out, the configuration of EEGNet+M2 has an opposite trend in the range of 20 ∼ 40Hz. This observation raises what seems to serve as a cautionary tale that it is crucial to take care when smoothing data in the frequency domain, as the response may be complicated and hard to predict a priori.

Model sensitivity on morphisms between samples.
Considering two samples x i and x j each associated with a different label i and j in the N classification problem, we define a morphism g j i parameterized by u ∈ [0, 1] such that x i = g j i (0) * x i and x j = g j i (1) * x i . The abstract operation * will be made explicit below, as an example. We further note that in the above setting, a value u j i always exists such that the model's confidence score (usually represented by the softmax value from the last dense layer's output) for label i first drops below its score for label j. The lower the value of u j i is, the more likely the model under examination will change its prediction on sample x i from label i to label j.
For visualization, we set u j i as a point in polar coordinates (ρ, θ) = (u j i , where v j = 0, · · · , N − 2 is some indexing for different j. These points will serve as the vertices of an N − 1 polygon. The resulting summation S i = j =i u j i then represent how likely a model is to choose label i against all other labels under the considered morphism g. Furthermore, if u j i + u i j = 1 then , in which case we can check the values of S i , i = 0, · · · , N − 1 among different models on the same selected "representative" samples per label for comparing their "preferences" among candidate labels under the chosen morphism g. As a demonstration of the above concept, we choose the simple discrete linear interpolation for g, defined by g j i (u) * x i = (1 − u)x i + ux j as the morphism operation, where samples {x i } are selected so that all considered models have correct predictions on them. The resulting summaries are shown in Figure 5. Each donut plot of the above two rows is the visualization of S i for a specific model. The last row gives an example of expanding more detailed information per slice by visualizing a triangle (3-polygon) for each label. All models being compared here assign the lowest values to the HVLA category, meaning models are more likely to assign other labels for the input HVLA sample when g morphs it away to other samples of different labels. Also, note that both the backbone model and the case when CBAM  figure 2). Additionally, we examine how the scores S i for i = 0, 1, 2, 3 are spread across the four labels by checking the standard deviation (std), thus indicating how each model distributes their prediction "preference" among the 4 categories given the selected input samples and morphism g. Here we find that the std for the backbone EEGNet is 0.269, while the insertion of CBAM and SE raises the std to 0.274 and 0.292, respectively, where the distributions are notably more skewed. However, MCAM( M1) has an std of 0.271, which is the close to the case where no attention module is inserted at all, while MCAM( M2) has by far the lowest value std of 0.164 followed by a std of 0.215 for the MCAM( M3).

Conclusion
We have constructed a parameter-efficient attention module called MCAM for emotion classification tasks with limited EEG data. MCAM allows one to put constraints on the embedded function's monotonicity for mapping a deep feature Gram matrix to form an effective attention matrix during feature refinements. Experiments show that MCAM's effectiveness is comparable to state-of-the-art attention modules with additional benefits. Additionally, a sensitivity analysis with different levels of lowpass filtering has been conducted, along with a novel morphing analysis designed to improve insight into the model's behavior through visualization. Future work will focus on designing more generalizable and interpretable models on limited and corrupted data sets.

Acknowledgement
This work was partially supported by the Fundamental Research Funds for the Central Universities, Sun Yat-sen University (22qntd2901)