Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ lambeq can be installed with the command:
pip install lambeq
```

The default installation of lambeq includes Bobcat parser, a state-of-the-art statistical parser (see [related paper](https://arxiv.org/abs/2109.10044)) fully integrated with the toolkit.
The default installation of lambeq includes Bobcat parser, a statistical parser (see [related paper](https://arxiv.org/abs/2109.10044)) fully integrated with the toolkit.

To install lambeq with optional dependencies for extra features, run:

Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Contributions to ``lambeq`` are welcome, especially with regard to adding:
- Tensor and circuit :term:`ansätze <ansatz (plural: ansätze)>` (extensions of the :py:class:`.TensorAnsatz` and :py:class:`.CircuitAnsatz` classes)
- New :term:`trainers <trainer>`, :term:`models <model>`, and optimizers for the :py:mod:`.training` package.

All accepted contributions will be included in the next official release and contributors will be properly attributed in the corresponding release notes.
Accepted contributions are typically included in a subsequent official release, subject to release planning, and contributors are properly attributed in the corresponding release notes.

Opening a pull request
----------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/_templates/lambeq_landing_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h2 class="heading-style-h2">Tutorials</h2>
<div class="spacer-small"></div>
<a href="training.html" class="product_link-wrap w-inline-block">
<p class="product_link-text">Training models</p>
<p class="product_description is-list">Learn how to use the provided state-of-the-art trainers to train your models for language processing tasks.</p>
<p class="product_description is-list">Learn how to use the provided trainers to train your models for language processing tasks.</p>
</a>
</div>
</div>
Expand All @@ -178,7 +178,7 @@ <h2 class="heading-style-h2">Advanced</h2>
<div class="spacer-small"></div>
<a href="tutorials/extend-lambeq.html" class="product_link-wrap w-inline-block">
<p class="product_link-text">Extending lambeq</p>
<p class="product_description is-list">Learn how to take advantage of the extensible nature of lambeq and how to add new features tailored to you work.</p>
<p class="product_description is-list">Learn how to take advantage of the extensible nature of lambeq and how to add new features tailored to your work.</p>
</a>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/cite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ The :py:term:`DisCoCirc` extension introduced in Release :ref:`rel-0.5.0` is des
.. code-block:: bash

@article{krawchuk2025,
title={Efficient {G}eneration of {P}arameterised {Q}uantum {C}ircuits from {L}arge {T}exts,
title={Efficient {G}eneration of {P}arameterised {Q}uantum {C}ircuits from {L}arge {T}exts},
author={Colin Krawchuk
and Nikhil Khatri
and Neil John Ortega
and Dimitri Kartsaklis
and Dimitri Kartsaklis},
year={2025},
journal={arXiv preprint arXiv:2505.13208},
}
4 changes: 2 additions & 2 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Glossary
A :term:`compositional model` of meaning which represents a sentence as a multiset of words; that is, it does not take into account the order of words or any other syntactic relationship between them.

Bobcat
A state-of-the-art statistical :term:`CCG <Combinatory Categorial Grammar (CCG)>` parser based on :cite:p:`clark_2021`. Bobcat is ``lambeq``'s default parser.
A statistical :term:`CCG <Combinatory Categorial Grammar (CCG)>` parser based on :cite:p:`clark_2021`. Bobcat is ``lambeq``'s default parser.

cap
A special morphism in a :term:`rigid category`, which, together with a :term:`cup` morphism, obey certain conditions called :term:`snake equations`. In diagrammatic form, a cap is depicted as a wire with downward concavity (:math:`\cap`). In the context of :term:`DisCoCat`, a cap is mostly used to "bridge" disconnected wires in order to alter the normal "flow" of information from one word to another, for example in cases such as *type-raising*.
Expand Down Expand Up @@ -51,7 +51,7 @@ Glossary
The DIStributional COmpositional CATegorical model of natural language meaning developed by Bob Coecke, Mehrnoosh Sadrzadeh and Steve Clark :cite:p:`coecke_2010`. The model applies a :term:`functor` :math:`F: \textrm{Grammar} \to \textrm{Meaning}` whose left-hand side is a free pregroup over a partially ordered set of basic grammar types, and the right-hand side is the category whose morphisms describe a sequence of operations that can be evaluated on a classical or quantum computer.

DisCoCirc
DIStributional COmpositional CIRCuit. A framework of compositional models (still at the experimental stage) with the ability to encode entire paragraphs or even documents into a quantum circuit, based on :cite:p:`coecke_2021a`. The generated quantum circuits capture the core semantic information of the provided text, and can be trained as a regular machine learning model.
DIStributional COmpositional CIRCuit. A framework of compositional models (still at the experimental stage) with the ability to encode entire paragraphs or even documents into a quantum circuit, based on :cite:p:`coecke_2021a`. The generated quantum circuits are intended to represent selected semantic relationships in the provided text, and can be trained as a regular machine learning model.

DisCoPy
DIStributional COmpositional PYthon. A Python library for working with :term:`monoidal categories <monoidal category>` :cite:p:`de_felice_2021`. It includes abstractions for creating all standard :term:`quantum gates <quantum gate>` and building :term:`quantum circuits <quantum circuit>`. Additionally, it is equipped with many language-related features, such as support for :term:`pregroup grammars <pregroup grammar>` and :term:`functors <functor>` for implementing :term:`compositional models <compositional model>`.
Expand Down
14 changes: 7 additions & 7 deletions docs/guide/lambeq-basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
lambeq and compositionality
===========================

``lambeq`` is a state-of-the-art software toolkit designed for implementing compositional :term:`natural language processing (NLP)` models using :term:`string diagrams <string diagram>` on a quantum computer. Language is `compositional` in nature :cite:p:`tull_2024`; this is expressed through the `principle of compositionality` which states that the meaning of a complex expression is determined by the meanings of its parts and the rules used to combine them. This concept, rooted in formal linguistics and philosophy, aligns with how humans intuitively process language.
``lambeq`` is a software toolkit designed for implementing compositional :term:`natural language processing (NLP)` models using :term:`string diagrams <string diagram>` on a quantum computer. Language is approximately `compositional` in nature :cite:p:`tull_2024`; this is expressed through the `principle of compositionality` which states that the meaning of a complex expression is determined by the meanings of its parts and the rules used to combine them. This concept, rooted in formal linguistics and philosophy, aligns with how humans intuitively process language.

``lambeq`` is particularly well-suited for tasks involving natural language processing on quantum computers, although it is also applicable to classical computational environments. It provides tools for:

- Parsing sentences into syntactic structures (:term:`CCG <Combinatory Categorial Grammar (CCG)>`, :term:`pregroup grammars <pregroup grammar>`, dependency graphs).
- Converting syntactic structures into compositional semantic representations (:term:`string diagrams <string diagram>`, :term:`tensor networks <tensor network>`).
- Encoding and parameterising syntacic structures into :term:`quantum circuits <quantum circuit>`.
- Encoding and parameterising syntactic structures into :term:`quantum circuits <quantum circuit>`.
- Training and evaluating NLP models using either classical or quantum :ref:`machine learning <sec-ml-lambeq>`.
- Integration with state-of-the-art ML and QML tools, such as :term:`PyTorch` and :term:`PennyLane`.
- Integration with widely used ML and QML tools, such as :term:`PyTorch` and :term:`PennyLane`.

``lambeq`` is rooted in the formalism of :term:`monoidal categories <monoidal category>` :cite:p:`coecke_2010`, a branch of `category theory` that provides a robust algebraic framework for structuring and reasoning about compositionality. This foundation enables us to model linguistic structures and semantic compositions in a mathematically rigorous yet computationally efficient manner. For this reason, ``lambeq``'s models have some unique advantages over other traditional statistical approaches.
``lambeq`` is rooted in the formalism of :term:`monoidal categories <monoidal category>` :cite:p:`coecke_2010`, a branch of `category theory` that provides a robust algebraic framework for structuring and reasoning about compositionality. This foundation enables us to model linguistic structures and semantic compositions in a mathematically rigorous yet computationally efficient manner. For this reason, ``lambeq``'s models have some characteristics that differ from traditional statistical approaches.

1. **Scalability to Quantum Computing:** ``lambeq``'s mathematical foundations make it uniquely compatible with quantum algorithms, where transformations in quantum states can represent semantic composition. In fact, ``lambeq`` is able to uniquely encode entire linguistic structures directly into :term:`quantum circuits <quantum circuit>`, enabling training without reliance on neural networks or other "classical" components.
2. **Interpretability:** The mathematical operations used to combine meanings are transparent and tied directly to linguistic principles. This enables trust in decision making and allows for accountability, while it also makes debugging and error analysis easier and more effective.
1. **Scalability to Quantum Computing:** ``lambeq``'s mathematical foundations are compatible with quantum algorithms, where transformations in quantum states can represent semantic composition. ``lambeq`` can be used to encode linguistic structures directly into :term:`quantum circuits <quantum circuit>`, enabling out-of-the-box training of parameterised quantum circuits.
2. **Interpretability:** The mathematical operations used to combine meanings are transparent and tied directly to linguistic principles. This can support clearer reasoning about model behaviour and accountability, while also helping with debugging and error analysis.
3. **Generalisation and flexibility:** The framework is highly abstract, allowing generalization across different types of related data representations (:term:`syntax trees <syntax tree>`, string diagrams, tensor networks, quantum circuits).
4. **Theoretical depth for linguistic analysis:** The compositional nature of ``lambeq``'s models allows for deeper theoretical insights into linguistic phenomena, bridging gaps between computational linguistics and formal linguistics.
4. **Connections to formal linguistics:** The compositional nature of ``lambeq``'s models is intended to align computational representations with concepts from formal linguistics, which may help relate model structure to linguistic theory.
5. **Interdisciplinary applications:** Since compositionality is a fundamental aspect in many other fields (e.g. systems theory, programming languages, bioinformatics, or even human cognition), ``lambeq`` can facilitate interdisciplinary research.

Related research
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/ml_basic.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Basic concepts
==============

In ``lambeq``, all low-level processing that takes place in machine learning training is hidden in the :py:mod:`.training` package, which provides convenient high-level abstractions for all important supervised learning scenarios with the toolkit, classical and quantum. More specifically, the :py:mod:`.training` package contains the following high-level/abstract classes and several concrete implementations for them:
In ``lambeq``, all low-level processing that takes place in machine learning training is hidden in the :py:mod:`.training` package, which provides convenient high-level abstractions for many supervised learning scenarios with the toolkit, classical and quantum. More specifically, the :py:mod:`.training` package contains the following high-level/abstract classes and several concrete implementations for them:

- :py:class:`.Dataset`: A class that provides functionality for easy management and manipulation of datasets, including batching, shuffling, and preparation based on the selected backend (:term:`tket`, NumPy, :term:`PyTorch`).
- :py:class:`.Model`: The abstract interface for ``lambeq`` :term:`models <model>`. A :term:`model` bundles the basic attributes and methods used for training, given a specific backend. It stores the :term:`symbols <symbol>` and the corresponding weights, and implements the forward pass of the model. Concrete implementations are the :py:class:`.PytorchModel`, :py:class:`.TketModel`, :py:class:`.NumpyModel`, and :py:class:`.PennyLaneModel` classes (for more details see Section :ref:`sec-models` below).
- :py:class:`.LossFunction`: Implementations of this class compute the distance between the predicted values of the :term:`model` and the true values in the dataset. This is used to adjust the model weights so that the average loss accross all data instances can be minimised. ``lambeq`` supports a number of loss functions, such as :py:class:`.CrossEntropyLoss`, :py:class:`.BinaryCrossEntropyLoss`, and :py:class:`.MSELoss`.
- :py:class:`.LossFunction`: Implementations of this class compute the distance between the predicted values of the :term:`model` and the true values in the dataset. This is used to adjust the model weights so that the average loss across all data instances can be minimised. ``lambeq`` supports a number of loss functions, such as :py:class:`.CrossEntropyLoss`, :py:class:`.BinaryCrossEntropyLoss`, and :py:class:`.MSELoss`.
- :py:class:`.Optimizer`: a ``lambeq`` optimizer calculates the gradient of a given :term:`loss function` with respect to the parameters of a model. It contains a :py:meth:`~lambeq.Optimizer.step` method to modify the model parameters according to the optimizer's update rule. Currently, for the quantum case we support the SPSA algorithm by :cite:p:`spall_1998`, implemented in the :py:class:`.SPSAOptimizer` class, the Rotosolve algorithm :cite:p:`ostaszewski_2021` with class :py:class:`.RotosolveOptimizer`, and the Nelder-Mead algorithm :cite:p:`nelder_1965,gao_2012` with class :py:class:`~lambeq.NelderMeadOptimizer`, while for the classical and hybrid cases we support :term:`PyTorch` optimizers.
- :py:class:`.Trainer`: The main interface for supervised learning in ``lambeq``. A :term:`trainer` implements the (quantum) machine learning routine given a specific backend, using a :term:`loss function` and an optimizer. Concrete implementations are the :py:class:`.PytorchTrainer` and :py:class:`.QuantumTrainer` classes.

Expand Down
20 changes: 10 additions & 10 deletions docs/guide/ml_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Circuits containing only :py:class:`Bra <lambeq.backend.quantum.Bra>`, :py:class

In the common use case of using a :py:data:`~lambeq.text2diagram.stairs_reader` or a :py:class:`.TreeReader` with discarding for binary classification, the process involves measuring (:py:class:`Measure <lambeq.backend.quantum.Measure>`) one of the "open" qubits, and discarding (:py:class:`Discard <lambeq.backend.quantum.Discard>`) the rest of them.

One advantage that the :py:class:`.NumpyModel` has over the :py:class:`.TketModel` is that it supports the just-in-time (jit) compilation provided by the library ``jax``. This speeds up the model's diagram evaluation by an order of magnitude. The :py:class:`.NumpyModel` with ``jit`` mode enabled can be instantiated with the following command:
One advantage that the :py:class:`.NumpyModel` has over the :py:class:`.TketModel` is that it supports the just-in-time (jit) compilation provided by the library ``jax``. This may be able to speed up the model's diagram evaluation. The :py:class:`.NumpyModel` with ``jit`` mode enabled can be instantiated with the following command:

.. code-block:: python

Expand Down Expand Up @@ -52,7 +52,7 @@ To use the :py:class:`.NumpyModel` with ``jit`` mode, you need to install ``lamb
PennyLaneModel
--------------

:py:class:`.PennyLaneModel` uses :term:`PennyLane` and :term:`PyTorch` to allow classical-quantum machine learning experiments. With ``probabilities=False``, :py:class:`.PennyLaneModel` performs a state vector simulation, while with ``probabilties=True`` it performs a probability simulation. The state vector and probability simulations correspond to unitary and density matrix simulations.
:py:class:`.PennyLaneModel` uses :term:`PennyLane` and :term:`PyTorch` to allow classical-quantum machine learning experiments. With ``probabilities=False``, :py:class:`.PennyLaneModel` performs a state vector simulation, while with ``probabilities=True`` it performs a probability simulation. The state vector and probability simulations correspond to unitary and density matrix simulations.

To run the model on real quantum hardware, ``probabilities=True`` must be used, so that the ``lambeq`` circuits are optimized using the parameter-shift rule to calculate the gradients.

Expand Down Expand Up @@ -85,14 +85,14 @@ By using different backend configurations, :py:class:`.PennyLaneModel` can be us
:header: "Use case", "Configurations"
:widths: 25, 50

"Exact non :term:`shot-based <shots>` simulation with state outputs", "``{'backend': 'default.qubit', 'probabilities'=False}``"
"Exact non shot-based simulation with probability outputs", "``{'backend': 'default.qubit', 'probabilities'=True}``"
"Noiseless shot-based simulation", "``{'backend': 'default.qubit', 'shots'=1000, 'probabilities'=True}``"
"Noisy shot-based simulation on local hardware", "``{'backend': 'qiskit.aer', noise_model=my_noise_model, 'shots'=1000, 'probabilities'=True}``, where ``my_noise_model`` is an AER :py:class:`NoiseModel`."
"Noisy shot-based simulation on cloud-based emulators", "| ``{'backend': 'qiskit.ibmq', 'device'='ibmq_qasm_simulator', 'shots'=1000, 'probabilities'=True}``
| ``{'backend': 'honeywell.hqs', device=('H1-1E' or 'H1-2E'), 'shots'=1000, 'probabilities'=True}``"
"Evaluation of quantum circuits on a quantum computer", "| ``{'backend': 'qiskit.ibmq', 'device'='ibmq_hardware_device', 'shots'=1000, 'probabilities'=True}``, where ``ibmq_hardware_device`` is one that you have access to via your IBMQ account.
| ``{'backend': 'honeywell.hqs', device=('H1' or 'H1-1' or 'H1-2'), 'shots'=1000, 'probabilities'=True}``"
"Exact non :term:`shot-based <shots>` simulation with state outputs", "``{'backend': 'default.qubit', 'probabilities': False}``"
"Exact non shot-based simulation with probability outputs", "``{'backend': 'default.qubit', 'probabilities': True}``"
"Noiseless shot-based simulation", "``{'backend': 'default.qubit', 'shots': 1000, 'probabilities': True}``"
"Noisy shot-based simulation on local hardware", "``{'backend': 'qiskit.aer', 'noise_model': my_noise_model, 'shots': 1000, 'probabilities': True}``, where ``my_noise_model`` is an AER :py:class:`NoiseModel`."
"Noisy shot-based simulation on cloud-based emulators", "| ``{'backend': 'qiskit.ibmq', 'device': 'ibmq_qasm_simulator', 'shots': 1000, 'probabilities': True}``
| ``{'backend': 'honeywell.hqs', 'device': 'H1-1E', 'shots': 1000, 'probabilities': True}`` (or with ``'device': 'H1-2E'``)"
"Evaluation of quantum circuits on a quantum computer", "| ``{'backend': 'qiskit.ibmq', 'device': 'ibmq_hardware_device', 'shots': 1000, 'probabilities': True}``, where ``ibmq_hardware_device`` is one that you have access to via your IBMQ account.
| ``{'backend': 'honeywell.hqs', 'device': 'H1', 'shots': 1000, 'probabilities': True}`` (or with ``'device': 'H1-1'`` or ``'device': 'H1-2'``)"

All of these backends are compatible with hybrid quantum-classical models. Note that using quantum hardware or cloud-based emulators are much slower than local simulations.

Expand Down
Loading
Loading