Module 1.1 · Deepens pages 2 & 3
Load a tokenizer, load a model, encode a prompt, generate, decode. That's the entire mechanism — no chat formatting, no memory, nothing hidden. Run it once before any of that gets added, so you see exactly what's missing.
The script
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")
model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")
prompt = "Hi, how are you?"
inputs = tokenizer(prompt, return_tensors="pt") # text -> token ids (page bc-02)
outputs = model.generate(**inputs, max_new_tokens=30) # ids in -> more ids out (page bc-03)
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) # ids -> text again
from_pretrained is doing the "download a folder, read config.json, build the right shape, load the weights in" work from the last page — one line hides all of that. Download bc-01-ten-lines.py ⬇
What you should see
python bc-01-ten-lines.py
Hi, how are you? I hope you're doing well. I've been thinking about the project for a while now, and I'm really excited about the idea of creating a
Real output from this exact script. Nothing about "reply" or "conversation" exists yet in these ten lines — that's Module 2, once a chat template is introduced.
Change prompt = "Hi, how are you?" to prompt = "The best way to learn to code is" and re-run. It reads much more like a normal reply this time — predict why before you run it: is the model doing something different, or is this prompt just a better fit for "keep writing the same kind of text"?
So what
Without a chat template, the model isn't ignoring you — it's doing exactly what it was asked: continue this text.