Open AccessOpen Access||Research Article

Integrating Quantum Computing with BERT: A Hybrid Model with Attention Mechanisms for Email Spam Identification

Kashif Iqbal1, Muntaha Mehboob1, Muhammad Talha1, Wasil Ahmed2, Muhammad Umar Sheikh3, Muhammad Hasan Tariq1

1 Department of Computer Science & Artificial Intelligence, Beaconhouse International College, Karachi, 75190, Pakistan

2 Department of Computer Science, SZABIST University, Karachi, 75600, Pakistan

3 Department of Human Resources & Administration, SEED Ventures (Pvt.), Karachi, 75600, Pakistan

Download PDF</>HTML Version

Abstract

Spam email detection is an important task in natural language processing (NLP) and cybersecurity. The emergence of large pre-trained language models such as Bidirectional Encoder Representations from Transformers (BERT) has significantly improved classification accuracy for these tasks. At the same time, the new era of Quantum Machine Learning (QML) investigates whether parameterized quantum circuits (PQCs) can function as effective and possibly more efficient components in classical deep learning systems. In this paper, we propose a new framework that we design as a hybrid of quantum and classical that relies on the merging of a frozen pre-trained BERT (BERT-base-uncased) encoder with a VQC, which, if implemented in PennyLane as we did, allows us to construct a quantum circuit (QN). A multi-headed quantum network with dressing, which extends the initial single circuit design into an array of three parallel circuits with reloaded variational layers, powered by the attention-gated projection layer, and accompanied by a classical residual layer before classification (this multi-head design is a proposal and is not evaluated in this paper). This neural network can be used to classify emails as spam/ham on the Enron Dataset. Contextual embeddings are generated using BERT and dimensionally reduced using a linear layer to match the dimensions of a quantum circuit comprising 5 qubits. The VQC with 4 layers of entanglement is then used to process this embedding, followed by a linear layer converting quantum expectation values to logits. The model is trained for different epoch sizes such as 5 epochs, 10 epochs, and 15 epochs using class-weighted cross-entropy loss to account for label imbalance (class ratios between 50:50 and 78:22 depending on the Enron sub-corpus, see Table 2). A schematic representation of the proposed architecture and quantum circuit diagram with explanations has been included. Empirical results are reported for the baseline BERT–VQC classifier only, on six Enron sub-corpora (single training runs; at 15 epochs the mean validation accuracy is 91.0% and the mean F1-score is 87.4%). We additionally propose, as a design extension, a multi-head dressed quantum network with an attention-gated projection layer, three parallel circuits and residual fusion; its architecture, parameter budget and evaluation protocol are specified, but it has not yet been trained or evaluated. No classical BERT+Dense baseline was trained under the same protocol, so the study establishes feasibility and a reproducible protocol for hybrid BERT–VQC spam classification rather than a quantum advantage.

Keywords

Quantum machine learningVariational quantum circuitHybrid quantum-classical neural networkBERTNatural language processingSpam classification

Graphical Abstract

Integrating Quantum Computing with BERT: A Hybrid Model with Attention Mechanisms for Email Spam Identification — graphical abstract

Novelty Statement

This study demonstrates hybrid spam classification using frozen BERT embeddings and five-qubit variational quantum circuits, achieving 91% accuracy and proposing an unevaluated attention-gated multi-head architecture.