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.2.1.tar.gz (31.7 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.2.1-cp312-cp312-manylinux_2_34_x86_64.whl (653.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ngram_trie-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b4262389f1f1e03c6e50ede151398b32445583e50aee6d36b86862f9e8a10d70
MD5 ee115393eb9e014fd13bb758953511d2
BLAKE2b-256 78cf83a7a7f4acb9a388a76f649dea3b29869157fccf055325f098b8805a6c9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ngram_trie-1.2.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 59654211fbc3fd3362cfee62e88c82d91fc2ec3e7adb123804d3b0cec1d2909c
MD5 5a1c9d52f8b5116be411a471ac71feb7
BLAKE2b-256 97fc9aa9eb96b7cfa7197a957cce0d1d7aed29758688442fcda89917e4ede385

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