The Pattern Language Models Use

Before learning smaller pieces, a tokenizer may need to separate runs of letters, numbers, and punctuation. A regular expression can describe those initial groups while retaining information about the spaces around them.

14 sections · 15 questions · 4 coding challenges

1 / 14

Why Put Rules Before a Learned Vocabulary?

BOTIE

A learned subword tokenizer can merge neighbouring units into larger pieces. Before it learns or applies those merges, we may want to decide which kinds of characters are allowed to be grouped together. Otherwise a frequent combination could cross a boundary we wanted to retain.

GPT-2's released 2019 encoder used a regular expression to divide text into groups before byte-level BPE. The pattern distinguished contractions, letter sequences, number sequences, punctuation, and whitespace, with particular handling of a leading space. This is a concrete design from a particular model family, rather than a rule followed by every language model.

The first stage controls the regions in which later merges operate. The learned vocabulary then determines how those regions are divided into tokens. Separating those jobs explains why two tokenizers can both use BPE and still produce different results. We will inspect the pattern's decisions before following any learned merges.

Sources for this history