Reading each word from its meaningful piece

About a third of Khmer words were being labelled from a blank piece that looks the same for every word. Moving the label to the first piece with letters improved all three matched training runs.

Summary

FindingEvidenceSize
Words whose label was read from a blank "▁" pieceValidation set, 2,088 words37.4% of words, 33.6% of name starts
Effect of the fix aloneMatched runs, only the label position changed; 3 seeds+2.3 F1 on average; 3 of 3 seeds better
Release that introduced it (v17)Not controlled: the training recipe also changed+9.7 pooled F1 (95% range +3.5 to +16.4)
The problem

The model was asked to judge a blank tile

In plain words: Neam's language model doesn't read whole words. It cuts each word into smaller pieces first. For Khmer, it often adds an empty "start of word" piece in front. The usual recipe takes each word's answer from its first piece, so for a third of words the model had to decide "is this a name?" at that empty piece. It is the same piece for every word, so it can only borrow clues from its neighbours, not from the word itself.

Neam labels whole words: "this word starts a person's name", "this word continues an organization", and so on. But Khmer ALBERT, the model Neam is built on, works on subwords: a SentencePiece tokenizer splits each word into one or more pieces. A piece that begins a word carries a "▁" marker.

Often the marker is attached to the first piece, as in ▁កម្ពុជា. But when Khmer words are passed in already split, the tokenizer frequently emits the marker as a piece of its own, followed by the real content: ▁ + រាជ. On Neam's validation set this happens to 37.4% of words and 33.6% of the words that start a name.

The standard recipe for word labelling with BERT-style models puts each word's label on its first piece and ignores the rest. With a bare "▁" in front, that first piece is the same token for every word. Its representation inside the model isn't empty, because the transformer mixes in context from the surrounding pieces. But it has no letters of its own, so the label has to rest on borrowed context instead of the word itself.

Try it

See which piece each method reads

The pieces are real outputs of Neam's tokenizer. Switch methods to see which piece each one takes the label from.

piece the label is read from label read from a blank "▁"

What the switch changes: only the highlight showing where each method reads the label. The tags under each word are the released model's predictions (trained with the meaningful-piece method) and stay the same in both views. The switch doesn't rerun a first-piece model; the controlled test below compares the two methods.

The fix

Skip the blank, read the first real piece

In plain words: if a word starts with an empty piece, Neam takes the answer from the next piece instead, the first one that actually contains Khmer letters. Nothing else about the model changes.

For word j split into pieces tj,1 … tj,n, the label goes on the first piece that isn't a bare marker. All other pieces are ignored by the training loss, exactly as before. The same choice is saved in the model's configuration, so training and prediction always read the same piece.

π(j) = min { k : tj,k ≠ "▁" } instead of π(j) = 1
Technical detail: the code in Neam

From neam/preprocess.py. word_ids maps each piece to its word; tokens are the piece strings.

positions, content = {}, set()
for position, word_id in enumerate(word_ids):
    if word_id is None or word_id in content:
        continue
    if word_id not in positions:
        positions[word_id] = position          # first piece, as a fallback
    if tokens[position].strip('▁'):        # has real content
        positions[word_id] = position          # read the label here
        content.add(word_id)

A word made only of markers keeps its first piece. Checkpoints trained before this change have no recorded position and keep reading the first piece, so older models still load correctly.

Evidence

Does it really help?

In plain words: we trained pairs of models that were identical except for this one choice. The new method won every time once the models were trained properly. That controlled test is the real evidence. The release that introduced it also jumped a lot, but other things changed in that release too, so the bigger number can't all be credited to this fix.

Controlled test: only the label position changes

This is the evidence that the fix itself helps.

Validation F1 (%), five epochs, same data and settings, three seeds.

SeedFirst pieceMeaningful piece
4270.3271.62
4367.2669.91
4469.0672.07
Mean68.8871.20 (+2.3)

The new method found 3 to 5 more exact entities on every seed, and organizations improved every time.

In the release history (not a controlled test)

v12 → v17, the release that introduced the fix. Exact-span F1 (%).

v12 held-out
62.1
v17 held-out
74.3
v12 people
69.4
v17 people
93.9
v12 organizations
40.3
v17 organizations
55.6

Pooled over both test sets the step was worth +9.7 points (95% range +3.5 to +16.4), so the release clearly improved. But v17 also changed how models were trained (one five-epoch run from the base model, at a higher learning rate), and it was the best of three seeds. With the old first-piece method, the new recipe scored about the same as v12 (68.88 vs 69.03 validation), which suggests the alignment did much of the work. Still, read +9.7 as the gain of the whole release, not of alignment alone.

Where it does not help

With only two training epochs, both methods underfit and the advantage disappears (56.34 vs 54.83 mean). The model needs enough training for its labelling layer to use the extra information. The controlled runs used the validation labels of the time (107 entities) and the evaluation sets are small, so the exact size of the gain is uncertain even though its direction is not.

Prior work

What was known, and what Neam adds

In plain words: other developers had already run into the blank piece, and researchers have compared ways of reading a word from its pieces. We didn't find anyone who measured this exact problem for Khmer and showed how much fixing it is worth.

Already known

  • The stand-alone "▁" piece has been reported by developers using the multilingual XLM-R model, for example in Hugging Face Transformers issues #8958 and #9637. In practice, people often work around it.
  • Ács, Kádár and Kornai, "Subword Pooling Makes a Difference" (EACL 2021), compared first-piece, last-piece and learned ways of reading a word, across nine languages.

What Neam adds

  • Measures how often the blank piece decides a Khmer word's label: 37.4% of words and 33.6% of name starts.
  • A controlled test that isolates the fix, and its effect on a released system: the largest single gain, with a confidence interval above zero.
  • A one-line rule that is saved with the model, so training and prediction can't drift apart.

We searched for earlier work that measures this fix and found none, but we can't rule out that it exists. The fair description is: a known tokenizer pitfall, measured and fixed for Khmer NER in Neam.

Credits

Built on the work of

Content-subword alignmentNeamThe rule, the measurements and the controlled test on this page.
Khmer ALBERT small · Seanghay YathKhmer NLPA Cambodia-based developer. The pretrained Khmer model every Neam member is fine-tuned from (seanghay/albert-khmer-small, Apache 2.0). Its tokenizer produces the pieces shown above.
SentencePiece · Kudo & Richardson (Google)MethodThe subword tokenizer, including the "▁" word marker.
ALBERT · Lan et al. (Google)MethodThe model architecture, which shares weights across layers to stay small (9.3M parameters per member).
First-subword labelling · Devlin et al. (BERT)MethodThe standard recipe this case study improves on.
Hugging Face TransformersLibraryThe fast tokenizer's word mapping that makes the alignment possible.