Skip to main content

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

  1. Include it in the Cargo.toml:

    [dependencies]
    ngram-trie = { git = "https://github.com/behappiness/ngram-trie" }
    

Installation Python

  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ngram_trie-1.1.9.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ngram_trie-1.1.9-cp312-cp312-manylinux_2_34_x86_64.whl (664.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file ngram_trie-1.1.9.tar.gz.

File metadata

  • Download URL: ngram_trie-1.1.9.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.8

File hashes

Hashes for ngram_trie-1.1.9.tar.gz
Algorithm Hash digest
SHA256 bfa1f0f27cc13dfd7675de1d78a7e971095190be3fddae63769f94091daaf5cb
MD5 2a8c3db35ba9e7ff6824bd07e7cea302
BLAKE2b-256 072922beada694183b7f976259d8e5f5c3e04d3e49a5836f332bbbf11cd94045

See more details on using hashes here.

File details

Details for the file ngram_trie-1.1.9-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ngram_trie-1.1.9-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ffe66aee75e9506df1e91334c6750d16224a8125384ec553da65207f84641e22
MD5 57d4e1d83b0a0da4bff42bad46b996af
BLAKE2b-256 2c2d2569f02ddada2de32507392f7792f24d2ab8cd536cb62fdbcc0e4c54e56b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page