Manuscript Offprint

arXiv:2610.17725

Beyond Model Scaling: Rethinking Sequence Construction for Transformer-based Network Intrusion Detection

Zeeshan Zulkifl Shah, Muhammad Ikram, Dali Kaafar, Yipeng Zhou

Zeeshan Zulkifl Shah, Muhammad Ikram, Dali Kaafar, and Yipeng Zhou

Macquarie University, Sydney, Australia

{zeeshanzulkifl.shah,muhammad.ikram,dali.kaafar,yipeng.zhou}@mq.edu.au

Abstract—Transformer-based network intrusion detection systems (NIDS) have shown strong potential for detecting multi-stage cyberattacks, yet most methods construct input sequences using fixed temporalization schemes rather than treating sequence construction as a systems design decision. In flow-based intrusion detection, timestamp-based windowing often fragments related attack activities while merging unrelated communications, reducing the behavioral context available to transformers. We present a unified pipeline abstraction that decomposes transformer-based NIDS into four design dimensions—traffic representation, temporalization, transformer backbone, and prediction aggregation—and propose session-coherent temporalization, which constructs sequences from communication sessions instead of fixed time windows. Experiments on three complementary intrusion detection datasets show that temporalization is the dominant factor governing transformer performance: session-coherent temporalization more than doubles Macro-F1 over timestamp-based windowing, enabling lightweight transformers to achieve up to 0.95 Macro-F1 at substantially higher inference throughput than pretrained models. We further vary the transformer size from 0.65M to 3.38M parameters and find that larger transformer models provide no measurable accuracy improvement despite substantially higher computational cost, while zero-shot cross-dataset evaluation shows only modest gains under domain shift. These results indicate that preserving communication-session semantics, rather than scaling transformer capacity, is the key to accurate and efficient transformer-based intrusion detection.

I. INTRODUCTION

The widespread adoption of end-to-end encryption has fundamentally changed the operating environment of modern network intrusion detection systems (NIDS). As payload inspection becomes increasingly impractical, operational NIDS must rely primarily on flow-level telemetry, where attacks are manifested not by individual flows but through coordinated sequences of network interactions, including reconnaissance, exploitation, lateral movement, and command-and-control communication [10]. Consequently, effective intrusion detection increasingly depends on preserving these temporal relationships while simultaneously satisfying the latency and throughput requirements of high-speed operational networks.

Temporal dependencies provide essential evidence for understanding attack progression [23], yet existing NIDS often fail to preserve them. Signature-based systems such as Suricata [26] and Snort [24], [19] rely on manually crafted rules and consequently struggle to detect previously unseen attacks [25]. Learning-based approaches improve generalization by modeling flow-level telemetry directly [1], [2], while recent networking research has explored sequence-aware traffic representations for encrypted traffic analysis and lightweight malicious-traffic classification at the network edge [13], [5]. Nevertheless, many existing NIDS either classify flows independently or rely on fixed sequence-construction heuristics that fragment related attack stages while grouping unrelated communications into the same context. As encrypted traffic continues to dominate Internet-scale deployments [6], [7], preserving communication semantics has become a fundamental systems challenge rather than merely a machine learning problem.

Transformer architectures naturally model long-range dependencies through self-attention [27], making them attractive for flow-based intrusion detection [14], [8]. Deployment-oriented networking systems have similarly investigated sequence-aware intrusion detection with execution inside programmable networks [33]. Unlike natural language, however, network traffic has no intrinsic sequential representation. Before transformer inference, asynchronous flows must first be organized into input sequences, a process we refer to as temporalization [3]. Temporalization is therefore not merely a preprocessing step; it is a fundamental systems design decision that determines which communication dependencies are preserved for learning and which are irreversibly discarded.

Existing transformer-based NIDS [14], [15], [8] typically construct sequences using fixed timestamp windows or simple batching heuristics. Although computationally convenient, these strategies frequently separate related attack stages across different sequences while simultaneously merging unrelated communications into the same context, producing behaviorally incoherent inputs (see §III-C). Consequently, transformers are forced to learn from distorted communication context, limiting detection performance irrespective of model capacity. We argue that temporalization should be treated as a first-class systems design dimension rather than a fixed implementation detail. More fundamentally, we hypothesize that the effectiveness of transformer-based NIDS is governed more by sequence construction than by continually increasing transformer capacity.

Motivated by this observation, we introduce session-coherent temporalization, a communication-session-aware sequence construction strategy that organizes flows according to communication sessions instead of arbitrary timestamp windows. By preserving communication semantics across related interactions, session-coherent temporalization enables transformers to model within-session attack behavior more coherently than under timestamp-based windowing.

More broadly, we present a unified transformer-NIDS design framework (see §III) that decomposes the detection pipeline into four independent systems design dimensions: traffic representation, temporalization, transformer backbone, and prediction aggregation. This modular abstraction enables controlled evaluation of each design dimension in isolation while eliminating confounding factors that have complicated comparisons among existing transformer-based NIDS.

Using this framework, we systematically evaluate transformer-based NIDS across three complementary flow-based intrusion detection datasets: UNSW-NB15 [16], CICIDS2018 [22], and MQCIDS [20]. Our evaluation spans multiple traffic representations, temporalization strategies, transformer capacities, aggregation mechanisms, and context lengths while jointly considering detection effectiveness and deployment performance. The results demonstrate that temporalization, rather than transformer scale, is the dominant systems design choice governing transformer-based intrusion detection. More broadly, they advocate a pipeline-centric view of transformer-based NIDS, where engineering behavior-preserving sequence construction is more effective than continually scaling model architectures.

Contributions. Our main contributions are as follows:

• Systems insight into transformer-based NIDS. We demonstrate that temporalization is the dominant systems design dimension governing transformer-based intrusion detection. Treating sequence construction as fixed preprocessing fundamentally confounds the evaluation of transformer architectures, whereas preserving communication-session semantics consistently contributes larger gains than increasing model capacity.

• Session-coherent temporalization. We propose session-coherent temporalization, a communication-session-aware sequence construction strategy that organizes flows according to communication sessions rather than arbitrary timestamp windows. The proposed method preserves within-session behavioral continuity, enabling transformers to learn from communication-consistent contexts while reducing fragmentation and cross-session contamination.

• Comprehensive deployment-oriented evaluation. Through extensive experiments on UNSW-NB15, CICIDS2018, and MQCIDS, we show that session-coherent temporalization more than doubles Macro-F1 over conventional timestamp-based windowing while enabling compact transformers to achieve up to 0.95 Macro-F1 and sustain inference throughput approaching 10610^{6} processed flow records per second. We further show that scaling transformer capacity yields negligible benefit, whereas cross-dataset experiments indicate that domain shift remains the principal barrier to robust zero-shot deployment.

For reproducibility, we release an open-source artifact containing implementation details, experimental evidence, and supplementary materials [21].

References (33)

  • A survey of data mining and machine learning methods for cyber security intrusion detection
  • A survey on data-driven network intrusion detection
  • On the evaluation of sequential machine learning for network intrusion detection
  • The relationship between precision-recall and ROC curves (opens the publisher in a new tab)
  • Adaptive clustering-based malicious traffic classification at the network edge
  • Measuring HTTPS adoption on the web
  • Google transparency report: HTTPS encryption on the web
  • Network intrusion detection based on n-gram frequency and time-aware transformer
  • DeBERTaV3: Improving DeBERTa using ELECTRA-style pre-training with gradient-disentangled embedding sharing (opens arXiv in a new tab)
  • Intelligence-driven computer network defense informed by analysis of adversary campaigns and intrusion kill chains
  • ibm-research/CTI-BERT Hugging Face
  • ET-BERT: A contextualized datagram representation with pre-training transformers for encrypted traffic classification
  • FS-Net: A flow sequence network for encrypted traffic classification
  • FlowTransformer: A transformer framework for flow-based network intrusion detection systems
  • Transformer-based classification of IoT network traffic with flow-to-window aggregation
  • UNSW-NB15: A comprehensive data set for network intrusion detection systems (UNSW-NB15 network data set)
  • A pretrained language model for cyber threat intelligence
  • PyTorch: An Imperative Style, High-Performance Deep Learning Library
  • Snort: Lightweight intrusion detection for networks
  • Deception meets diagnostics: Deception-based real-time threat detection in healthcare web systems
  • Beyond Model Scaling: Rethinking Sequence Construction for Transformer-based Network Intrusion Detection – reproducibility artifact
  • Toward generating a new intrusion detection dataset and intrusion traffic characterization
  • ATTACK2VEC: Leveraging temporal word embeddings to understand the evolution of cyberattacks
  • Snort 3 rule writing guide and documentation
  • Outside the closed world: On using machine learning for network intrusion detection
  • Suricata user guide — suricata 8.0.5 documentation
  • Attention is all you need
  • Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference
  • Transformers: State-of-the-art natural language processing
  • Qwen2.5 Technical Report
  • AOC-IDS: Autonomous online framework with contrastive learning for intrusion detection
  • Achieving 100Gbps intrusion prevention on a single server
  • RIDS: Towards advanced IDS via RNN model and programmable switches co-designed approaches