---
title: "Peek2 — paper by Zai and Klampanos (2026)"
description: "Peek2 uses this to replace the regex's try-and-fall-back matching with a single lookup in a 7×7 table. 17 references."
authors: ["Liu Zai", "Iraklis A. Klampanos"]
year: 2026
venue: "Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop)"
source: "https://aclanthology.org/2026.acl-srw.10/"
doi: "10.18653/v1/2026.acl-srw.10"
licence: "CC BY 4.0 (ACL Anthology)"
licence_url: "https://creativecommons.org/licenses/by/4.0/"
summary_licence: "Elamur Cosmic License"
canonical: "https://research.elamur.ai/free/en/papers/zai-2026-peek2-regex-free-byte-level/"
---
[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/zai-2026-peek2-regex-free-byte-level/)

[home](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2026](https://md.research.elamur.ai/free/en/papers/2026/page/44/) / Peek2: Regex-free Byte-level Byte-Pair Encoding Pretokenizer for LLM Inference on Edge Devices

# Peek2: Regex-free Byte-level Byte-Pair Encoding Pretokenizer for LLM Inference on Edge Devices

**Authors:** Liu Zai and Iraklis A. Klampanos · **Year:** 2026 · **Venue:** [Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop)](https://md.research.elamur.ai/free/en/venues/acl/) ([ACL 2026](https://md.research.elamur.ai/free/en/venues/acl/2026/)) · **Publisher:** [Association for Computational Linguistics](https://md.research.elamur.ai/free/en/publishers/association-for-computational-linguistics/) · **Licence:** [CC BY 4.0 (ACL Anthology)](https://creativecommons.org/licenses/by/4.0/)

**Links:** [Publisher's page](https://aclanthology.org/2026.acl-srw.10/) · [PDF](https://aclanthology.org/2026.acl-srw.10.pdf) · [DOI 10.18653/v1/2026.acl-srw.10](https://doi.org/10.18653/v1/2026.acl-srw.10) · [OpenAlex](https://openalex.org/W7166818623)

**Citations:** 0 citations (OpenAlex, 2026-10-14)

## Summary
Byte-level BPE tokenizers start with a pretokenization step that splits text into fragments before pair merging. This step usually relies on a complex regular expression, and it stays sequential. On edge hardware such as PCs, laptops and embedded devices, the regex engine can cost throughput and cold-start time. The authors analyse the cl100k-style pattern used by GPT-3, LLaMa-3 and Qwen-2.5. They show that the character set can be reduced to seven categories. With those categories, the branch a segment belongs to depends only on its first two characters.

Peek2 uses this to replace the regex's try-and-fall-back matching with a single lookup in a 7×7 table. It then calls a simple branch-specific scanning function. The method runs in linear time with constant memory, and its output matches the original pretokenizer exactly, including its quirks. Built in Safe Rust inside Hugging Face tokenizers, Peek2 more than doubles pretokenization speed and gives modest end-to-end encoding gains. No model retraining is needed.

## Key points
- PeekCategorize sorts each Unicode scalar into one of 7 classes, such as ASCII space, quote, CR/LF, and the Letter/Whitespace/Number classes. The table that picks among Branch0–Branch6 is inspired by Hopcroft's DFA minimization.
- The algorithm runs in O(n) time with O(1) space. NFA regex engines, by comparison, can reach O(n×k) or O(n×m).
- It is implemented in Safe Rust on Hugging Face tokenizers 0.22.3-dev.0 and tested on an Intel Core i5-13600KF. The four test datasets are FineWeb (en), Fineweb-Edu-Chinese (cn), codesearchnet (code) and opc-fineweb-math (math).
- Pretokenization alone speeds up by 2.20× (cn) to 2.48× (en). Full LLaMa-3 encoding improves by 1.03–1.14×, while gains in BPE training are smaller.
- Pretokenization's share of encoding time drops sharply, for example from 22.8% to 14.0% on code. Experiments are limited to desktop CPUs.

*Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.*

## Institutions

- [University of Glasgow](https://md.research.elamur.ai/free/en/universities/university-of-glasgow/) — University, Glasgow, United Kingdom · 14 works · 746 citations

📚 Shelves (4): [🖥️ Computer Science](https://md.research.elamur.ai/free/en/shelves/computer-science/) · 18,614 works · [🤖 Artificial Intelligence](https://md.research.elamur.ai/free/en/shelves/computer-science/artificial-intelligence/) · 17,965 works · [🎭 Arts and Humanities](https://md.research.elamur.ai/free/en/shelves/arts-and-humanities/) · 17,450 works · [🗣️ Language and Linguistics](https://md.research.elamur.ai/free/en/shelves/arts-and-humanities/language-and-linguistics/) · 17,296 works

🧭 Topics (2): [🧠 Language models & pretraining](https://md.research.elamur.ai/free/en/topics/language-models/) · 3,894 works · [✂️ Tokenization & segmentation](https://md.research.elamur.ai/free/en/topics/tokenization/) · 124 works

## Cite

Cite as: Liu Zai and Iraklis A. Klampanos. 2026. Peek2: Regex-free Byte-level Byte-Pair Encoding Pretokenizer for LLM Inference on Edge Devices. Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop).

The paper itself, not this page. BibTeX from the library's record of the work.

```bibtex
@inproceedings{zai2026peek2,
  title = {{Peek2: Regex-free Byte-level Byte-Pair Encoding Pretokenizer for LLM Inference on Edge Devices}},
  author = {Liu Zai and Iraklis A. Klampanos},
  booktitle = {Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop)},
  year = {2026},
  doi = {10.18653/v1/2026.acl-srw.10},
  url = {https://doi.org/10.18653/v1/2026.acl-srw.10}
}
```

- [← previous Pedagogic Applications of Argument Maps to Enhance Critical Thinking: Thought Seeds, Argument Mapping, Collaborative Mapping](https://md.research.elamur.ai/free/en/papers/narra-2026-pedagogic-applications-argument-maps-enhance/)
- [next → PEGRL: Improving Machine Translation by Post-Editing Guided Reinforcement Learning](https://md.research.elamur.ai/free/en/papers/shen-2026-pegrl-improving-machine-translation-post/)
- [↑ back to papers of 2026](https://md.research.elamur.ai/free/en/papers/2026/page/44/)

## References

17 references, 5 of them with a card of ours. ↗ leads to the work, «find» searches for one we have no id for yet.

1. AI@Meta. 2024. Llama 3 model card. [find](https://scholar.google.com/scholar?q=AI%40Meta%2E+2024%2E+Llama+3+model+card%2E)
2. Philip Bille and Mikkel Thorup. 2010. Regular expression matching with multi-strings and intervals. In Proceedings of the Twenty-First Annual ACM-SIAM Symposium on Discrete Algorithms, SODA ’10, page 1297–1308, USA. Society for Industrial and Applied Mathematics. [find](https://scholar.google.com/scholar?q=Philip+Bille+and+Mikkel+Thorup%2E+2010%2E+Regular+expression+matching+with+multi%2Dstrings+and+intervals%2E+In+Proceedings+of+the+Twenty%2DFirst+Annual+ACM%2DSIAM+Symposium+on+Discrete+Algorithms%2C+SODA+%E2%80%9910%2C+page+)
3. Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel Ziegler, Jeffrey Wu, Clemens Winter, and… [find](https://scholar.google.com/scholar?q=Tom+Brown%2C+Benjamin+Mann%2C+Nick+Ryder%2C+Melanie+Subbiah%2C+Jared+D+Kaplan%2C+Prafulla+Dhariwal%2C+Arvind+Neelakantan%2C+Pranav+Shyam%2C+Girish+Sastry%2C+Amanda+Askell%2C+Sandhini+Agarwal%2C+Ariel+Herbert%2DVoss%2C+Gretchen)
4. Russ Cox. 2007. Regular expression matching can be simple and fast (but is slow in java, perl, php, python, ruby, ...). [find](https://scholar.google.com/scholar?q=Russ+Cox%2E+2007%2E+Regular+expression+matching+can+be+simple+and+fast+%28but+is+slow+in+java%2C+perl%2C+php%2C+python%2C+ruby%2C+%2E%2E%2E%29%2E)
5. Zixu Hao, Huiqiang Jiang, Shiqi Jiang, Ju Ren, and Ting Cao. 2024. Hybrid slm and llm for edge-cloud collaborative inference. In Proceedings of the Workshop on Edge and Mobile Foundation Models, EdgeFM ’24, page 36–41, New York, NY, USA. Association for Computing Machinery. [find](https://scholar.google.com/scholar?q=Zixu+Hao%2C+Huiqiang+Jiang%2C+Shiqi+Jiang%2C+Ju+Ren%2C+and+Ting+Cao%2E+2024%2E+Hybrid+slm+and+llm+for+edge%2Dcloud+collaborative+inference%2E+In+Proceedings+of+the+Workshop+on+Edge+and+Mobile+Foundation+Models%2C+EdgeF)
6. John Hopcroft. 1971. An n log n algorithm for minimizing states in a finite automaton. In Zvi Kohavi and Azaria Paz, editors, Theory of Machines and Computations, pages 189–196. Academic Press. [find](https://scholar.google.com/scholar?q=John+Hopcroft%2E+1971%2E+An+n+log+n+algorithm+for+minimizing+states+in+a+finite+automaton%2E+In+Zvi+Kohavi+and+Azaria+Paz%2C+editors%2C+Theory+of+Machines+and+Computations%2C+pages+189%E2%80%93196%2E+Academic+Press%2E)
7. Siming Huang, Tianhao Cheng, Jason Klein Liu, Jiaran Hao, Liuyihan Song, Yang Xu, J. Yang, J. H. Liu, Chenchen Zhang, Linzheng Chai, Ruifeng Yuan, Zhaoxiang Zhang, Jie Fu, Qian Liu, Ge Zhang, Zili Wang, Yuan Qi, Yinghui Xu, and Wei Chu. 2024. [Opencoder: The open cookbook for top-tier code large lang…](https://md.research.elamur.ai/free/en/papers/huang-2025-opencoder-open-cookbook-top-tier/)
8. Hamel Husain, Ho-Hsiang Wu, Tiferet Gazit, Miltiadis Allamanis, and Marc Brockschmidt. 2019. [Codesearchnet challenge: Evaluating the state of semantic code search](https://md.research.elamur.ai/free/en/papers/husain-2020-codesearchnet-challenge-evaluating-state-semantic/). ArXiv.
9. Anthony Moi and Nicolas Patry. 2025. HuggingFace’s Tokenizers. [find](https://scholar.google.com/scholar?q=Anthony+Moi+and+Nicolas+Patry%2E+2025%2E+HuggingFace%E2%80%99s+Tokenizers%2E)
10. Guilherme Penedo, Hynek Kydlíček, Loubna Ben allal, Anton Lozhkov, Margaret Mitchell, Colin Raffel, Leandro Von Werra, and Thomas Wolf. 2024. [The fineweb datasets: Decanting the web for the finest text data at scale](https://md.research.elamur.ai/free/en/papers/penedo-2024-fineweb-datasets-decanting-web-finest/). In The Thirty-eight Conference on Neural Information Processing Systems Datasets a…
11. Craig W Schmidt, Varshini Reddy, Haoran Zhang, Alec Alameddine, Omri Uzan, Yuval Pinter, and Chris Tanner. 2024. [Tokenization is more than compression](https://md.research.elamur.ai/free/en/papers/schmidt-2024-tokenization-is-more-than-compression/). In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, pages 678–702, Miami, Florida, USA. Association for Compu…
12. Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016. [Neural machine translation of rare words with subword units](https://md.research.elamur.ai/free/en/papers/sennrich-2016-neural-machine-translation-rare-words/). In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1715–1725, Berlin, Germany. Association for Computational Lin…
13. Jianshu She, Wenhao Zheng, Zhengzhong Liu, Hongyi Wang, Eric P. Xing, Huaxiu Yao, and Qirong Ho. 2025. Token level routing inference system for edge devices. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations), pages 159–166, V… [find](https://scholar.google.com/scholar?q=Jianshu+She%2C+Wenhao+Zheng%2C+Zhengzhong+Liu%2C+Hongyi+Wang%2C+Eric+P%2E+Xing%2C+Huaxiu+Yao%2C+and+Qirong+Ho%2E+2025%2E+Token+level+routing+inference+system+for+edge+devices%2E+In+Proceedings+of+the+63rd+Annual+Meeting+)
14. Qwen Team. 2024. Qwen2.5: A party of foundation models. [find](https://scholar.google.com/scholar?q=Qwen+Team%2E+2024%2E+Qwen2%2E5%3A+A+party+of+foundation+models%2E)
15. Ken Thompson. 1968. Programming techniques: Regular expression search algorithm. Commun. ACM, 11(6):419–422. [find](https://scholar.google.com/scholar?q=Ken+Thompson%2E+1968%2E+Programming+techniques%3A+Regular+expression+search+algorithm%2E+Commun%2E+ACM%2C+11%286%29%3A419%E2%80%93422%2E)
16. Amos You. 2025. Blockbpe: Parallel bpe tokenization. Preprint, arXiv:2507.11941. [find](https://scholar.google.com/scholar?q=Amos+You%2E+2025%2E+Blockbpe%3A+Parallel+bpe+tokenization%2E+Preprint%2C+arXiv%3A2507%2E11941%2E)
17. Yijiong Yu, Ziyun Dai, Zekun Wang, Wei Wang, Ran Chen, and Ji Pei. 2025. Opencsg chinese corpus: A series of high-quality chinese datasets for llm training. Preprint, arXiv:2501.08197. — [arXiv:2501.08197](https://arxiv.org/abs/2501.08197) [find](https://scholar.google.com/scholar?q=Yijiong+Yu%2C+Ziyun+Dai%2C+Zekun+Wang%2C+Wei+Wang%2C+Ran+Chen%2C+and+Ji+Pei%2E+2025%2E+Opencsg+chinese+corpus%3A+A+series+of+high%2Dquality+chinese+datasets+for+llm+training%2E+Preprint%2C+arXiv%3A2501%2E08197%2E+%E2%80%94+%5BarXiv%3A2501%2E0)

*Updated 2 November 2026*
