All courses

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

▶ Watch this lesson Start the whole course

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.

Why doesn't a base model just answer?

Type `What is the capital of France?` into a freshly pretrained model, before any post-training. Often you get no "Paris". You get more questions instead: `What is the capital of Germany? What is the largest river in Europe?` The model has seen plenty of geography, so it knows the answer. **Why does it reply like this, and how do you write a prompt that actually gets the answer?**

It guesses the document, then continues it

Pretraining taught the model one skill: given a prefix, predict how documents in the corpus continue. It has no notion of a user or a request. The prompt is just the start of some document, and the model continues it the way such documents usually go. On the web, a bare question usually sits in a quiz sheet, a homework list or a forum post. The model also copies the **quality** of the text it imitates: a sloppy-looking page gets a sloppy continuation.

Continuation as a mixture over document types

The base model generates $y$ from $p_\theta(y\mid x)=\prod_t p_\theta(y_t\mid x, y_{<t})$. Training pushes $p_\theta$ toward the corpus distribution $p$: how often $y$ follows $x$ in the corpus. Group the corpus documents by type $c$ (quiz, FAQ, forum, …): $$p(y\mid x)=\sum_c p(c\mid x)\,p(y\mid x,c)$$ The type $c$ is never written down. Because $p_\theta$ approximates $p$, the model implicitly averages over it in the same way. **Prompting a base model means choosing $x$ so that $p(c\mid x)$ piles onto a type whose usual continuation is what you want.**

Worked numbers: bare question vs FAQ prefix

These numbers are illustrative. **Prompt A** is the bare question plus a newline. Say the model's belief over document types is quiz list 0.5, forum 0.3, FAQ 0.2. The chance the next line is the answer is 0.1, 0.2 and 0.9 for those types. $0.5(0.1)+0.3(0.2)+0.2(0.9)=0.29$. **Prompt B** has a header `Geography FAQ (reviewed by experts)`, one example pair `Q: …Spain?\nA: Madrid.`, then `Q: …France?\nA:`. Now FAQ gets 0.98 and its answer chance is 0.95. Other types get 0.02, with answer chance 0.5. $0.98(0.95)+0.02(0.5)\approx0.94$.

Building a document-prefix prompt

Three design moves: 1. Add a header that names a trustworthy kind of document. 2. Add one example that fixes the format. 3. End the prompt exactly where the answer should begin. The model doesn't know the answer is "done". It keeps writing the document, here the next Q and A. So you cut its output at a **stop pattern**: the text that starts the next item.
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

A base model doesn't answer; it continues whatever document your prompt looks like, copying that document's format and quality. To steer it, write the opening of a document whose natural next words are the output you want, then cut the output where that item ends.

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.