Skip to main content

kute (Python)

Python bindings for the Kannaka Universal Tokenization Engine. The Rust engine does the work; this package is a thin layer over it.

from kute import Engine, Vocabulary

engine = Engine()
vocab = engine.train(
    source="./agent_messages.jsonl",
    algorithm="bpe",
    adapter="jsonl",
    vocab_size=2048,
    vocabulary_id="example:agent:messages",
)
tokens = engine.encode('{"from": "kannaka", "intent": "request_observation"}', vocabulary=vocab)
original = engine.decode(tokens, vocabulary=vocab)
results = engine.evaluate(vocabulary=vocab, dataset="./evaluation.jsonl")
vocab.save("agent-vocabulary.kvf")
same = Vocabulary.load("agent-vocabulary.kvf")

encode returns a list of token ids. Those ids only mean something with the vocabulary that produced them, so decode takes the same vocabulary.

decode returns str for vocabularies trained through the text adapter and bytes for everything else. decode_bytes always returns bytes.

Since 0.5.0:

small = engine.train("corpus/", vocabulary_id="example:text", vocab_size=8192)
large = engine.train("corpus/", vocabulary_id="example:text", vocab_size=32768, resume_from=small)
# large is the vocabulary one run to 32768 would give (bpe, sequence-bpe)

found = kute.discover([["START", "HEAT", "DONE"], ...], min_support=5)
found["patterns"]   # recurring runs and gapped pairs, strongest first

Added in 0.9:

# Whole event records, by column. Every field comes back.
container, report = kute.events_pack(open("events.jsonl", "rb").read(),
                                     symbol_field="event", time_field="t", group_field="unit")
records = kute.events_unpack(container)          # canonical JSON Lines, source order
kute.events_inspect(container)                   # the header alone

# Numbers, exactly or within a bound that is checked on every value.
container, report = kute.signals_pack(values, max_error=0.01)
values_back = kute.signals_unpack(container)
report["header"]["max_error_observed"]

# The next version of an event vocabulary; every existing id is kept.
child = vocabulary.evolve([["PURGE"], ["FLOW", "ALARM", "PURGE"]], version="0.2.0")

kute.ZSTD says whether the package was built with Zstandard; codec="zlib" is always available. An evolved vocabulary is not better by being newer: on the data measured so far it was rejected about as often as accepted (docs/shadow.md).

embed_test_vectors=True stores short excerpts of the training data in the vocabulary for verify to check. It is off unless asked.

Build

pip install maturin
cd bindings/python
maturin develop --release        # into the active virtualenv
# or: maturin build --release    # wheel under target/wheels
pip install pytest tiktoken
pytest tests

Metadata

Release files for kute-engine 0.9.2

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

Source distribution (sdist)

Source distribution for kute-engine 0.9.2
File Size Uploaded Provenance Actions
kute_engine-0.9.2.tar.gz 185.9 kB Without provenance Details for kute_engine-0.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kute-engine 0.9.2
File Interpreter ABI Platform Actions
kute_engine-0.9.2-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for kute_engine-0.9.2-cp39-abi3-win_amd64.whl

Total release size: 2.3 MB

Release files / kute_engine-0.9.2.tar.gz

Download URL kute_engine-0.9.2.tar.gz
Size 185.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5cff995a739e41e5664ed786ee4dbddcc28288cddb701b8b5480d5b9fda3c1c6
BLAKE2b-256 checksum
How to use checksums
b6e7a4b4cd1a08e7c2fb66af2e0ae6ec6e1f7114c490a652d06cc01843e4ef50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / kute_engine-0.9.2-cp39-abi3-win_amd64.whl

Download URL kute_engine-0.9.2-cp39-abi3-win_amd64.whl
Size 2.1 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e44ad64bcd395171a49df21ea4cdd859fbe19c1b25e37947ee4701e3c09c497d
BLAKE2b-256 checksum
How to use checksums
138888506c042d1f4cb0df181e0e87967785e12b9bdc3b539e83af3369cd55ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for kute-engine 0.9.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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