Explainable Feature-Token Transformers for Network Intrusion Detection: SHAP-Based Interpretability and Class-Imbalance Mitigation on NSL-KDD
Preprint
- 15 August 2026
- preprint
- Published by Elsevier in SSRN Electronic Journal
Abstract
Security teams are increasingly unwilling to act on alerts from classifiers whose reasoning they cannot inspect, turning explainability into a hard requirement for network intrusion detection systems (NIDS). This paper proposes a lightweight feature-tokenized Transformer for multi-class intrusion detection, benchmarked on NSL-KDD (125,973 training and 22,544 test records across five categories, whose test partition contains 17 attack subtypes never seen during training) against Random Forest, an MLP, and an RBF-kernel SVM. It reaches 77.28% accuracy, weighted F1 of 0.723, and MCC of 0.670, edging out the other deep models while Random Forest keeps the lead on macro-precision (0.835) and macro AUC (0.957). SHAP gradient attributions for the Transformer are cross-checked against Random Forest's impurity-based importances, agreeing on 6 of the top 10 discriminative features but diverging on the rest — evidence feature-importance rankings are model-dependent rather than fixed. All models, including the proposed Transformer, initially failed to detect the minority R2L and U2R attack categories (recall 0.8% and 0%), reproducing a well-documented NSL-KDD limitation. Rather than stopping at diagnosis, we test two mitigations: inverse-frequency class-weighted loss and SMOTE-based minority oversampling. Classweighting lifts R2L and U2R recall to 29.7% and 40.3% at a cost to accuracy, while SMOTE lifts them to 25.5% and 28.4% while also improving accuracy (78.3%) and MCC (0.680) beyond baseline. These results show attention-based tabular Transformers are a viable, interpretable, improvable alternative to classical ensemble detectors, where explainability analysis can directly motivate a low-cost fix for a benchmark's best-known failure mode rather than merely describing it.Keywords
This publication has 4 references indexed in Scilit:
- Giant Trevally Optimization Driven CNN Transformer Framework for Intrusion-aware Secure Cloud StorageInternational Journal of Intelligent Engineering and Systems, 2026
- NetPhish-Mix: A Multi-Modal Phishing Detection Method Utilizing URL Graphs and Page Screenshot Vision TransformerEngineering, Technology & Applied Science Research, 2025
- SMOTE: Synthetic Minority Over-sampling TechniqueJournal of Artificial Intelligence Research, 2002
- Random ForestsMachine Learning, 2001