Fast Byte Pair Encoding (BPE) tokenizer with Python bindings powered by PyO3.
Project description
fast-bpe-rs
A blazing-fast Byte Pair Encoding tokenizer — written in Rust, usable from Python.
Quick start
Install
pip install fast-bpe-rs
No prebuilt wheel for your platform?
pipwill compile from source. You'll need a Rust toolchain installed first.
Train
from fast_bpe_rs import BPE
bpe = BPE(r"(?s).+") # regex pattern for pre-splitting text
bpe.train(258, ["low low low low", "lower lower", "newest newest newest"])
For real corpora, use a GPT-style split pattern:
bpe = BPE(
r"(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}"
r"| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"
)
bpe.train(50_000, corpus_lines)
Encode & Decode
ids = bpe.encode("low lower newest")
text = bpe.decode_to_string(ids)
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_bpe_rs-0.3.2.tar.gz.
File metadata
- Download URL: fast_bpe_rs-0.3.2.tar.gz
- Upload date:
- Size: 105.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62ae089b970e0bdee0b2a7407c983f92c2d7ac2be20578d48a87a19eef093fa9
|
|
| MD5 |
5275db666b47511b8885e657901cc73f
|
|
| BLAKE2b-256 |
2ee11cec7ebaf612fa2448a3030420eee3494923ada4d32e2ad1c262d28320b7
|
Provenance
The following attestation bundles were made for fast_bpe_rs-0.3.2.tar.gz:
Publisher:
release.yml on zhixiangli/fast-bpe-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_bpe_rs-0.3.2.tar.gz -
Subject digest:
62ae089b970e0bdee0b2a7407c983f92c2d7ac2be20578d48a87a19eef093fa9 - Sigstore transparency entry: 1232625462
- Sigstore integration time:
-
Permalink:
zhixiangli/fast-bpe-rs@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhixiangli
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_bpe_rs-0.3.2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: fast_bpe_rs-0.3.2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 944.5 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc8b85942ca8cc773ae139a1e29c8694c52b18cf69d520b0f886e686c07da8cb
|
|
| MD5 |
fb45e348f4ee7600696cdbb40306e277
|
|
| BLAKE2b-256 |
3c4594904de9e1e22425b900f124027e51572e91f1300e4ec0070f2e09958e2d
|
Provenance
The following attestation bundles were made for fast_bpe_rs-0.3.2-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on zhixiangli/fast-bpe-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_bpe_rs-0.3.2-cp310-abi3-win_amd64.whl -
Subject digest:
dc8b85942ca8cc773ae139a1e29c8694c52b18cf69d520b0f886e686c07da8cb - Sigstore transparency entry: 1232626150
- Sigstore integration time:
-
Permalink:
zhixiangli/fast-bpe-rs@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhixiangli
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_bpe_rs-0.3.2-cp310-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: fast_bpe_rs-0.3.2-cp310-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63283a75bee6509b66a51307d20e737cfc98c5c3083a7d555cbaa0b28b0c81ec
|
|
| MD5 |
464bfccdffc9fb95fc4b00a0f725fa9c
|
|
| BLAKE2b-256 |
ae56082e7221891a2fd462f1cc86a50cb0e2a4132e7b2bbbc0d34c22fd47f23f
|
Provenance
The following attestation bundles were made for fast_bpe_rs-0.3.2-cp310-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release.yml on zhixiangli/fast-bpe-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_bpe_rs-0.3.2-cp310-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
63283a75bee6509b66a51307d20e737cfc98c5c3083a7d555cbaa0b28b0c81ec - Sigstore transparency entry: 1232625844
- Sigstore integration time:
-
Permalink:
zhixiangli/fast-bpe-rs@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhixiangli
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_bpe_rs-0.3.2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_bpe_rs-0.3.2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 904.9 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
173ca86859234d51a006f1e0d735dcc271fedfc31546f362ac68fbaaf245d8c8
|
|
| MD5 |
c51ef0842b6e0ea550da8f8488240d34
|
|
| BLAKE2b-256 |
80cb6c5441532fab1c8ae40063b57340670f9d78c982aeeccdd4ac826b9d1474
|
Provenance
The following attestation bundles were made for fast_bpe_rs-0.3.2-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on zhixiangli/fast-bpe-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_bpe_rs-0.3.2-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
173ca86859234d51a006f1e0d735dcc271fedfc31546f362ac68fbaaf245d8c8 - Sigstore transparency entry: 1232626448
- Sigstore integration time:
-
Permalink:
zhixiangli/fast-bpe-rs@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhixiangli
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9cf9bfb54cc70647d096d56b0363975d3f2d9e97 -
Trigger Event:
push
-
Statement type: