DisCoCat (Distributional Compositional Categorical) is motivated by a profound structural coincidence: the mathematical framework underlying quantum mechanics (monoidal categories with tensor products) is the same framework that describes formal grammar and compositional semantics.
Pregroup grammar assigns types to words using a type system with left ($l$) and right ($r$) adjoints:
Basic types:
n = noun phrase
s = sentence
np = noun phrase (same as n in some formulations)
p = prepositional phrase
Word type assignments:
"Alice" : n (noun)
"likes" : n^r · s · n^l (transitive verb: takes noun on right and left)
"Bob" : n (noun)
"big" : n · n^l (adjective: left-cancels with following noun)
Sentence parsing: "Alice likes Bob"
n (n^r · s · n^l) n
─────────────────────────
(cancellation)
n^r · n ⊗ s ⊗ n^l · n
1 ⊗ s ⊗ 1
= s ✓ (valid sentence type)
The type reductions correspond to cups in string diagrams:
DisCoCat translates the grammatical string diagram into a tensor network computation:
"Alice likes Bob" → String Diagram:
Alice likes Bob
│ │ │ │
│ ╔═════╧═╧═════╗ │
│ ║ cup n^r⊗n ║ │
│ ╚════╤════════╝ │
│ │ ╔═════╧═╧═════╗
│ │ ║ cup n⊗n^l ║
│ │ ╚═════╤═══════╝
│ │ │
[A ∈ ℝⁿ] [L ∈ ℝⁿ⊗ᵈ⊗ⁿ] [B ∈ ℝⁿ]
│
∀i,j: contraction over noun spaces
│
Result: s = L(A, B) ∈ ℝᵈ (sentence meaning vector)
Where:
A = meaning vector of "Alice" ∈ ℝⁿ
L = meaning tensor of "likes" ∈ ℝⁿ ⊗ ℝᵈ ⊗ ℝⁿ
B = meaning vector of "Bob" ∈ ℝⁿ
s = L(A, B) (tensor contraction over noun wires)
= Σᵢⱼ Aᵢ Lᵢₖⱼ Bⱼ (Einstein summation) ∈ ℝᵈ
DisCoCat is formalised as a strong monoidal functor $F$ from the grammar category $\textbf{FGram}$ to the semantics category $\textbf{FVect}$ (or $\textbf{Circ}$):
The functor maps:
The key innovation: replace $\textbf{FVect}$ with $\textbf{Circ}$ (the category of quantum circuits):
lambeq (Kartsaklis et al. 2021) is the software library implementing the full DisCoCat-to-circuit pipeline:
LAMBEQ PIPELINE ═══════════════════════════════════════════════════════════════════ Step 1: PARSING Input: "Alice likes Bob" Tool: bobcat parser (CCG/pregroup) Output: Pregroup diagram (string diagram) Step 2: REWRITE RULES (optional) Input: String diagram Simplifications: curry, remove cups, merge wires Purpose: Reduce circuit size before translation Output: Simplified diagram Step 3: PARAMETERISATION Input: Simplified diagram Assign: n qubits per noun-type wire Each word → ansatz circuit (IQP, StronglyEntangling, etc.) Output: Parameterised quantum circuit Step 4: CIRCUIT COMPILATION Input: Abstract circuit Target: Qiskit, PennyLane, pytket Apply: Hardware topology mapping, gate decomposition Output: Hardware-specific circuit Step 5: TRAINING Input: Labelled sentences Forward: Execute circuits → measure expectation ⟨Z_s⟩ Loss: Cross-entropy L = -y log⟨Z_s⟩ Gradient: Parameter-shift rule Update: Adam / SPSAOptimiser Output: Trained circuit parameters θ* Step 6: INFERENCE Input: New sentence Output: ⟨Z_s⟩ → class probabilities → classification
Each word in a sentence is mapped to a quantum circuit block. Noun connections (cups) become qubit connections (Bell measurements or post-selection).
"Alice likes Bob" → Quantum Circuit: Alice (noun, 1 qubit): |0⟩ ──[Ry(θ_A₁)]──[Rz(θ_A₂)]──●── ... → noun wire (1 qubit out) "likes" (transitive verb, 3 qubits: n^r ⊗ s ⊗ n^l): |0⟩ ──[Ry(θ_L₁)]────────────────────── [CNOT]── → n^r wire |0⟩ ──[Ry(θ_L₂)]──[Ry(θ_L₃)]──[CNOT]────────── → s wire (output) |0⟩ ──[Ry(θ_L₄)]────────────────────── [CNOT]── → n^l wire Bob (noun, 1 qubit): |0⟩ ──[Ry(θ_B₁)]──[Rz(θ_B₂)]──●── ... → noun wire (1 qubit out) Cup connections (grammatical contractions): Alice wire ──┬── Bob wire noun wire (from likes n^r) ──(Bell measure) noun wire (from likes n^l) ──(Bell measure) Sentence wire: s qubit from "likes" → measure Z → ⟨Z_s⟩ ∈ [-1, 1] Classification: ⟨Z_s⟩ → sigmoid → P(class=1)
Instantaneous Quantum Polynomial: $H^{\otimes n}$ then diagonal gates. Classically hard to simulate. Small circuit depth.
$L$ layers of parameterised single-qubit rotations followed by CNOTs with periodic boundary. High expressibility — prone to barren plateaus for large $n$.
For binary sentence classification (e.g. sentiment analysis):
DisCoCat/lambeq represents the structure-preserving approach to quantum NLP, while Quixer/HyQuT represent the black-box deep learning approach. Key differences:
| Approach | DisCoCat / lambeq | Quixer / HyQuT |
|---|---|---|
| Grammar | Explicit (functorial) | Implicit (attention patterns) |
| Compositionality | Exact (categorical) | Emergent |
| Scalability | Limited (circuit per sentence) | Scales with sequence length |
| Interpretability | High (grammatical structure visible) | Low (black-box) |