DistilBERT and Ernie: the ABC's of Tokenisation

Eric Famanas

~5 min read

DistilBERT and Ernie: the ABC's of Tokenisation — original article animation

This month let's get back into something a bit more technical. As part of my research in abstracting and identifying risk signals that are present within team communications, I am having to explore different tokenisation and NLP analysis techniques to ensure an accurate semantic meaning is captured within the given context of a software development project team. During this process, I am learning more about Bidirectional Encoder Representations from Transformers, or BERT, as it's more commonly known.

Not to be confused from Bert and Ernie from Sesame Street, an old children's show in the United States by the late Jim Henson. I don't think they would tokenise words very well.

As the title implies, we will be focusing on tokenisation for models such as DistilBERT, which is a different type of BERT model which is trained via knowledge distillation, as well as some insights into the model itself.

Inspecting and Selecting Words for Tokenisation

The name DistilBERT is memorable, and it inevitably invites comparison to its larger predecessor; it's also one of the different types of models that I have tested, such as SBERT, another BERT variant, and FastText. There are different pro's and con's to the different tokenisation models, which I won't get into here. Instead, it is necessary to understand the pre-requisite, foundational knowledge about tokenisation with respect to natural language processing (NLP) systems.



Inspecting and Selecting Words for Tokenisation

In most NLP systems, tokenisation is treated as a preprocessing step, a preparation function that is executed before embeddings and transformers take over.

Raw Text
   ↓
[ Tokeniser ]
   ↓
Discrete Token IDs
   ↓
Embeddings
   ↓
Transformer Layers
   ↓
Output

Once text is segmented into tokens, the model never sees the original string again. It sees only discrete symbols drawn from a fixed vocabulary, each carrying statistical weight accumulated during training. Token boundaries are therefore not neutral; they define what counts as a unit of meaning.

Original Text:
"MicroserviceOrchestrationLayer"

Tokenised (subword):
["Micro", "service", "Or", "chestration", "Layer"]

Tokenised (subword, alternative approach):
["Micro", "service", "Or", "che", "stration", "Layer"]

There are also subword tokenisation strategies such as Byte Pair Encoding (BPE) or WordPiece; they allow models to handle rare words by decomposing them into more frequent fragments. However, these flexibility strategies comes at a cost; the fragmentation alters how context is distributed across tokens, how long-range dependencies are represented, and how specialised terminology is perceived.

Preparation is Key for Better Training Results

Tokenisation is often treated as a preprocessing detail, but from an architecture standpoint, it is the first commitment a system makes about how language will be represented.

Before a transformer layer is initialised, before weights are trained, raw text has already been segmented into discrete units drawn from a fixed vocabulary. From this point onward, the model no longer operates on whole words, or in terms of data primitives, strings; instead, it operates on token IDs. The segmentation strategy and vocabulary construction therefore define the representational space within which all subsequent learning occurs. Being unaware of this process leads to unpredictable behaviour, particularly with untrained models.



Preparation is Key for Better Training Results

This distinction becomes clearer when comparing an untrained model to a trained one; even though an untrained transformer has random weights, it still consumes token sequences produced by the same tokenisation process. Model training does not alter the vocabulary or the segmentation rules; it only adjusts how the model responds to the token boundaries it has been given.

In other words, optimisation happens within scaffolding that has been pre-defined, otherwise known as a perceptual framework. If a term, such as a series of words or even a sentence, has been fragmented into subword units, the model must learn to reconstruct its meaning probabilistically across multiple tokens before any meaning or semantic inference can even happen. If a concept is consistently represented as a single token, it continues to operate inside a different statistical profile, meaning the singular idea it represents is carried forward alongside that isolated token, e.g. as Micro-service vs. micro service, both segmentations can represent completely different concepts.

DistilBERT Bootcamp: Full Metal Tokens

Honestly, I couldn't resist the analogy here. Those of you who have served, or are even familiar with the infamous bootcamp scenes of Full Metal Jacket will be able to draw some parallels. If not, that's okay, you're not missing much :). Anyway, continuing on....



DistilBERT Bootcamp: Full Metal Tokens

....by the time distillation or parameter compression is introduced, the perceptual boundaries of the perception framework have already been established. Distillation can optimise over the learned representations of a concept or semantic, but it cannot recover distinctions that tokenisation never encoded cleanly, hence why understanding and deciding how text is discretised into tokens is so critical.

In bootcamp, we learned rules and repetition so the results become predictable and the failures obvious. Tokenisation models are no different.

DistilBERT is a good example of how important this is. Although it is smaller and computationally lighter than its parent model, BERT, it does not introduce a new tokenisation strategy; instead, it inherits the same vocabulary and segmentation rules. This means DistilBERT optimises over the same token boundaries that were fixed upstream.

Because tokenisation influences how meaning is partitioned before training, distillation operates over representations that already reflect those segmentations; if a specialised term is fragmented across multiple subword tokens in BERT, it still remains fragmented in DistilBERT and will carry its behaviour within the same perceptual framework. Therefore, it is unable recover semantic cohesion of certain key words or phrases that were never encoded as a single unit. Whole terms like Micro-service Orchestration Layer may lose their meaning entirely.

Despite these complexities, models like DistilBERT may amplify certain trade-offs without redefining them. Even though there are efficiency improvements and latency drops, the representational assumptions embedded in the BERT tokeniser remain intact. In this sense, DistilBERT is not a different way of seeing language; it is a compressed way of reasoning within the same segmented, discrete view.

Remember, Tokenise Responsibly

The nuances of tokenisation are easy to overlook because they don't routinely come up when discussing machine learning in casual conversation (yes, casually discussing machine learning, haha! What a time we live in!). Tokenising happens before any training, optimisation or NLP model comparisons. However, it is the first important architectural decision to be made about a system.



Remember, Tokenise Responsibly

DistilBERT makes this more apparent instead of complicating it; its compression reduces parameters and overall cost of inference, but it also inherits the same compartmentalised view of language that was originally established by the parent model, BERT. Where this model differs is how efficiently it operates within those rules and boundaries established prior.

Tokenisation is not a processing detail, it is the commitment that shapes everything that follows. So remember:

Tokenise responsibly.

Systems Orchestrator

CTO · Technology leadership