lambeq is a toolkit for quantum natural language processing (QNLP).
- Documentation: https://cqcl.github.io/lambeq/
- User support: lambeq-support@cambridgequantum.com
- Contributions: Please read our guide.
- If you want to subscribe to lambeq's mailing list, send an email to lambeq-users@cambridgequantum.com with the word "subscribe" as subject.
Note: Please do not try to read the documentation directly from the preview provided in the repository, since some of the pages will not be rendered properly.
- Python 3.7+
The base lambeq can be installed with the command:
pip install lambeq
This does not include optional dependencies such as depccg and PyTorch,
which have to be installed separately. In particular, depccg is required
for lambeq.ccg2discocat.DepCCGParser
.
Warning: depccg is available only on MacOS and Linux. If you are using Windows, please install the base lambeq. This means that the DepCCGParser
class will not be available on Windows, but you can still use all other compositional models from the reader
module. Support for parsing on Windows will be added in a future version.
To install lambeq with depccg, run instead:
pip install cython numpy
pip install 'lambeq[depccg]'
depccg_en download
See below for further options.
This runs an interactive installer to help pick the installation destination and configuration.
- Run:
sh <(curl 'https://cqcl.github.io/lambeq/install.sh')
This requires Git to be installed.
-
Download this repository:
git clone https://github.com/CQCL/lambeq
-
Enter the repository:
cd lambeq
-
Make sure
pip
is up-to-date:pip install --upgrade pip wheel
-
(Optional) If installing the optional depccg dependency, the following packages must be installed before depccg:
pip install cython numpy
Further information can be found on the depccg homepage.
-
Install lambeq from the local repository using pip:
pip install --use-feature=in-tree-build .
To include depccg, run instead:
pip install --use-feature=in-tree-build .[depccg]
To include all optional dependencies, run instead:
pip install --use-feature=in-tree-build .[all]
-
If using a pretrained depccg parser, download a pretrained model:
depccg_en download
The docs/examples directory contains notebooks demonstrating usage of the various tools in lambeq.
Example - parsing a sentence into a diagram (see docs/examples/ccg2discocat.ipynb):
from lambeq.ccg2discocat import DepCCGParser
depccg_parser = DepCCGParser()
diagram = depccg_parser.sentence2diagram('This is a test sentence')
diagram.draw()
Note: all pre-trained depccg models apart from the basic one are broken, and depccg has not yet been updated to fix this. Therefore, it is recommended to just use the basic parser, as shown here.
Run all tests with the command:
pytest
Note: if you have installed in a virtual environment, remember to install pytest in the same environment using pip.
To build the documentation, first install the required dependencies:
pip install -r docs/requirements.txt
then run the commands:
cd docs
make clean
make html
the docs will be under docs/_build
.
To rebuild the rst files themselves, run:
sphinx-apidoc --force -o docs lambeq
Distributed under the Apache 2.0 license. See LICENSE
for more details.
If you wish to attribute our work, please cite the accompanying paper:
@article{kartsaklis2021lambeq,
title={lambeq: {A}n {E}fficient {H}igh-{L}evel {P}ython {L}ibrary for {Q}uantum {NLP}},
author={Dimitri Kartsaklis and Ian Fan and Richie Yeung and Anna Pearson and Robin Lorenz and Alexis Toumi and Giovanni de Felice and Konstantinos Meichanetzidis and Stephen Clark and Bob Coecke},
year={2021},
journal={arXiv preprint arXiv:2110.04236},
}