Optimization of a Hybrid Quantum-Classical ML Model for Research Sentiment Classification

P2MI-Community Service March - November 2024

Dr. Fariska Zakhralativa Ruskanda, ST.,
School of Electrical Engineering and Informatics

Rahmat Mulyawan, ST., MY., M.Sc
School of Electrical Engineering and Informatics

Dr. Eng. Infall Syafalni, ST., MSc.
School of Electrical Engineering and Informatics

Abstract

This study explores the use of hybrid quantum-classical machine learning methods for Quantum Natural Language Processing (QNLP)-based sentiment analysis in the Noisy Intermediate-Scale Quantum (NISQ) era. By adopting the GeneralQC ansatz inspired by Circuit-Centric Quantum Classifiers (CCQC), this study develops parameterized quantum circuits (PQC) to improve the accuracy and efficiency of sentiment classification. The Rx-CNOT and Rx-CRz models achieve 96.91% accuracy, more than 15 points ahead of SimpleSA, with consistent performance despite the variety of nouns. However, these models require significantly larger computational resources, especially for the Rx-CRz model with 218 parameters. These results demonstrate the great potential of QNLP in outperforming classical NLP models, with opportunities for further development through additional ansatz construction and more flexible parameter tuning.

Keyword: Quantum NLP, klasifikasi sentimen, ansatz, hybrid quantum-classical machine learning

Pendahuluan

Quantum computing has significant applications in Quantum Machine Learning (QML), allowing it to process complex data that classical systems struggle with. The Noisy Intermediate-Scale Quantum Machine Learning (NISQ) era has opened up opportunities for QML experimentation, despite its inherent vulnerability to noise and errors. With Variational Quantum Algorithms (VQA) techniques, fields like Quantum Natural Language Processing (QNLP) are flourishing, enabling more structured and accurate natural language analysis, particularly in tasks like sentiment analysis.

Recent advances in QNLP, particularly in sentiment analysis, have demonstrated the potential of quantum-based methods to outperform traditional NLP models. Previously, researchers developed novel quantum circuit architectures, such as SimpleSA and Circuit-Centric Quantum Classifiers (CCQC), to improve sentiment classification accuracy and computational efficiency. These architectures balance expressivity with a low number of trainable parameters, making them suitable for binary classification on NISQ devices.

This research aims to explore alternative hybrid quantum-classical machine learning methodologies for sentiment analysis. Specifically, the project seeks to implement and evaluate a novel ansatz algorithm inspired by the CCQC framework. By enhancing the interpretative power and computational efficiency of QNLP models, this research aims to improve the performance of QNLP-based sentiment classification and expand the library of quantum-based machine learning applications in preparation for the post-NISQ era.

Metodologi

The process of converting sentences into trainable quantum circuits involves several steps, starting with importing and pre-distributing the dataset into training, development, and test sets to ensure vocabulary consistency. Sentences are parsed using the Bobcat Parser from the Lambeq library, resulting in string diagrams that undergo grammar validation and simplification using rewriting rules. Invalid diagrams are discarded, and valid diagrams are transformed into a more compact form by removing redundant components, thus halving the number of qubits. Stemming is applied to unify the various word forms, and the diagrams are converted into parameterized quantum circuits (PQCs) using the GeneralQC ansatz, which incorporates a NOT box to handle negation. Finally, the PQCs are compiled into training, prediction, and cost functions, with a binary cross-entropy loss used for evaluation. The SPSA optimizer adjusts the circuit parameters, and model performance is assessed through inference on the test set.

The GeneralQC ansatz combines the SimpleSA noun nonparameterization strategy with the Circuit-Centric Quantum Classifiers (CCQC) circuit architecture. Its structure includes two code blocks, each with a single-qubit gate and a linearly related 2-qubit gate controlled by a span parameter r. Three gate constructions are explored: H-CRx, Rx-CNOT, and Rx-CRz, which represent combinations of single-qubit gates and controlled single-qubit gates.

EksperimendanHasil

The Rx-CNOT model achieved an accuracy of 87.63% after 800 iterations, outperforming SimpleSA's 83.51%, while H-CRx and Rx-CRz performed slightly worse, at 82.47% and 79.12%, respectively. When nouns were removed, both Rx-CNOT and Rx-CRz showed significant improvement, achieving an accuracy of 96.91%, outperforming SimpleSA by over 13%. However, the GeneralQC model required more computational resources, with the training time for the Rx-CRz model exceeding 112 hours, compared to SimpleSA's 17 hours. This increase in time is due to the larger number of trainable parameters, with the Rx-CRz circuit using up to 218 parameters and 20 rotation gates, compared to SimpleSA's 58 parameters and 3 rotation gates.

Gambar 1. Pipeline QNLP
Gambar 2. KonstruksiGeneralQCAnsatz
Gambar 3. Hasil EksperimenAnsatz
Kesimpulan

The GeneralQC ansatz outperforms the SimpleSA ansatz in sentiment classification, with the Rx-CNOT and Rx-CRz models achieving 96.91% accuracy, over 15 points higher than SimpleSA. Rx-CNOT outperforms H-CRx due to its wider output space and consistent performance across SVAO and SXA sentence types, while Rx-CRz excels in SXA but is slightly weaker in SVAO sentences. Both models benefit from a noun non-parameterization strategy, which makes them robust to variations in noun usage. Future research could explore additional ansatz constructions and apply looser regularization methods, such as restricted rotation gates, to limit the influence of nouns. Extending this regularization approach to other parts of speech could further improve model performance by adjusting word bins based on semantic role.