Forward Sampling¶
sample_corpus draws yields of a fixed length \(L\) from the chart's distribution conditioned on
length,
\(p(s \mid \text{length} = L, \mathbf{w}) = Z(s; \mathbf{w}) / \sum_{s' \text{ of length } L} Z(s'; \mathbf{w})\),
where \(Z\) is the chart weight of a yield. It
enumerates every sequence of length \(L\) over the deduction's vocabulary \(V\), computes each
\(\log Z\) exactly by the chart, normalizes with a softmax, and draws from the resulting categorical
distribution. The procedure is exact, and its cost is the \(|V|^L\) enumeration.
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:
|
| RETURNS | DESCRIPTION |
|---|---|
list of list of str
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the deduction's vocabulary cannot be determined, or if no
yield of length |