Fast WordPiece Tokenization
Open accessThe DOI matches its Crossref record; 14 of the 14 references it cites were found in a registry or an index.
Abstract
Tokenization is a fundamental preprocessing step for almost all NLP tasks.In this paper, we propose efficient algorithms for the Word-Piece tokenization used in BERT, from singleword tokenization to general text (e.g., sentence) tokenization.When tokenizing a single word, WordPiece uses a longest-matchfirst strategy, known as maximum matching.The best known algorithms so far are ( 2 ) (where is the input length) or ( ) (where is the maximum vocabulary token length).We propose a novel algorithm whose tokenization complexity is strictly ( ).Our method is inspired by the Aho-Corasick algorithm.We introduce additional linkages on top of the trie built from the vocabulary, allowing smart transitions when the trie matching cannot continue.For general text, we further propose an algorithm that combines pre-tokenization (splitting the text into words) and our linear-time Word-Piece method into a single pass.Experimental results show that our method is 8.2x faster than HuggingFace Tokenizers and 5.1x faster than TensorFlow Text on average for general text tokenization.
Overview
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Integrity signals
Registry
Cites
Statistics
Verification
Claims the paper makes
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Self-check
Percentages, sums and reported differences re-computed from the paper’s own numbers.
The self-check needs the paper’s full text.
Citations
Cites
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019) · Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) · doi:10.18653/v1/n19-1423 · Cited by 54,325 · cited 3×
“In this paper, we propose efficient algorithms for WordPiece, the subword tokenization used in BERT (Devlin et al., 2019).”
BackgroundMethodInfluentialLanguage Models are Few-Shot Learners
Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., et al. (2020) · arXiv · doi:10.48550/arxiv.2005.14165 · Cited by 23,372
Error bounds for convolutional codes and an asymptotically optimum decoding algorithm
Viterbi, A. (1967) · IEEE Transactions on Information Theory · doi:10.1109/tit.1967.1054010 · Cited by 6,759 · cited 1×
“SentencePiece is based on unigram language modeling, and the optimal segmentation can be found in 𝑂 ( 𝑛𝑚 ) time with the Viterbi algorithm (Viterbi, 1967).”
MethodXLNet: Generalized Autoregressive Pretraining for Language Understanding
Yang, Z., Dai, Z., Yang, Y., Carbonell, J., Salakhutdinov, R., & Le, Q. V. (2019) · arXiv · doi:10.48550/arxiv.1906.08237 · Cited by 6,687 · cited 5×
“More recently, subword tokenization techniques have become a near-universal feature of modern NLP models, including BERT (Devlin et al., 2019), GPT-3 (Brown et al., 2020), XLNet (Yang et al., 2019), etc. Common subword tokenization techniques include Byte-Pair Encoding (BPE) (Schus-ter and Nakajima, 2012; Sennrich et…”
BackgroundMethodInfluentialEfficient string matching: an aid to bibliographic search
Aho, A. V., & Corasick, M. J. (1975) · Communications of the ACM · doi:10.1145/360825.360855 · Cited by 2,944
Kudo, T., & Richardson, J. (2018) · Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing: System Demonstrations · doi:10.18653/v1/d18-2012 · Cited by 2,869
Fredkin, E. (1960) · Communications of the ACM · doi:10.1145/367390.367400 · Cited by 1,090 · cited 2×
“Inspired by the Aho-Corasick algorithm (Aho and Corasick, 1975), we organize vocabulary tokens in a trie (Fredkin, 1960) and introduce precomputed failure links and failure pops.”
MethodSpeech and Language Processing, 2nd Edition
Jurafsky, D. S., & Martin, J. (2008) · Cited by 1,063
Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates
Kudo, T. (2018) · Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers) · doi:10.18653/v1/p18-1007 · Cited by 1,021 · cited 4×
“Finally, we discuss the complexity of algorithms for Byte-Pair Encoding (BPE) (Schuster and Naka-jima, 2012; Sennrich et al., 2016) and Sentence-Piece (Kudo, 2018).”
MethodInfluentialRegular models of phonological rule systems
Kaplan, R. M., & Kay, M. (1994) · OLAC - Open Language Archives Community · doi:10.5555/204915.204917 · Cited by 944
(1997) · Cited by 914
Japanese and Korean voice search
Schuster, M., & Nakajima, K. (2012) · 2012 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) · doi:10.1109/icassp.2012.6289079 · Cited by 862 · cited 7×
“More recently, subword tokenization techniques have become a near-universal feature of modern NLP models, including BERT (Devlin et al., 2019), GPT-3 (Brown et al., 2020), XLNet (Yang et al., 2019), etc. Common subword tokenization techniques include Byte-Pair Encoding (BPE) (Schus-ter and Nakajima, 2012; Sennrich et…”
BackgroundMethodInfluentialTokenization as the initial phase in NLP
Webster, J. J., & Kit, C. (1992) · Proceedings of the 14th conference on Computational linguistics - · doi:10.3115/992424.992434 · Cited by 362 · cited 2×
“It can be also adapted to address other MaxMatch variants, such as Backward MaxMatch (Webster and Kit, 1992), recognizing unseen characters as single-character tokens (Palmer, 2000), or combing with transformation rules (Sassano, 2014).”
BackgroundMethodOptimizing Chinese word segmentation for machine translation performance
Chang, P.-C., Galley, M., & Manning, C. D. (2008) · Proceedings of the Third Workshop on Statistical Machine Translation - StatMT '08 · doi:10.3115/1626394.1626430 · Cited by 296 · cited 1×
“Recent CWS work focuses on machine learning-based segmentation approaches, but MaxMatch remains a commonly referenced baseline (Chang et al., 2008).”
Background
Cited by
A review of large language models and autonomous agents in chemistry
Ramos, M. C., Collison, C. J., & White, A. D. (2025) · Chemical Science · doi:10.1039/d4sc03921a · Cited by 274
Wang, F., Zhang, Z., Zhang, X., Wu, Z., Mo, T., Lu, Q., Wang, W., Li, R., Xu, J., Tang, X., et al. (2025) · ACM Transactions on Intelligent Systems and Technology · doi:10.1145/3768165 · Cited by 106
Large language models transform biological research: from architecture to utilization
Wang, T., & Luo, Z. (2025) · Science China Information Sciences · doi:10.1007/s11432-024-4466-3 · Cited by 14
Metadata
- Authors
- Song, X., Salcianu, A., Song, Y., Dopson, D., & Zhou, D.
- Venue
- Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing
- Published
- 2021
- Pages
- 2089-2103
- OpenAlex
- W3204880395
- Cited by
- 172
- References
- 14
- FWCI
- 9.63
- Type
- conference paper
- Language
- en
- Open access
- hybrid
About these checks
Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.
Statistics and arithmetic are recomputed, not judged.
Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.
What counts as a claim ›How we measure confidence ›How we check this ›
Are you an author, or do you see a problem with this page? Request a review
Data sources
Bibliographic data: Semantic Scholar, OpenAlex, Crossref.
Contains information from the Semantic Scholar Academic Graph Datasets, made available under the ODC Attribution License (ODC-BY 1.0).
Semantic Scholar’s data is described in: Kinney, R., et al. (2023). The Semantic Scholar Open Data Platform. arXiv:2301.10140.