Showcasing Sentiment Classification and Word Prediction in The Quantum Natural Processing Area
Showcasing Sentiment Classification and Word Prediction in The Quantum Natural Processing Area
Abstract
The advent of quantum computers makes it possible to perform quantum computations in
different areas like machine learning, finance, or chemistry. This paper showcases one of the
emerging areas under quantum machine learning, quantum natural language processing. We
present two quantum natural language processing tasks, sentiment classification and missing
word prediction in a sentence. We show how these tasks can be achieved even in real quantum
computers using the two main libraries in this subfield, DisCoPy, and lambeq.
Keywords 1
quantum computing, quantum machine learning, quantum natural language processing
28th Conference on Information Society and University Studies (IVUS’2023), May 12, 2023, Kaunas, Lithuania
EMAIL: [email protected] (D. Peral-García); [email protected] (J. Cruz-Benito); [email protected]
(F. J. García-Peñalvo)
ORCID: 0000-0003-3299-206X (D. Peral-García); 0000-0003-2045-8329 (J. Cruz-Benito); 0000-0001-9987-5584
(F. J. García-Peñalvo)
©️ 2023 Copyright for this paper by its authors.
Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0).
CEUR Workshop Proceedings (CEUR-WS.org)
CEUR
ceur-ws.org
Workshop ISSN 1613-0073
Proceedings
The first one allows the user to define string diagrams and monoidal functors, and the second
one provides different tools to transform and manipulate a sentence, for example, convert it
into string diagrams.
2. Applications
Using the two libraries cited in the previous section, DisCoPy [14, 15] and Lambeq [16], we are
going to present the process to train two different models, one for sentiment classification and one of
word prediction.
2.1. Classification
The classification task in machine learning is used to differentiate between two categories or labels;
it can be used in images, e.g., classifying between cats and dogs or, as we do in this paper,
classifying sentences in positive or negative sentiment. In this section, we start explaining the
modeling process and, after that, an example of codification, transform, and training. First, the
input sentence is encoded into a string diagram using a parser, for example, DepCGG or BobCat
parser [Figure 3]. Second, lambeq allows rewriting the string diagram to reduce complexity,
simplify it, and improve performance in the future training step. Third, the diagram is
parameterized, and we convert it into a circuit using an ansatz. Some examples of the ansatzs
that lambeq provides are SpiderAnsatz [Figure 4], IQPAnsatz [Figure 5], Sim14Ansatz,
Sim15Ansatz or StronglyEntanglementAnsatz. Fourth, when the parameterisable circuit is
created, a compatible backend with the model must be defined. For example, we can use a
quantum backend like the qiskit [17] backend with the TketModel, or we can use classical
resources (compatible with Jax [18] and GPU) with the PytorchModel. Finally, the trainer has
different options to personalize and adapt to the model like a typical classical trainer: loss
functions, epochs, optimizers, hyperparameters, and evaluation functions.
Figure 3: String Diagram