Jessie Dong

Part-of-Speech and Lemma Information in Subword Tokenization

Morpheme boundaries and language-model loss for tokenizers that read tags and lemmas

Contributors: Anish Chaudhuri and Maya Vendhan

Motivation

A language model reads a continuous text as a sequence of tokens as generated by a tokenizer. Common subword tokenization methods such as byte-pair encoding and the unigram model generate vocabularies based on the relative frequencies of characters. Such methods do not leverage the grammar of the language. For example, in Turkish, öğrencilerin (meaning "of the students") can be represented as the lemma öğrenci, the plural suffix -ler, and the genitive suffix -in. However, byte-pair encoding trained on the Turkish Wikipedia corpus splits the word into öğrenc, iler, and in, encasing the stem-final letter of the lemma in the token for the plural suffix.

Part-of-speech tags and lemmas are cheap linguistic resources. Part-of-speech taggers exist for over sixty languages, and tagging a large corpus is a one-time effort. Tokenizers can leverage this information in various ways: Byte-pair encoding merge scores can be weighted by the probability of a part-of-speech transition at the word boundary for each merge. Merges occurring within content word types (i.e., nouns, verbs, and adjectives) can be weighted to increase the likelihood of learning whole words. Words can be split on lemma boundaries before subword training; we term this method Lemma2Word. Initial experiments found that these methods yield large gains, but these experiments did not involve held-out words, gold morpheme boundaries, or multiple runs.

Overview

We train tokenizers on the same set of Wikipedia paragraphs for each of five languages, with a vocabulary budget of 8,000 types and three training sample seeds. We provide part-of-speech and lemma information using Stanza. We evaluate boundary precision and recall against gold morpheme boundaries derived from lemmas as computed by MorphScore. We measure compression on held-out paragraphs, and language modeling performance via bits per character in a small language model. We test byte-pair encoding and the unigram model, both trained on the same text, as baselines.

Grouped bar chart of boundary F1 for six tokenizers in five languages
Figure 1: Boundary F1 versus gold morpheme boundaries for six tokenizers in five languages. Each bar represents a mean over three training seeds, and error bars represent one standard deviation.

Weighting by part-of-speech transition probability does not yield an improvement in boundary F1 greater than the difference between training seeds in four of the five languages. Compression is unchanged. The part-of-speech weighting is only applied to merges joining a word to the following space, and the token sets contain the same frequent token pairs as unweighted byte-pair encoding, for example "of the" in English and "de la" in Spanish. The expected transition probability at a covered boundary is no higher than at any other boundary: the transition probability tells us the likelihood of a word order, but does not help us split words internally.

Doubling the weight of merges within nouns, verbs, and adjectives shifts the vocabulary budget to whole content words. In Tamil, where byte-pair encoding almost never splits at the stem boundary, this increases boundary F1 from 4.4% to 22.2%. In Spanish and Turkish, boundary F1 decreases, as whole-word tokens are learned instead of the suffixes that byte-pair encoding would learn.

Lemma2Word increases boundary recall, from 54.4% to 88.2% in English and 7.4% to 84.5% in Tamil. Boundary recall increases by 23 to 34 points in the remaining three languages. Lemma2Word uses 4–8% more tokens than byte-pair encoding without any lemmas. The benefit persists on words absent from the training text in English, Tamil, and Turkish, due to these languages' long distinctive suffixes, but the benefit is almost lost in Spanish and Danish. A variant that uses a lemmatizer at tokenization time regains nearly all the gold boundaries, but requires running a neural lemmatizer on every word.

Boundary F1 against vocabulary budget for six tokenizers in five languages
Figure 2: Boundary F1 at vocabulary budgets of 2,000, 8,000, and 32,000 types for seed 0. The methods' ranking is the same in all budgets.

The unigram model is the best-performing tokenizer without linguistic resources, and is even competitive in Tamil without a lemmatizer. Allowing the space marker to merge freely is as important as leveraging linguistic signals. Allowing the space marker to be a freely merging token over the standard word-initial marker increases boundary F1 in four of the five languages due to the fact that words with a prefixed marker are no longer tokenized as whole words.

Claude Sonnet, asked to mark the morpheme boundaries of 400 words per language without modifying any character, finds more gold boundaries than any tokenizer in four languages. We observe 91% recall in English and 96% recall in Turkish. It is less successful than Lemma2Word in Danish, and less precise, since it marks some derivational affixes and parts of compounds that are not marked in the gold standard. It even sometimes uses the underlying suffix rather than the surface suffix in Tamil, although this is forbidden by the character-level constraint. The responses of Claude Sonnet have no fixed vocabulary, and cost many orders of magnitude more per word than any of the tokenizers. Thus the evaluation measures the model's morphological knowledge, not the performance of a tokenizer that might be constructed on the basis of the model.

We also trained a 7M-parameter language model on text segmented using each tokenizer, passing over the text six times. This model ranks the tokenizers in a way that is different from the performance on morpheme boundaries. The best (lowest) bits-per-character, measured on held-out text, is achieved by the unigram model in every language. For example, the unigram model achieves 2.53 bits per character in English, while byte pair encoding achieves 2.81. The tokenizer with the best morpheme boundary F1 score (Lemma2Word) gives the worst (highest) bits per character. Adding part-of-speech weighting has no effect on the bits-per-character, changing it by less than 0.03. Thus this suggests that more morpheme boundaries do not necessarily make a better tokenizer for a language model, at least at the scale tested here.