Research
A Hybrid Classical-Quantum Fine Tuned BERT for Text Classification
Overview Research area: Quantum machine learning applied to natural language processing, specifically hybrid classical-quantum fine-tuning of pre-trained language models for text classification. Techn
- arXiv
- 2511.17677
- Published
- 2025-11-21
- Authors
- Abu Kaisar Mohammad Masum, Naveed Mahmud, M. Hassan Najafi, Sercan Aygun
AI summary
Overview
Research area: Quantum machine learning applied to natural language processing, specifically hybrid classical-quantum fine-tuning of pre-trained language models for text classification.
Technical level: Intermediate. The paper assumes familiarity with BERT-style transformer models and basic neural network fine-tuning, but explains quantum computing fundamentals (qubits, superposition, entanglement, quantum gates, variational circuits) from the ground up.
Scope: The paper proposes and empirically evaluates a hybrid model that connects a pre-trained BERT encoder to a trainable n-qubit variational quantum circuit, comparing its F1 and accuracy against a classical BERT baseline and an MLP tf-idf baseline across five text classification datasets.
What This Paper Is About
Fine-tuning BERT for text classification is computationally expensive and demands careful hyper-parameter tuning, largely because the standard approach attaches a fully connected multi-layer perceptron with many hyper-parameters to BERT's output. The authors ask whether replacing that classical classification head with a quantum variational circuit can match or beat classical baselines. They build a hybrid pipeline in which a pre-trained BERT produces embeddings, a quantum layer encodes and transforms those embeddings, and a classical output layer produces the final class prediction.
Key Contributions
- A hybrid architecture that integrates an n-qubit (2–10 qubit) variational quantum circuit directly with a fine-tuned classical BERT model for text classification.
- Systematic evaluation across quantum circuit configurations, including varying qubit counts, with a circuit depth of 4, H gates, Y-rotation gates, CNOT gates, angle encoding, and a Pauli-Z feature map.
- Cross-dataset benchmarking on five datasets (IMDb, Spam, SST, Yelp, Twitter), comparing the proposed model against classical BERT and an MLP using tf-idf features.
- A training-time analysis showing how wall-clock training duration scales with qubit count for each dataset.
Main Findings
- Competitive or better F1 scores: The classical-quantum BERT achieves F1 of 0.64 (train and validation) on IMDb versus 0.63 for both classical BERT and MLP tf-idf; 0.86 (train and validation) on Twitter versus 0.83 for classical BERT and 0.82/0.83 for MLP tf-idf; and 0.79 (train and validation) on Yelp versus 0.78 for classical BERT and 0.78/0.75 for MLP tf-idf.
- Ties on Spam and SST: On the Spam dataset, all three models reach F1 of 0.95 for both training and validation. On SST, both the classical-quantum BERT and classical BERT reach 0.82 for both training and validation, while the MLP scores 0.70 (train) and 0.72 (validation).
- Accuracy across 2–10 qubits (Table 3): The proposed model reaches 0.67 ± 0.04 on IMDb, 0.96 ± 0.03 on Spam, 0.86 ± 0.02 on Twitter, 0.82 ± 0.02 on SST, and 0.79 ± 0.01 on Yelp. For comparison, the paper reports Lambeq (3 qubits) at 0.93 on Spam and 0.59 on SST; Hybrid QBERT (5 qubits) at 0.97 on Spam; and Adapting QBERT (10 qubits) at 0.89 on SST.
- Training time grows with qubit count, but unevenly by dataset: IMDb goes from 2760 seconds at 2 qubits to 3900 seconds at 10 qubits; Spam from 2880 to 4140 seconds; SST from 2988 to 4740 seconds; Yelp from 3126 to 8612 seconds; and Twitter from 3480 to 8910 seconds. The authors characterize IMDb, Spam, and SST as relatively stable in training time, while Yelp and Twitter show steeper increases.
- The quantum layer does not always win: On SST, the hybrid model matches rather than exceeds the classical BERT, which the authors describe as evidence that the quantum-enhanced model remains competitive even when it does not outperform.
- Simulation, not real quantum hardware: All experiments use a quantum circuit simulator (PennyLane's default simulator), because the authors state current quantum hardware is not yet fault-tolerant enough to achieve actual computational speedup.
Methodology in Plain English
The authors start with a pre-trained BERT model, which reads input text and outputs a 768-dimensional vector representation of the last hidden state. Because a quantum circuit with a limited number of qubits cannot consume 768 features directly, they insert a pooling layer that reduces 768 dimensions down to n_q dimensions, one feature per qubit.
Each reduced feature d_i is encoded into a qubit using angle encoding: an R_y rotation by angle d_i turns a |0⟩ state into cos(d_i)|0⟩ + sin(d_i)|1⟩. The resulting quantum state is passed through a shallow variational quantum circuit, depth 4. That circuit's first layer applies Hadamard gates to create superposition, the next layer applies trainable R_y rotation gates (the parameters that get optimized), and a following layer of CNOT gates creates entanglement so the qubits become correlated.
The circuit is then measured, specifically by taking expectation values of Pauli-Z observables, converting the quantum state back into a classical vector. A second classical pooling layer reduces n features to 2 features, which produces the classification prediction. The prediction is compared against the true label using a mean-square-error loss, and quantum gradients are computed to update the variational circuit parameters.
Training used an NVIDIA T4 GPU with PyTorch 2.1.0+cu118, transformers 4.35.2 for BERT, scikit-learn 1.2.2 for model selection and classification reports, and PennyLane 0.33.1 with the default simulator for the quantum circuits. Settings were 10 epochs, batch size 32, maximum sequence length 25, learning rate 1×10⁻³, and a quantum weight of 0.01 intended to blend quantum features without overwhelming the classical model.
Why This Matters
Impact on research: The work sits at the intersection of pre-trained language models and quantum machine learning, testing whether a variational quantum circuit can serve as a drop-in replacement for the classical classification head on top of BERT. Even where results only match classical baselines, the paper argues this is an important step toward understanding where quantum advantage might eventually materialize in NLP.
Real-world applications (as suggested by the paper's dataset choices):
- Sentiment analysis of movie reviews (IMDb)
- Email spam detection (Spam dataset)
- Social media opinion monitoring, such as airline sentiment on Twitter
- Review and customer-feedback classification (Yelp), plus general sentiment treebank text (SST)
Industry relevance: The paper is relevant to organizations exploring quantum computing as a future accelerator for NLP workloads, and it provides practical data on the cost side of that trade-off. Training times of thousands of seconds per run and the need for GPU-accelerated simulation mean the approach is currently a research direction rather than a production replacement for classical fine-tuning. The work was supported by the National Science Foundation under Grant No. 2019511 and gifts from NVIDIA.
Future Directions
- Improving computational efficiency and reducing training time, which the authors explicitly identify as an area where further optimization could be beneficial.
- Addressing scalability limits imposed by quantum devices, including the gap between simulated circuits and fault-tolerant quantum hardware.
- Testing whether the hybrid approach scales to larger qubit counts and deeper circuits, since the study caps at 10 qubits and circuit depth 4, and prior work suggests more qubits can help on harder datasets.
- Investigating the training-time growth seen on Yelp and Twitter, which the authors suggest may stem from more complex patterns or higher data dimensionality, and which would need to be controlled before larger-scale use.
Target Audience
This paper is most useful to machine learning researchers and graduate students working on quantum machine learning, hybrid classical-quantum architectures, or efficient fine-tuning of pre-trained language models. It also suits practitioners evaluating whether quantum circuits are ready to be integrated with transformer-based NLP pipelines, and readers who want a concrete, dataset-by-dataset accounting of where a quantum classification head helps, ties, or costs more training time.
Authors’ abstract
Fine-tuning BERT for text classification can be computationally challenging and requires careful hyper-parameter tuning. Recent studies have highlighted the potential of quantum algorithms to outperform conventional methods in machine learning and text classification tasks. In this work, we propose a hybrid approach that integrates an n-qubit quantum circuit with a classical BERT model for text classification. We evaluate the performance of the fine-tuned classical-quantum BERT and demonstrate its feasibility as well as its potential in advancing this research area. Our experimental results show that the proposed hybrid model achieves performance that is competitive with, and in some cases better than, the classical baselines on standard benchmark datasets. Furthermore, our approach demonstrates the adaptability of classical-quantum models for fine-tuning pre-trained models across diverse datasets. Overall, the hybrid model highlights the promise of quantum computing in achieving improved performance for text classification tasks.