What the Model Actually Sees
Almost nobody has printed the complete input their own feature sends. Doing it once, and accounting for every part, is the start of treating it as a designed object.
Print the whole thing once
Here is an exercise worth doing before reading any further, on whatever feature you currently have running. Find the place where the input is assembled, add a line that writes the finished string to a file, run one real request, and read the file.
Almost nobody has done this. The input exists only as the result of running the assembling code, and reading that code is not the same as reading its output, because the code is a set of branches and the output is one specific document.
What the exercise finds, reliably, is some combination of the following: an instruction contradicting another instruction three hundred lines below it, a piece of a previous feature nobody removed, a placeholder that was never filled so the input literally contains the words insert context here, a date that is six months stale, an example of the desired output that no longer matches the desired output, and several thousand tokens of a document that was supposed to be summarised and was pasted in whole.
body = assemble(system_text, examples, passages, question)
open("/tmp/last_input.txt", "w").write(body) # the whole thing, as sent
print(len(body), "characters", count_tokens(body), "tokens")
reply = model(body)The pieces and who wrote each
Having printed it, the next step is to account for every part. A typical input in a working feature has five or six, and they were written at different times for different reasons.
| tokens | share of the input | sent every time | last changed, months ago | |
|---|---|---|---|---|
| the instruction about tone and role | 310 | 9 | 1 | 14 |
| rules added after complaints | 540 | 16 | 1 | 2 |
| three worked examples | 620 | 18 | 1 | 9 |
| six retrieved passages | 1300 | 38 | 0 | 0 |
| the conversation so far | 580 | 17 | 0 | 0 |
| the question | 60 | 2 | 0 | 0 |
The table has an uncomfortable implication. The piece that is most carefully considered, which is usually the question or the retrieved material, is a small part of what the model reads, and the majority of the input is historical.
| step | the part | who wrote it | when | has anybody read it since |
|---|---|---|---|---|
| 1 | the role and tone instruction | whoever built the prototype | at the start | no |
| 2 | do not speculate about pricing | a product manager, after one incident | month nine | no |
| 3 | always reply in British English | a different person, after a different incident | month eleven | no |
| 4 | the worked examples | an engineer, copied from a notebook | month three | no |
| 5 | the passage template | the search work, generated | month seven | the code, not the output |
The part you send every time
Of the pieces, some vary with the request and some do not. The fixed part has a property the rest lack: it is multiplied by every single request you serve.
| step | the part sent every time | tokens, once | tokens a day at 4,000 requests | times the question's own 60 tokens | what happened |
|---|---|---|---|---|---|
| 1 | the instruction about tone and role | 310 | 310 times 4,000, so 1,240,000 | 310 divided by 60, so about 5 times | Written for a prototype fourteen months ago and sent a million and a quarter times a day ever since, unread. |
| 2 | rules added after complaints | 540 | 540 times 4,000, so 2,160,000 | 540 divided by 60, so 9 times | The row worth arguing about. Each rule was added once, after one complaint, and together they are the largest daily cost of anything nobody has read as a set. |
| 3 | three worked examples | 620 | 620 times 4,000, so 2,480,000 | 620 divided by 60, so about 10 times | Examples earn their place more often than rules do, and they are still the single largest fixed item here. |
| 4 | the three of them together | 310 plus 540 plus 620, so 1,470 | 1,470 times 4,000, so 5,880,000 | 1,470 divided by 60, so about 24 times | Read the row backwards and it sets a length rather than a price: a budget stated in tokens a day, divided by the four thousand requests, is what the fixed part is allowed to be. That is what turns an open ended document into one with an edge. |
This is the argument for the instruction lessons that follow being about brevity as well as clarity. A rule that earns its place is worth sending four thousand times a day. A rule added after one incident, covering a case that has not recurred since, is being sent four thousand times a day as well.
Tokens rather than words
The last thing to get right is the unit. Models read, and bills count, pieces of words rather than words, produced by a scheme that splits common sequences into single pieces and rare ones into several.
For ordinary English prose the ratio is roughly four characters to a piece, so a thousand words is about thirteen hundred pieces. The ratio is not stable. Code is worse, because punctuation and indentation each count. Identifiers in code are worse again, since an unusual variable name may be five pieces. Languages other than English are usually worse, sometimes by a factor of two or three for the same meaning. Long numbers, identifiers and dates are all expensive.
| words | characters | tokens | characters per token | |
|---|---|---|---|---|
| a paragraph of English prose | 120.0 | 680.0 | 160.0 | 4.3 |
| the same text in a language with long compounds | 96.0 | 720.0 | 310.0 | 2.3 |
| a function in Python | 45.0 | 520.0 | 190.0 | 2.7 |
| a list of forty order identifiers | 40.0 | 480.0 | 320.0 | 1.5 |
The next lesson is about the largest fixed piece in most inputs, which is the instructions, and about why a rule that reads well often fails in practice.
Recap
- The input to a model in a real feature is assembled by a program from several pieces, most of which were written at different times by different people for different reasons.
- Printing the whole assembled input, exactly as it is sent, is a half hour of work that reliably finds something nobody meant to be there.
- The fixed part is sent on every single request, so its length is multiplied by your traffic and is the one piece worth measuring before anything else.
This is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents