Concepts / Tokenization and Token IDs in Language Models

Tokenization and Token IDs in Language Models

Running a pretrained model on a spam instruction and reading the generated text is a direct way to test whether it already follows instructions.

  • Programming

Testing a Model Before Adapting It

Suppose you plan to turn a language model into a spam classifier. A natural first question is whether the model can already do the job before you invest any effort in adapting it. The simplest test is to give the model an instruction in plain language, ask it to answer with a fixed set of labels, and then read what it produces. This article uses that test as a way into how a model reads its input as token IDs, what it returns, and what that output tells you about the training the model has received so far.

The summary of the source puts the idea directly: running a pretrained model on a spam instruction and reading the generated text is a direct way to test whether it already follows instructions. Everything you need to answer the question is in that generated text.

Sending the Instruction Through the Model

The instruction in this practice asks whether a short message is spam and requests an answer of either yes or no. The message is a typical promotional line claiming the reader is a winner and has been specially selected for a cash prize and an award. The model does not read the instruction as letters on a screen. It receives the instruction as a sequence of token IDs, which are integers that stand in for pieces of text. The model then generates a continuation of a fixed length, and that continuation is converted back into readable text.

Spam instructionplain-language questionwith yes or no label setToken IDsintegers representing thepromptPretrained modelgenerates a continuationGeneratedcontinuationfixed length, as token IDsReadable textconverted back from IDsconverted tofed inproducesconverted back
Where does the instruction go in, where does the generated text come out, and at what point does the model's output stop matching what was asked?

The conversion steps are the important part to track. Text goes in as token IDs and comes out as token IDs before it is shown to you as text. A token ID is the number the model actually operates on, so the model's behavior is always a behavior over sequences of these integers. The source does not describe how a particular tokenizer splits a sentence, so the next illustration is generic: it only shows that each piece of the prompt is mapped to an integer.

Isinteger token IDthisinteger token IDmessageinteger token IDspaminteger token ID?integer token ID
How does a sentence become a sequence of token IDs, and how does each token map to a specific integer in the vocabulary? The exact splits and numbers depend on the tokenizer, so these labels are illustrative only.

Making a Prediction Before the Reveal

Before you look at what the model actually returns, make a prediction. The prompt is clear, the label set is restricted to yes or no, and the message is an obvious example of spam. If the model were behaving like a classifier that follows instructions, what would you expect the first words of its continuation to be?

What do you think happens?

If the model were following the instruction as a classifier, what would the first words of its continuation be?

  • A yes or no label

  • A new spam message

  • A repeat of the instruction itself

  • A request to explain its reasoning

Reveal answer
Answer:

A yes or no label

The instruction names a restricted label set of yes or no and asks for a spam decision. An instruction-following classifier would answer with one of those labels first.

Reading the Continuation for Structure

The reveal is the core of this practice. Once you have run the test, the output is the evidence, and your job is to compare it against the expectation you formed a moment ago. The point is not that the model produced something unusual. The point is that its output differs from what an instruction-following classifier would produce.

When you read the generated text, look at the structure rather than at its surface meaning. The model does not stop after a single answer. It keeps producing words that mirror the form of the prompt, including another request to decide whether a text is spam, followed by the beginning of a new message. The output therefore looks like a continuation of a document, not a reply addressed to you.

Worked example

Diagnosing the spam test output

You give a pretrained model the spam instruction with the yes or no label set and read the continuation. How do you decide whether it follows the instruction?

  1. 1
    Check the first words

    An instruction-following classifier would begin with yes or no. If the continuation begins with something else, the instruction has not been carried out.

  2. 2
    Check the form

    Look for whether the output answers you or extends the prompt. Repeating the request for another decision and then starting a new message means the output mirrors the prompt's pattern.

  3. 3
    Separate knowledge from behavior

    The output shows a failure to treat the instruction as a request. It does not show that the model lacks knowledge of what spam is.

Result

The model is struggling to follow the instruction. It continues the pattern of the prompt rather than returning the requested label.

Why Pretraining Alone Falls Short

The source gives a direct explanation for the result. The model has only undergone pretraining and has not undergone instruction fine-tuning. Pretraining teaches a model to predict and produce text in general. It does not, by itself, teach the model to treat a particular piece of text as a command and to respond to it in the expected format.

Where Instruction Fine-Tuning Fits

Instruction fine-tuning is the step meant to close this gap. It trains the model on examples of instructions so that its ability to follow those instructions improves. The source frames this as the reason the next step is to prepare the model for classification fine-tuning. The order matters: the model first needs to be able to follow instructions in general, and classification fine-tuning then specializes it for the spam task.

Pretrainingpredict and produce text ingeneralInstructionfine-tuninglearn to followinstructionsClassificationfine-tuningspecialize for the spamtaskthenthen
In what order do the training stages happen, and what does each stage add to the model before the next one begins?

Read the pipeline as a dependency chain. Each stage adds a capability that the next stage assumes is already present. Classification fine-tuning assumes the model can already follow instructions in general, which is exactly what the spam test showed it could not yet do.

Mistakes When Reading the Test Output

  • Common mistake

    Treating the continuation as a wrong answer to the question

    What it looks like

    Seeing extra text after the first words and concluding the model answered yes but added a note.

    Why it fails

    The model does not stop after a single answer. Its output keeps the prompt's form and starts a new message, so it is a continuation rather than a reply.

    Do this instead

    Judge the output by its structure: whether the requested label appears at the start and whether the model answers at all.

  • Common mistake

    Concluding the model does not know what spam is

    What it looks like

    Deciding the model has no understanding of promotional messages after one bad output.

    Why it fails

    The source locates the problem in instruction following, not in missing knowledge of spam.

    Do this instead

    Describe the failure as a failure to carry out the instruction in the requested form.

  • Common mistake

    Assuming instruction fine-tuning is the same as classification fine-tuning

    Why it fails

    The source places instruction fine-tuning first, to teach following instructions in general, and classification fine-tuning second, to specialize for the spam task.

    Do this instead

    Keep the two stages separate and in that order.

  • Common mistake

    Forgetting that the model works on token IDs, not on letters

Trace the Test Yourself

EASY

Write out, in order, the path a spam instruction takes from the moment you type it to the moment you read the model's continuation. Name where text is converted to token IDs and where the output is converted back. Then state, in one sentence, what a pretrained-only model's continuation would need to look like to count as following the instruction.

Hints
  • Start with the instruction as text and end with readable text.
  • The model operates on token IDs in between.
  • An instruction-following answer begins with one of the requested labels.
MEDIUM

Suppose a model's continuation begins with a new spam message instead of yes or no. Explain whether this shows the model lacks knowledge of spam or fails to follow the instruction, and which training stage the source says would address it.

Hints
  • The source separates behavior from knowledge.
  • Look for the stage that teaches following instructions.

Key Takeaways

  • A pretrained model receives the instruction as a sequence of token IDs, generates a fixed-length continuation, and that continuation is converted back into readable text.
  • A pretrained-only model may continue the prompt's pattern instead of returning the requested yes or no label, which shows it is struggling to follow instructions.
  • The source attributes this to the lack of instruction fine-tuning, not to missing knowledge of spam.
  • Instruction fine-tuning comes before classification fine-tuning, because the model must first learn to follow instructions in general before it is specialized for the spam task.

Related concepts

More concepts starting with T