A Python library for working with weighted context-free grammars (WCFGs), weighted finite state automata (WFSAs) and weighted finite state transducers (WFSTs). The library provides efficient implementations for grammar operations, parsing algorithms, and language model functionality.
Quick Start
This library can be installed via pip:
pip install genlm-grammar
Key Features
Grammar Operations
- Support for weighted context-free grammars with various semirings (Boolean, Float, Real, MaxPlus, MaxTimes, etc.)
- Grammar transformations:
- Local normalization
- Removal of nullary rules and unary cycles
- Grammar binarization
- Length truncation
- Renaming/renumbering of nonterminals
Parsing Algorithms
- Earley parsing (O(n³|G|) complexity)
- Standard implementation
- Rescaled version for numerical stability
- CKY parsing
- Incremental CKY with chart caching
- Support for prefix computations
Language Model Interface
BoolCFGLM: Boolean-weighted CFG language modelCKYLM: Probabilistic CFG language model using CKYEarleyLM: Language model using Earley parsing
Finite State Automata
- Weighted FSA implementation
- Operations:
- Epsilon removal
- Minimization (Brzozowski's algorithm)
- Determinization
- Composition
- Reversal
- Kleene star/plus
Additional Features
- Semiring abstractions (Boolean, Float, Log, Entropy, etc.)
- Efficient chart and agenda-based algorithms
- Grammar-FST composition
- Visualization support via Graphviz
Development
See DEVELOPING.md for information on how to install the package in development mode.
Metadata
Release files for genlm-grammar 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| genlm_grammar-0.2.0.tar.gz | 1.9 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| genlm_grammar-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / genlm_grammar-0.2.0.tar.gz
| Download URL | genlm_grammar-0.2.0.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b589fd7416c1068fc4c8eca5ccc5b63ea280bfd107ab8f5a1cb8af2846e94e14
|
|
BLAKE2b-256 checksum How to use checksums |
2a80cf0fa1578966848198d87c243b2ce2ad4898baf0fbd5a1960ba846e09afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / genlm_grammar-0.2.0-py3-none-any.whl
| Download URL | genlm_grammar-0.2.0-py3-none-any.whl |
|---|---|
| Size | 53.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
393524396b454f7ef70d1f854111c62782689cd43abff2056b92463069925062
|
|
BLAKE2b-256 checksum How to use checksums |
02fbcf71d9e738396f16fb9e565cf72574c12e6e1ad5973a6fa5eb934a7dd00c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|