TDDM-Melatt: A Decoupled Memory and Diffusion Framework for Generalizable Encrypted Traffic Classification
Analyze & explore related research in Conceptio
Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.
arXiv:2608.30745v1 [cs.LG] 31 Aug 2026
TDDM-Melatt: A Decoupled Memory and Diffusion Framework for Generalizable Encrypted Traffic Classification Ze Chen
Qiming Yu
Zijia Song
National University of Defense Technology Hefei, Anhui, China chenze@nudt.edu.cn
National University of Defense Technology Hefei, Anhui, China yuqiming24@nudt.edu.cn
National University of Defense Technology Hefei, Anhui, China songzijia@nudt.edu.cn
Guozheng Yang∗
Wei Yan
National University of Defense Technology Hefei, Anhui, China yangguozheng17@nudt.edu.cn
National University of Defense Technology Hefei, Anhui, China yan.wei2023@nudt.edu.cn
Abstract
Keywords
The widespread adoption of encrypted traffic poses severe challenges to current security situational awareness systems based on network traffic monitoring. In existing dataset-driven training and testing studies, limitations such as shortcut learning induced by spurious feature correlations and sample imbalance caused by the longtail distribution of real-world traffic result in weak generalization of traffic identification performance to real-world network traffic. To address these limitations, we propose TDDM-Melatt, a disentangled memory-based traffic classification framework with diffusion-based data augmentation. First, we design Melatt, a memory-decoupled traffic representation model, which employs Competitive Gating Long Short-Term Memory (CG-LSTM) to construct the encoder and decoder. We design a spurious-correlation-free pre-training and inference paradigm, employing strict topology anonymization and a frozen pre-trained encoder strategy to cut off the model’s learning pathways for spurious features. During pre-training, computing the reconstruction loss between different traffic classes and each memory prototype forces the model to learn prototype-aligned representations. During inference, classification is performed efficiently by a downstream classifier on the frozen representations. Second, we propose a Traffic Denoising Diffusion Model (TDDM) tailored to the characteristics of traffic data. Addressing the structured nature of high-dimensional sparsity and strong feature correlations in traffic data, we design a lightweight residual noise prediction network and a compact noise sampling mechanism, solving the problem of having only class labels as conditional guidance for traffic diffusion models. Extensive experiments are conducted on 4 representative public benchmark datasets. Under strict flow-level splitting and anonymization, TDDM-Melatt outperforms 6 basic classification models and 6 SOTA representation learning models. The proposed method provides a new and effective technical pathway for encrypted traffic classification in real-world network environments.
Network Security, Deep Learning, Encrypted Traffic Identification
CCS Concepts • Security and privacy → Network security. ∗ Corresponding Author.
1
Introduction
Object recognition in the human brain relies on prototype memories stored in the hippocampus, forming a closed-loop cognitive process of “memory storage–feature matching–reconstructive recognition.” Visual information captured by the eyes is encoded into abstract features by the visual cortex and subsequently undergoes precise matching and reconstruction with memory prototypes via the hippocampus. High matching confidence leads to successful recognition, whereas low confidence results in classification as unknown or anomalous. This cognitive mechanism offers profound inspiration for network traffic inspection. If a “memory module” storing behavioral prototypes of traffic can be constructed, the reconstruction error naturally serves as a training objective when traffic of a given class cannot be accurately reconstructed by its own class-specific prototypes. Motivated by this insight, this paper focuses on encrypted traffic classification—a challenge in network security—and proposes a novel solution. In recent years, with the increasing sophistication of cybersecurity threats and the strengthening of privacy protection regulations, the adoption of encryption protocols in Internet communications has exceeded 80% [41]. While encryption effectively safeguards user privacy, it also introduces substantial technical obstacles to network traffic monitoring and security auditing. Traditional Deep Packet Inspection (DPI) [5, 14] techniques are rendered ineffective due to the inability to decrypt encrypted payloads, compelling security researchers to shift toward deep learning approaches. Explicit identifiers commonly retained in public datasets [13, 30, 49, 61], such as IP, Port, and flow IDs, exhibit strong yet non-causal statistical correlations with traffic labels. Models tend to prioritize learning such “shortcut features”. This reliance on spurious correlations severely degrades generalization capability, manifesting as inflated accuracy on public test sets followed by precipitous performance drops upon real-world deployment [64, 72]. Furthermore, most studies [30, 75] adopt packet-level sample partitioning, whereby packets from the same flow are distributed across both training and test sets. This practice causes models to learn
Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
flow-specific idiosyncrasies instead of class-generalizable patterns, further amplifying the detrimental effects of spurious correlations. In the context of fine-tuning traffic classification models, high accuracy on encrypted datasets has led to the controversial claim that pre-training enables models to extract patterns from encrypted payloads. In real-world network environments, traffic exhibits highly imbalanced class distributions. Extreme data skewness causes models to be dominated by majority classes during training. Generative Adversarial Networks (GANs) [1, 12, 40] have been explored to mitigate data imbalance. However, GANs are prone to training instability and mode collapse. Diffusion models, as an emerging class of generative models, have achieved remarkable success in image synthesis [11, 22, 66], yet their application to network traffic remains in its infancy and struggles to accommodate the structured nature of traffic data. To address the aforementioned limitations, we propose TDDMMelatt, a decoupled memory and diffusion framework for generalizable encrypted traffic classification. The main contributions are summarized as follows: • We propose Melatt, a modular traffic memory model. The architecture comprises a CG-LSTM-based encoder and a memory-augmented multi-head cross-attention decoder, enhancing the capacity to extract and reconstruct dynamic traffic information. • We establish a pre-training and inference paradigm free of spurious correlations. During data preprocessing, explicit flow identifiers are rigorously removed, and timestamp information is generalized. Freezing the parameters of the pre-trained encoder during downstream classification tasks ensures the cross-scenario generalization capability in real network environments. • We design TDDM, a traffic denoising diffusion model tailored to the structural characteristics of traffic data. In light of the structured characteristics of traffic data, we construct a lightweight diffusion generation architecture that achieves a reduction of more than 30% in the dimensionality of the features. By adopting a class-wise training paradigm, we propose a condition-guided compact noise sampling mechanism to improve class convergence during generation. • We conduct comprehensive experimental evaluations on 4 public datasets. Under strict flow-level sample partitioning and topology anonymization, TDDM-Melatt outperforms 6 baseline classifiers and 6 SOTA models.
2
Problem Statement
Encrypted traffic classification constitutes a fundamental capability within cyberspace security defense frameworks, and its technological evolution is deeply intertwined with the upgrade of encryption protocols, the mutation of network attack patterns, and the shifting landscape of regulatory requirements. With the widespread deployment of next-generation encryption protocols such as TLS 1.3 and QUIC, traditional payload-based DPI [5, 14] techniques have become increasingly ineffective, prompting a pivot toward representation learning-based classification methods as Table 1. ETBERT [30], YaTC [71], NetMamba [60], and TrafficFormer [75] have
Ze Chen, Qiming Yu, Zijia Song, Guozheng Yang, and Wei Yan
Table 1: Comparison of the Traffic Analysis Methods.
Methods netFound YaTC NetMamba ET-BERT TrafficFormer Pcap-Encoder
ML Models BERT ViT Mamba BERT BERT T5
Modality Flow Flow Flow Packet Packet Flow
Detection Abilities Encrypted
Non IP/Port
✓ ✓ ✓ ✓ ✓ ✓
✓ ✓ × ✓ × ×
achieved improved classification performance. Nevertheless, when migrating from laboratory settings to real-world environments, existing approaches frequently encounter precipitous performance degradation. The prevailing research paradigm in encrypted traffic classification relies on supervised learning over labeled datasets, implicitly assuming the existence of stable causal relationships between features and labels. This assumption, however, engenders a severe “shortcut learning” phenomenon, which has become a critical bottleneck restricting model generalization. Public datasets routinely retain explicit identifiers such as IP, Port, and flow IDs. These features exhibit strong yet non-causal correlations with traffic labels [2, 45]. For instance, specific applications often utilize well-known ports, and particular attack traffic frequently originates from specific IP prefixes. During training, supervised models preferentially learn these “low-cost, high-discriminability” shortcut features. Such reliance on spurious correlations yields outstanding performance on test sets drawn from the same distribution as the training data [64, 72], yet once deployed in real networks where IP and Port diverge, model performance collapses dramatically. The packetlevel sample partitioning commonly adopted in existing studies [30, 75] further amplifies the detrimental effects of spurious correlations. Several works split distinct packets belonging to the same flow across training and test sets, thereby enabling models to learn flow-specific idiosyncrasies. This partitioning scheme, which inherently involves data leakage, leads to severe overestimation of actual model performance in experimental evaluations. More critically, full fine-tuning (unfrozen encoder) of existing representation learning models severely erodes the generic features acquired during pre-training [27]. When deployment environments shift, the model forfeits both the generalization benefits of pretrained knowledge and becomes excessively reliant on training-setspecific shortcut features, ultimately resulting in sharp performance attenuation in real-world network contexts. This phenomenon underscores a fundamental tension between theoretical innovation and practical deployment in encrypted traffic classification. Another major challenge is the long-tail distribution of traffic in real network environments [56, 74]. In operational networks, benign traffic and flows from popular applications overwhelmingly dominate the total volume. In contrast, malicious traffic and niche applications flows are not only scarce in aggregate but also exhibit sample counts that may differ by several orders of magnitude across categories. Such extreme imbalance causes models to be dominated by majority class samples during training, leading to
TDDM-Melatt: A Decoupled Memory and Diffusion Framework for Generalizable Encrypted Traffic Classification
decision boundaries severely skewed against minority classes [38]. In pursuit of high overall accuracy, models tend to classify samples as majority classes, resulting in unacceptably low recognition rates for minority classes. In cybersecurity defense scenarios, however, it is precisely these exceedingly rare minority samples that carry the highest security value [53]. To mitigate the scarcity of minority class samples [17], data augmentation techniques have been extensively explored in encrypted traffic classification. In recent years, GANs [1, 12, 40] have been applied to address data imbalance. However, GANs are plagued by training instability and mode collapse. Diffusion models, as an emerging class of generative models, have achieved breakthrough successes in image synthesis and natural language processing [11, 22, 66], offering a promising new avenue for traffic data augmentation. Nonetheless, the application of diffusion models to network traffic remains in its infancy, and existing efforts have merely performed a straightforward model transfer by converting traffic data into images. Moreover, existing traffic classification models [8, 10, 28, 30, 44, 55, 60, 71, 75] are typically designed with a deep coupling among core components such as the encoder, the pretrained backbone, and the classification head. When transitioning across tasks, extensive architectural redesign and model retraining are often required, incurring prohibitively high development and tuning costs [42]. This “one-task-one-model” development paradigm impedes the iterative evolution of traffic classification systems and hinders their capacity to adapt to rapidly evolving cybersecurity threats [6]. This section systematically delineates major challenges confronting contemporary traffic classification research: (1) the trap of shortcut learning and spurious correlations under the supervised learning paradigm; (2) the class imbalance of real-world network traffic and the limitations of existing data augmentation methods; (3) the scenario-binding nature of model architectures and deficiencies in cross-task adaptability. In light of the aforementioned challenges, the core research question of our work is formulated as follows: How can we construct an encrypted traffic classification framework that is capable of escaping spurious correlations, accommodating extreme data distributions, supporting rapid cross-scenario adaptation, and generating high-fidelity traffic samples? To address this question, we draw inspiration from the cognitive mechanisms of the human brain and propose a decoupled memory and diffusion framework for generalizable encrypted traffic classification.
3
Methodology Overview
The overall framework proposed in our work is illustrated in Figure 1(a). It comprises three core components: a memory representation model termed Melatt, a traffic data augmentation module based on denoising diffusion probabilistic models termed TDDM, and a downstream task classifier. The traffic memory representation model, which serves as a pre-training architecture, consists of an encoder, a memory module, and a decoder. This model performs a sequence of operations on input traffic features, including encoding, memory bank addressing, and reconstruction decoding. The conditional diffusion augmentation module functions as an
Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
independent generative component capable of synthesizing highfidelity minority class samples conditioned on specified class labels. The downstream task classifier is designed as a flexible and extensible classification engine. Embracing a modular design philosophy, it supports seamless transitions from lightweight traditional models to complex deep architectures, thereby accommodating diverse deployment scenarios (e.g., resource-constrained edge devices or high-performance servers). To highlight the decoupled nature of the framework, and unless otherwise specified, the classifier is implemented using a straightforward XGBoost [7] model. We construct an independent external memory module, the Melatt architecture illustrated in Figure 1(b). Emulating the cognitive process of “perception–memory–decision” in the human brain, this module realizes the decoupling of feature extraction and knowledge storage. The module consists of multiple learnable memory matrices and a content-based addressing mechanism [20]. Each memory slot corresponds to the prototype features of a specific traffic class, supporting independent pre-training and flexible insertion or deletion. To overcome the prevalent “fuzzy memory” problem in neural networks, we introduce a negative entropy-based regularization constraint that enforces sharpening of the attention distribution. To address the dual nature of network traffic characterized by both periodicity and burstiness, we design a Competitive Gating Long Short-Term Memory (CG-LSTM) in both the encoder and the decoder. By placing its 3 gates within a shared softmax competitive framework, CG-LSTM forces the model to allocate a finite total “attentional budget” at each time step, thereby enhancing its discriminative capacity for dynamic traffic patterns. Furthermore, we integrate a multi-head cross-attention mechanism [8, 34, 46] within the decoder, which enables dynamic querying of multiple prototype patterns stored in the memory module at each decoding step, ultimately generating more accurate reconstructed sequences. Traffic data is characterized by high dimensionality, sparsity, and strong feature interdependencies [59], while generic generative models often suffer from distribution drift and feature distortion when applied to this domain. To address these issues, we propose TDDM, a denoising diffusion model specifically tailored for structured traffic data. First, we design a feature selection method based on Random Forest Gini importance. This method prunes redundant features that exhibit high zero-value ratios or low classification contributions, achieving a dimensionality reduction of over 30% while preserving 95% of the critical information. Second, we eschew the complex convolutional and attention-based architectures commonly employed in image diffusion models. Instead, we adopt a lightweight MLP-based residual network as the noise predictor and adopt a class-wise training paradigm to avoid unnecessary cross-modal computational overhead. To further enhance the distributional consistency of generated samples, we propose a compact noise sampling mechanism. Finally, a nearest-neighbor feature padding strategy is employed to restore the complete feature dimensionality by leveraging the manifold consistency in the low-dimensional latent space.
4 Methodological Details 4.1 Encoder and Decoder Encoder Based on Competitive Gating LSTM.
···
12.3% 11.8% 9.4% 8.9% 8.4% 7.1% 6.5% 6.1% ···
Random Forest
(a) Overall Network
···
Feature Selection
CG-LSTM
LeakyReLU
Attention Module
BatchNorm1d
zm
Decoder
Classifier
Memory Database
Encoder
··· Content-based Addressing
Linear Layer Q
K
···
Decoder
temb T-1
MatMul
tT
tT-1 temb T
Linear Layer
Linear Layer
Nearest Imputation
Time Step Embedding Layer
··· ···
Center Guidance ResidualBlock × 5
LeakyReLU
···
tt
Linear Layer
t2
V MatMul Scale Softmax
CG-LSTM
t1
···
output
z
Encoder
Other Classes
···
Traffic Flow
Memory Model
Diffusion Model
Imbalanced Classes
RobustScaler
X
Ze Chen, Qiming Yu, Zijia Song, Guozheng Yang, and Wei Yan
Memory Database
Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
Cross Atten tion
Linear Layer
···
Weighted Sum
Residual
Memory Module
(c) Diffusion Model
(b) Memory Model Network
Figure 1: Framework Overview. Traditional LSTM networks [19, 51] employ 3 independent sigmoidal gating mechanisms, allowing the forget gate, input gate, and output gate to simultaneously approach unity. This results in a lack of selectivity in the information flow through the memory cell, making it difficult to decisively switch between bursty traffic and quiescent background states. To address these challenges, we design a CG-LSTM, the structure of which is depicted in Figure 2. ht-1
CG-LSTM
ht
tanh
tanh
ft
···
tanh Linear
xt-1
σ
pointwise operation
Ct
Ct-1 it tanh
ht-1 Linear
σ
ot
ht
xt
···
neural network
When encountering a traffic burst, the model may allocate the majority of its budget to the input gate 𝑖𝑡 to rapidly incorporate novel features. During quiescent periods, the budget is preferentially assigned to the forget gate 𝑓𝑡 to maintain the baseline representation of benign traffic. When the model needs to propagate long-range periodic patterns, the budget is concentrated on the output gate 𝑜𝑡 , enabling high-fidelity propagation of the memory state. Define the element-wise multiplication as ⊙.The candidate memory cell state 𝑪˜ 𝑡 = tanh (𝑾 𝑐 [𝒉𝑡 −1 ; 𝒙 𝑡 ] + 𝒃 𝑐 ). The update equations for the CG-LSTM cell state 𝑪 𝑡 and hidden state 𝒉𝑡 are given by: 𝑪 𝑡 = 𝑓𝑡 ⊙ 𝑪 𝑡 −1 + 𝑖𝑡 ⊙ 𝑪˜ 𝑡 ,
𝒉𝑡 = 𝑜𝑡 ⊙ tanh(𝑪 𝑡 ).
(3)
σ Gradient Enhanced Sigmoid
Figure 2: Structure of CG-LSTM. In conventional LSTM networks [19, 23, 51], the forget gate 𝑓𝑡 , input gate 𝑖𝑡 , and output gate 𝑜𝑡 are each computed via independent sigmoidal activation functions. Consequently, all 3 gating values may simultaneously approach unity, leading to scenarios where the model erases substantial portions of historical information while concurrently writing new content, thereby inducing memory confusion. The CG-LSTM replaces the independent sigmoidal activations with a joint softmax operation, thereby constraining 3 gates to form a probability distribution at each time step: [𝑓𝑡 , 𝑖𝑡 , 𝑜𝑡 ] = softmax 𝑾 𝑔 [𝒉𝑡 −1 ; 𝒙 𝑡 ] + 𝒃 𝑔 , (1) where 𝑾 𝑔 ∈ R3× (𝑑ℎ +𝑑𝑥 ) hidden state of previous step 𝒉𝑡 −1 , traffic vector 𝒙 𝑡 , and 𝒃 𝑔 ∈ R3 . This formulation enforces the following constraints: 𝑓𝑡 + 𝑖𝑡 + 𝑜𝑡 = 1, 𝑓𝑡 , 𝑖𝑡 , 𝑜𝑡 ≥ 0. (2) Under this design, the model allocates a finite “gating resource budget” across the forget, input, and output operations at each time step.
Compared with standard LSTM, CG-LSTM shares a single weight matrix across 3 gates, reducing the parameter count by approximately one-third. Furthermore, the extreme values (0 or 1) produced by the softmax output are more conducive to gradient propagation than the intermediate values typically output by sigmoidal functions, thereby alleviating the vanishing gradient problem in long sequences. When minority class traffic appears, the model is compelled to shift its gating budget from the forget gate toward the input gate in order to record novel features. This mechanism inherently amplifies the learning weight assigned to minority class samples, thereby enhancing robustness in class-imbalanced scenarios. The encoder is constructed by stacking multiple CG-LSTM layers. For an input traffic feature sequence 𝑿˜ = {𝒙 1, 𝒙 2, . . . , 𝒙𝑇 } (𝑇 denotes the sequence length), the encoder iteratively updates the cell state and hidden state at each time step according to Equation (3). We adopt the hidden state 𝒉𝑇 from the final time step as the global temporal fingerprint of the traffic sequence. This fingerprint is subsequently transformed via a linear projection to yield a latent vector of dimension 𝐿. A batch normalization layer and a LeakyReLU activation function are appended to the encoder output. Ultimately, the encoder produces a latent vector 𝒛𝑡 ∈ R𝐿 , which serves dually as the initial state for the decoder and as the query vector for the subsequent memory module.
TDDM-Melatt: A Decoupled Memory and Diffusion Framework for Generalizable Encrypted Traffic Classification
Decoder Based on Cross-Attention . The decoder takes the memory vector 𝒛𝑚 output by the memory module as its initial state. It employs a multi-layer stack of CG-LSTM units as its backbone and incorporates a multi-head cross-attention mechanism [57] to facilitate the fusion of global memory information with locally generated features. The overall architecture of the decoder comprises a CG-LSTM module, a multi-head cross-attention module, a residual connection, and layer normalization module and a fully connected reconstruction layer. The CG-LSTM structure within the decoder is identical to that of the encoder. The multi-head cross-attention module serves as the core enhancement component of the decoder. By dynamically retrieving canonical traffic patterns from the global memory matrix, it mitigates the information closure problem. In this module, the intermediate feature sequence output by the CG-LSTM serves as the Query, representing the local temporal characteristics at the current generation step. The external memory matrix 𝑴 ∈ R𝑁 ×𝐿 serves simultaneously as both the Key and the Value, where 𝑁 denotes the number of memory slots and 𝐿 denotes the dimension of each memory slot. A multi-head attention mechanism [8, 34, 46] is employed to concurrently retrieve the most pertinent global prototype patterns from multiple distinct feature subspaces conditioned on the current local features: MultiHead(𝑸, 𝑴, 𝑴) = Concat(head1, . . . , head𝐻 )𝑾 𝑂 ,
(4)
𝑄 head𝑖 = Attention(𝑸𝑾 𝑖 , 𝑴𝑾 𝑖𝐾 , 𝑴𝑾 𝑉𝑖 ).
(5)
where 𝑾 𝑂 is the learnable projection matrix for the output. 𝑸 𝑲𝑇 𝑽. (6) Attention(𝑸, 𝑲, 𝑽 ) = softmax √ 𝑑𝑘 The outputs of multiple attention heads are concatenated and subsequently transformed via a linear projection to yield the attentionaugmented feature sequence. To alleviate the vanishing gradient problem during the training of deep neural networks, residual connections and layer normalization are introduced after the multihead cross-attention module. These mechanisms fuse the original CG-LSTM output with the attention-enhanced features. Finally, a fully connected layer maps the fused feature sequence back to the original 𝐷-dimensional feature space of the input, producing the final reconstructed traffic sequence.
4.2
Memory Model and Pre-training Constraints
Memory Module. The Melatt emulates the cognitive process of “perception–memory– decision” in the human brain by introducing an independent external memory unit, thereby realizing the decoupling of feature extraction and knowledge storage. This liberates the encoder from the burdensome task of parameter storage, allowing it to concentrate exclusively on extracting temporal features, while long-term knowledge retention is delegated to the external memory module. The memory module constitutes the core component of Melatt. It consists of multiple learnable memory matrices 𝑴 ∈ R𝑁 ×𝐿 and a content-based addressing mechanism. Each 𝑴 comprises 𝑁 memory slots, each corresponding to a prototype feature of a target traffic class. These memory slots are iteratively optimized and updated during the pre-training process. Notably, each memory matrix can be pre-trained independently, and different pre-trained memory
Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
matrices can be flexibly inserted into or removed from the memory bank, provided that their dimensionality remains consistent. Given the latent vector 𝒛𝑖 output by the encoder, the memory module computes its similarity with all memory slots via a contentbased addressing mechanism. The relevance score 𝒆 for the mem√ ory slots is expressed as 𝒆 = 𝒛𝑖 · 𝑴𝑇 / 𝐿. The attention weight 𝜔 = Softmax(𝒆) is computed via the softmax function, where the weight represents the “memory strength” of the input traffic with respect to each memory prototype. To address the prevalent “fuzzy memory” problem in neural networks (requiring that a given traffic flow correspond unambiguously to a single distinct memory prototype), we introduce a regularization constraint based on negative entropy. During training, the entropy of the attention distribution is minimized: ∑︁ Lent = − 𝜔𝑖 log 𝜔𝑖 . (7) This constraint enforces the attention weight distribution to become sharper and sparser, compelling the model to match a specific memory prototype with high precision during reconstruction. Ultimately, the model reconstructs the sequence using the attention-weighted memory content 𝒛𝑚 = 𝜔𝑴, yielding the encoder output. Loss Function. The efficacy of Melatt is highly contingent upon the constraints imposed during the pre-training phase. A conventional, singular reconstruction error criterion is insufficient to guarantee that the latent space acquires structured semantic information. To this end, we devise 4 pre-training constraints. Reconstruction Loss. We employ the Smooth L1 Loss as the reconstruction loss to mitigate the influence of outliers on gradient updates. Compared with the traditional MSE loss, Smooth L1 exhibits L1 robustness in large error regions, making it less susceptible to domination by outliers, and smoothly transitions to L2 loss in small error regions, thereby ensuring convergence stability. 𝑁
Lrec =
1 ∑︁ SmoothL1(𝑿˜ 𝑖 , 𝑿˜ 𝑚𝑖 ), 𝑁 𝑖=1
(8)
where 𝑿˜ 𝑚 denotes the traffic reconstructed by the decoder. Compactness Constraint. To prevent the latent vector 𝒛𝑖 output by the encoder from deviating substantially from the memory readout 𝒛𝑚 , we introduce a compactness constraint. This constraint enforces the feature vectors in the latent space to closely adhere to the memory prototypes, thereby enhancing the continuity of the feature manifold: Lcomp = E∥𝒛𝑖 − 𝒛𝑚 ∥ 22 .
(9)
By minimizing the distance between the latent vector and the memory readout vector, the model is encouraged to encode inputs into a subspace consistent with the memory prototypes, thus preventing excessive dispersion of latent features. Entropy Regularization and Diversity Constraints. Equation (7) prescribes a negative entropy-based regularization constraint, Lent , which compels the model to match a specific memory prototype with high precision during traffic reconstruction. Concurrently, redundant prototype features may appear in the memory bank, where multiple memory slots learn similar or identical feature patterns, causing “mode collapse”. To prevent this, we maximize the distance between any pair of distinct memory slots
Conference acronym ’XX, June 03–05, 2018, Woodstock, NY
Ze Chen, Qiming Yu, Zijia Song, Guozheng Yang, and Wei Yan
Ldiv = −
∑︁ 1 ∥𝒎𝑖 − 𝒎 𝑗 ∥ 22 . 𝑁 (𝑁 − 1) 𝑖≠𝑗
(10)
The negative sign ensures that minimizing Ldiv is equivalent to maximizing the pairwise distances among memory slots. Total Loss. The aggregate loss function during the pre-training phase is formulated as a weighted sum of the losses defined in Equations (7), (8), (9), and (10). In practice, while the reconstruction loss retains its original scale (weight of 1), we set the weighting coefficients as 𝛼 comp = 0.05, 𝛼 ent = 0.05, and 𝛼 div = 0.0005. This configuration yielded favorable outcomes across all our experiments. It is important to emphasize that the nearest-prototype matching paradigm, driven by Lrec , is the pre-training objective. During inference, the decoder outputs the reconstructed feature vector X̃𝑚𝑖 ∈ R𝐷 , which is concatenated with the encoder’s latent vector z𝑖 ∈ R𝐿 to form a compact representation [ X̃𝑚𝑖 ; z𝑖 ]. This representation is provided to downstream classifier for final classification. The pre-training process ensures that X̃𝑚𝑖 inherently encodes the quality of prototype matching, making the inference pipeline efficient and decoupled from the memory module’s per-prototype computational overhead.
4.3
Feature Selection and Padding
Preprocessed Flow-Level Statistical Features. We extract a total of 76 flow-level statistical features from each bidirectional flow, all derived exclusively from packet headers (IP and TCP/UDP layers) without accessing any encrypted payload. These features span five functional categories: length/size statistics, temporal and IAT features, packet/byte count features, rate features, and flag/initialization features. The complete list of all 76 features, organized by category, is provided in Appendix Table 8. Feature Selection Based on Gini Importance. Traffic data differs fundamentally from image data [59], the domain in which diffusion models have been most extensively applied. A substantial proportion of traffic features assume zero values, as summarized in Table 2. The table presents, for each of the four datasets, the fraction of features whose zero proportion exceeds the threshold 𝛾. In each dataset, over 10% of the features are identically zero across all samples. A higher zero-value ratio for a given feature indicates a greater prevalence of zero entries across all classes within the dataset. This phenomenon may correspond to one of two scenarios: (1) the feature constitutes a distinguishing characteristic of a specific traffic class relative to others; (2) the feature exhibits consistent behavior across different classes, manifesting as a uniformly high zero-value ratio. In the latter case, the feature conveys negligible information, contributes virtually nothing to downstream tasks, and simultaneously degrades the training efficiency of the diffusion model while increasing the risk of overfitting. To address this issue, we introduce a feature selection method based on Random Forest importance scores. Specifically, a Random Forest classifier is first trained on the training partition designated for the diffusion model. The Gini Importance [73] of each feature is subsequently computed, which quantifies the contribution of
Table 2: Statistics of Feature Zero-Value Ratios Dataset
𝛾 = 100%
𝛾 > 95%
𝛾 > 90%
𝛾 > 80%
CIC-IDS-2017 ISCX-VPN-2016 USTC-TFC2016 CSTNET-TLS1.3
10.39% 11.84% 11.84% 10.53%
19.48% 27.63% 18.42% 15.79%
23.38% 46.05% 21.05% 19.74%
27.27% 64.47% 38.16% 21.05%
a feature to classification performance via the mean reduction in node impurity. The Gini impurity at a given node is defined as: Í Gini(𝑖) = 1 − 𝑘 𝑝𝑘2 , where 𝑝𝑘 denotes the proportion of samples belonging to the 𝑘-th class at forest node 𝑖. For a node with 𝑛𝑖 total samples, the reduction in Gini impurity resulting from a split is given by: 𝑛 right 𝑛 left ΔGini = Gini(𝑖) − Gini(𝑖 left ) − Gini(𝑖 right ). (11) 𝑛𝑖 𝑛𝑖 After normalization, the Gini Importance for each feature is obtained. Features are then ranked in descending order of their importance. We retain the minimal subset of features whose cumulative importance reaches a predefined threshold, while the remaining features are deemed low-contribution and are consequently pruned. &