Multilingual Tokenization and Vocabulary Allocation › Script coverage and the character tail

Michael BrenndoerferNovember 25, 20265 min read
Language AI HandbookAll chapters
Part 26 of 67Multilingual Language Models and Cross-Lingual Transfer
Chapter 184Multilingual Tokenization and Vocabulary Allocation › Script coverage and the character tail
Reading section 4 of 11 · Script coverage and the character tail · 5 minSection 4 of 11 · 5 min

Section 4 of 11 · 5 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

SentencePiece's character_coverage sets a target share of character occurrences used to form the training alphabet after normalization. Without byte fallback, characters outside that alphabet may map to the unknown ID. Required characters can reserve entries in addition to those selected by occurrence mass. SentencePiece model schema

The default is 0.9995, or a target of 99.95% of observed occurrences. This setting determines occurrence mass, not the fraction of distinct types kept. A language with little data in the corpus can contribute many rare code points to the global tail. Losing a code point can erase a distinction even when the unknown ID is rare overall.

For a separate descriptive check, use all 14 aligned rows per language, including the four held out of tokenizer training. Sort code points within each language by frequency and keep the smallest number of distinct code points whose cumulative mass reaches the threshold. These counts describe the constructed data before SentencePiece-specific preprocessing or exclusions.

PythonIn [15]
CollapseExpand
def character_tail(sentences):
    """Return the cumulative uncovered fraction as characters are kept by rank."""
    counts = Counter("".join(sentences))
    frequencies = np.array(sorted(counts.values(), reverse=True), dtype=float)
    covered = np.cumsum(frequencies) / frequencies.sum()
    ranks = np.arange(1, len(covered) + 1)
    return ranks, 1.0 - covered


tails = {
    code: character_tail(sentences)
    for code, sentences in parallel_corpus.items()
}
ConsoleOut [16]
CollapseExpand
         distinct characters  characters for 99.95% coverage
Korean                    91                              91
Chinese                   87                              87
Thai                      53                              53
Hindi                     46                              46
Spanish                   39                              39
Arabic                    35                              35
Finnish                   33                              33
Swahili                   33                              33
English                   31                              31

The bar chart compares the number of distinct code points needed to reach the same within-language threshold across all 14 aligned rows.

VisualizationOut [18]
CollapseExpand
Coverage counts differ by language, with Korean and Chinese highest in the toy corpus.
Distinct code points needed to cover 99.95 percent of occurrences within each language across all 14 aligned rows. Every observed code point is required in these short samples.

Each sample is small enough that even one omitted occurrence would exceed the 0.05% allowance. Each bar therefore equals that sample's inventory size. The chart does not measure how the threshold divides a corpus pooled across languages.

Setting character_coverage=1.0 asks SentencePiece to cover the full occurrence mass it counts during training. The realized alphabet depends on trainer preprocessing and on how the coverage threshold is calculated. SentencePiece 0.2.2 rounds the computed coverage ratio to a float. The ratio can round up to 1.0 before a rare observed character is included. Check the realized alphabet and test round-trip recovery separately on held-out text from each language. Byte fallback can preserve normalized code points that the learned pieces cannot spell directly.

How normalization changes encoded length

SentencePiece normalizes text before learning and encoding pieces. Its default nmt_nfkc uses a variant of Unicode NFKC and includes whitespace handling. Standard NFC and NFKC prefer composed forms where possible. NFD and NFKD use decomposed forms, and the compatibility forms also fold distinctions such as some fullwidth characters and ligatures. The toy training example uses identity normalization so input preservation can be checked directly. SentencePiece normalization

PythonIn [19]
CollapseExpand
syllable = "한"
nfc = unicodedata.normalize("NFC", syllable)
nfd = unicodedata.normalize("NFD", syllable)

print(
    f"NFC form: {len(nfc)} code point(s), {len(nfc.encode('utf-8'))} UTF-8 bytes"
)
print("  " + ", ".join(f"U+{ord(ch):04X}" for ch in nfc))
print(
    f"NFD form: {len(nfd)} code point(s), {len(nfd.encode('utf-8'))} UTF-8 bytes"
)
print("  " + ", ".join(f"U+{ord(ch):04X}" for ch in nfd))
ConsoleOut [19]
CollapseExpand
NFC form: 1 code point(s), 3 UTF-8 bytes
  U+D55C
NFD form: 3 code point(s), 9 UTF-8 bytes
  U+1112, U+1161, U+11AB

The syllable 한 occupies one code point in NFC and three in NFD. A syllable without a final consonant, such as 가, decomposes into two. A pipeline that keeps the decomposed form can spend three times as many byte or code-point tokens on 한. A learned tokenizer may merge the jamo and use a different number of tokens. A normalizer that composes both inputs to the same syllable gives the tokenizer the same representation in both cases.

PythonIn [20]
CollapseExpand
non_nfc = [
    (code, sentence)
    for code, sentences in parallel_corpus.items()
    for sentence in sentences
    if unicodedata.normalize("NFC", sentence) != sentence
]
print(f"Sentences in this corpus that are not NFC: {len(non_nfc)}")
ConsoleOut [20]
CollapseExpand
Sentences in this corpus that are not NFC: 0

The audit found zero strings that change under NFC among the 126 aligned strings. Run the same check on your own corpus because normalization can affect which distinctions remain available to the model. For example, NFKC maps the fullwidth Latin letter A to A. If the source distinction matters, use an appropriate normalizer before comparing tokenizer outputs.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy