Quantum Natural
Language Processing II

Now You can try it Yourself with Lambeq

In our blog about QNLP we reported that we had performed NLP on quantum hardware. The feedback and interest was tremendous – which is not surprising given the topic, and we promised you a further exciting update before the end of the year.

We are excited to finally be able to share with you the news that we have released “lambeq” (we also refer to it as 𝛌ambeq), an open-source software toolkit, which turns your favourite sentences into quantum circuits, ready to be implemented on existing quantum hardware. Our lambeq toolkit will enable both the professional and the enthusiast to linguistically interact with quantum computers just as we at Cambridge Quantum have been doing for quite some time now.

Our detailed technical account of lambeq can be found in this paper, which explains the pipeline and components of the toolkit in some depth. However a brief overview of the pipeline will be given in this blog.

The pipeline is shown here:

The first step in the process is to parse a sentence. For selected compositional models a syntax tree will be produced with the help of a statistical CCG (Combinatory Categorial Grammar) parser. The next step is to convert the parse tree into a string diagram, more details about the theory and practice of this process can be found here. A string diagram expresses amongst other things the grammatical structure of a sentence.

For example, the sentence: “We are explaining how lambeq works”
in string diagram format becomes:

The python library DisCoPy is used by lambeq as a backend to store and manipulate these string diagrams.

Following on from this the string diagram can be simplified or transformed by the application of rewrite rules. One might want to do this for example to make the diagram easier to transform to a suitable circuit for the currently available quantum hardware. A re-written string diagram is then converted into an actual quantum circuit or tensor network, depending on the choice of whether it is executed on a quantum or classical computer, respectively. This conversion is conditioned on the user’s choice of ansätze – a pre-defined selection of which are available within the toolkit.

As an example, the quantum circuit for the sentence “we are explaining how lambeq works” is:

This output can then, via a quantum compiler like Cambridge Quantum’s tket that is part of Cambridge Quantum’s open-source quantum computing SDK be guided towards a quantum simulator or one of the increasingly many available quantum computers. In the case of a tensor network for a classical experiment the output can be passed to a ML library such as PyTorch or Jax.

You can find the open-source Python code for lambeqon this online repository. You can read about our own implementations here, which could inspire you to do even wilder stuff.

As some of you who have heard our Chief Scientist Bob Coecke speak, lambeq is the first step in our ambitious QNLP program, that in turn is part of an even more ambitious and broad focus on AI that we refer to as our Compositional Intelligence (CI) program. Cambridge Quantum’s Compositional Intelligence project aims to provide AI with intelligible reasoning mechanisms going well beyond traditional GOFAI ones. Our main source of inspiration comes from reasoning structures developed within categorical quantum mechanics (CQM), such as the now widely known ZX-calculus:

These novel compositional reasoning mechanisms have made CQM so effective by giving up the Birkhoff-von Neumann style propositional structures and replacing them with ones able to deal with the non-Boolean data that we also see in modern machine learning. In the context of CQM, results include both logical completeness theorems that establish this reasoning to be on par with matrix calculations, as well as state-of-the-art techniques for quantum technology. These entirely novel reasoning mechanisms moreover point us towards quantum-native quantum hardware implementations, at the cutting-edge of the ongoing quantum tech revolution. So keep watching this space!



Quantum Natural Language Processing
Professor Bob Coecke
Professor Stephen Clark
How to Make Qubits Speak
Grammar-Aware Question- Answering on Quantum Computers
QNLP in Practice: Running Compositional Models of Meaning on a Quantum Computer
lambeq: An Efficient High-Level Python Library for Quantum NLP
A CCG-Based Version of the DisCoCat Framework
DisCoPy: Monoidal Categories in Python
Tket: A Retargetable Compiler for NISQ Devices
lambeq GitHub
I.e.: Good Old-Fashioned Artificial Intelligence
Picturing Quantum Processes
Kindergarten Quantum Mechanics Graduates
Quantum NLP




Cambridge Quantum’s scientists regularly post on Medium, a hub for social journalism and a hybrid of publications, blogs and publishers.

Follow us there for more of our news and updates.


Read on Medium