# harvardnlp/pytorch-struct

Fast, general, and tested differentiable structured prediction in PyTorch

Repository: https://github.com/harvardnlp/pytorch-struct
Canonical: https://ross.abutalabs.com/products/pytorch-struct
Homepage: http://harvardnlp.github.io/pytorch-struct
Language: Jupyter Notebook
License: MIT
License Family: permissive
Last push: 2022-04-20T08:21:20+00:00

## Health v2 (maintenance only)
Score: 23/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 0, release rhythm 8, longevity 100
- inputs: {"age_days": 2564, "days_push": 1596, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1133, forks 93 (observed 2026-08-28T04:03:42.964536+00:00)

## What it is
Torch-Struct is a PyTorch library of tested, GPU-accelerated implementations of core structured prediction algorithms such as CRFs, HMMs, HSMMs, dependency tree CRFs, and PCFGs. It is designed to be used as efficient batched layers inside other deep learning models, providing marginals, argmax, sampling, entropy, and partition computations.

## Use cases
- compute differentiable marginals for linear-chain CRFs in PyTorch
- train hidden Markov models with deep learning models
- implement dependency parsing with a tree CRF layer
- run inside-outside algorithms for probabilistic context-free grammars
- sample and compute argmax from structured distributions on GPU
- add semi-Markov CRF segmentation layers to a neural network

## When to choose
- you need differentiable structured prediction layers (CRF, HMM, PCFG) in PyTorch
- you want batched, GPU-accelerated dynamic programming for sequence or tree structures
- you need marginals, argmax, sampling, or log-partition for structured models

## When to avoid
- you need structured prediction in TensorFlow, JAX, or non-PyTorch frameworks
- you need actively maintained software with recent releases
- your models only involve unstructured classification or regression

## Facets
- artifact type: library
- maturity: maintenance
- function: machine-learning, deep-learning, nlp
- domain: machine-learning, deep-learning
- platform: python
- tags: structured-prediction, pytorch, crf, hmm, pcfg, dependency-parsing, differentiable-computation, natural-language-processing, gpu

## Member repositories
- harvardnlp/pytorch-struct (main) score 23

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:03:42.964536+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T06:37:26.622013+00:00, confidence not recorded.
  - readme: https://github.com/harvardnlp/pytorch-struct (fetched 2026-08-28T04:03:42.964536+00:00, sha 34491538217a)
  - homepage: http://harvardnlp.github.io/pytorch-struct (fetched 2026-08-29T12:42:17.750631+00:00, sha fc663b4a31e4)
- Data as of 2026-08-30T08:39:29.467469+00:00.
