liveBook · Manning

Wordpiece

As explained in Natural Language Processing in Action, Second Edition

WordPiece tokenization is a subword tokenization technique that represents text using frequent word fragments and character sequences.

WordPiece tokenization represents text with reusable word fragments and character sequences rather than complete words. Prefixes, suffixes, and interior pieces can transfer patterns across related words, helping a language pipeline handle unfamiliar forms and large vocabularies. Unlike word tokenizers, subword tokenizers must be trained over a corpus until their vocabulary converges. section 2.2 section 2.2.1

WordPiece is useful when a pipeline needs to:

  • Reuse fragments across related words, including prefixes, suffixes, and interior syllables. section 2.2
  • Represent new words through smaller pieces instead of discarding them as unknown whole-word entries. section 2.2
  • Compress a large natural-language vocabulary into a more computation-friendly token inventory. section 2.2 section 2.2.1

From fragments to transformer inputs

A practical exploration begins by fitting a character n-gram CountVectorizer to text, inspecting frequent one- and two-character fragments, and comparing their counts. WordPiece belongs to the same broader subword-tokenization family, but its fitted vocabulary is used directly as model tokens. In BERT, sequences add [CLS] and [SEP] tokens, combine token, segment, and positional embeddings, and randomly mask 15% of WordPiece tokens during pretraining. section 9.3.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains fragment intuition, corpus fitting, frequency inspection, and BERT usage, but does not detail the WordPiece merge algorithm.
Examples
Uses character n-gram frequency tables and BERT’s [CLS], [SEP], segment, positional, and masked WordPiece tokens.
What it assumes
Assumes basic tokenization awareness while developing the distinction between words, fragments, characters, and machine-oriented encodings.
What you can do after
Evaluate how subword fragments support vocabulary coverage and inspect corpus statistics before using tokens in transformer training.
How it connects
Connects subword tokenization with BPE, character n-grams, CountVectorizer, BERT, embeddings, and masked language modeling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.