A Rust-based n-gram trie library for Python
Project description
ngram-trie
ngram-trie is a Rust library designed to efficiently handle n-gram data structures using a trie-based approach. It provides functionalities for fitting, saving, loading, and querying n-gram models, with support for various smoothing techniques.
Installation Rust
-
Include it in the Cargo.toml:
[dependencies] ngram-trie = { git = "https://github.com/behappiness/ngram-trie" }
Installation Python
-
Install from pip:
pip install ngram-trie
Example Usage
from ngram_trie import PySmoothedTrie
trie = PySmoothedTrie(n_gram_max_length=7, root_capacity=None)
trie.fit(tokenized_data, n_gram_max_length=7, root_capacity=None, max_tokens=None)
trie.set_rule_set(["++++++", "+++++", "++++", "+++", "++", "+"])
trie.fit_smoothing()
trie.get_prediction_probabilities(tokenized_context)
Specify the smoothing
trie.fit_smoothing("modified_kneser_ney"/"stupid_backoff")
Unsmoothed
from ngram_trie import PySmoothedTrie
trie = PySmoothedTrie(n_gram_max_length=7, root_capacity=None)
trie.fit(tokenized_data, n_gram_max_length=7, root_capacity=None, max_tokens=None)
trie.set_rule_set(rules)
trie.get_unsmoothed_probabilities(tokenized_context)
Dev
cargo add pyo3 --features extension-module
Build wheel
maturin build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ngram_trie-1.2.0.tar.gz.
File metadata
- Download URL: ngram_trie-1.2.0.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
224faf8ab533f3326b9a69dd6972e11cf0eff8b769db9aa453320e1299ca43d0
|
|
| MD5 |
a579246131405d69862739917be241b7
|
|
| BLAKE2b-256 |
4d5ce2b07b2c3e91a24a7677f037d24fb3cf74023e068f776ff9520dc7b3bdfa
|
File details
Details for the file ngram_trie-1.2.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: ngram_trie-1.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 636.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fcb8a925bc1cf18ab002c94341f2f79665577290f8d8d6a5f1b63a2ff1b1710
|
|
| MD5 |
70ffef6491cc61121feeb8a775b0228f
|
|
| BLAKE2b-256 |
b551881e75e1f010123bdc980b529afa5e2506bfa8c7615217987c46e4673232
|