Manuscript Offprint
arXiv:2609.37672NetLexicon: Learning Discrete Behavioral Representations for Encrypted Web Traffic Analysis
Abstract
Encrypted Web traffic analysis requires effective representations of observable communication behavior. Existing pretraining methods often adapt NLP/CV objectives and sequence architectures, motivating learning objectives that capture traffic-specific interaction patterns. We present NetLexicon, a discrete pretraining framework that learns reusable behavioral states from unlabeled traffic. It converts contextual traffic windows into discrete states through vector quantization, constructing a compact traffic lexicon. We design two complementary pretraining objectives. State Transition Prediction (STP) forecasts subsequent sequence structure and packet features from observed history, while Statistical Feature Alignment (SFA) grounds learned states in window-level traffic statistics. Together, they guide the lexicon to capture recurring communication behaviors and their evolution.
We evaluate NetLexicon on four benchmarks covering Web application identification, service type identification, and malware detection. NetLexicon improves Macro-F1 by up to 25.5 percentage points over the strongest baseline on each benchmark and reduces fine-tuning time per epoch by up to 23.6Γ relative to the evaluated baselines. Further analysis shows that the learned discrete states capture recognizable patterns in packet size, timing, and data transfer. These results demonstrate that incorporating observable behavioral structure into pretraining supports effective, efficient, and interpretable representations for encrypted traffic analysis.
1 Introduction
Web activities such as page retrieval and content delivery produce observable traffic patterns even under encryption. Encrypted traffic analysis uses observable packet lengths, directions, and timing to identify websites, applications, and potential threats, supporting Web service management, network measurement, and security . To support these tasks, supervised models learn to associate observed traffic patterns with application or activity labels, making labeled examples central to their training and adaptation. High-quality labels are expensive to obtain and maintain, while evolving services, applications, and network environments cause distribution shifts that require repeated model updates . This motivates learning reusable representations from abundant unlabeled traffic to reduce downstream labeling requirements and adaptation costs.
Self-supervised pretraining offers a promising approach [8, 15, 20, 48]. Inspired by natural language processing (NLP) and computer vision (CV), recent methods learn traffic representations through tokenization, serialization, and masked prediction and

Figure 1: Model size and classification performance on CipherSpectrum [43]. NetLexicon achieves the highest Macro-F1 with under 2M parameters.
reconstruction objectives, while exploring larger or more complex backbones [5, 20, 40, 48, 49, 51]. Figure 1 compares performance and model size on CipherSpectrum [43], where NetLexicon achieves the highest Macro-F1 with under 2M parameters. This motivates a closer look at objective design: how can traffic-intrinsic behavioral characteristics support efficient learning of meaningful communication representations?
In this paper, traffic semantics refers to the patterns of data transfer and interaction produced by application activities and protocol exchanges, such as concentrated responses following requests, sustained bulk transfer, and intermittent exchanges of small amounts of data. Packet lengths characterize exchange volume, inter-arrival times capture transmission rhythms, and direction changes and burst structures describe endpoint interactions . For example, a short upstream burst followed by large downstream packets in Web traffic may reflect content delivery following a request, while small bidirectional exchanges separated by longer intervals may reflect lightweight background interactions. Their combination and evolution within flow context provide a direct basis for learning traffic semantics.
Existing methods have advanced input organization and sequence modeling. As summarized in Table 1, prior approaches incorporate flow-level context and traffic-specific objectives to varying degrees, while explicitly grounding learned representations in observable behavior remains underexplored. Learning reusable traffic semantics calls for objectives that connect two complementary properties: temporal dependencies make the current interaction predictive of subsequent transmissions, while recurring packet-length, direction, and timing patterns provide observable characteristics of shared behaviors across flows. These observations motivate our central question: how can self-supervised traffic pretraining abstract encrypted interaction patterns into reusable behavioral states and learn their evolution over time?
Gao et al.
Table 1: Comparison of traffic pretraining designs.
| Method | Header Only | Flow Context | Traffic Objective | Behavior Grounding |
|---|---|---|---|---|
| ET-BERT [20] | β | β | β | β |
| YaTC [48] | β | β | β | β |
| NetMamba [40] | β | β | β | β |
| TrafficFormer [51] | β | β | β | β |
| Pcap-Encoder [49] | β | β | β | β |
| NetLexicon (Ours) | β | β | β | β |
The model encodes multiple packets to capture inter-packet dependencies.
The pretraining task is tailored to traffic characteristics.
Representations are aligned with observable traffic behavior.
We introduce NetLexicon , a discrete pretraining framework that encodes packet and burst sequences within flow-level context using header fields and metadata such as packet sizes and timing. It maps window representations to a finite set of codewords through vector quantization [38], constructing a traffic lexicon. Similar window-level behaviors share states, whose sequence describes how communication evolves.
To learn states that capture how traffic evolves and what behavior each window exhibits, we design two self-supervised pretraining objectives: State Transition Prediction (STP) and Statistical Feature Alignment (SFA). STP predicts subsequent sequence structure and packet features from observed context, encouraging the learned states to preserve information about future communication behavior. SFA aligns each quantized state with packet-length, direction, and inter-arrival-time statistics from the same window, grounding the state in observable behavioral characteristics. Together, our objectives shape the traffic lexicon through temporal prediction and statistical alignment, enabling it to capture recurring behaviors and their evolution.
We pretrain NetLexicon on backbone and QUIC/HTTP3 application traffic [6, 12] and evaluate it on four tasks. Website fingerprinting on CSTNET [20] and encrypted application fingerprinting on CipherSpectrum [43] assess its ability to distinguish Web-related communication behaviors. Service type identification on ISCXVPN [9] and malware detection on USTC-TFC [41] assess its broader applicability. We further examine interpretability through associations between representations and behavioral statistics, codebook utilization, and codeword cases, alongside training and inference overhead.
We make the following contributions:
-
Reframing traffic pretraining. We connect packet lengths, inter-arrival times, and directions to interaction patterns, organizing encrypted traffic representations through shared behavioral states and their evolution.
-
Learning a discrete traffic lexicon. We introduce NetLexicon, which combines vector quantization with our STP and SFA objectives to learn predictive and behaviorally grounded discrete states from unlabeled traffic.
-
Effectiveness, efficiency, and interpretability. Across four Web-related and broader traffic classification tasks, NetLexicon
improves Macro-F1 by up to 25.5 percentage points, reduces fine-tuning time per epoch by up to , and learns interpretable states aligned with meaningful communication behaviors.
2.1 Traffic Representation Learning
Traffic classification identifies applications, services, and malicious activities from observed traffic flows, supporting network measurement and security. Dynamic ports and payload encryption have driven the use of statistical features, including packet size distributions, inter-arrival times, and flow statistics [11, 28, 35, 36]. Conventional approaches combine these features with classifiers such as SVMs and random forests [26, 28]. Deep learning methods further learn representations from packet and flow data using CNNs, RNNs, and GNNs [1, 19, 21, 23, 34, 42], with applications to website fingerprinting, encrypted stream identification, and mobile traffic analysis [30β33, 37]. These developments establish representation learning as an important component of traffic analysis.
Self-supervised pretraining learns transferable representations by constructing supervision from unlabeled data and adapting the pretrained encoder to labeled downstream tasks [4, 8, 15, 16]. Two common approaches are sequence modeling, which predicts masked or future observations, and contrastive learning, which aligns related samples and separates unrelated ones [4, 29]. Traffic pretraining methods build on these ideas through masked byte modeling in ET-BERT, masked autoencoder reconstruction in YaTC, and sequence modeling with architectures such as NetMamba and TrafficFormer [20, 40, 48, 51]. Other studies further explore relationships between packets and flows, multimodal information, and representations built around bursts [5, 14, 46]. Together, these methods provide a foundation for learning from large traffic corpora and adapting to downstream classification tasks.
Recent studies emphasize the importance of what these representations learn. Pcap-Encoder revisits pretraining objectives based on packet headers, while CipherSpectrum and related critiques show how dataset artifacts, spurious correlations, and evaluation practices affect encrypted traffic classification [43, 49]. Broader studies in security machine learning also highlight shortcut learning and data leakage as concerns for reliable evaluation [3, 17]. These findings motivate pretraining objectives grounded in observable communication behavior. For NetLexicon, this means learning representations that preserve packet size, direction, and timing patterns together with their temporal dependencies, providing a behavioral foundation for adaptation across traffic analysis tasks.
2.2 Learning Discrete Traffic States
Network traffic exhibits recurring patterns shaped by protocol behavior and communication dynamics, including packet structure, timing, bursts, and relationships across packets [46]. These patterns motivate a representation of traffic as transitions among latent behavioral states, such as request bursts, sustained responses, and intermittent exchanges. In NetLexicon, a traffic state denotes a learned behavioral category for traffic windows that captures recurring communication patterns across flows. Grouping similar
https://anonymous.4open.science/r/Open-NetLexicon/
Gao et al.
windows into shared states provides a compact way to organize these patterns, while state sequences describe how interactions evolve. This perspective connects the choice of representation to the behavioral semantics available in encrypted traffic [43].
Learning discrete latent variables requires handling nondifferentiable assignments during optimization [18, 24]. We build on Vector Quantized Variational Autoencoders (VQ-VAE), which map each encoder output to its nearest entry in a learned codebook and use the corresponding index as a discrete latent variable [38]. This produces a finite vocabulary of reusable representations [10, 38]. In our setting, codewords represent behavioral states of traffic windows. Related traffic models also exploit burst and flow structure. Flow-MAE uses preprocessing based on bursts and learns from fixed byte patches, while TrafficFormer represents directional bursts as tokens for masked modeling [14, 51]. Building on these traffic organization cues, NetLexicon quantizes contextual window representations into a discrete traffic lexicon. We design State Transition Prediction and Statistical Feature Alignment to shape this lexicon through future behavior prediction and alignment with observable window statistics.
3 NetLexicon
Goal. NetLexicon aims to learn reusable traffic semantics from unlabeled flows by abstracting the interaction patterns of Web activities into discrete behavioral states. These states capture how data is exchanged and how communication evolves, supporting downstream traffic analysis.
Challenges. Packet lengths, directions, and timing jointly reflect communication behavior, whose interpretation depends on the surrounding flow context. Learning a shared state vocabulary requires preserving these temporal dependencies while associating each state with observable characteristics of recurring interactions across flows.
Solutions. NetLexicon encodes packet and burst sequences within flow context and quantizes window representations into a discrete traffic lexicon. We design State Transition Prediction (STP) to capture how interactions evolve and Statistical Feature Alignment (SFA) to characterize the behavior each window exhibits. Together, they guide the lexicon toward predictive states grounded in measurable traffic patterns. Figure 2 presents the overall framework.
3.1 Framework
The input to NetLexicon is a bidirectional flow defined by source IP, destination IP, source port, destination port, and transport protocol, with packets ordered chronologically. Following TrafficFormer [51], a burst contains consecutive packets in the same direction, and a window contains consecutive bursts, with by default. We insert a [SEP] token after each burst and a [WIN] token after every bursts. These markers expose interaction boundaries within the packet sequence.
Each packet token contains seven normalized features and seven binary missing indicators, yielding a 14-dimensional input. The features are packet size, direction, inter-arrival time, TCP flags, IPID delta, relative TCP sequence number, and relative TCP acknowledgement number. Table 2 summarizes the selection, which emphasizes observable communication behavior and relative transport progress. [PAD] tokens are zero filled and masked out from attention and all pretraining losses.
Table 2: Feature choices in NetLexicon.
| Feature group | Used in model | Easy shortcut | Behavior |
|---|---|---|---|
| Packet size | β | β | β |
| Direction | β | β | β |
| Interarrival time | β | β | β |
| TCP flags | β | β | β |
| IPID | β | β | β |
| Raw IPID | β | β | β |
| Rel. SEQ | β | β | β |
| Abs. SEQ | β | β | β |
| Rel. ACK | β | β | β |
| Abs. ACK | β | β | β |
| IP address | β | β | β |
| Port number | β | β | β |
| TTL | β | β | β |
Indicates whether the feature primarily reflects communication behavior and state evolution, without encoding endpoint identity or arbitrary absolute values.
Packet features, token types, and positions are embedded into a shared hidden space and processed by a causal transformer. The output at position uses observations up to . At each valid [WIN] position, the encoder therefore summarizes the traffic prefix through the current window. We quantize this representation into a discrete state. STP supervises the encoded sequence through predictions at valid token positions, while SFA aligns quantized window states with statistics from their corresponding windows.
3.2 Discrete Traffic Lexicon
The traffic lexicon groups contextual windows into a finite set of reusable behavioral states. Quantization encourages recurring patterns to share codewords, while causal encoding provides the packet, burst, and historical context needed to distinguish their roles in an interaction.
Let denote the representation at the boundary of window , and let be a learned codebook with . The state index is assigned by nearest-neighbor lookup
and its quantized representation is
Across a flow, these assignments produce a state sequence and its corresponding representations .
We update the codebook through exponential moving averages (EMA) of assignment counts and assigned representations, as shown in Algorithm 1. A straight-through estimator passes gradients from quantized representations to encoder outputs. The commitment loss keeps the outputs close to their assigned codewords
where is the stop-gradient operator and is the number of valid windows in the batch.
The default codebook contains entries, with EMA decay 0.99 and stability constant . Every 500 steps, entries with EMA assignment counts below 0.01 are checked for reinitialization to
Gao et al.

Figure 2: Overview of NetLexicon.
Algorithm 1 EMA based codebook update in NetLexicon
Require: Window representations , codebook , EMA states and , decay rate , stability constant
Ensure: Assignments and updated codebook
1: for each do
2:
3: end for
4: for each codeword index do
5:
6:
7:
8:
9:
10: end for
11: Periodically reinitialize underutilized codewords
12: return and
maintain codebook utilization. Section 4 examines sensitivity to codebook and window sizes.
3.3 State Transition Prediction
We design STP to make representations predictive of how communication evolves. Request bursts, responses, and waiting periods provide context for subsequent packets and interaction boundaries. A useful window state should therefore summarize the observed interaction and preserve information about what follows. STP uses this temporal dependency as supervision through two prediction heads, as illustrated in Figure 3.
Following causal self-attention [39], position t attends to positions up to t and predicts a target at . We construct the targets by shifting the input sequence by one position. The heads operate at valid positions, using quantized states at [WIN] positions and contextual encoder outputs elsewhere. Predictions at window boundaries thus train the discrete states to capture future behavior, while predictions at other positions provide dense supervision for the shared encoder.
The first head predicts whether the next token is a packet, a burst separator, or a window separator. This task captures whether the sequence continues within a burst or reaches an interaction boundary. Let denote the target and the predicted distribution. The loss is
where T contains valid positions whose next token is also valid.
When the next token is a packet, the second head predicts its normalized feature vector, including packet size, direction, timing, and transport information. Let contain these positions, with target and prediction , where . The feature loss is
Together, the type head learns the structural progression of the sequence, and the feature head learns the characteristics of the packets that follow. Their combined objective is
where and balance the two losses.
3.4 Statistical Feature Alignment
We design SFA to associate each discrete state with measurable characteristics of its traffic window. STP encourages a state to predict subsequent behavior, while SFA preserves information about the behavior exhibited within the current window. It provides this supervision by aligning two views of the same communication segment, as shown in Figure 4.
The first view is the quantized state , and the second is a statistical vector computed from the same window. We use features summarizing packet and byte volume, directional balance, packet length and timing distributions, TCP control flags, and active or idle behavior. These statistics provide supervision directly from observed traffic. The state incorporates preceding
Gao et al.

Figure 3: An illustration of the State Transition Prediction task.

Figure 4: Loss computation of Statistical Feature Alignment.
flow context, while summarizes the current window. Aligning them anchors the contextual state to the behavior observed in that segment.
Two learnable heads project the state and statistical views into a shared contrastive space
Both heads output 64-dimensional vectors, which are normalized before comparison. Within a batch of valid windows, forms a positive pair. Pairing the same state view with statistics from another window, for , forms a negative pair. Using cosine similarity , SFA minimizes the InfoNCE loss [29]
with temperature . The loss encourages each state view to match its corresponding statistical view more closely than those of other windows. This guides quantized states to preserve the statistical characteristics of their assigned windows, giving the traffic lexicon an observable behavioral basis.
3.5 Pretraining Objective and Adaptation
The full pretraining objective combines temporal prediction, codebook commitment, and statistical alignment
Table 3: Downstream datasets after preprocessing.
| Dataset | Task | Flows | Classes |
|---|---|---|---|
| CSTNET [20] | Web APP fingerprinting | 45.16K | 120 |
| CipherSpectrum [43] | Web APP fingerprinting | 164.2K | 42 |
| ISCXVPN [9] | Service type identification | 2.184K | 7 |
| USTC-TFC [41] | Malware detection | 114.3K | 17 |
where and by default. All supervision is constructed from unlabeled traffic through subsequent token types, packet features, and window statistics. The objectives jointly train the shared encoder and associated prediction and projection heads. Gradients pass through quantization to the encoder, while the codebook follows the EMA update in Algorithm 1.
For downstream tasks, NetLexicon initializes the embedding layer and encoder with pretrained parameters and pools the contextual [WIN] representations into a flow representation. A task-specific classification head maps this representation to downstream labels. Fine-tuning uses cross-entropy loss on labeled flows, adapting the pretrained behavioral representations to the target task.
4 Evaluation
We evaluate NetLexicon across four downstream tasks to examine classification performance, the contribution of its pretraining components, and the behavioral information captured by the discrete traffic lexicon. We further compare model size, fine-tuning time, inference latency, and memory usage to assess its cost.
4.1 Experimental Setup
Pretraining Data. Our pretraining corpus combines MAWI [6] and VisQUIC [12]. MAWI provides diverse backbone traffic from the WIDE trans-Pacific link, while VisQUIC contributes encrypted QUIC/HTTP3 application traffic from modern Web environments. Their combination covers both backbone communication and application interactions across TCP and UDP. We use SplitCap [27] to extract bidirectional flows following the definition in Section 3. The resulting corpus contains 1,057,331 flows and approximately 86.34 million packets, with 820,986 flows from MAWI and 236,345 from VisQUIC.
Downstream Data and Splits. Table 3 summarizes the four downstream datasets after preprocessing. CSTNET supports web application fingerprinting across 120 classes using TLS 1.3 traffic. CipherSpectrum also targets web application fingerprinting and balances each application class across three TLS 1.3 cipher suites, reducing correlations between application labels and cipher configurations. These datasets assess fine-grained discrimination in web application related settings. ISCXVPN covers service categories under VPN conditions, and USTC-TFC contains normal application and malware traffic, extending evaluation to broader traffic analysis tasks.
We apply the flow and burst preprocessing described in Section 3 and construct sliding windows of five consecutive bursts. Flows containing fewer than one complete window are discarded. Each dataset is randomly partitioned within each class at the flow level into training, validation, and test sets with an 8:1:1 ratio and seed 42. All windows from the same flow remain in the same split. The resulting flow partitions are shared across methods.
Gao et al.
Table 4: Performance comparison on Service Type Identification and Malware Detection.
| Method | ISCXVPN [9] | USTC-TFC [41] | ||||||
|---|---|---|---|---|---|---|---|---|
| Accuracy | Precision | Recall | F1-Score | Accuracy | Precision | Recall | F1-Score | |
| ET-BERT [20] | 0.4178 | 0.3665 | 0.3018 | 0.2850 | 0.9681 | 0.9073 | 0.8956 | 0.9011 |
| YaTC [48] | 0.6000 | 0.5985 | 0.5274 | 0.5373 | 0.9799 | 0.9531 | 0.9523 | |
| NetMamba [40] | 0.4044 | 0.3405 | 0.3965 | 0.3321 | 0.5333 | 0.6914 | 0.4114 | 0.4215 |
| TrafficFormer [51] | 0.6044 | 0.5566 | 0.5452 | 0.5485 | 0.9753 | 0.9169 | 0.9215 | |
| Pcap-Encoder [49] | 0.5411 | 0.5117 | 0.5413 | 0.5124 | 0.5465 | 0.4830 | 0.5820 | 0.5041 |
| NetLexicon (Ours) | 0.8267 | 0.8100 | 0.8003 | 0.8034 | 0.9889 | 0.9658 | 0.9474 | 0.9547 |
Table 5: Performance comparison on Web Application Fingerprinting.
| Method | CSTNET [20] | CipherSpectrum [43] | ||||||
|---|---|---|---|---|---|---|---|---|
| Accuracy | Precision | Recall | F1-Score | Accuracy | Precision | Recall | F1-Score | |
| ET-BERT [20] | 0.6039 | 0.5944 | 0.5396 | 0.5335 | 0.4440 | 0.3695 | 0.4514 | 0.3961 |
| YaTC [48] | 0.7356 | 0.7283 | 0.7069 | 0.7030 | 0.8022 | 0.7908 | 0.7894 | 0.7799 |
| NetMamba [40] | 0.7146 | 0.7233 | 0.6849 | 0.6836 | 0.2665 | 0.2260 | 0.2602 | 0.2088 |
| TrafficFormer [51] | 0.7616 | 0.7473 | 0.7287 | 0.7322 | 0.8650 | 0.8606 | 0.8633 | 0.8614 |
| Pcap-Encoder [49] | 0.4180 | 0.4010 | 0.3950 | 0.3980 | 0.4360 | 0.4210 | 0.4090 | 0.4149 |
| NetLexicon (Ours) | 0.8838 | 0.8757 | 0.8614 | 0.8637 | 0.9104 | 0.9049 | 0.8999 | 0.9002 |
Training Settings. We implement NetLexicon in PyTorch 2.5.1 and conduct experiments on NVIDIA A100 GPUs. The encoder contains four causal transformer layers with hidden size 192, feed-forward size 768, 16 attention heads, and a maximum sequence length of 256. The codebook contains 128 states, and the pretraining objectives follow Section 3. We pretrain for 20 epochs on one GPU with batch size 128, using AdamW with a learning rate of , cosine decay, and 1,000 warmup steps. The pretraining checkpoint is selected by validation loss.
Fine-tuning follows two stages. We first freeze the backbone and train the classification head at ten times the base learning rate, then unfreeze the model for end-to-end optimization. The base learning rate is , and the batch size is 128. We use AdamW with weight decay and gradient clipping, and optimize cross-entropy loss. The fine-tuning checkpoint is selected by validation accuracy, with the test split evaluated after checkpoint selection.
Baselines. We compare NetLexicon with ET-BERT [20], YaTC [48], NetMamba [40], TrafficFormer [51], and Pcap-Encoder [49]. These methods cover byte sequence modeling, flow image reconstruction, alternative sequence backbones, and header-based pretraining. We retain their public pretrained checkpoints and use consistent downstream partitions, fine-tuning settings, checkpoint-selection criteria, and evaluation metrics wherever applicable.
Each baseline retains its input representation. ET-BERT and TrafficFormer use five packets with 64 bytes per packet. YaTC and NetMamba use flow images. Pcap-Encoder operates on packet-level samples in our reproduction. Thus, the comparison evaluates adaptation from each method's existing pretrained model under the shared downstream protocol.
Metrics. We report accuracy, macro-precision, macro-recall, and Macro-F1 for classification, with Macro-F1 as the primary metric because it gives equal weight to each class. Behavioral analysis examines codebook utilization, associations between representation distances and traffic statistics, and representative codeword profiles. Efficiency measurements cover parameter count, fine-tuning time per epoch, inference latency, and GPU memory usage.
4.2 Traffic Classification
Tables 4 and 5 report classification results across all four tasks. NetLexicon achieves the highest accuracy and Macro-F1 on each dataset. On CSTNET, it reaches 86.37% Macro-F1 across 120 web application classes, exceeding the strongest baseline by 13.15 percentage points. On CipherSpectrum, it achieves 90.02% Macro-F1, improving over TrafficFormer by 3.88 points. The latter result shows that the advantage remains when application classes are balanced across cipher configurations. Together, these two benchmarks demonstrate the usefulness of the learned representation for fine-grained encrypted traffic classification in web application settings.
The results also extend to other traffic analysis tasks. On IS-CXVPN, NetLexicon improves Macro-F1 from 54.85% to 80.34%, a gain of 25.49 percentage points under VPN conditions. On USTC-TFC, the strongest baseline already reaches 95.23%, and NetLexicon achieves a smaller improvement to 95.47%. The different gain sizes reflect the varying difficulty and baseline performance of the tasks. Component Ablation. Figure 5 examines the contribution of the main components on CSTNET and CipherSpectrum. The full model achieves the highest Macro-F1 among the evaluated variants. Removing STP reduces performance, supporting the value of temporal supervision through future packet and sequence prediction. Jointly
Gao et al.

(a) Macro-F1 of Each Variant
(b) Active Codes (count 8)
(c) F1 Drop of Each Variant
Figure 5: Component ablation on CSTNET and CipherSpectrum, showing Macro-F1, codebook utilization, and performance drops.
removing LEX and SFA also reduces performance, demonstrating the contribution of the discrete lexicon together with statistical alignment. Removing SFA decreases the number of active codes from 97 to 61 on CSTNET and from 124 to 118 on CipherSpectrum, indicating that alignment with window statistics encourages broader codebook utilization. Removing pretraining causes the largest Macro-F1 drops, reaching 12.10 and 9.18 percentage points on the two datasets, respectively, highlighting the importance of the initialization learned from unlabeled traffic.
Parameter Sensitivity. We also examine codebook and window sizes through independently trained configurations on CipherSpectrum. For , test accuracy ranges from 90.95% to 91.16%, indicating limited sensitivity to codebook capacity in this range. Both and achieve an active-code ratio of 98.4%. Window size introduces a tradeoff between statistical context and flow coverage. Although achieves higher classification performance, 47.96% of its windows contain only three or four packets, providing limited context for window statistics. Increasing to 7 and 9 reduces usable short-flow coverage to 85.6% and 68.9%, respectively. The default balances these considerations. These sensitivity results were obtained after fixing the default configuration and were not used for its selection.
4.3 Traffic Semantics Analysis
We examine whether the learned representations preserve observable communication behavior through a quantitative comparison with baselines and an analysis of representative codewords. On the CipherSpectrum test set, 124 of the 128 codes receive at least eight assignments, showing broad use of the available state vocabulary. Association with Observable Behavior. We focus on packet length and inter-arrival time, which characterize the scale and pacing of data exchange. Both are established signals in statistical traffic

Figure 6: Association between representation distances and differences in packet size and inter-arrival time on Cipher-Spectrum.
classification, encrypted stream identification, and VPN traffic analysis [9, 26, 28, 33]. Full-flow mean packet size and serve as common probes for comparing the representations learned by different methods.
Using the same 16,441 CipherSpectrum test flows, we compute pairwise embedding distances within each application class and correlate them with differences in the corresponding traffic attribute. We then average the Spearman correlations across classes. This measures whether representations distinguish behavioral variation among flows with the same application label. Figure 6 shows that NetLexicon achieves correlations of 0.4476 for packet size and 0.3537 for inter-arrival time, approximately and those of the strongest baselines. Error bars denote 95% confidence intervals from 10,000 bootstrap resamples over classes. These results show that the learned representation retains size and timing information beyond the separation of application classes.
Representative Codewords. Figure 7 examines two codewords from the fine-tuned CipherSpectrum model. For each codeword, we summarize packet size, throughput, and inter-arrival time over its assigned windows and inspect the corresponding application composition. This connects the statistical profile of a state with the traffic sources in which it appears.
Code #4 groups windows with medium packet sizes, relatively low throughput, and longer inter-arrival times, forming a profile of sparse exchanges. More than half of its assigned windows come from adblockplus.org, with additional windows from naver.com, trustarc.com, google-analytics.com, and yahoo.co.jp. Code #56 exhibits larger packet sizes, higher throughput, and shorter inter-arrival times, forming a profile of sustained transfer. Its dominant application is typekit.net, with additional contributions from mozilla.net, gmx.net, web.de, and gstatic.com.
These examples illustrate two distinct communication patterns represented by the lexicon. Their behavioral interpretation follows from the measured size, throughput, and timing profiles, while the application composition shows that each state is reused across traffic from multiple sources. Together with the quantitative comparison, they provide evidence that the learned states organize windows around observable communication behavior.
4.4 Efficiency and Overhead
Figure 8 compares parameter count, fine-tuning time, inference latency, and GPU memory usage. These measurements characterize
Gao et al.

(a) Packet Size Dist
(b) Flow Throughput Dist
(c) Inter-Arrival Time Dist
(d) App Composition
Figure 7: Traffic profiles of two representative codewords in the fine-tuned CipherSpectrum model [43].
ET-BERT
YaTC
NetMamba
TrafficFormer
Pcap-Encoder
NetLexicon(Ours)

(a) Model Size
(b) Fine-tuning Duration
(c) Inference Latency
(d) GPU Memory Usage
Figure 8: Comparison of model size, fine-tuning time per epoch, inference latency, and GPU memory usage.
both the cost of adapting a pretrained model and the resources required for inference.
NetLexicon contains 1.9M parameters and requires 3.0 minutes per fine-tuning epoch, with 4,106 batches in each epoch. Its epoch time is up to lower than the evaluated baselines, supporting efficient adaptation to downstream tasks. At an inference batch size of 32, the measured latency is 11.1 ms and GPU memory usage is 0.9 GB. Together with the classification results, these measurements show that NetLexicon achieves strong performance with a compact model and modest computational requirements.
5 Discussion
Benefits and Tradeoffs of Discretization. Our results suggest that a compact vocabulary of traffic states can preserve information useful across several classification tasks. The value of this vocabulary lies in sharing behavioral patterns across flows. For example, sustained transfer and intermittent exchange can occur in multiple applications, allowing a shared state to capture common communication behavior while downstream supervision determines its relevance to a particular task. This perspective places traffic semantics at the level of interaction patterns and treats the lexicon as a reusable summary of these behaviors.
The granularity of this representation introduces a tradeoff. Sharing codewords can consolidate similar interactions and reduce sensitivity to minor variations, while also merging distinctions that matter for fine-grained classification. The codebook capacity and the context used to assign states therefore jointly determine which behavioral differences remain visible. STP and SFA guide this process through predictive and statistical signals. Their effectiveness should be assessed through both downstream performance and the behavioral structure of learned states, alongside careful evaluation of dataset artifacts and shortcut learning [3, 17, 43, 49].
Limitations and Future Work. Reusing behavioral states across environments depends on how consistently the underlying interactions appear in observable traffic. Changes in network conditions or protocol implementations can alter packet sizes and timing, motivating adaptation of both the encoder and the codebook. Future work could explore how to incorporate new behaviors while preserving useful existing states. Larger contexts or hierarchical representations could further connect local window patterns into longer interaction sequences.
Deployment requires considering the full encoding pipeline. A compact codebook makes state storage and lookup inexpensive, while producing contextual window representations still requires neural computation. Prior work on programmable switches and network hardware offers useful directions for efficient traffic analysis [2, 22, 25, 44, 45, 50, 52]. An important next step is to investigate
Gao et al.
whether the learned state assignments can supervise a smaller encoder or a hardware-compatible predictor, jointly addressing inference cost and behavioral fidelity [7, 13, 25, 45, 47].
6 Conclusion
In this paper, we presented NetLexicon, a traffic pretraining framework that learns traffic semantics through a compact lexicon of reusable behavioral states. Motivated by evolving applications and deployments under limited labeling budgets, NetLexicon models how end-to-end communication behavior evolves over time. STP makes the learned states predictive of future traffic behavior, while SFA grounds them in window statistics. Across downstream traffic classification tasks, NetLexicon improves Macro-F1 by up to 25.5 percentage points over strong baselines, reduces fine-tuning time per epoch by up to 23.6Γ, and learns interpretable states aligned with meaningful communication behaviors. These results support discrete behavioral modeling as a promising approach to efficient and interpretable traffic analysis.
References
[1] Giuseppe Aceto, Domenico Ciuonzo, Antonio Montieri, and Antonio Pescapè. 2019. MIMETIC: Mobile Encrypted Traffic Classification Using Multimodal Deep Learning. Computer Networks 165 (2019), 106944.
[2] Albert Gran Alcoz, BalΓ‘zs Vass, Pooria Namyar, Behnaz Arzani, GΓ‘bor RΓ©tvΓ‘ri, and Laurent Vanbever. 2025. Everything Matters in Programmable Packet Scheduling. In USENIX Symposium on Networked Systems Design and Implementation (NSDI). 1467β1485.
[3] Daniel Arp, Erwin Quiring, Feargus Pendlebury, Alexander Warnecke, Fabio Pierazzi, Christian Wressnegger, Lorenzo Cavallaro, and Konrad Rieck. 2022. Dos and Don'ts of Machine Learning in Computer Security. In USENIX Security Symposium (USENIX Security). 3971β3988.
[4] Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton. 2020. A Simple Framework for Contrastive Learning of Visual Representations. In International Conference on Machine Learning (ICML). 1597β1607.
[5] Xu-Yang Chen, Lu Han, De-Chuan Zhan, and Han-Jia Ye. 2025. MIETT: Multi-Instance Encrypted Traffic Transformer for Encrypted Traffic Classification. In AAAI Conference on Artificial Intelligence (AAAI), Vol. 39. 15922β15929.
[6] Kenjiro Cho, Koushirou Mitsuya, and Akira Kato. 2000. Traffic Data Repository at the WIDE Project. In USENIX Annual Technical Conference (ATC).
[7] Lorenzo De Marinis, Emilio Paolini, Rana Abu Bakar, Filippo Cugini, and Francesco Paolucci. 2023. Cascaded Look Up Table Distillation of P4 Deep Neural Network Switches. In IEEE Global Communications Conference (GLOBECOM). 2111β2116.
[8] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. In North American Chapter of the Association for Computational Linguistics (NAACL). 4171β4186.
[9] Gerard Draper-Gil, Arash Habibi Lashkari, Mohammad Saiful Islam Mamun, and Ali A. Ghorbani. 2016. Characterization of Encrypted and VPN Traffic Using Time-Related Features. In International Conference on Information Systems Security and Privacy (ICISSP). 407β414.
[10] Patrick Esser, Robin Rombach, and Bjorn Ommer. 2021. Taming Transformers for High-Resolution Image Synthesis. In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). 12873β12883.
[11] Michael Finsterbusch, Chris Richter, Eduardo Rocha, Jean-Alexander Muller, and Klaus Hanssgen. 2013. A Survey of Payload-Based Traffic Classification Approaches. IEEE Communications Surveys & Tutorials (COMST) 16, 2 (2013), 1135β1156.
[12] Barak Gahtan, Robert J. Shahla, Reuven Cohen, and Alex M. Bronstein. 2025. Exploring QUIC Dynamics: A Large-Scale Dataset for Encrypted Traffic Analysis. In IEEE International Mediterranean Conference on Communications and Networking (MeditCom). 1β6.
[13] Xiangyu Gao, Tong Li, Yinchao Zhang, Ziqiang Wang, Xiangsheng Zeng, Su Yao, and Ke Xu. 2025. FENIX: Enabling In-Network DNN Inference with FPGA-Enhanced Programmable Switches. arXiv preprint arXiv:2507.14891 (2025).
[14] Zijun Hang, Yuliang Lu, Yongjie Wang, and Yi Xie. 2023. Flow-MAE: Leveraging Masked AutoEncoder for Accurate, Efficient and Robust Malicious Traffic Classification. In International Symposium on Research in Attacks, Intrusions and Defenses (RAID). 297β314.
[15] Kaiming He, Xinlei Chen, Saining Xie, Yanghao Li, Piotr DollΓ‘r, and Ross Girshick. 2022. Masked Autoencoders Are Scalable Vision Learners. In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). 16000β16009.
[16] Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross Girshick. 2020. Momentum Contrast for Unsupervised Visual Representation Learning. In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). 9729β9738.
[17] Arthur S. Jacobs, Roman Beltiukov, Walter Willinger, Ronaldo A. Ferreira, Arpit Gupta, and Lisandro Z. Granville. 2022. AI/ML for Network Security: The Emperor Has No Clothes. In ACM SIGSAC Conference on Computer and Communications Security (CCS). 1537β1551.
[18] Eric Jang, Shixiang Gu, and Ben Poole. 2016. Categorical Reparameterization with Gumbel-Softmax. arXiv preprint arXiv:1611.01144 (2016).
[19] Peng Lin, Kejiang Ye, Yishen Hu, Yanying Lin, and Cheng-Zhong Xu. 2022. A Novel Multimodal Deep Learning Framework for Encrypted Traffic Classification. IEEE/ACM Transactions on Networking (ToN) 31, 3 (2022), 1369β1384.
[20] Xinjie Lin, Gang Xiong, Gaopeng Gou, Zhen Li, Junzheng Shi, and Jing Yu. 2022. ET-BERT: A Contextualized Datagram Representation with Pre-training Transformers for Encrypted Traffic Classification. In ACM Web Conference (WWW). 633β642.
[21] Chang Liu, Longtao He, Gang Xiong, Zigang Cao, and Zhen Li. 2019. FS-Net: A Flow Sequence Network for Encrypted Traffic Classification. In IEEE Conference on Computer Communications (INFOCOM). 1171β1179.
[22] Zaoxing Liu, Hun Namkung, Georgios Nikolaidis, Jeongkeun Lee, Changhoon Kim, Xin Jin, Vladimir Braverman, Minlan Yu, and Vyas Sekar. 2021. Jaqen: A High-Performance Switch-Native Approach for Detecting and Mitigating Volumetric DDoS Attacks with Programmable Switches. In USENIX Security Symposium (USENIX Security). 3829β3846.
[23] Mohammad Lotfollahi, Mahdi Jafari Siavoshani, Ramin Shirali Hossein Zade, and Mohammdsadegh Saberian. 2020. Deep Packet: A Novel Approach for Encrypted Traffic Classification Using Deep Learning. Soft Computing 24, 3 (2020), 1999β2012.
[24] Chris J. Maddison, Andriy Mnih, and Yee Whye Teh. 2016. The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables. arXiv preprint arXiv:1611.00712 (2016).
[25] Oliver Michel, Roberto Bifulco, Gabor Retvari, and Stefan Schmid. 2021. The Programmable Data Plane: Abstractions, Architectures, Algorithms, and Applications. ACM Computing Surveys (CSUR) 54, 4 (2021), 1β36.
[26] Andrew W. Moore and Denis Zuev. 2005. Internet Traffic Classification Using Bayesian Analysis Techniques. In ACM SIGMETRICS International Conference on Measurement and Modeling of Computer Systems (SIGMETRICS). 50β60.
[27] Netresec. 2026. SplitCap. [Online]. Available: https://www.netresec.com/?page=SplitCap. Accessed: Apr. 2026.
[28] Thuy T. T. Nguyen and Grenville Armitage. 2009. A Survey of Techniques for Internet Traffic Classification Using Machine Learning. IEEE Communications Surveys & Tutorials (COMST) 10, 4 (2009), 56β76.
[29] Aaron van den Oord, Yazhe Li, and Oriol Vinyals. 2018. Representation Learning with Contrastive Predictive Coding. arXiv preprint arXiv:1807.03748 (2018).
[30] Abbas Razaghpanah, Arian Akhavan Niaki, Narseo Vallina-Rodriguez, Srikanth Sundaresan, Johanna Amann, and Phillipa Gill. 2017. Studying TLS Usage in Android Apps. In International Conference on Emerging Networking Experiments and Technologies (CoNEXT). 350β362.
[31] Abbas Razaghpanah, Narseo Vallina-Rodriguez, Srikanth Sundaresan, Christian Kreibich, Phillipa Gill, Mark Allman, and Vern Paxson. 2015. Haystack: In Situ Mobile Traffic Analysis in User Space. arXiv preprint arXiv:1510.01419 (2015), 1β13.
[32] Vera Rimmer, Davy Preuveneers, Marc Juarez, Tom Van Goethem, and Wouter Joosen. 2017. Automated Website Fingerprinting through Deep Learning. arXiv preprint arXiv:1708.06376 (2017).
[33] Roei Schuster, Vitaly Shmatikov, and Eran Tromer. 2017. Beauty and the Burst: Remote Identification of Encrypted Video Streams. In USENIX Security Symposium (USENIX Security). 1357β1374.
[34] Meng Shen, Jinpeng Zhang, Liehuang Zhu, Ke Xu, and Xiaojiang Du. 2021. Accurate Decentralized Application Identification via Encrypted Traffic Analysis Using Graph Neural Networks. IEEE Transactions on Information Forensics and Security (TIFS) 16 (2021), 2367β2380.
[35] Justine Sherry, Shaddi Hasan, Colin Scott, Arvind Krishnamurthy, Sylvia Ratnasamy, and Vyas Sekar. 2012. Making Middleboxes Someone Else's Problem: Network Processing as a Cloud Service. ACM SIGCOMM Computer Communication Review (CCR) 42, 4 (2012), 13β24.
[36] Justine Sherry, Chang Lan, Raluca Ada Popa, and Sylvia Ratnasamy. 2015. Blind-Box: Deep Packet Inspection over Encrypted Traffic. In ACM Special Interest Group on Data Communication (SIGCOMM). 213β226.
[37] Payap Sirinam, Mohsen Imani, Marc Juarez, and Matthew Wright. 2018. Deep Fingerprinting: Undermining Website Fingerprinting Defenses with Deep Learning. In ACM SIGSAC Conference on Computer and Communications Security (CCS). 1928β1943.
[38] Aaron Van Den Oord, Oriol Vinyals, et al. 2017. Neural Discrete Representation Learning. Advances in Neural Information Processing Systems (NeurIPS) 30 (2017).
Gao et al.
[39] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Εukasz Kaiser, and Illia Polosukhin. 2017. Attention Is All You Need. In Advances in Neural Information Processing Systems (NIPS). 5998β6008.
[40] Tongze Wang, Xiaohui Xie, Wenduo Wang, Chuyi Wang, Youjian Zhao, and Yong Cui. 2024. NetMamba: Efficient Network Traffic Classification via Pre-training Unidirectional Mamba. In IEEE International Conference on Network Protocols (ICNP). 1β11.
[41] Wei Wang, Ming Zhu, Xuewen Zeng, Xiaozhou Ye, and Yiqiang Sheng. 2017. Malware traffic classification using convolutional neural network for representation learning. In International conference on information networking (ICOIN). 712β717.
[42] Xin Wang, Shuhui Chen, and Jinshu Su. 2020. App-Net: A Hybrid Neural Network for Encrypted Mobile Traffic Classification. In IEEE Conference on Computer Communications Workshops (INFOCOM Workshops). 424β429.
[43] Nimesha Wickramasinghe, Arash Shaghaghi, Gene Tsudik, and Sanjay Jha. 2025. SoK: Decoding the Enigma of Encrypted Network Traffic Classifiers. In IEEE Symposium on Security and Privacy (S&P). 1825β1843.
[44] Guorui Xie, Qing Li, Yutao Dong, Guanglin Duan, Yong Jiang, and Jingpu Duan. 2022. Mousika: Enable General In-Network Intelligence in Programmable Switches by Knowledge Distillation. In IEEE Conference on Computer Communications (INFOCOM). 1938β1947.
[45] Jinzhu Yan, Haotian Xu, Zhuotao Liu, Qi Li, Ke Xu, Mingwei Xu, and Jianping Wu. 2024. Brain-on-Switch: Towards Advanced Intelligent Network Data Plane via NN-Driven Traffic Analysis at Line-Speed. In USENIX Symposium on Networked Systems Design and Implementation (NSDI). 419β440.
[46] Luming Yang, Lin Liu, JunJie Huang, Zhuotao Liu, Shiyu Liang, Shaojing Fu, and Yongjun Wang. 2025. MM4Flow: A Pre-trained Multi-Modal Model for Versatile Network Traffic Analysis. In ACM SIGSAC Conference on Computer and Communications Security (CCS). 1664β1678.
[47] Yinchao Zhang, Su Yao, Yong Feng, Kang Chen, Tong Li, Zhuotao Liu, Yi Zhao, Lexuan Zhang, Xiangyu Gao, Feng Xiong, et al. 2025. Pegasus: A Universal Framework for Scalable Deep Learning Inference on the Dataplane. In ACM Special Interest Group on Data Communication (SIGCOMM). 692β706.
[48] Ruijie Zhao, Mingwei Zhan, Xianwen Deng, Yanhao Wang, Yijun Wang, Guan Gui, and Zhi Xue. 2023. Yet Another Traffic Classifier: A Masked Autoencoder Based Traffic Transformer with Multi-Level Flow Representation. In AAAI Conference on Artificial Intelligence (AAAI), Vol. 37. 5420β5427.
[49] Yuqi Zhao, Giovanni Dettori, Matteo Boffa, Luca Vassio, and Marco Mellia. 2025. The Sweet Danger of Sugar: Debunking Representation Learning for Encrypted Traffic Classification. In ACM Special Interest Group on Data Communication (SIGCOMM). 296β310.
[50] Zhipeng Zhao, Hugo Sadok, Nirav Atre, James C. Hoe, Vyas Sekar, and Justine Sherry. 2020. Achieving 100Gbps Intrusion Prevention on a Single Server. In USENIX Symposium on Operating Systems Design and Implementation (OSDI). 1083β1100.
[51] Guangmeng Zhou, Xiongwen Guo, Zhuotao Liu, Tong Li, Qi Li, and Ke Xu. 2025. TrafficFormer: An Efficient Pre-trained Model for Traffic Data. In IEEE Symposium on Security and Privacy (S&P). 1844β1860.
[52] Guangmeng Zhou, Zhuotao Liu, Chuanpu Fu, Qi Li, and Ke Xu. 2023. An Efficient Design of Intelligent Network Data Plane. In USENIX Security Symposium (USENIX Security). 6203β6220.
A Feature Definitions
This appendix summarizes the packet-level input features used by NetLexicon and the window-level statistical summaries used by SFA. The two groups are presented separately because they play different roles in the model. Packet-level features serve as sequential inputs to the causal encoder and also act as regression targets in STP. In contrast, window-level statistics provide the auxiliary summary view used by SFA.
Packet-level Features. Although the raw dataset contains a larger packet-level feature set, NetLexicon uses only seven dimensions as packet-level model inputs. These features are selected to capture packet size, directionality, timing, and lightweight transport-level progression signals, while avoiding reliance on a large number of protocol-specific or deployment-specific fields.
In implementation, the encoder does not consume the raw 7-dimensional packet feature vector directly. Instead, each packet token is represented by a 14-dimensional input vector, formed by
Table 6: Packet-level raw features used by NetLexicon.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 0 | Packet Size | Packet length, clipped to 1500. | B |
| 1 | Direction | 0 for the first-packet direction, and 1 for the reverse direction. | - |
| 2 | Inter-Arrival Time | Time since the previous packet; the first packet is 0. | ms |
| 3 | TCP Flags | Encoded TCP flags; set to -1 when TCP is unavailable. | - |
| 4 | ΞIPID | Difference from the previous same-direction IP identifier; -1 if unavailable. | - |
| 5 | Relative Seq | TCP sequence number relative to the same-direction initial sequence number; -1 for non-TCP packets. | - |
| 6 | Relative Ack | TCP acknowledgment number relative to the opposite-direction initial sequence number; -1 if unavailable. | - |
concatenating a normalized 7-dimensional feature vector with a 7-dimensional missing-value indicator. Let denote the raw packet feature vector of packet token . The final packet input is
where denotes the normalized feature vector and denotes the corresponding missing-value mask. Raw missing or inapplicable values are encoded as . During preprocessing, such entries are replaced by zero in the normalized branch and are explicitly marked through the missing-value mask.
The packet-level normalization is feature-specific. Packet size is scaled by 1500, direction is kept in its original binary form, and TCP flags are scaled by 255. For heavy-tailed timing and transport-progress features, NetLexicon applies logarithmic compression before standardization. Specifically, inter-arrival time is transformed by and then z-score normalized; relative sequence number and relative acknowledgment number are transformed by and then z-score normalized. By contrast, IPID is directly z-score normalized. Formally,
where and denote the corresponding normalization statistics, and is a small constant for numerical stability. If a feature is missing in the raw input, its normalized value is set to 0 and the
Gao et al.
corresponding mask entry is set to 1. For non-packet tokens, including [SEP], [WIN], and PAD, the feature input is set to the all-zero vector, while token type is represented separately.
Window-level Statistical Summaries. For each valid window, NetLexicon computes a 37-dimensional statistical summary over a sliding window of five consecutive bursts. These features are not used as sequential input tokens. Instead, they provide a window-level statistical view aligned with the quantized discrete state used by SFA. For clarity, we organize them by the type of traffic behavior they describe.
Basic traffic statistics. This group captures coarse traffic volume and directional asymmetry within a window. It summarizes how much traffic appears in each direction, how many packets are observed, and how packet sizes behave at a basic aggregate level.
Table 7: Window-level basic traffic statistics.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 1 | Flow Duration | Sum of inter-arrival times in the window. | ms |
| 2 | Total Fwd Packets | Number of forward packets. | count |
| 3 | Total Bwd Packets | Number of backward packets. | count |
| 4 | Total Fwd Bytes | Total forward packet bytes. | B |
| 5 | Total Bwd Bytes | Total backward packet bytes. | B |
| 6 | Fwd Packet Length Mean | Mean forward packet size. | B |
| 7 | Bwd Packet Length Mean | Mean backward packet size. | B |
| 8 | Fwd Packet Length Std | Std. of forward packet sizes. | B |
| 9 | Bwd Packet Length Std | Std. of backward packet sizes. | B |
| 10 | Flow Bytes/s | Total bytes divided by window duration. | B/s |
Packet-length statistics. This group describes the shape of the packet-size distribution within the window. Beyond first- and second-order statistics, it also includes extrema and skewness, allowing the summary to reflect whether traffic is concentrated around a narrow size range or exhibits more asymmetric patterns.
Table 8: Window-level packet-length statistics.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 11 | Packet Length Mean | Mean packet size over all packets. | B |
| 12 | Packet Length Std | Std. of packet sizes over all packets. | B |
| 13 | Packet Length Variance | Variance of packet sizes. | |
| 14 | Packet Length Max | Maximum packet size. | B |
| 15 | Packet Length Min | Minimum packet size. | B |
| 16 | Fwd Packet Length Max | Maximum forward packet size. | B |
| 17 | Bwd Packet Length Max | Maximum backward packet size. | B |
| 18 | Packet Length Skewness | Skewness of the packet-size distribution. | - |
Timing statistics. This group characterizes the temporal structure of the interaction. In addition to flow-level inter-arrival-time summaries, it includes direction-specific timing statistics so that the forward and backward directions can exhibit distinct pacing behaviors within the same window.
TCP control statistics. This group summarizes transport-level events within the window, including setup, acknowledgment, reset,
Table 9: Window-level timing statistics.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 19 | Flow IAT Mean | Mean inter-arrival time over all packets. | ms |
| 20 | Flow IAT Std | Std. of inter-arrival times over all packets. | ms |
| 21 | Flow IAT Max | Maximum inter-arrival time. | ms |
| 22 | Flow IAT Min | Minimum inter-arrival time. | ms |
| 23 | Fwd IAT Mean | Mean IAT over adjacent forward packets. | ms |
| 24 | Fwd IAT Std | Std. of IAT over adjacent forward packets. | ms |
| 25 | Bwd IAT Mean | Mean IAT over adjacent backward packets. | ms |
| 26 | Bwd IAT Std | Std. of IAT over adjacent backward packets. | ms |
and teardown behavior. It provides a compact representation of control-plane activity without requiring explicit protocol parsing.
Table 10: Window-level TCP control statistics.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 27 | FIN Flag Count | Number of packets with FIN set. | count |
| 28 | SYN Flag Count | Number of packets with SYN set. | count |
| 29 | RST Flag Count | Number of packets with RST set. | count |
| 30 | PSH Flag Count | Number of packets with PSH set. | count |
| 31 | ACK Flag Count | Number of packets with ACK set. | count |
| 32 | URG Flag Count | Number of packets with URG set. | count |
Flow-behavior statistics. This final group provides a coarse summary of burstiness and activity patterns. It complements the previous groups by describing how traffic intensity varies over time and how active and idle periods are distributed within the window.
Table 11: Window-level flow-behavior statistics.
| Idx | Feature | Definition | Unit |
|---|---|---|---|
| 33 | Fwd Packets/s | Forward packet rate. | packets/s |
| 34 | Bwd Packets/s | Backward packet rate. | packets/s |
| 35 | Active Mean | Mean duration of active periods. | s |
| 36 | Active Std | Std. of active-period duration. | s |
| 37 | Idle Mean | Mean duration of idle periods. | s |
Taken together, these groups form the window-level statistical view used by SFA. They help anchor the learned discrete states to stable and observable traffic behaviors.
B Implementation Details
We initialize the baselines from their publicly released pretrained checkpoints and retain their respective input formats. ET-BERT [20] and TrafficFormer [51] represent each flow using five packets with 64 bytes per packet. YaTC [48] and NetMamba [40] convert each flow into a image following their preprocessing pipelines. Pcap-Encoder [49] uses individual packets as samples in our reproduction. For NetLexicon, each packet is represented by seven normalized features and seven missing indicators, with separate embeddings for token types and positions. Padding positions are masked from attention and pretraining losses. The STP prediction heads and SFA projection heads are used during pretraining. Downstream classification pools the contextual [WIN] representations
Gao et al.
and applies a task-specific classification head. We first train this head with the backbone frozen, then fine-tune the model jointly. An AdamW optimizer is instantiated over the trainable parameters at each stage, with the head-only stage using ten times the base learning rate. All windows from a flow inherit its dataset split.
C Additional Codebook Entries
Table 12 reports the 50 most frequently activated codebook entries on the CipherSpectrum [43] test split after fine-tuning. For each code, we show its assignment count, key traffic statistics, dominant application, and a heuristic behavioral tag. These entries exhibit recurring patterns such as TCP startup, short download-heavy bursts, balanced exchanges, and longer transfers with idle gaps. Their assignment counts indicate how frequently each state is reused, while the statistical profiles describe the communication behavior associated with it. Together, these observations provide a concrete view of how the learned codebook organizes traffic windows into interpretable behavioral patterns across the evaluated traces.
Gao et al.
Table 12: Top 50 active codebook entries from the fine-tuned CipherSpectrum model on the test split.
| Code | Count | Dur. | Fwd | Bwd | FwdB | BwdB | SYN | IAT | Dominant APP | Tag |
|---|---|---|---|---|---|---|---|---|---|---|
| 91 | 10049 | 64 | 3 | 4 | 191 | 4411 | 0.0 | 11 | ctfassets | short + DL-heavy |
| 45 | 7561 | 44 | 3 | 4 | 255 | 4401 | 0.0 | 7 | googletagmanager | short + DL-heavy |
| 34 | 4032 | 207 | 3 | 4 | 160 | 4488 | 0.0 | 39 | gstatic | medium + DL-heavy |
| 33 | 4000 | 25 | 5 | 4 | 1774 | 1623 | 2.0 | 3 | hubspot | startup + balanced |
| 6 | 2447 | 113 | 5 | 4 | 1731 | 1640 | 2.0 | 15 | google-analytics | startup + balanced |
| 66 | 2341 | 27 | 4 | 3 | 835 | 1582 | 2.0 | 5 | ctfassets | startup + DL-heavy |
| 126 | 2222 | 122 | 3 | 4 | 348 | 3846 | 0.0 | 21 | arin | short + DL-heavy |
| 121 | 1993 | 10 | 4 | 3 | 1155 | 1639 | 1.9 | 2 | startup + short | |
| 20 | 1897 | 290 | 3 | 4 | 447 | 5015 | 0.0 | 45 | adblockplus | medium + DL-heavy |
| 32 | 1743 | 612 | 4 | 4 | 476 | 2833 | 0.0 | 89 | trustarc | medium + DL-heavy |
| 117 | 1671 | 53 | 4 | 4 | 699 | 2213 | 0.9 | 9 | garmin | short + startup |
| 36 | 1607 | 424 | 4 | 3 | 1187 | 1604 | 2.0 | 65 | arin | startup + balanced |
| 103 | 1553 | 321 | 3 | 4 | 359 | 3435 | 0.0 | 53 | segment | medium + DL-heavy |
| 120 | 1528 | 290 | 3 | 4 | 224 | 3787 | 0.0 | 46 | googletagmanager | medium + DL-heavy |
| 127 | 1518 | 1073 | 3 | 4 | 391 | 3821 | 0.0 | 197 | arin | idle-gap + DL-heavy |
| 54 | 1450 | 30 | 3 | 3 | 194 | 3187 | 0.0 | 5 | ctfassets | short + DL-heavy |
| 59 | 1405 | 26 | 3 | 5 | 461 | 1326 | 0.0 | 4 | mozilla | short + response-heavy |
| 77 | 1330 | 478 | 4 | 4 | 1075 | 2745 | 0.0 | 66 | arin | medium + balanced |
| 69 | 1316 | 169 | 3 | 4 | 281 | 3895 | 0.1 | 25 | short + DL-heavy | |
| 48 | 1271 | 34 | 4 | 4 | 322 | 2369 | 0.0 | 5 | typekit | short + DL-heavy |
| 101 | 1266 | 910 | 3 | 4 | 359 | 2242 | 0.0 | 147 | robinhood | idle-gap + DL-heavy |
| 107 | 1244 | 65 | 3 | 4 | 251 | 3070 | 0.0 | 10 | steamstatic | short + DL-heavy |
| 21 | 1232 | 243 | 3 | 4 | 408 | 3792 | 0.0 | 34 | garmin | medium + DL-heavy |
| 68 | 1220 | 84 | 3 | 4 | 476 | 4041 | 0.0 | 12 | steamstatic | short + DL-heavy |
| 49 | 1149 | 7 | 3 | 5 | 170 | 6559 | 0.0 | 1 | gstatic | dense + DL-heavy |
| 104 | 1127 | 781 | 4 | 4 | 735 | 2939 | 0.0 | 117 | getpocket | idle-gap + DL-heavy |
| 100 | 1120 | 115 | 4 | 4 | 264 | 2684 | 0.0 | 16 | ying | short + DL-heavy |
| 90 | 1067 | 98 | 3 | 5 | 367 | 5899 | 0.0 | 14 | getpocket | short + DL-heavy |
| 19 | 1013 | 17 | 4 | 4 | 625 | 614 | 0.0 | 2 | hs-scripts | dense + balanced |
| 113 | 929 | 482 | 3 | 4 | 437 | 3993 | 0.0 | 71 | cookielaw | medium + DL-heavy |
| 43 | 924 | 118 | 3 | 4 | 257 | 3893 | 0.0 | 19 | googletagmanager | short + DL-heavy |
| 102 | 876 | 592 | 3 | 4 | 369 | 3068 | 0.0 | 94 | googletagmanager | medium + DL-heavy |
| 92 | 779 | 33 | 3 | 4 | 194 | 3346 | 0.0 | 5 | xnxx-cdn | short + DL-heavy |
| 70 | 773 | 48 | 3 | 4 | 183 | 4696 | 0.0 | 9 | naver | short + DL-heavy |
| 84 | 754 | 782 | 3 | 4 | 279 | 3395 | 0.0 | 125 | cookielaw | idle-gap + DL-heavy |
| 22 | 701 | 110 | 5 | 4 | 727 | 1233 | 0.0 | 13 | googletagmanager | short + balanced |
| 40 | 695 | 555 | 4 | 3 | 1029 | 1684 | 1.8 | 85 | ubuntu | startup + balanced |
| 0 | 686 | 247 | 4 | 4 | 887 | 2671 | 0.0 | 28 | wistia | medium + balanced |
| 108 | 660 | 250 | 3 | 4 | 300 | 3283 | 0.0 | 40 | coinbase | medium + DL-heavy |
| 28 | 659 | 979 | 4 | 4 | 1567 | 1960 | 1.1 | 128 | gmx | startup + idle-gap |
| 115 | 657 | 328 | 3 | 5 | 165 | 6621 | 0.0 | 55 | googletagmanager | medium + DL-heavy |
| 46 | 648 | 532 | 3 | 4 | 202 | 4286 | 0.0 | 86 | segment | medium + DL-heavy |
| 82 | 646 | 720 | 3 | 3 | 551 | 3680 | 0.0 | 121 | getpocket | idle-gap + DL-heavy |
| 112 | 605 | 166 | 4 | 3 | 773 | 1589 | 1.7 | 27 | like-video | startup + balanced |
| 111 | 588 | 50 | 5 | 4 | 1912 | 1712 | 1.9 | 8 | typekit | startup + balanced |
| 10 | 559 | 13 | 2 | 4 | 124 | 5851 | 0.0 | 2 | googletagmanager | dense + DL-heavy |
| 4 | 545 | 774 | 4 | 3 | 919 | 1509 | 1.3 | 120 | adblockplus | startup + idle-gap |
| 56 | 532 | 33 | 3 | 5 | 275 | 4982 | 0.0 | 5 | typekit | short + DL-heavy |
| 61 | 524 | 192 | 3 | 4 | 267 | 4933 | 0.0 | 33 | coinbase | medium + DL-heavy |
| 83 | 514 | 108 | 4 | 4 | 1505 | 1041 | 0.0 | 14 | wistia | short + balanced |
Note: The underlined rows correspond to the representative codewords analyzed in Figure 7.
Dominant APP denotes the most frequent application among windows assigned to each code and is descriptive only rather than a semantic label; it does not imply that the code is exclusive to that application, as each code may still be shared across multiple applications.
Tag is a coarse rule-based summary derived from aggregate statistics: startup indicates elevated SYN activity, DL-heavy indicates substantially larger backward than forward bytes, balanced indicates comparable bidirectional byte volume, idle-gap indicates relatively large duration or mean inter-arrival time, dense indicates very small mean inter-arrival time, and response-heavy indicates a larger backward packet count with modest byte volume.