Using our framework, once the meanings of words and phrases are encoded as quantum states and processes, we are able to prepare quantum states that encode the meaning of grammatical sentences on quantum hardware. Posing a question to the quantum computer, constructed by the vocabulary and grammar the quantum computer has learned, it returns the answer.

Naturally, we next turned our attention toward the design and execution of an experiment that is non-trivial, not least of all since our design is predicated on the program being scalable. This means that the dimension of the meaning space grows significantly with the number of qubits available whilst the size of the circuits dictated by the grammar does not grow too large with the size of the sentence.

Interestingly, we note further that QNLP on NISQ devices is a novel playground for quantifying the scalability of quantum machine learning algorithms and experimenting with various quantum meaning spaces. Being able to accommodate large chunks of text is crucial if we aspire to graduate from sentence to text, and we know that we have made the first step towards this vision.

The technical details. Our experimental workflow is as follows. Let G be the grammar category, which is the mathematical model where grammar diagrams are generated. As stated above, a grammar diagram (or network) encodes the information flow of word-meanings in a grammatical sentence.

In more detail, a diagram is none other than a grammatical and syntactic parsing of a sentence according to a specified grammar model. This diagram is then instantiated as a quantum circuit that lives in the category QCirc(θ). Next, the meaning of the words is encoded in quantum states in such quantum circuits. Specifically, any state can be prepared from a classical reference state, and so by “state” we refer to the circuit (or process) that prepares it. Then the composition of words in a sentence corresponds to composition of circuits representing words. This results in a circuit that prepares a state encoding the meaning of a sentence.

Importantly, the circuits are parameterised by a set θ. In other words, these ‘grammatical quantum circuits’ are a family spanned by θ. By allowing circuits to depend on parameters we create the semantic space in which the meanings of the words, and consequently whole sentences, are encoded.

Once a quantum circuit is created from a sentence, it needs to be evaluated in order to compute the meaning. We may choose to perform this evaluation on a classical computer, where we employ state-of-the-art methods for performing the costly task of multiplying exponentially big matrices. On the other hand, we may choose to implement the circuit on a quantum computer.

The parameterised quantum circuit of a subject-verb-object sentence like ‘Alice hates Bob’ looks like this:

Each of the parts of speech (subject, verb, object) is a quantum circuit defined as a function of some parameters. For example, there are sets of parameter values θ₀, θ₁, θ₂ such that:

subj(θ₀)=Alice verb(θ₁)=hates obj(θ₂)=Bob

The values are determined empirically by a text corpus and are then used to answer questions about the corpus.

In order to ensure that our experiment can be executed effectively on near-term NISQ devices, but at the same time be complex enough to be interesting, we chose a vocabulary of a few words, for example

{Alice, Bob, loves, hates, rich, cute}

and generated not some, but all grammatical sentences from their combinations. From these sentences, we created their corresponding parameterised circuits. Moreover, we interpret the grammar diagrams such that the semantic space is one-dimensional, i.e. just a number indicating the truth-value of the sentence. This number is obtained by evaluating the quantum circuit C(θ) corresponding to the sentence:

0<|C(θ)|²<1

A value close to 1 represents “true” and a value close to 0 indicates “false”.

The labeled toy corpus would look like:

K={(Alice loves Bob, false), (Bob is cute, true), (Alice is rich, true), …}

Now that we have our corpus of sentences and ‘truth universe’, we split the corpus K=R∪E in a training set R and a test set E. Sentences in the training set R are used to do supervised quantum machine learning in order to learn the parameters that result in the correct measurement of the truth-labels. In this way, the parameters for the circuits that prepare the meaning states for nouns {Alice, Bob}, verbs {is, loves, hates}, and adjectives {rich, cute}, are learned.

The scheme for learning the parameters for words in sentences in the training set is as follows. The circuit of a sentence in the training set is evaluated for the current set of parameters on the quantum computer. By sampling measurement outcomes we estimate |C(θ)|². This number is read by a classical computer that checks how well this matches the desired truth label of the sentence. If there is a mismatch, our system updates the parameters so that the quantum computer may evaluate an updated circuit. Iterating this procedure until the parameters converge and all truth labels are reproduced for the sentences in the training set. Note that finding the optimal sequence of updates is, in general, a hard optimization problem, so it is important that our quantum semantic space is well designed and allows the learning to be as tractable as possible. This design feature is critical.