Deduction Primitives¶
Abstract building blocks for chart-based weighted deduction:
Axiom, Deduction, Goal, Schedule, and the
DeductiveSystem protocol. The concrete agenda-based
DeductionSystem (in quivers.stochastic.agenda) is the
canonical realization used by the DSL compiler; the symbols here
exist for custom-deduction subclasses and the inside-algorithm
framework in quivers.stochastic.inside.
primitives
¶
Abstract weighted deductive system framework.
A weighted deductive system (Shieber, Schabes & Pereira 1995; Goodman 1999; Nederhof 2003) provides a categorical abstraction for parsing algorithms. The core structure is a V-enriched hypergraph where:
- Items are nodes, indexed into a chart tensor.
- Deduction rules are weighted hyperedges.
- The semiring V determines the scoring algebra.
- A schedule determines the evaluation order.
Different parsing algorithms (CKY, Earley, agenda-based) are different schedules over the same deductive system. Different semirings (log-prob, Viterbi, boolean, counting) yield different computations from the same rules.
The five abstract primitives are:
Axiom— creates and populates the initial chart.Deduction— a single weighted inference step (chart -> chart).Goal— extracts the result from a completed chart.Schedule— evaluation strategy (ordering of deductions).DeductiveSystem— ties axiom, deductions, goal, schedule, and semiring into a single nn.Module.
Axiom
¶
Bases: Module
Initial items in a weighted deductive system.
An axiom creates the chart tensor and populates it with initial weights derived from the input. For span-based chart parsing, this is the lexical step.
forward
abstractmethod
¶
forward(input: Tensor, semiring: ChartSemiring) -> Tensor
Create and populate the initial chart.
| PARAMETER | DESCRIPTION |
|---|---|
input
|
Raw input (e.g. token indices).
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The chart tensor with initial items filled in. |
Source code in src/quivers/stochastic/deduction/primitives.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Deduction
¶
Bases: Module
A weighted inference step in a deductive system.
A deduction reads from the chart, applies inference rules, and writes updated weights. This is a morphism in the V-enriched category of chart states.
forward
abstractmethod
¶
forward(chart: Tensor, semiring: ChartSemiring, **context) -> Tensor
Apply this deduction step.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
Current chart state.
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
**context
|
Schedule-provided context (e.g.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Updated chart. |
Source code in src/quivers/stochastic/deduction/primitives.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
Goal
¶
Bases: Module
Extract the result from a completed chart.
A goal identifies which chart items constitute the answer and extracts their weights.
forward
abstractmethod
¶
forward(chart: Tensor) -> Tensor
Extract goal items from the chart.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
Completed chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Goal item weights. |
Source code in src/quivers/stochastic/deduction/primitives.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
Schedule
¶
Bases: ABC
Evaluation strategy for a deductive system.
Different schedules compute the same fixpoint in different orders. CKY processes spans bottom-up; an agenda schedule uses a priority queue. The schedule is independent of the deduction rules.
run
abstractmethod
¶
run(chart: Tensor, deductions: ModuleList, semiring: ChartSemiring) -> Tensor
Execute deductions on chart to fixpoint.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
Chart with axioms filled in.
TYPE:
|
deductions
|
The deduction steps.
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Completed chart. |
Source code in src/quivers/stochastic/deduction/primitives.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
DeductiveSystem
¶
DeductiveSystem(axiom: Axiom, deductions: list[Deduction], goal: Goal, schedule: Schedule, semiring: ChartSemiring | None = None)
Bases: Module
A weighted deductive system evaluated to fixpoint.
This is the abstract core of all parsing algorithms::
input -> axiom -> schedule(deductions) -> goal -> output
The system is an nn.Module whose learnable parameters come from the axiom (e.g. lexical weights) and deductions (e.g. rule weights).
| PARAMETER | DESCRIPTION |
|---|---|
axiom
|
Initial item population.
TYPE:
|
deductions
|
Inference rules.
TYPE:
|
goal
|
Result extraction.
TYPE:
|
schedule
|
Evaluation strategy.
TYPE:
|
semiring
|
Scoring algebra (default: LOG_PROB).
TYPE:
|
Source code in src/quivers/stochastic/deduction/primitives.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
forward
¶
forward(input: Tensor) -> Tensor
Run the deductive system on input.
| PARAMETER | DESCRIPTION |
|---|---|
input
|
Raw input (e.g. token indices).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Goal item weights. |
Source code in src/quivers/stochastic/deduction/primitives.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |