Source-linked AI summary
QNLP in Practice: Running Compositional Models of Meaning on a Quantum Computer
Robin Lorenz, Anna Pearson, Konstantinos Meichanetzidis, Dimitri Kartsaklis, Bob Coecke
TL;DR
The paper asks whether NLP models can be practically implemented on quantum hardware, an area where experimental work remains largely unexplored. It implements syntax-sensitive and simpler compositional models as quantum circuits, trains them on sentence-classification tasks, and finds smooth convergence with meaningful results on simulations and quantum hardware.
Problem
Experimental implementations of NLP models on quantum hardware remain largely unexplored, despite quantum computing's potential relevance to language representation and processing.
Method
The paper maps compositional sentence representations to quantum circuits, implements models with different degrees of syntax sensitivity, and trains them for binary sentence classification.
Results
All models converge smoothly and produce good results on simulated and quantum hardware runs, with syntax sensitivity matching the differing demands of the classification tasks.
Takeaways & Limitations
The experiments provide a proof of concept that practical QNLP can be conducted on small noisy quantum computers and offer an accessible account of its implementation process.
Takeaways & Limitations
Scalability remains constrained because longer sentences increase circuit width and therefore quantum resource costs.
Abstract
from arXiv · showhide
Quantum Natural Language Processing (QNLP) deals with the design and implementation of NLP models intended to be run on quantum hardware. In this paper, we present results on the first NLP experiments conducted on Noisy Intermediate-Scale Quantum (NISQ) computers for datasets of size greater than 100 sentences. Exploiting the formal similarity of the compositional model of meaning by Coecke, Sadrzadeh and Clark (2010) with quantum theory, we create representations for sentences that have a natural mapping to quantum circuits. We use these representations to implement and successfully train NLP models that solve simple sentence classification tasks on quantum hardware. We conduct quantum simulations that compare the syntax-sensitive model of Coecke et al. with two baselines that use less or no syntax; specifically, we implement the quantum analogues of a "bag-of-words" model, where syntax is not taken into account at all, and of a word-sequence model, where only word order is respected. We demonstrate that all models converge smoothly both in simulations and when run on quantum hardware, and that the results are the expected ones based on the nature of the tasks and the datasets used. Another important goal of this paper is to describe in a way accessible to AI and NLP researchers the main principles, process and challenges of experiments on quantum hardware. Our aim in doing this is to take the first small steps in this unexplored research territory and pave the way for practical Quantum Natural Language Processing.
1. Introduction
This paper advances practical QNLP by running linguistically motivated sentence-classification experiments on NISQ hardware and comparing models with different syntax sensitivity. It reports smooth convergence and task-dependent performance patterns across simulations and hardware runs.
- Motivation: QNLP aims to develop NLP models explicitly designed for execution on quantum hardware, extending beyond predominantly classical simulations.The paper positions its experiments as a response to the limited practical evidence available in the field.
- Scope: The paper presents two complete NLP experiments with datasets containing approximately 100–150 sentences on quantum hardware, without claiming quantum advantage.Its focus is the process, challenges, and limitations of running NLP models on current NISQ computers.
- Method: The experiments classify sentences using quantum compositional models that compute state vectors and convert them into binary labels, trained with binary cross entropy and SPSA.The implemented models span bag-of-words, word-sequence, and fully syntax-based composition.
- Method: DisCoCat is used for syntax-based composition because its derivations form tensor networks compatible with quantum-computer data processing.The model also provides a formal treatment of the interaction between syntax and semantics.
- Experiments: The datasets comprise 130 grammar-generated food-versus-IT sentences and 105 RelPron noun phrases classified by relative-clause type.The authors characterize both tasks as small-scale and simple by NLP standards, yet challenging for current NISQ hardware.
- Results: All models converge smoothly and produce good results in simulations and quantum hardware runs, with performance tracking task-specific syntax requirements.Bag-of-words and word-sequence models perform better on meaning classification, whereas DisCoCat performs best on the relative-pronoun task.
- Contributions: The paper contributes quantum versions of compositional NLP models, a detailed account of training and execution challenges, and larger-scale hardware experiments.It presents these experiments as a proof of concept that practical QNLP is within reach.
2. Related Work
Related work spans NISQ quantum machine learning, quantum algorithms for language problems, quantum-inspired classical NLP, and compositional QNLP. The paper extends this trajectory from theoretical and simulated studies toward medium-scale experimental QNLP on NISQ hardware.
- NISQ and QML: NISQ quantum machine-learning protocols commonly use variational quantum circuits whose parameters are trained with machine-learning methods.The paper situates its work within broader hybrid classical–quantum algorithm research.
- Quantum language algorithms: Other quantum-language research targets parsing, context-free languages, or string matching through algorithms such as Grover search and quantum annealing.These approaches address language-related problems without employing the compositional model used here.
- Adjacent work: Quantum-inspired classical NLP studies are abundant but fragmented, while quantum neural-network research is related but not directly focused on NLP implementation.The paper distinguishes these directions from experimental compositional QNLP.
- Compositional QNLP: Compositional QNLP implements NLP models inspired by DisCoCat, linking theoretical speedups and NISQ-compatible foundations with experimentally evaluated workflows.Prior work includes classical simulation and a 16-sentence NISQ proof of concept.
3. Compositional Models for Sentence Representation
Sentence representations range from syntax-insensitive bag-of-words models to word-sequence and fully syntax-sensitive models. DisCoCat maps grammatical derivations to tensor contractions, making its sentence representations suitable for quantum implementation, while the paper also introduces quantum-friendly word-sequence and bag-of-words baselines.
- Bag-of-words models: Bag-of-words models represent sentences as unordered word symbols or embeddings, so they cannot model syntactic relationships.They can nevertheless be lightweight and effective when examining words in isolation is sufficient for classification.
- Word-sequence models: Word-sequence models process words from left to right, preserving order and capturing local interactions and some longer-range dependencies.The paper uses a simpler quantum-friendly tensor-network version in which word matrices are multiplied in sentence order after acting on a start vector.
- Syntax-sensitive models: Fully syntax-sensitive models compose words according to a parser-provided tree rather than a fixed left-to-right sequence.Recursive neural networks are one example, while the usefulness of fully syntax-sensitive models remains under debate.
- DisCoCat: DisCoCat is chosen because its sentence representations form tensor networks compatible with quantum processing and because input parse trees reduce the complexity learned during training.The paper contrasts this explicit syntax with large conventional models that can learn syntactic features from training data.
- DisCoCat: DisCoCat assigns word tensors according to pregroup grammatical types and translates grammar reductions into tensor contractions that produce a sentence vector.For example, a transitive verb has type nr · s · nl and is represented as a third-order tensor mapping N ⊗ N to S.
- Comparative setup: The experiments compare quantum-friendly DisCoCat, word-sequence, and bag-of-words models across different degrees of syntax sensitivity.The word-sequence and bag-of-words versions provide baselines for the syntax-based model.
4. Introduction to Quantum Computing
Quantum computing represents information with qubits, transforms it through unitary gates arranged in circuits, and obtains probabilistic predictions by measurement. These circuits provide the diagrammatic and linear-algebraic foundation used for the paper’s quantum models.
- Diagrammatic operations: The merge operation m combines multiple word vectors into a single sentence vector in the bag-of-words representation.Its diagrammatic form is a merge-dot.
- Qubits and measurement: A qubit state is a normalized complex superposition of the basis states |0⟩ and |1⟩.The basis-state amplitudes determine measurement probabilities.
- Quantum circuits: Quantum evolution applies unitary linear maps to qubit states, with circuit wires and boxes representing composition and tensor products.For multiple qubits, the joint state space is formed by tensor products.
- Quantum gates: The paper introduces basic gates including Hadamard, CNOT, parameterised X-rotations, and controlled Z-rotations.Controlled rotations apply the target operation conditionally on the control qubit’s state.
- Qubits and measurement: Measurement is probabilistic: repeated circuit executions estimate outcome probabilities from observed bit strings.These empirical probabilities connect circuit theory with hardware experiments.
- Hardware considerations: Quantum hardware is challenging because qubits experience environmental errors and unwanted interactions, while post-selection can require rare measurement outcomes.The paper notes that the physical implementation of qubits varies across quantum computers.
5. The General Pipeline
The QNLP pipeline converts sentences into quantum circuits through parsing, diagram construction, rewriting, ansatz selection, compilation, and measurement-based evaluation. Its key optimization bends noun states to reduce costly cups and the associated post-selection burden.
- Compilation: A quantum compiler translates the circuit into hardware-specific code after the diagram has been optimized and converted through the ansatz.The resulting code can then be run on quantum hardware.
- Parser and DisCoCat derivation: The pipeline begins with a sentence parser and constructs a DisCoCat diagram by representing words as states connected by cups.The syntax-based model uses grammatical types and reduction rules to form the diagram.
- Rewrite: Diagram rewriting changes the representation without changing its mathematical meaning, enabling hardware-specific or general computational advantages.The paper applies compact-closure equivalences before circuit realization.
- Rewrite: Bending down nouns reduces the number of cups because noun states are transformed into equivalent diagram components.In the example, three cups become one; generally, the reduction equals the number of nouns.
- Ansätze: An ansatz maps the abstract diagram to a parametrised circuit by choosing qubit counts and parametrised quantum states or effects for word wires.Further parameter values determine each word’s concrete embedding.
- Measurement and post-selection: Cups require post-selection, so reducing them can improve statistical feasibility by lowering the number of qubits whose outcomes must satisfy conditions.The unreduced example would require post-selecting 6 of 7 qubits, compared with 4 of 5 after rewriting.
6. The Tasks
The paper evaluates quantum sentence-classification models on two binary tasks: topic-based meaning classification and a more challenging relative-pronoun benchmark. The datasets are small enough for current hardware experiments but already impose substantial computational limits.
- Meaning classification: The meaning-classification task contains 130 short sentences, evenly divided between food and IT topics.Sentences are generated from a fixed 17-word vocabulary using simple syntactic forms.
- Meaning classification: Shared vocabulary across the two meaning-classification classes prevents the task from being completely trivial.Four words occur in both classes.
- Relative-pronoun classification: The relative-pronoun task uses 105 noun phrases selected from RelPron, with an overall vocabulary of 115 words.Each word occurs at least three times in the dataset.
- Relative-pronoun classification: The relative-pronoun benchmark is more challenging than meaning classification because its larger vocabulary makes the words sparser.Its phrases contain relative clauses and are adapted from the original definition-to-term task.
- Hardware constraints: Sentence and dataset lengths already approach the limits of available quantum hardware.Doubling the number of sentences would begin to create an infeasible time cost under shared resources.
7. Experiments
The experiments train and compare quantum-friendly sentence models in classical simulation and on IBM NISQ hardware. Results show task-dependent advantages for syntax-sensitive models, smooth convergence, and statistically supported quantum-run classification performance, while hardware-versus-simulation comparisons remain inconclusive.
- Experimental setup: The experiments train task-specific word representations using the unified pipeline, with SPSA optimisation applied to binary cross-entropy objectives.The implementation uses lambeq, DisCoPy, TKET, and the IBM ibmq bogota device for the model and hardware stages.
- Model parametrisation: Single-qubit word states use either a three-parameter Euler ansatz or a one-parameter Rx ansatz, while multi-qubit states use IQP-based circuits.The parameterisation choice is applied consistently across words with the corresponding representation, and DisCoCat assigns different qubit arities to adjectives and verbs.
- Classical simulation: In classical simulation, bag-of-words performs best on MC, while DisCoCat matches or slightly outperforms the 231-parameter word-sequence model on RP with only 168 parameters.Bag-of-words performs no better than random guessing on RP, whereas the lower-parameter word-sequence model performs worse than DisCoCat.
- Sanity check: In the sanity-check task, bag-of-words fails completely, while DisCoCat outperforms the convergent word-sequence model despite using fewer parameters.The comparison is consistent with the task requiring syntax-sensitive representations rather than merely word-order information.
- Quantum runs: On quantum hardware, the cost decreases with SPSA iterations despite NISQ noise, and after 100 and 130 iterations test errors are 16.7% for MC and 32.3% for RP, respectively.The corresponding F-scores are 0.85 and 0.75; permutation tests report p ≤0.001 for MC and p ≤0.10 for RP against random guessing.
- Quantum runs: Quantum-run test errors cannot be conclusively compared with simulations because the experiments used one noisy hardware run versus many averaged noiseless classical runs.The RP quantum curve also exhibits overfitting around iteration 60.
8. Future Work and Conclusions
The paper establishes practical QNLP experiments on small noisy quantum computers and identifies future work on scalable resources, model design, broader grammars, and meaningful quantum advantage.
- Conclusions: The authors implemented two NLP experiments on small noisy quantum computers, testing three compositional models with different degrees of syntax sensitivity.They describe the tasks as well-defined but simple, and report meaningful results on their datasets.
- Future model design: Task-specific ansatz optimization remains open because the study did not search for optimal word-circuits for individual tasks.The paper highlights a trade-off between ansatz performance on one task and general performance across many tasks.
- Scalability: Scaling QNLP requires resource estimation because longer sentences increase circuit width and can impose exponential time costs through post-selection.The paper notes that future protocols may avoid post-selecting many qubits by using more sophisticated measurement schemes.
- Future model design: The DisCoCat framework can extend beyond pregroup grammars, including CCG-derived syntax trees that can be instantiated as quantum circuits.This creates a broader space of possible QNLP models based on alternative grammatical formalisms.
- Conclusions: The experiments provide a proof-of-concept foundation for applying QNLP to larger-scale textual data and real-world tasks.The authors frame this direction as moving beyond the proof-of-concept setting used to introduce the approach.
- Quantum advantage: Potential quantum advantage would require QNLP tasks that are hard to simulate classically while also outperforming classical state-of-the-art methods.The paper identifies high entanglement and interference, or compositionally hard-to-simulate circuits, as possible routes.