Course contentsShow
← Machine Learning and Deep Learning
Lesson 1232 of 3,53827. Pretrained Language Models: GPT Family and BeyondFree lesson

Instruction Format and Template Design

Standardizing instruction formats with system/user/assistant roles and special tokens for chat models.

Instruction Format and Template Design

You'll learn how to structure prompts with clear roles and special tokens so chat models know who's speaking and what to respond to.

Why Standardized Formats Matter

When you fine-tune a language model to follow instructions, you can't just throw raw text at it randomly. The model needs a consistent structure to understand who is saying what. Think of it like a play script: without clearly marked character names and dialogue, actors wouldn't know their lines.

The Role-Based Template System

Modern instruction-tuned models use a three-role system:

  • System: Sets behavior guidelines (e.g., "You are a helpful assistant")
  • User: The human's question or instruction
  • Assistant: The model's expected response

During supervised fine-tuning, you wrap training examples in this format so the model learns the conversation structure.

Special Tokens as Markers

Templates use special tokens (unique strings the model recognizes) to separate roles:

<|system|>You are a helpful coding tutor.<|end|>
<|user|>Explain what a loop is<|end|>
<|assistant|>A loop is a programming construct that repeats...<|end|>

These tokens act like punctuation marks for conversations. Different model families use different tokens (e.g., [INST] and [/INST] for some models, <|im_start|> for others), but the principle remains the same.

Why This Design Works

By standardizing the format across all training examples, the model learns:

  • Where each conversational turn begins and ends
  • Which text to condition on (system + user) and which to generate (assistant)
  • How to maintain context across multi-turn dialogues

Without consistent templates, the model would confuse instructions with responses or ignore system-level guidance.

Key Takeaway: Instruction format templates use role markers and special tokens to create a structured conversation format that helps models reliably distinguish between instructions they receive and responses they should generate.