FlowletFormer: Network Behavioral Semantic Aware Pre-training Model for Traffic Classification

Liming Liu, Ruoyu Li, Qi Li, Meijia Hou, Yong Jiang, Mingwei XuarXiv 2025 · DOI

Introduction

Network traffic classification is a cornerstone of network management and security. While recent adaptations of Large Language Models (LLMs) like BERT (e.g., ET-BERT) have shown promise, they often treat raw packet data as a flat sequence of "words," typically 4-hex bigrams. This "mechanical" approach fails to account for the structured, hierarchical nature of network protocols. Specifically, standard tokenization often overlooks critical 1-byte fields and ignores the functional differences between identical hex values appearing in different protocol layers.

To address these gaps, we present FlowletFormer, a BERT-based pre-training model designed to be network behavioral semantic aware. By moving beyond treating traffic as simple text and instead respecting its logical structure, FlowletFormer achieves state-of-the-art (SOTA) performance across multiple benchmarks, particularly in data-scarce scenarios.

Methodology: Flowlets and Field Tokenization

The core innovation of FlowletFormer lies in its departure from arbitrary "burst" segmentation. Instead, it groups packets into Flowlets—coherent behavioral units defined by logical interactions, such as an HTTP request-response pair, separated by an Inter-Arrival Time (IAT) threshold.

The FlowletFormer pipeline: from raw PCAP to token sequences via flowlet generation and field tokenization.

Complementing this is Field Tokenization, which treats protocol header fields as "morphemes"—the smallest units of meaning. Unlike bigram tokenization, this ensures that a 1-byte field (like IP version) remains a single token, preserving its semantic integrity and preventing the fragmentation of protocol logic.

Model Architecture and Pre-training

FlowletFormer integrates domain-specific knowledge directly into the transformer architecture through a Protocol Stack Alignment-Based Embedding. This layer explicitly identifies which TCP/IP layer a token belongs to (Network, Transport, or Application), allowing the model to distinguish between identical hex values used in different contexts (e.g., a port number vs. a header length).

The FlowletFormer architecture, illustrating the pre-training tasks (MFM and FPT) and the protocol-aware embedding layer.

The model is pre-trained using two novel tasks:

  1. Masked Field Model (MFM): Instead of random masking, the model selectively masks "key fields" like ports and sequence numbers, forcing it to learn the underlying protocol logic.
  2. Flowlet Prediction Task (FPT): The model learns to predict the relationship between two Flowlets (e.g., are they in the correct temporal order?), which helps capture flow-level continuity and behavioral patterns.

Evaluation and Results

FlowletFormer was pre-trained on 30GB of unlabeled raw traffic from sources like ISCX-VPN2016 and CIC-IDS2017. It was then fine-tuned on eight datasets covering service identification, security (malware/IoT), and privacy (website fingerprinting).

Key results include:

  • SOTA Performance: FlowletFormer outperformed baselines like ET-BERT and TrafficFormer on 7 out of 8 datasets, achieving over a 5% F1-score improvement on five of them.
  • Few-Shot Resilience: The model demonstrates remarkable accuracy even with limited labeled data. On the ISCX-VPN-App dataset, it maintained an F1 of 0.8009 with only 40% of the training data, significantly outperforming supervised models.
  • Semantic Understanding: Probing tests showed that the model develops a deep functional understanding of network services, correctly identifying relationships between related ports and protocols.

Conclusion

FlowletFormer demonstrates that incorporating domain-specific "grammar" into transformer models is far more effective than brute-force sequence modeling for network traffic. While the model currently faces challenges related to fixed input lengths and computational overhead, its ability to capture behavioral semantics marks a significant step forward in robust traffic classification. Future work will focus on optimizing for real-time deployment and exploring multi-modal data integration.

Summary updated

BibTeX
@misc{liu2025flowletformer,
  author = {Liming Liu and Ruoyu Li and Qi Li and Meijia Hou and Yong Jiang and Mingwei Xu},
  title = {{FlowletFormer: Network Behavioral Semantic Aware Pre-training Model for Traffic Classification}},
  year = {2025},
  eprint = {2508.19924},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.19924},
}
Figure