Abstract
Traditional Network Intrusion Detection Systems (NIDS) often suffer from poor domain adaptation, failing when deployed in environments different from their training data. This research proposes a transformer-based approach that treats network traffic flows as a language. By utilizing a BERT model to process sequences of flows, the system captures vital temporal context, allowing it to distinguish between benign traffic and sophisticated attacks more effectively. Experimental results demonstrate that this method maintains high accuracy across diverse datasets, significantly outperforming standard machine learning baselines in cross-domain scenarios.
Introduction
The primary challenge in modern NIDS is "brittleness"—the inability of a model to generalize from a controlled training environment to real-world target domains. Most existing models analyze "singular flows" in isolation, ignoring the sequential nature of network communication. This lack of temporal context makes it difficult to identify multi-stage attacks or differentiate them from benign traffic spikes. By framing network flow analysis as a sequence modeling problem, researchers can leverage advanced Natural Language Processing (NLP) techniques to improve robustness and domain adaptation.
Methodology
The core innovation lies in the analogy between network traffic and human language: a single network flow is treated as a "word," and a sequence of flows constitutes a "sentence."
Feature Engineering and Embedding
For each flow, six key features are extracted: Source Port, Destination Port, Protocol+Flags, Number of Packets, Number of Bytes, and Duration. These features are discretized and encoded. Each encoded feature is transformed into a 128-dimensional vector, which are then concatenated to form a 768-dimensional vector representing the entire flow.
BERT Architecture
These flow vectors are processed by a BERT (Bidirectional Encoder Representations from Transformers) model. BERT's bidirectional nature allows it to consider the context of a flow relative to all other flows in a sequence simultaneously. The model is first pre-trained using a Masked Language Model (MLM) task to learn the underlying structure of network traffic. Subsequently, it is fine-tuned with a linear layer and softmax output for binary classification (benign vs. malicious).
Experimental Setup
The model was evaluated using three distinct datasets to test its domain adaptation capabilities:
- CIDDS-001 (OpenStack): The "internal" subset was used for primary training and in-domain testing.
- CIDDS-001 (External Server): Real traffic from an external server, representing a domain shift.
- CIDDS-002: A dataset emulating a small business environment to test generalization to entirely different architectures.
Results
The proposed BERT-based method was compared against several baselines, including Energy-based Flow Classifiers (EFC), Decision Trees (DT), and Multi-Layer Perceptrons (MLP).
As shown in the results, the proposal achieved an Accuracy and F1 score of 0.994 on the internal test set, matching the performance of top-tier Decision Trees. However, the true strength of the model appeared in cross-domain testing. On the CIDDS-001 External set, the proposal maintained an accuracy of 0.895, whereas the MLP dropped to 0.573. Similarly, on CIDDS-002, the proposal reached 0.916 accuracy, significantly outperforming the Decision Tree's 0.818.
Discussion and Conclusion
The results indicate that modeling the relationships between flows provides a stabilizing effect against domain shifts. While individual flow features may vary across networks, the structural patterns of attack sequences remain more consistent. This research highlights the versatility of Transformer architectures beyond text, positioning them as powerful engines for any data that has sequential dependencies.
Future work will focus on refining sampling logic—perhaps grouping flows by host—and moving toward self-supervised anomaly detection to reduce dependency on labeled malicious data. Additionally, validating the model on more contemporary, high-speed traffic datasets remains a priority for real-world deployment.
Summary updated