r/java • • 48m ago

Tok'n'Roll: Token-perfect tokenizers for Python but 100% written in Java 🤯

https://pypi.org/project/toknroll

Tok'n'Roll is the tokenization substrate of Quixotic and can be installed as follows:

pip install toknroll

But, why is a Python wheel being posted in r/java ?

What if I told you that Tok'n'Roll is written 100% in safe Java e.g. no Unsafe.

Tok'n'Roll outperforms the industry standards: both Tiktoken and Hugging Face tokenizers (1.0rc5), which are Python wrappers over Rust codebases.

But why? The Rust codebases are riddled with unsafe usages ... not so safe after all. The Java implementation is quite nice IMHO, it just proves that Java can be extremely performant. Why wrap Rust when you can wrap Java.

This is one-of-a-kind project, inspired by Florian Enner's work on StaticFX.

The whole Java-to-Python approach is quite interesting, the Python wheel is just ~5.6MB, supports Linux, Windows and macOS.

Benchmarks:

PS: I'm the author, everything is open source, Apache 2.0.

0 Upvotes

1 comment sorted by