A library for structured prediction (e.g., parsing, sequence labeling) with PyTorch. Provides differentiable implementations of dynamic programming algorithms like CYK, Inside-Outside, and Viterbi. Current version 0.5, last updated 2022. Low release cadence.
pip install torch-structVerified import paths — ran on the pinned version, not inferred.
Creates a linear-chain CRF from random potentials and computes the log-partition function.
Remove `genbmm` imports; use torch.bmm or einsum instead. Replace removed models with custom implementations.
Replace `Semiring` usage with `StructDistribution` and log-potential pattern.
Ensure inputs are log-space (e.g., use torch.log(probs) if you have probabilities).
Pass a `lengths` tensor of shape (batch,) to the constructor: `dist = LineCRF(log_potentials, lengths=lengths)`.
Use `StructDistribution` instead: `from torch_struct import StructDistribution`.
Check the expected input shape for the struct class. For LineCRF, use (batch, N, C). For TreeCRF, use (batch, N, N, C).
Ensure batch size > 1 or set model.eval() during inference.