Skip to main content

prsr

Latent-variable PCFG training and left-corner parsing in PyTorch, on CPU or GPU. prsr reimplements three ModelBlocks and Berkeley parser components:

  • prsr.gcg: the gcg15 reannotation of Penn Treebank trees.
  • prsr.train: split-merge training of latent-variable PCFGs, as the Berkeley parser 1.7 trains them.
  • prsr.Parser: compilation of a PCFG into left-corner factors and a batched beam parser that follows ModelBlocks' synproc and reports per-word surprisal.

prsr ships no treebank data. Training needs your own copy of the Penn Treebank or another treebank.

import prsr

from prsr.gcg import training_lines

lines = training_lines(open("train.gcg15").read().splitlines())
trees = [prsr.training_tree(line) for line in lines]
grammar = prsr.train([t for t in trees if t is not None])
grammar.save("grammar/")

parser = prsr.Parser.from_grammar(prsr.Grammar.load("grammar/"), beam=5000)
for index, parse in parser.parse_stream([s.split() for s in sentences]):
    print(parse.surprisal, parse.preterminals, parse.tree())

Each Parse holds a sentence's words, per-word surprisal in bits, and the states of the best path. parse.failed is true when the beam emptied; then tree() returns None. device="auto", the default of train and Parser.from_grammar, uses a GPU when one is visible.

The stable API is prsr.train, Grammar, Parser, Parse, Pcfg, Tree, training_tree, the version constants, and prsr.gcg. Other modules may change in minor versions.

prsr.TRAIN_VERSION and prsr.PARSE_VERSION change whenever the same input would give a different grammar, or a different exported model, parse, or surprisal. If you cache prsr's results, include them in the cache key.

Metadata

Release files for prsr 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prsr 0.1.0
File Size Uploaded Provenance Actions
prsr-0.1.0.tar.gz 106.7 kB With provenance Details for prsr-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prsr 0.1.0
File Interpreter ABI Platform Actions
prsr-0.1.0-py3-none-any.whl Python 3 none any Details for prsr-0.1.0-py3-none-any.whl

Total release size: 205.8 kB

Release files / prsr-0.1.0.tar.gz

Download URL prsr-0.1.0.tar.gz
Size 106.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2a7da0f1868386ebc3c591c3729f4d579f84b0b3b41667dc06c3001c2bfa5aed
BLAKE2b-256 checksum
How to use checksums
9e278eefe53e1964e430fb9a75f6f6a693309255f4626b44eada250a5b3ad688
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / prsr-0.1.0-py3-none-any.whl

Download URL prsr-0.1.0-py3-none-any.whl
Size 99.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d163e5713e8228da81c6caf02757b1774a6269579871edded5b7fead15922ce7
BLAKE2b-256 checksum
How to use checksums
c372a7efdae6fde6aec448bd380f97ed46a590198f28ca06b69db3bcd3984165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for prsr 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for prsr-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page