https://github.com/cqcl/qnlp_lorenz_etal_2021_resources

Code and resources for the Lorenz et al. (2021) QNLP paper

https://github.com/cqcl/qnlp_lorenz_etal_2021_resources

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: acm.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.4%) to scientific vocabulary
Last synced: 7 months ago · JSON representation

Repository

Code and resources for the Lorenz et al. (2021) QNLP paper

Basic Info
  • Host: GitHub
  • Owner: CQCL
  • License: gpl-3.0
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage:
  • Size: 77.1 KB
Statistics
  • Stars: 27
  • Watchers: 8
  • Forks: 13
  • Open Issues: 0
  • Releases: 0
Created about 5 years ago · Last pushed over 2 years ago
Metadata Files
Readme License

README.md

Code and resources for Lorenz et al. "QNLP in Practice" paper

This repository holds the code and the datasets for the paper:

  • Lorenz, Pearson, Meichanetzidis, Kartsaklis, Coecke (2023). QNLP in Practice: Running Compositional Models of Meaning on a Quantum Computer, Journal of Artificial Intelligence Research, Vol. 76 [pdf]

The paper presents results on the first NLP experiments conducted on Noisy Intermediate-Scale Quantum (NISQ) computers for datasets of size >= 100 sentences. Exploiting the formal similarity of the compositional model of meaning by Coecke et al. (2010) with quantum theory, we create representations for sentences that have a natural mapping to quantum circuits. We use these representations to implement and successfully train two NLP models that solve simple sentence classification tasks on quantum hardware. We describe in detail the main principles, the process and challenges of these experiments, in a way accessible to NLP researchers, thus paving the way for practical Quantum Natural Language Processing.

Note\ Although the code in this repository is functional and may still serve as a useful resource, as of May 2023 we would strongly encourage users to install the open source QNLP package lambeq, which offers more up-to-date functionality and features and greatly simplifies experiments similar to the ones described in the paper. In fact, in lambeq's training tutorials you can find implementations of the same MC and RP experiments performed in the paper that are much more intuitive and accessible compared to the notebooks of this repository. You can install lambeq by typing pip install lambeq.

Code requirements

For running the code, you will need Python 3.7 or later. Further, the following packages must also be installed:

  • discopy (v0.3.5)
  • pytket (v0.10.1)
  • qiskit (v0.25.4)
  • pytket-qiskit

Instructions

The two notebooks mc_task.ipynb and rp_task.ipynb, in the folder code show, in an exemplary way, the implementation of the pipeline for the two binary classification tasks, MC and RP, respectively. See Sec. 5 of the paper for the general pipeline, Sec. 6 for a description of the tasks and Sec. 7 for an explanation of this implementation in the notebooks, specifically Sec. 7.4 for the implementation of the quantum runs in these two notebooks. The analogous implementations of the classcial simulations for the MC and RP task as described in Sec. 7.3 of the paper can be found in the two notebooks mc_task_simulation.ipynb and rp_task_simulation.ipynb, respectively.

The folder datasets contains the raw data (train, dev and test subsets, respectively) as txt files, which are the input read by the notebooks.

In all 4 mentioned notebooks any settings one may want to alter as part of the implementation, such as the choice of 'ansatz', are all done in the first cell as explained therein. For the two notebooks mc_task.ipynb and rp_task.ipynb concerning the quantum runs the first cell in addition allows to choose the hardware on which to run the computation. Note that by default backend = AerBackend() envokes a simulator provided through pytket, which does not require any IBMQ account. Provided access to an IBMQ account, the user may use the corresponding commented-out lines in the first cell to set the backend to a device-specific one instead. This may be through IBMQEmulatorBackend(<backend_name>, <credentials>), which provides a simulator that has a device-specific noise model, or through IBMQBackend(<backend_name>, <credentials>), in order to compute on actual IBM quantum hardware of one's choice.

Finally, running the notebook mc_task_simulation.ipynb or rp_task_simulation.ipynb requires making discopy compatible with jax by setting IMPORT_JAX = True in discopy's config.py.

Remarks

  • It is worth emphasising that the fluctuations in the RP task are considerable and that a user is recommended to do several runs to get an impression for the variances.

Links

For further help see:

  • for discopy: https://discopy.readthedocs.io/en/main/index.html
  • for pytket: https://cqcl.github.io/pytket/build/html/index.html
  • for qiskit: https://qiskit.org/documentation/
  • for lambeq: https://cqcl.github.io/lambeq/index.html

Owner

  • Name: Cambridge Quantum
  • Login: CQCL
  • Kind: organization
  • Location: Cambridge, UK

Quantum Software and Technologies

GitHub Events

Total
  • Watch event: 2
  • Fork event: 2
Last Year
  • Watch event: 2
  • Fork event: 2

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 18
  • Total Committers: 3
  • Avg Commits per committer: 6.0
  • Development Distribution Score (DDS): 0.556
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dimitri Kartsaklis d****t@g****m 8
Dimitri Kartsaklis d****s@c****m 6
RobinWLorenz r****z@c****m 4
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 3
  • Total pull requests: 1
  • Average time to close issues: 25 days
  • Average time to close pull requests: about 3 hours
  • Total issue authors: 3
  • Total pull request authors: 1
  • Average comments per issue: 2.67
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • nlpirate (1)
  • dtchang (1)
  • WeileiZeng (1)
Pull Request Authors
  • RobinWLorenz (1)
Top Labels
Issue Labels
Pull Request Labels