Instruction Dataset Schemas: Alpaca, ChatML, and ShareGPT Multi-Turn Conventions
Agent-Assisted Exploration
Prerequisites
Completion of Day 60 foundational pre-training assessment and Python JSON data modeling.
Learning Objective
Master the structural schemas of instruction datasets, distinguishing between Alpaca single-turn format, ChatML role delimiters, and ShareGPT multi-turn conversational trees.
Instructions
Study source: within this activity's existing reading/practice time, use Hugging Face LLM Course: Fine-tuning LLMs, Chapter 11.2: Common Template Formats; Hands-on Exercise, then explain one connection to the local task in your own words. Keep the local exercise and acceptance checks; use its original explanation if the external source is unavailable. 1. Inspect Stanford Alpaca schema: top-level keys 'instruction' (task description), 'input' (optional context), and 'output' (target response).
2. Contrast with ChatML markup format: structured text wrapped in explicit demarcation tokens (<|im_start|>system...<|im_end|>, <|im_start|>user...<|im_end|>, <|im_start|>assistant...<|im_end|>).
3. Analyze ShareGPT multi-turn schema: a list of message objects under 'conversations' with alternating 'from' ('human'/'gpt') and 'value' fields.
4. Understand why ambiguous plain text delimiters (such as 'User: ... Assistant:') suffer from prompt injection and delimiter hijacking, whereas dedicated boundary tokens enforce strict role sandboxing.
Practice & Prediction Log
Write a Python normalization function normalize_to_chatml(record) that detects whether a record is Alpaca format or ShareGPT format and returns a canonical list of message dictionaries [{'role': ..., 'content': ...}]. Test with both empty and populated 'input' fields.
For Alpaca with an 'input' field, combine 'instruction' and 'input' into the user message, or structure 'instruction' as system context and 'input' as user query.
def normalize_to_chatml(record):
messages = []
if 'instruction' in record and 'output' in record:
if record.get('input', '').strip():
content = f"{record['instruction']}\n\nInput:\n{record['input']}"
else:
content = record['instruction']
messages.append({'role': 'user', 'content': content})
messages.append({'role': 'assistant', 'content': record['output']})
elif 'conversations' in record:
role_map = {'human': 'user', 'gpt': 'assistant', 'system': 'system'}
for turn in record['conversations']:
messages.append({'role': role_map.get(turn['from'], turn['from']), 'content': turn['value']})
return messages
Write a schema normalization pipeline that converts both Alpaca and ShareGPT records to verified ChatML message structures with 100% field compliance.
Authoritative Source Resources & Provenance
Hugging Face LLM Course: Fine-tuning LLMs
Relevant Section / Range: Chapter 11.2: Common Template Formats; Hands-on Exercise
Verified Version & Date: Public edition checked 2026-11-01; moving pages may change
Sequenced templates, supervised fine-tuning and evaluation teaching with exercises/quizzes. LoRA method and memory claims are checked against the original paper, PEFT and the local parameter ledger, not accepted wholesale from Chapter 11.4.
Python, PyTorch, language-model training and the preceding chat-format lessons.
Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.
Compared Candidate Sources & Selection Analysis (2)
Retained for initialization and the low-rank method, not a beginner teaching sequence.
Retained for actual API and implementation defaults; reference documentation is not a complete teaching course.
Stanford Alpaca: An Instruction-following LLaMA Model
Relevant Section / Range: README 'Data Release' (alpaca_data.json fields instruction, input, output)
Verified Version & Date: Stanford CRFM Release (Verified: 2026-10-30)
Pioneering instruction fine-tuning dataset schema establishing the instruction/input/output format widely used across open source LLMs.
LLM fine-tuning concepts, Python dictionary data structures.
Standard Alpaca schemas and data transformation scripts are completely specified in lesson materials.
Compared Candidate Sources & Selection Analysis (2)
Pioneered academic instruction tuning across NLP benchmarks; Alpaca format provides the standardized single-turn JSON schema for consumer fine-tuning.
Commercially permissive instruction dataset; Alpaca establishes the architectural schema archetype.
OpenAI ChatML (Chat Markup Language) Specification and Guide
Relevant Section / Range: chatml.md: ChatML v0 message format (<|im_start|>role ... <|im_end|>)
Verified Version & Date: openai-python tag v0.28.1, last MIT-licensed release containing chatml.md (Verified: 2026-10-31)
Standardized token delimiter schema (<|im_start|>, <|im_end|>) separating system, user, and assistant roles to prevent prompt injection and role confusion.
Tokenizer special token concepts, conversation tree data structures.
Full ChatML delimiter specs, role headers, and token stream representations are embedded in the curriculum.
Compared Candidate Sources & Selection Analysis (2)
Uses Human:/Assistant: plain text delimiters; ChatML provides formal token-level demarcation with dedicated boundary tokens.
FastChat conversation template; ChatML is the universal token-delimited primitive.