Skip to main content

Python bindings for the v11 knowledge-first tokenizer (pure Rust)

Project description

v11-tokenizer — Python bindings

Pure-Rust knowledge-first tokenizer, exposed as a Python module via PyO3.

Install

From source:

cd v-tokenizers/v11/python
maturin develop --release

Then from any Python script in the same venv:

import v11

tok = v11.Tokenizer.from_file("../v11/artifacts/v11.vocab.bin")
print(tok)                                         # <v11.Tokenizer vocab_size=71260>
print(tok.vocab_size)                              # 71260
print(tok.pad_id, tok.unk_id, tok.bos_id, tok.eos_id)  # 0 1 2 3

ids = tok.encode("def fibonacci(n):")
pieces = tok.encode_pieces("def fibonacci(n):")
text = tok.decode(ids)

API

method returns notes
Tokenizer.from_file(path) Tokenizer Load from a .vocab.bin file
tok.encode(text) list[int] Tokenize to ids
tok.encode_pieces(text) list[str] Tokenize to piece strings
tok.decode(ids) str Reverse to text
tok.id_to_piece(id) str | None Look up a single id
tok.piece_to_id(piece) int | None Look up a single piece
tok.vocab_size int Total pieces
tok.pad_id, unk_id, bos_id, eos_id int Special token ids
len(tok) int Same as vocab_size

Performance

Encode throughput on a single thread (release build):

~9.3M tokens/sec
~28 MB/sec

That's roughly 10-40× faster than the Python sentencepiece package on comparable inputs, because the longest-match is a single Aho-Corasick pass with no C++ FFI hops.

Build a wheel for distribution

maturin build --release
ls target/wheels/
# v11_tokenizer-0.1.0-cp312-abi3-macosx_11_0_arm64.whl

License

Apache 2.0

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

v11_tokenizer-0.1.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distributions

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

v11_tokenizer-0.1.1-cp39-abi3-win_amd64.whl (148.7 kB view details)

Uploaded CPython 3.9+Windows x86-64

v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (248.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (236.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

v11_tokenizer-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (216.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

v11_tokenizer-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (220.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file v11_tokenizer-0.1.1.tar.gz.

File metadata

  • Download URL: v11_tokenizer-0.1.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for v11_tokenizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f989bd1eebd3265d87695dbf83899243cf76fe59d6fe5c63808002c3b80243c
MD5 240c2e62fe31f4a7d6a7dafc126232fa
BLAKE2b-256 6533f416448e9b321bbeb80717d635b8dbbf8ce95235e4c3f70aa1a5ffa1a3f4

See more details on using hashes here.

File details

Details for the file v11_tokenizer-0.1.1-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for v11_tokenizer-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fda47f13e53b2f433e0db2c8b72046b53555a11dc11b4194bd00fa4c37b30602
MD5 82a4c7b990e4e7f600a8b502b567818a
BLAKE2b-256 755e35ad766fa72034c3ddd536a66659f419d98cef89322fa75e1375d37df289

See more details on using hashes here.

File details

Details for the file v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 390fb5cb8c068bb9a3fbeccf3c18ee7118d4190076a7648fe1bb03d0004047a8
MD5 57e82010626029aae7c5217f0f615060
BLAKE2b-256 de9fef8429b75ce0ca4a5aa49479908b4dcb2a5b6dd85481c4e2cfa36d302f96

See more details on using hashes here.

File details

Details for the file v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for v11_tokenizer-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4abcfc4dad7e7a60fd4443ee448355313ab36960930ded7919f55765319cdc12
MD5 bf71817dddd5df0717c131a95c7eeeeb
BLAKE2b-256 1ce5d9edc05b57049ed8ed572d7349aeeaf983d4e0a2ff37081a6364f0d9b3f6

See more details on using hashes here.

File details

Details for the file v11_tokenizer-0.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for v11_tokenizer-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6b4fc28a0f5ff59e36cf817232839d9ea94a744f81224b8a4897f3976967984
MD5 dd6f178cae9bba3c1aa42eb3198bdb71
BLAKE2b-256 d641e97fed81612f2d4aa901623704c72b62c9a3a74d703df68b7b6d8c46da53

See more details on using hashes here.

File details

Details for the file v11_tokenizer-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for v11_tokenizer-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b6a9fb564bfbe848c96648c3b633e49b290cd6dd7555f45de1855221b58b0c49
MD5 3c6f70705e9a90e2bf2a5579995180dd
BLAKE2b-256 bf28a00786a4a51414e47b3802cbdb7556d21e91747645c3785354f1b861f631

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