Advanced Usage: Semirings
All of the distributional code is implemented through a series of
semiring objects. These are passed through dynamic programming
backends to compute the distributions.
Standard Semirings
-
class torch_struct.LogSemiring[source]
Implements the log-space semiring (logsumexp, +, -inf, 0).
Gradients give marginals.
-
class torch_struct.StdSemiring[source]
Implements the counting semiring (+, *, 0, 1).
-
class torch_struct.MaxSemiring[source]
Implements the max semiring (max, +, -inf, 0).
Gradients give argmax.
Higher-Order Semirings
-
class torch_struct.EntropySemiring[source]
Implements an entropy expectation semiring.
Computes both the log-values and the running distributional entropy.
Based on descriptions in:
Parameter estimation for probabilistic finite-state transducers [Eis02]
First-and second-order expectation semirings with applications to minimum-risk training on translation forests [LE09]
Sample Selection for Statistical Grammar Induction []
Sampling Semirings
-
class torch_struct.SampledSemiring[source]
Implements a sampling semiring (logsumexp, +, -inf, 0).
“Gradients” give sample.
This is an exact forward-filtering, backward-sampling approach.
-
class torch_struct.MultiSampledSemiring[source]
Implements a multi-sampling semiring (logsumexp, +, -inf, 0).
“Gradients” give up to 16 samples with replacement.
Dynamic Programming
-
class torch_struct.LinearChain(semiring=<class 'torch_struct.semirings.semirings.LogSemiring'>)[source]
Represents structured linear-chain CRFs, generalizing HMMs smoothing, tagging models,
and anything with chain-like dynamics.
-
class torch_struct.SemiMarkov(semiring=<class 'torch_struct.semirings.semirings.LogSemiring'>)[source]
edge : b x N x K x C x C semimarkov potentials
-
class torch_struct.DepTree(semiring=<class 'torch_struct.semirings.semirings.LogSemiring'>)[source]
A projective dependency CRF.
- Parameters
arc_scores_in – Arc scores of shape (B, N, N) or (B, N, N, L) with root scores on
diagonal. –
Note: For single-root case, do not set cache=True for now.
-
class torch_struct.CKY(semiring=<class 'torch_struct.semirings.semirings.LogSemiring'>)[source]