[Paper Review] lambeq: An Efficient High-Level Python Library for Quantum NLP
lambeq is an open-source, high-level Python library that enables end-to-end quantum natural language processing (QNLP) by converting sentences into quantum circuits via string diagrams and tensor networks. It supports multiple compositional models, syntactic parsing, circuit optimization, and integration with quantum and classical machine learning frameworks, achieving perfect test accuracy in both noiseless and noisy quantum simulations on a small NLP benchmark.
We present lambeq, the first high-level Python library for Quantum Natural Language Processing (QNLP). The open-source toolkit offers a detailed hierarchy of modules and classes implementing all stages of a pipeline for converting sentences to string diagrams, tensor networks, and quantum circuits ready to be used on a quantum computer. lambeq supports syntactic parsing, rewriting and simplification of string diagrams, ansatz creation and manipulation, as well as a number of compositional models for preparing quantum-friendly representations of sentences, employing various degrees of syntax sensitivity. We present the generic architecture and describe the most important modules in detail, demonstrating the usage with illustrative examples. Further, we test the toolkit in practice by using it to perform a number of experiments on simple NLP tasks, implementing both classical and quantum pipelines.
Motivation & Objective
- To bridge the gap between theoretical QNLP and practical implementation on near-term quantum hardware.
- To provide a modular, extensible, and user-friendly toolkit for researchers to prototype and experiment with quantum NLP pipelines.
- To support multiple compositional models—bag-of-words, word-sequence, and syntax-based DisCoCat—offering varying degrees of syntactic sensitivity.
- To enable seamless integration with quantum compilers and classical ML libraries such as PyTorch and JAX for training and simulation.
- To lay the foundation for future support of advanced features like diagrammatic differentiation, transformer-based parsing, and document-level discourse modeling.
Proposed method
- The pipeline begins with Combinatory Categorial Grammar (CCG) parsing to generate syntactic structure, using a state-of-the-art parser integrated into the toolkit.
- Parse trees are converted into string diagrams using DisCoPy, a backend library for diagrammatic reasoning and tensor network manipulation.
- String diagrams are transformed via rewriting rules to simplify or optimize the representation before circuit conversion.
- The string diagrams are mapped to quantum circuits using parameterized ansätze, with support for both quantum and classical (tensor network) execution.
- The library supports both noiseless and noisy quantum simulations using the IBM Quantum Aer simulator, with SPSA as the optimization algorithm.
- The toolkit is designed to be extensible, allowing plug-in of new compositional models, parsers, ansätze, and future integration with diagrammatic differentiation for automatic differentiation in quantum machine learning.
Experimental results
Research questions
- RQ1Can a high-level, modular Python library streamline the end-to-end implementation of quantum NLP pipelines from natural language to quantum circuits?
- RQ2How do different compositional models—ranging from bag-of-words to syntax-sensitive DisCoCat—impact the performance and expressivity of quantum NLP models?
- RQ3To what extent can quantum circuits trained via SPSA on noisy simulators achieve high accuracy on small-scale NLP tasks?
- RQ4Can the same pipeline be used for both classical tensor network training and quantum circuit execution with minimal code changes?
- RQ5What is the feasibility of scaling QNLP pipelines using a diagrammatic, compositional approach that preserves linguistic structure?
Key findings
- The toolkit successfully converts sentences into quantum circuits using three distinct compositional models, with the syntax-aware DisCoCat model offering the most linguistically faithful representation.
- Classical experiments using tensor networks achieved perfect accuracy on the Lorenz et al. (2021) meaning classification dataset, demonstrating the viability of classical simulation for model development.
- In noiseless quantum simulations, the quantum pipeline converged successfully with perfect test accuracy, despite early-stage instability and fluctuation.
- Even under noisy shot-based simulation conditions, the quantum pipeline achieved perfect test accuracy, indicating robustness to noise in small-scale experiments.
- The library enables reproducible and modular experimentation, with support for both quantum and classical workflows within a single, unified framework.
- The toolkit has already been used in prior research, including early quantum NLP experiments on hardware and the creation of a large-scale DisCoCat resource of over 3,000 parsed sentences from 'Alice in Wonderland'.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.