You may have noticed. Our model keeps rambling, and repeating itself. That's because it's a base model. Most models come in two versions, base, and instruct.
A base model has only been pretrained. It continues text, like a very good autocomplete. An instruct model is a base model that was then fine-tuned, on many examples of questions and good answers. So it follows instructions, and knows when to stop. In other words, every instruct model is itself a fine-tuned model.
We ask both versions the same question. The instruct model gets the question through its chat template, which we'll explain next. The base model has no template, so it gets plain text. Run it. The base model gives one sentence, then repeats it, again and again. The instruct model gives a proper answer. Still small, and not perfect, but it's trying to help.
app.pypython
from transformers import AutoTokenizer, AutoModelForCausalLMquestion = "What is a bookshop?"for name in ["HuggingFaceTB/SmolLM2-135M", "HuggingFaceTB/SmolLM2-135M-Instruct"]: tok = AutoTokenizer.from_pretrained(name) model = AutoModelForCausalLM.from_pretrained(name) if tok.chat_template: ids = tok.apply_chat_template( [{"role": "user", "content": question}], add_generation_prompt=True, return_dict=True, return_tensors="pt") else: ids = tok(question, return_tensors="pt") out = model.generate(**ids, max_new_tokens=30, do_sample=False) print(f"== {name.split('/')[1]}") print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True).strip())
Output
== SmolLM2-135M
A bookshop is a place where you can buy books. It is a place where you can buy books,
and it is a place where
== SmolLM2-135M-Instruct
A bookshop is a place where you can find a wide variety of books, from fiction and non-
fiction to children's and children's-themed
So which version should you start from? Usually the instruct version. It already understands questions and answers, so it needs fewer examples. Start from a base model only when you want full control over the format, or when you have lots of data. In our project, we'll start from the instruct model.
Let's recap. A base model only continues text. An instruct model was fine-tuned to follow instructions. And we'll usually fine-tune an instruct model. Next, the chat template that instruct models need.
Key takeaways
Base: continues
Instruct: follows
Start from instruct
Next up: Chat Templates — how a conversation becomes text