Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/course/en/chapter11/section2.ipynb
Views: 2935
Exploring Chat Templates with SmolLM2
This notebook demonstrates how to use chat templates with the SmolLM2
model. Chat templates help structure interactions between users and AI models, ensuring consistent and contextually appropriate responses.
SmolLM2 Chat Template
Let's explore how to use a chat template with the SmolLM2
model. We'll define a simple conversation and apply the chat template.
Apply chat template without tokenization
The tokenizer represents the conversation as a string with special tokens to describe the role of the user and the assistant.
Decode the conversation
Note that the conversation is represented as above but with a further assistant message.
Tokenize the conversation
Of course, the tokenizer also tokenizes the conversation and special token as ids that relate to the model's vocabulary.
Exercise: Process a dataset for SFT
Take a dataset from the Hugging Face hub and process it for SFT.
Difficulty Levels
🐢 Convert the `HuggingFaceTB/smoltalk` dataset into chatml format.
🐕 Convert the `openai/gsm8k` dataset into chatml format.
Conclusion
This notebook demonstrated how to apply chat templates to different models, SmolLM2
. By structuring interactions with chat templates, we can ensure that AI models provide consistent and contextually relevant responses.
In the exercise you tried out converting a dataset into chatml format. Luckily, TRL will do this for you, but it's useful to understand what's going on under the hood.