Base models continue documents
Explain that a pretrained model imitates whatever kind of document the prompt looks like, rather than answering questions. Design a prompt as a document prefix to steer a base model.
Builds on: Building a pretraining corpus, From base model to assistant
What the animation says
A question, no answer
Take a freshly pretrained model. No chat training yet, only pretraining. Type: what is the capital of France? Then press enter. It has read plenty of geography. It knows the answer. So what does it most likely write next?
It continues a document
More questions. Not Paris. Here's why. Pretraining taught one skill: given the start of a document, predict how it continues. There is no user and no request. Your prompt is just the top of some page. On the web, a bare question like this sits in a quiz sheet, a homework list, or a forum post. Those pages go on with more questions, so the model does too. It also copies quality: a sloppy-looking page gets a sloppy continuation.
A mix of document types
Let's make that precise. The page type is never written down. So the model spreads its belief over types: quiz list one half, forum point three, FAQ point two. Each type has its own chance that the next line is the answer: point one, point two, and point nine. Weight and add: point oh five, plus point oh six, plus point one eight. About point two nine. Now put an FAQ header and one example question with its answer above. What happens to that chance?
Write the top of the right page
It jumps to about point nine four. The header and example push FAQ to point nine eight, with an answer chance of point nine five. All other types share the remaining point oh two, at one half. Together, about point nine four. So prompting a base model means choosing a prefix that points at a page whose next words you want. Three moves: a header naming a trustworthy document. One example that fixes the format. And end exactly where the answer begins.
Know where to stop
Here it is as code. This function glues together the header, the example, and the new question. The prompt ends on A colon, so the next words are the answer. But the model doesn't know the answer is done. It keeps writing the page: Paris, then the next question. So you cut its output at a stop pattern: the text that starts the next item. Where should the cut go? Tap it.
Remember
That cut is what this split line does. It keeps just Paris. A base model doesn't answer. It continues whatever document your prompt looks like, copying its format and its quality. To steer it, write the opening of a page whose natural next words are what you want. Then cut where that item ends.
It guesses the document, then continues it
Continuation as a mixture over document types
Worked numbers: bare question vs FAQ prefix
Building a document-prefix prompt
def doc_prompt(question):
header = "Geography FAQ (reviewed by experts)\n\n"
shot = "Q: What is the capital of Spain?\nA: Madrid.\n\n"
return header + shot + f"Q: {question}\nA:"
prompt = doc_prompt("What is the capital of France?")
print(prompt)
# A base model continues the document past the answer,
# so cut at the start of the next item.
stop = "\n\nQ:"
fake_output = " Paris.\n\nQ: What is the capital of Italy?"
print(fake_output.split(stop)[0])
Remember
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses