Forward Sampling¶
sample_corpus draws length-fixed yields from the chart's
length-conditional distribution
\(p(s \mid \text{length} = L, \mathbf{w}) =
Z(s; \mathbf{w}) / \sum_{s' \text{ of length } L} Z(s'; \mathbf{w})\).
The implementation enumerates every length-\(L\) sequence over the
deduction's surface vocabulary, evaluates \(\log Z\) exactly via
the chart, softmaxes the log-weights, and draws a multinomial.
The procedure is exact (no MCMC over derivations); the \(|V|^L\)
enumeration is the cost of this implementation.
sample
¶
Sample fixed-length yields from a weighted deduction system.
sample_corpus draws length-fixed token sequences from the
length-conditional distribution induced by the chart's weights:
.. math::
p(s \mid \text{length} = L,\, \mathbf{w})
\;=\; \frac{Z(s; \mathbf{w})}
{\sum_{s' \text{ of length } L} Z(s'; \mathbf{w})}.
The sampler enumerates all :math:|V|^L sequences, evaluates each chart
partition score, normalizes those scores, and draws from the resulting
distribution. The chart marginalizes the derivation forest for each sequence.
sample_corpus
¶
sample_corpus(ded: DeductionSystem, *, length: int, n_samples: int, seed: int | None = None) -> list[list[str]]
Sample n_samples yields of length length from the
chart's length-conditional distribution under the deduction's
current parameters.
| PARAMETER | DESCRIPTION |
|---|---|
ded
|
The deduction with materialised parameters.
TYPE:
|
length
|
Length of yields to enumerate.
TYPE:
|
n_samples
|
Number of sentences to draw.
TYPE:
|
seed
|
Seed for the multinomial draws.
TYPE:
|
Source code in src/quivers/stochastic/deduction/sample.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |