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

pip install v11-tokenizer

The distribution is v11-tokenizer; the import is v11. Wheels are built against PyO3's stable ABI, so one wheel per platform covers every Python >= 3.9 — Linux (x86_64/aarch64), macOS (Intel/Apple silicon) and Windows x64. No Rust toolchain needed. (Use 0.1.1 or newer: 0.1.0 shipped only a macOS arm64 / cp312 wheel, so everywhere else pip fell back to building the sdist.)

For development, 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.2-cp39-abi3-macosx_11_0_arm64.whl

The cp39-abi3 tag is the stable-ABI build: that one file installs on any CPython >= 3.9, whatever interpreter built it. Releases produce one per platform via the matrix in .github/workflows/publish.yml.

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.2.tar.gz (20.4 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.2-cp39-abi3-win_amd64.whl (149.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

v11_tokenizer-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (248.6 kB view details)

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

v11_tokenizer-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (236.5 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

v11_tokenizer-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (216.7 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

v11_tokenizer-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl (220.4 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for v11_tokenizer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4e4eed1a93fa50cdf9610d040e34d4dcd406874fe9c70154168622f926a1518e
MD5 de795f4e85bb9f03822e8cb687738530
BLAKE2b-256 a462d2aa3959ae9fe97cbd08ab299ef13859c41461370ccad4e6b3180f387a5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for v11_tokenizer-0.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1bcbd864755b4ca6a5677eb300ad4aa5510b51e1085a0c9c70887338b5f6fb8e
MD5 31f639be3d143652e1fb87e3b6727dc4
BLAKE2b-256 e192f0a0052cb290929e106922fcdbe9c8935aca9d413cdadc1ca9f569884026

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for v11_tokenizer-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24921f244179430db7a67e66cbbeb4bc4ab18ef6af044216f08583f135353f0b
MD5 064076e81da5397029b2ccb27e535e70
BLAKE2b-256 b172e748c24eff8568712ee69824372d9f16fa0114a5fb218de18a384289235d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for v11_tokenizer-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 30f3e00c57b74c1181365e37098c06e6eba55f44fa694b8f7db5e086c5842a8e
MD5 6ac13e441831707f3338863ff1d13747
BLAKE2b-256 3b1f5a9983d2dcdc0698c1486cf468b33c6633922f36bfb8009b83033496514d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for v11_tokenizer-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c3f37556a3465153a825d762f69e2a477e657c1d83fcf406d8e1e46badafbd9
MD5 e01ab42309512040683b265dde49f587
BLAKE2b-256 12d8b8656c40cd1b8f1f31e66b0b7665c55e3c1282f7168856e802f8e0865839

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for v11_tokenizer-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 35c455ce0449f48e575b289c4904595d555a5daeb0f6c6682dfb57db4ffac541
MD5 6408375bbb8f1268e82591424e1f532c
BLAKE2b-256 2a563406d386c1d716b3c1e09352e45c6e29838cbca7073bd49eb3be5201ecd8

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