Quantum Natural Language Processing II
Now you can try it yourself with lambeq
by Dimitri Kartsaklis, Ian Fan, Richie Yeung, Anna Pearson, Robin Lorenz, Alexis Toumi, Giovanni de Felice, Konstantinos Meichanetzidis, Stephen Clark, Bob Coecke
In our blog about QNLP we reported that we had performed NLP on quantum hardware (QNLP) [1]. 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 CQ have been doing for quite some time now [2, 3, 4].
Our detailed technical account of lambeq can be found in this paper [5], 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 [6]. 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 [7] 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 CQC’s tket that is part of CQ’s open-source quantum computing SDK [8] 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 [9]. You can read about our own implementations here [2, 3, 4], 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. CQ’s Compositional Intelligence project aims to provide AI with intelligible reasoning mechanisms going well beyond traditional GOFAI [10] ones. Our main source of inspiration comes from reasoning structures developed within categorical quantum mechanics (CQM) [11], such as the now widely known ZX-calculus [12]:
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!
References:
[1] https://medium.com/cambridge-quantum-computing/quantum-natural-language-processing-748d6f27b31d
[2] B. Coecke, G. de Felice, K. Meichanetzidis, and A. Toumi.
How to make qubits speak.
arXiv preprint arXiv:2107.06776, 2021.
[3] K. Meichanetzidis, A. Toumi, G. de Felice, and B. Coecke.
Grammar-aware question- answering on quantum computers. arXiv:2012.03756, 2020.
[4] R. Lorenz, A. Pearson, K. Meichanetzidis, D. Kartsalkis, and B. Coecke. QNLP in practice: Running compositional models of meaning on a quantum computer.
arXiv:2102.12846, 2021.
[5] D. Kartsaklis, I. Fan, R. Yeung, A. Pearson, R. Lorenz, A. Toumi, G. de Felice, K. Meichanetzidis, S. Clark, and B. Coecke.
lambeq: An Efficient High-Level Python Library for Quantum NLP.
arXiv: 2110.04236, 2021.
[6] R. Yeung and D. Kartsaklis.
A CCG-Based Version of the DisCoCat Framework.
In Proceedings of the 2021 Workshop on Semantic Spaces at the Intersection of NLP, Physics, and Cognitive Science (SemSpace), pages 20–31, Groningen, The Netherlands, June 2021. Association for Computational Linguistics.
https://www.aclweb.org/anthology/2021.semspace-1.3
[7] G. de Felice, A. Toumi, and B. Coecke.
DisCoPy: Monoidal Categories in Python.
In Proceedings of the 3rd Annual International Applied Category Theory Conference. EPTCS, 2020
[8] S. Sivarajah, S. Dilkes, A. Cowtan, W. Simmons, A. Edgington, and R. Duncan.
t|ket>: A retargetable compiler for NISQ devices.
arXiv:2003.10611, 2020.
[9] https://github.com/CQCL/lambeq
[10] I.e.: Good Old fashioned Artificial Intelligence.
[11] Coecke, B. and A. Kissinger. 2017.
Picturing Quantum Processes. A First Course in Quantum Theory and Diagrammatic Reasoning.
Cambridge University Press.
[12] Coecke, B., Horsman, D., Kissinger, A., & Wang, Q. (2021).
Kindergarden quantum mechanics graduates (… or how I learned to stop gluing LEGO together and love the ZX-calculus).
arXiv:2102.10984.