Deductive Systems, Rule Schemas, and Span Components¶
The abstract framework for weighted deductive parsing, organized into three layers:
Deductive Systems¶
Five abstract primitives for weighted deductive parsing (Shieber, Schabes & Pereira 1995; Goodman 1999). The parsers in this package are instances of this framework.
Axiom: Creates and populates the initial chart from input.Deduction: A weighted inference step (chart → chart).Goal: Extracts the result from a completed chart.Schedule: Evaluation strategy (CKY bottom-up, Earley, agenda-based).DeductiveSystem: Ties axiom, deductions, goal, schedule, and semiring into a singlenn.Module.
For the full surface, see api/stochastic/deduction. The primitives themselves are documented at api/stochastic/deduction/primitives.
Rule Schemas¶
Composable functors CategorySystem → RuleSystem. Schemas are the abstract building blocks of grammar formalisms: each schema defines a structural rule pattern, and concrete rule instances are generated by instantiating the pattern over a finite category inventory.
Schemas compose via | (union) and can carry default weights via .weighted(w). Grammar formalisms are specific compositions:
CCG = EVALUATION | HARMONIC_COMPOSITION | CROSSED_COMPOSITIONLAMBEK = EVALUATION | ADJUNCTION_UNITS | TENSOR_INTRODUCTION | TENSOR_PROJECTIONNL = EVALUATIONLP = EVALUATION | COMMUTATIVE_EVALUATION | ADJUNCTION_UNITS
The ~20 atomic schemas (e.g. ForwardApplication, BackwardApplication) compose into 13 bundled schemas (e.g. EVALUATION, HARMONIC_COMPOSITION), which compose into grammar presets (CCG, LAMBEK, NL, LP).
schema
¶
Rule schemas: composable functors from CategorySystem to RuleSystem.
A RuleSchema is a functor that maps a CategorySystem to a
RuleSystem. Schemas are the abstract building blocks of grammar
formalisms: each schema defines a structural rule pattern, and
concrete rule instances are generated by instantiating the pattern
over a finite category inventory.
The two atomic schema types are:
BinaryRuleSchema: defined by a match predicate on category pairs:match(left, right) -> result | None.UnaryRuleSchema: defined by a match predicate on single categories:match(cat, system) -> list[result].
Schemas compose via | (union) and can carry default weights
via .weighted(w). Grammar formalisms are specific compositions::
CCG = EVALUATION | HARMONIC_COMPOSITION | CROSSED_COMPOSITION
LAMBEK = EVALUATION | ADJUNCTION_UNITS | TENSOR_INTRODUCTION | TENSOR_PROJECTION
The 13 bundled schemas (EVALUATION, HARMONIC_COMPOSITION, etc.) are themselves composed from ~20 atomic schemas (ForwardApplication, BackwardApplication, etc.), giving fine-grained control::
# only forward application, no backward
MY_GRAMMAR = ForwardApplication() | ForwardComposition()
RuleSchema
¶
Bases: ABC
A functor CategorySystem -> RuleSystem.
Schemas are the abstract specification of structural rules.
They compose via | (union) and + (alias for |).
weighted
¶
weighted(weight: float) -> RuleSchema
Attach a default weight to all rules from this schema.
| PARAMETER | DESCRIPTION |
|---|---|
weight
|
The weight every binary and unary rule receives.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleSchema
|
A |
Source code in src/quivers/stochastic/schema.py
UnionSchema
¶
UnionSchema(left: RuleSchema, right: RuleSchema)
Bases: RuleSchema
Union of two schemas (composes their rule systems via +).
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The first schema.
TYPE:
|
right
|
The second schema.
TYPE:
|
Source code in src/quivers/stochastic/schema.py
WeightedSchema
¶
WeightedSchema(inner: RuleSchema, weight: float)
Bases: RuleSchema
Schema wrapper that attaches a default weight to all rules.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The schema whose rules are weighted.
TYPE:
|
weight
|
The weight every rule of
TYPE:
|
Source code in src/quivers/stochastic/schema.py
BinaryRuleSchema
¶
Bases: RuleSchema
Schema for binary rules, defined by a match predicate.
Subclasses implement match(left, right) -> result | None.
The schema iterates over all category pairs and collects matches.
match
abstractmethod
¶
Test whether (left, right) triggers this rule.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Left antecedent.
TYPE:
|
right
|
Right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
Result category if the pair matches, else None. |
Source code in src/quivers/stochastic/schema.py
UnaryRuleSchema
¶
Bases: RuleSchema
Schema for unary rules, defined by a match predicate.
Subclasses implement match(cat, system) -> list[result].
The schema iterates over all categories and collects matches.
match
abstractmethod
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Find all valid results for a given input category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
Input category.
TYPE:
|
system
|
The full category inventory (needed for some schemas that must check existence of intermediate categories).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Category]
|
Valid result categories. |
Source code in src/quivers/stochastic/schema.py
ForwardApplication
¶
Bases: BinaryRuleSchema
C/B ⊗ B → C (right evaluation / forward application).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
BackwardApplication
¶
Bases: BinaryRuleSchema
A ⊗ A\C → C (left evaluation / backward application).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
ForwardComposition
¶
Bases: BinaryRuleSchema
C/B ⊗ B/A → C/A (right harmonic composition).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
BackwardComposition
¶
Bases: BinaryRuleSchema
A\B ⊗ B\C → A\C (left harmonic composition).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
ForwardCrossedComposition
¶
Bases: BinaryRuleSchema
C/B ⊗ B\A → C\A (right-left crossed composition).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
BackwardCrossedComposition
¶
Bases: BinaryRuleSchema
A/B ⊗ B\C → A/C (left-right crossed composition).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
CommutativeForwardApplication
¶
Bases: BinaryRuleSchema
B ⊗ C/B → C (commutative right evaluation).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
CommutativeBackwardApplication
¶
Bases: BinaryRuleSchema
A\C ⊗ A → C (commutative left evaluation).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
TensorIntroduction
¶
Bases: BinaryRuleSchema
A ⊗ B → A⊗B (product formation).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
LeftUnitElimination
¶
Bases: BinaryRuleSchema
I ⊗ A → A (left unitor).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
RightUnitElimination
¶
Bases: BinaryRuleSchema
A ⊗ I → A (right unitor).
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
ModalApplication
¶
Bases: BinaryRuleSchema
◇(C/B) ⊗ ◇B → ◇C (modal function application).
| PARAMETER | DESCRIPTION |
|---|---|
modality
|
The modality symbol (e.g. "◇", "□").
TYPE:
|
Source code in src/quivers/stochastic/schema.py
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
RightLifting
¶
Bases: UnaryRuleSchema
A → C/(A\C) (right adjunction unit / type raising).
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
LeftLifting
¶
Bases: UnaryRuleSchema
A → (C/A)\C (left adjunction unit / type raising).
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
LeftProjection
¶
Bases: UnaryRuleSchema
A⊗B → A (left tensor projection).
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
RightProjection
¶
Bases: UnaryRuleSchema
A⊗B → B (right tensor projection).
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
UnitCoercion
¶
Bases: UnaryRuleSchema
A → I (unit elimination / weakening).
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
ModalInjection
¶
Bases: UnaryRuleSchema
A → ◇A (modal introduction).
| PARAMETER | DESCRIPTION |
|---|---|
modality
|
The modality symbol (e.g. "◇", "□").
TYPE:
|
Source code in src/quivers/stochastic/schema.py
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
ModalProjection
¶
Bases: UnaryRuleSchema
◇A → A (modal elimination).
| PARAMETER | DESCRIPTION |
|---|---|
modality
|
The modality symbol (e.g. "◇", "□").
TYPE:
|
Source code in src/quivers/stochastic/schema.py
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
GeneralizedComposition
¶
Bases: RuleSchema
Generalized composition through nested slashes (B^n).
C/B ⊗ (B|₁Z₁)|₂Z₂...|ₙZₙ → (C|₁Z₁)|₂Z₂...|ₙZₙ
This is a special schema because the match recurses into nested slash structure. At depth 1 it is ordinary harmonic composition; this schema only generates rules for depth >= 2.
| PARAMETER | DESCRIPTION |
|---|---|
max_depth
|
Maximum nesting depth to traverse.
TYPE:
|
Source code in src/quivers/stochastic/schema.py
PatternBinarySchema
¶
PatternBinarySchema(left_pattern, right_pattern, conclusion_pattern, variables: frozenset[str], name: str = '')
Bases: BinaryRuleSchema
Binary rule schema from a DSL rule declaration.
Matches category pairs against two premise patterns and instantiates the conclusion pattern with bound variables.
| PARAMETER | DESCRIPTION |
|---|---|
left_pattern
|
Category pattern for the left antecedent.
TYPE:
|
right_pattern
|
Category pattern for the right antecedent.
TYPE:
|
conclusion_pattern
|
Category pattern for the consequent.
TYPE:
|
variables
|
Universally quantified pattern variables.
TYPE:
|
name
|
The rule's name (for description).
TYPE:
|
Source code in src/quivers/stochastic/schema.py
match
¶
Return the conclusion this rule derives from a pair, if any.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
The left antecedent.
TYPE:
|
right
|
The right antecedent.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Category or None
|
The conclusion category, or |
Source code in src/quivers/stochastic/schema.py
PatternUnarySchema
¶
Bases: UnaryRuleSchema
Unary rule schema from a DSL rule declaration.
Matches a single category against a premise pattern and instantiates the conclusion pattern with bound variables.
| PARAMETER | DESCRIPTION |
|---|---|
premise_pattern
|
Category pattern for the antecedent.
TYPE:
|
conclusion_pattern
|
Category pattern for the consequent.
TYPE:
|
variables
|
Universally quantified pattern variables.
TYPE:
|
name
|
The rule's name (for description).
TYPE:
|
Source code in src/quivers/stochastic/schema.py
match
¶
match(cat: Category, system: CategorySystem) -> list[Category]
Return the conclusions this rule derives from a category.
| PARAMETER | DESCRIPTION |
|---|---|
cat
|
The antecedent category.
TYPE:
|
system
|
The category inventory; conclusions outside it are dropped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of Category
|
The conclusion categories, empty when the rule does not apply. |
Source code in src/quivers/stochastic/schema.py
generalized_composition
¶
generalized_composition(max_depth: int = 2) -> RuleSchema
Create a generalized composition schema.
| PARAMETER | DESCRIPTION |
|---|---|
max_depth
|
Maximum nesting depth.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuleSchema
|
The generalized composition schema. |
Source code in src/quivers/stochastic/schema.py
Bundled schemas¶
Stochastic morphisms: Markov kernels over finite sets.
This module provides the probabilistic layer for quivers, implementing the category FinStoch of finite sets and stochastic maps (Markov kernels). This is the Kleisli category of the Giry monad restricted to finite sets, where:
- Objects are finite sets (same as the base category).
- Morphisms A -> B are stochastic matrices: tensors of shape (|A|, |B|) whose rows sum to 1.
- Composition is standard matrix multiplication.
- Identity is the Kronecker delta.
The package also re-exports MarkovAlgebra and its singleton
MARKOV from quivers.core.algebras, the algebra these morphisms
compose under.
Submodules
morphisms : StochasticMorphism, CategoricalMorphism families : Discretized distribution families transforms : condition, mix, factor, normalize queries : prob, marginal_prob, expectation giry : GiryMonad, FinStoch categories : Category types including atoms, slashes, products, unit, modals semiring : Chart semiring abstractions (LogProb, Viterbi, Boolean, Counting) schema : Composable rule schemas (functors CategorySystem -> RuleSystem) rules : Rule systems and the CCG / Lambek presets span : Span-based CKY components (LexicalAxiom, BinarySpanDeduction, etc.) parsers, ccg, lambek : Chart parsers inside : The inside algorithm over a rule system agenda : The agenda-driven weighted-deduction engine effect_lifts : Effect-lifted rule schemas for deduction systems deduction : Abstract weighted deductive system framework and its operations stdlib : Pre-registered deduction systems
EVALUATION
module-attribute
¶
EVALUATION = ForwardApplication() | BackwardApplication()
Forward and backward application, the evaluation maps of a biclosed category.
HARMONIC_COMPOSITION
module-attribute
¶
HARMONIC_COMPOSITION = ForwardComposition() | BackwardComposition()
Forward and backward harmonic composition.
CROSSED_COMPOSITION
module-attribute
¶
CROSSED_COMPOSITION = ForwardCrossedComposition() | BackwardCrossedComposition()
Forward and backward crossed composition.
COMMUTATIVE_EVALUATION
module-attribute
¶
COMMUTATIVE_EVALUATION = CommutativeForwardApplication() | CommutativeBackwardApplication()
Application with the argument on either side, for commutative (LP) grammars.
ADJUNCTION_UNITS
module-attribute
¶
ADJUNCTION_UNITS = RightLifting() | LeftLifting()
Right and left type raising, the units of the slash adjunctions.
TENSOR_INTRODUCTION
module-attribute
¶
TENSOR_INTRODUCTION = TensorIntroduction()
Product formation, A, B -> A*B.
TENSOR_PROJECTION
module-attribute
¶
TENSOR_PROJECTION = LeftProjection() | RightProjection()
Left and right projections out of a product category.
UNIT_INTRODUCTION
module-attribute
¶
UNIT_INTRODUCTION = LeftUnitElimination() | RightUnitElimination()
The left and right unitors, I*A -> A and A*I -> A.
UNIT_ELIMINATION
module-attribute
¶
UNIT_ELIMINATION = UnitCoercion()
Coercion of any category to the monoidal unit, A -> I.
MODAL_INTRODUCTION
module-attribute
¶
MODAL_INTRODUCTION = ModalInjection()
Modal injection, A -> <>A.
MODAL_ELIMINATION
module-attribute
¶
MODAL_ELIMINATION = ModalProjection()
Modal projection, <>A -> A.
MODAL_APPLICATION
module-attribute
¶
MODAL_APPLICATION = ModalApplication()
Function application under a modality.
Grammar presets and the schema registry¶
Stochastic morphisms: Markov kernels over finite sets.
This module provides the probabilistic layer for quivers, implementing the category FinStoch of finite sets and stochastic maps (Markov kernels). This is the Kleisli category of the Giry monad restricted to finite sets, where:
- Objects are finite sets (same as the base category).
- Morphisms A -> B are stochastic matrices: tensors of shape (|A|, |B|) whose rows sum to 1.
- Composition is standard matrix multiplication.
- Identity is the Kronecker delta.
The package also re-exports MarkovAlgebra and its singleton
MARKOV from quivers.core.algebras, the algebra these morphisms
compose under.
Submodules
morphisms : StochasticMorphism, CategoricalMorphism families : Discretized distribution families transforms : condition, mix, factor, normalize queries : prob, marginal_prob, expectation giry : GiryMonad, FinStoch categories : Category types including atoms, slashes, products, unit, modals semiring : Chart semiring abstractions (LogProb, Viterbi, Boolean, Counting) schema : Composable rule schemas (functors CategorySystem -> RuleSystem) rules : Rule systems and the CCG / Lambek presets span : Span-based CKY components (LexicalAxiom, BinarySpanDeduction, etc.) parsers, ccg, lambek : Chart parsers inside : The inside algorithm over a rule system agenda : The agenda-driven weighted-deduction engine effect_lifts : Effect-lifted rule schemas for deduction systems deduction : Abstract weighted deductive system framework and its operations stdlib : Pre-registered deduction systems
CCG
module-attribute
¶
The combinatory categorial grammar preset: application plus harmonic and crossed composition.
LAMBEK
module-attribute
¶
LAMBEK = EVALUATION | ADJUNCTION_UNITS | TENSOR_INTRODUCTION | TENSOR_PROJECTION
The Lambek calculus preset: application, type raising, and the product rules.
LP
module-attribute
¶
The Lambek calculus with permutation preset: application in both orders and type raising.
SCHEMA_REGISTRY
module-attribute
¶
SCHEMA_REGISTRY: dict[str, RuleSchema] = {'evaluation': EVALUATION, 'harmonic_composition': HARMONIC_COMPOSITION, 'crossed_composition': CROSSED_COMPOSITION, 'generalized_composition': GeneralizedComposition(), 'adjunction_units': ADJUNCTION_UNITS, 'tensor_introduction': TENSOR_INTRODUCTION, 'tensor_projection': TENSOR_PROJECTION, 'commutative_evaluation': COMMUTATIVE_EVALUATION, 'unit_introduction': UNIT_INTRODUCTION, 'unit_elimination': UNIT_ELIMINATION, 'modal_introduction': MODAL_INTRODUCTION, 'modal_elimination': MODAL_ELIMINATION, 'modal_application': MODAL_APPLICATION}
The bundled schemas by the name a DSL rules clause uses for each.
Span-Based CKY Components¶
Span-based instantiation of the abstract deductive framework for CKY chart parsing:
LexicalAxiom: Populates length-1 spans from a learnable lexicon.BinarySpanDeduction: Applies binary structural rules with learnable weights.UnarySpanDeduction: Applies unary rules to convergence.SpanGoal: Extracts the start-symbol score for the full span.CKYSchedule: Bottom-up evaluation by span length.
span
¶
Span-based CKY components for the deductive system framework.
This module instantiates the abstract deduction primitives
(Axiom, Deduction, Goal, Schedule) for span-indexed
chart parsing (CKY). Items are indexed by (i, j, A) where
[i, j) is a string span and A is a category index.
The chart tensor has shape (batch, n_categories, seq_len, seq_len+1)
(categories-first for efficient indexing of the start symbol).
Components
LexicalAxiom Populates length-1 spans from a learnable lexicon. BinarySpanDeduction Applies binary rules: chart[i,k,L] ⊗ chart[k,j,R] → chart[i,j,A]. UnarySpanDeduction Applies unary rules iteratively to convergence. SpanGoal Extracts chart[start_cat, 0, seq_len]. CKYSchedule Bottom-up evaluation by span length.
LexicalAxiom
¶
Bases: Axiom
Populate length-1 spans from a learnable lexicon.
Creates the chart tensor and fills
chart[b, :, i, i+1] = log_softmax(lexicon[tokens[b, i]]).
| PARAMETER | DESCRIPTION |
|---|---|
n_terminals
|
Vocabulary size.
TYPE:
|
n_categories
|
Number of category types.
TYPE:
|
Source code in src/quivers/stochastic/span.py
log_lexicon
property
¶
log_lexicon: Tensor
Log-probability lexicon, shape (n_terminals, n_categories).
forward
¶
forward(tokens: Tensor, semiring: ChartSemiring) -> SpanChart
Fill the length-1 spans from the lexicon.
| PARAMETER | DESCRIPTION |
|---|---|
tokens
|
Integer terminal indices of shape
TYPE:
|
semiring
|
The scoring semiring, recorded on the chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SpanChart
|
A chart whose cells |
Source code in src/quivers/stochastic/span.py
SpanChart
¶
SpanChart(cells: dict[tuple[int, int], Tensor], batch: int, seq_len: int, n_categories: int, device: device, semiring: ChartSemiring)
A span-indexed chart held as functional (non-in-place) cells.
This wraps a dict of (i, j) -> (batch, C) tensors. The
schedule fills cells bottom-up, and to_tensor() assembles
them into a dense (batch, C, seq_len, seq_len+1) tensor.
| PARAMETER | DESCRIPTION |
|---|---|
cells
|
The filled cells, keyed by span
TYPE:
|
batch
|
The batch size.
TYPE:
|
seq_len
|
The sentence length.
TYPE:
|
n_categories
|
The number of categories.
TYPE:
|
device
|
The device the dense chart is built on.
TYPE:
|
semiring
|
The scoring semiring; its
TYPE:
|
Source code in src/quivers/stochastic/span.py
to_tensor
¶
to_tensor() -> Tensor
Assemble cells into a dense chart tensor.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
Source code in src/quivers/stochastic/span.py
BinarySpanDeduction
¶
BinarySpanDeduction(rule_system: RuleSystem, learnable: bool = True)
Bases: Deduction
Binary rule application over span items.
For each split point k in [i+1, j), combines
chart[i, k, lefts] and chart[k, j, rights]
to produce chart[i, j, results].
| PARAMETER | DESCRIPTION |
|---|---|
rule_system
|
The structural rules.
TYPE:
|
learnable
|
Whether rule weights are learnable.
TYPE:
|
Source code in src/quivers/stochastic/span.py
forward
¶
forward(chart: Tensor | None, semiring: ChartSemiring, **context) -> Tensor
Apply binary rules for one span cell (i, j).
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
Unused; the cells are read from
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
**context
|
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The |
Source code in src/quivers/stochastic/span.py
UnarySpanDeduction
¶
UnarySpanDeduction(rule_system: RuleSystem, learnable: bool = True, iterations: int = 3)
Bases: Deduction
Unary rule application, iterated to approximate fixpoint.
| PARAMETER | DESCRIPTION |
|---|---|
rule_system
|
The structural rules.
TYPE:
|
learnable
|
Whether rule weights are learnable.
TYPE:
|
iterations
|
Number of fixpoint iterations.
TYPE:
|
Source code in src/quivers/stochastic/span.py
forward
¶
forward(chart: Tensor, semiring: ChartSemiring, **context) -> Tensor
Apply unary rules to a cell tensor.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
A
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
**context
|
Unused.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The updated |
Source code in src/quivers/stochastic/span.py
SpanGoal
¶
Bases: Goal
Extract chart[start_cat, 0, seq_len].
| PARAMETER | DESCRIPTION |
|---|---|
start_idx
|
Index of the start category.
TYPE:
|
Source code in src/quivers/stochastic/span.py
forward
¶
Read the start category's score over the whole sentence.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
The dense chart of shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The |
Source code in src/quivers/stochastic/span.py
CKYSchedule
¶
Bases: Schedule
Bottom-up CKY: process spans in increasing length order.
For each span length 2..n: 1. Apply binary deductions for each cell (i, i+span_len). 2. Apply unary deductions to the resulting cell.
run
¶
run(chart: SpanChart, deductions: ModuleList, semiring: ChartSemiring) -> Tensor
Fill the chart bottom-up and return it as a dense tensor.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
The chart
TYPE:
|
deductions
|
The
TYPE:
|
semiring
|
The scoring semiring.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The dense chart of shape |
Source code in src/quivers/stochastic/span.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |