Skip to content
Essay on priming language models
Menu
Appendix A, contents

Written by Klas Nevrin

This appendix

  1. A.1 One step, the whole context
  2. A.2 Only backward
  3. A.3 Word order
  4. A.4 Many heads, many layers
  5. A.5 Length
  6. A.6 Patterns from earlier in the context
  7. A.7 Searching by meaning
  8. A.8 What follows for a priming ecology, and what does not

All parts

  1. Introduction
  2. 1. What a polyphonic priming ecology is
  3. 2. How the priming texts are written
  4. 3. Holding many ways of knowing together
  5. 4. Why texts can shape what a model writes
  6. 5. Keeping the texts present over time
  7. 6. Where the thinking comes from
  8. 7. Who answers for what the model writes
  9. 8. Building a priming ecology
  10. Appendix A. Inside the model, step by step
  11. Appendix B. How to tell whether it works
  12. Appendix C. AI today, its uses and risks

Inside the model, step by step

The appendix in brief, 14–17 min

At each step, every attention head shares a fixed attention budget among the earlier tokens, so whatever gains weight takes it from the rest.

What one head attends to is one of many contributions mixed before a word is chosen.

Long contexts cost more, and material in their middle tends to be used less well than at the ends, though the studies do not separate length from position.

A polyphonic priming ecology's texts and any outside text it fetches arrive by the same channel. Supplying texts again fits the mechanism and promises nothing; a text pulling several ways fits it too, though the mechanism does not show the pulls.

This appendix is for readers who want the mechanism. The main text says that a language model writes from what stands in its context, and that texts placed there can shape what it writes; here that claim is followed inside the model, one step at a time. The appendix shows how the next token (a word or part of a word) is chosen from the context, which is all the text the model has in front of it at that moment; why an instruction can lose weight as a conversation grows; and why material placed in the context can pull a text in more than one direction.

Sections A.1 to A.6 follow attention, the part of a model that lets the pieces of a text bear on one another. A.7 describes how documents are searched by meaning, which is how a knowledge base, a collection of texts kept outside the model from which passages are fetched when a question calls for them, reaches the context. A.8 says what the mechanism does and does not imply for a polyphonic priming ecology, the way of working this text describes (chapter 1 takes the name apart).

The appendix describes the transformer, the architecture today's large language models are built on. Other architectures are being researched, and some models combine attention with other mechanisms; the transformer is described here because the models this text discusses are built on it, and what is said about the mechanism holds only as far as that remains so. Nothing in A.1 to A.7 is my own finding, and none of it is specific to priming ecologies apart from the fold-out on the word vector and one sentence in A.7 on the practice's word resonating.

A.1One step, the whole context

When a model is about to write the next token, everything in its context is available to it: the provider's instructions, the texts of a priming ecology where one is in use, the conversation, the words the model has itself just written. Inside the model, each token is held as a long list of numbers, and those lists are passed through many layers. The part of each layer that lets tokens bear on one another is called attention.

Each position in the text produces three things. A query is something like a question that position asks of the rest of the text. A key is something like a label each position offers, saying what it has. A value is what that position contributes if it is attended to. The paper that introduced today's architecture describes the mechanism in one sentence: "An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors".1 A vector, here, is simply a list of numbers. A textbook explains where the names come from: they "were inherited from the field of information retrieval", and the comparison of a query with the keys "returns a measure of similarity", so that how much a position draws on another depends on "the relative similarities between the nth query and all of the keys".2 The similarity is learned in training; it is not a matter of shared words. For example, it can let a word such as it draw on the noun it refers to.

What comes out is a mixture. "The output is computed as a weighted sum of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key".3 The scores of that comparison are passed through a function called softmax, which turns them into weights that "are non-negative and sum to one".4 That has a consequence the textbook states directly: the keys "'compete' with one another to contribute to the final result" (210). Each layer runs many such comparisons side by side, each called an attention head (A.4 says more). In one head, at one step, attention is a fixed budget shared out over the context. If one part of the text gets more of it, the rest gets less.

Figure A.1 shows one such step for one head. The thickness of each line is the weight; the line widths together make up the whole budget.

Figure A.1 One step, the whole context

A short context drawn as a row of tokens: an instruction, a fetched entry, a question, the answer so far. The last token in the context sends a query; that token and every earlier one offer a key; lines of different thickness show the weights, each line standing for the combined weight on one part of the text, the widths adding up to one; below, the weighted mixture of values.

Tap the drawing to open it larger
When a model is about to write its next token (a word or part of a word), every earlier token in its context can bear on it. At the last position in its context, the model compares that position with itself and every earlier token, and the resulting weights add up to one: if one part of the text gets more attention, the rest gets less. This is how the attention mechanism in today's models works5. The weights shown are illustrative.

A.2Only backward

A model that writes text may attend, at each position, only to that position itself and to the positions before it. The original paper puts it this way: the design is modified "to prevent positions from attending to subsequent positions", so that the prediction for a position "can depend only on the known outputs at positions less than i".6 The textbook calls this masked self-attention: each position "can only attend to its own embedding and those of tokens earlier in the sequence".7 An embedding is the list of numbers that stands for a token.

Two consequences follow. Everything the model has written so far is part of what it attends to when it writes the next token, so an early choice shapes what follows. And the model writes in a loop: it "outputs the probabilities over possible subsequent tokens", one is picked, and "the new extended sequence can be fed back" to produce the next.8

A.3Word order

Attention by itself does not know in which order tokens come. The textbook makes the point with a sentence: "The woman ate the raccoon has a different meaning than The raccoon ate the woman".9 Order therefore has to be added: "we must inject some information about the relative or absolute position of the tokens in the sequence".10 Models can also encode how far apart two tokens are, since "the absolute position of a word is much less important than the relative position between two words".11 Where a text stands in the context, and how far it lies from the point of writing, is therefore part of what the model works from.

A.4Many heads, many layers

A model does not run attention once. It has many attention heads in each layer, each with its own queries, keys and values, so that it can "jointly attend to information from different representation subspaces at different positions".12 Roughly, each head can pick up a different kind of relation between the same words. One head might, for instance, weigh the instruction heavily while another follows the last few words. And there are many layers. A model of a few years ago that the textbook describes had 96 layers with 96 heads each;13 the exact designs of today's closed models are not published.

Attention is only part of each layer. After it, a further network, the same one for every position, is applied to each position separately, and what each part computes is added to what was already there.14 Each position thus carries a running sum, often called the residual stream, which every layer reads from and adds to. Only at the end of all the layers does the model produce its scores for every token in its vocabulary, and softmax, the function that produced the attention weights in A.1, turns these scores into probabilities. Temperature, the setting for how often the less likely tokens are actually chosen, acts at this last step: every score is divided by the same number before softmax is applied, which changes neither which tokens are candidates nor their order (section 4.3 says more). So a large attention weight at one step, in one head, does not decide what is written. It is one of a great many contributions that are mixed, transformed and passed on before a word is chosen.

A.5Length

Every token attends to every earlier token, so the work grows quickly with length: "the computational complexity scales quadratically with the length of the sequence".15 With full attention over the whole text, doubling the text roughly quadruples the work of comparing tokens with one another. Within one answer, much of the work on earlier tokens is kept and reused as the model writes on (224). Across separate requests to the model the whole context is processed again unless the provider has kept the earlier work, and where it has not, a long context costs more at each request (section 8.9 gives estimates in energy).

Where material stands in a long context also changes how well it is used. Three findings bear on this, each measuring something different and each with its limits. In one study, performance "is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts".16 Another found that models give strong attention to the very first tokens of a text "even if they are not semantically important", a pattern its authors call an attention sink.17 And a study of instruction drift measured the share of attention that one head in one model gave to the system prompt (the instruction text placed ahead of the conversation) over twelve conversations, and found "sharp drops in attention between turns and rough plateaus within turns".18 Its authors are careful: the measurement "shows merely the co-occurrence of instruction drift and attention decay", and it "inspires the hypothesis that attention decay may internally contribute to instruction drift" (7).

The first of the three varies length and position separately.19 None of the three settles why material in a long context is used less well. Providers call the loss of recall in long contexts context rot;20 the name describes the effect, not its cause. Figure A.2 draws the three findings schematically.

Figure A.2 Length and attention

A long context drawn as a strip with three marks: a band at the very start; a dip in the middle; over several turns, the share going to the opening instruction stepping down.

Tap the drawing to open it larger
Three published measurements of how a model uses its context: extra attention on the very first tokens (an attention sink), weaker use of material in the middle of a long context, and, in one study, the attention one head gave to an opening instruction stepping down at each new turn of a conversation. Each finding comes from a different study and measures something different. The third shows attention falling while instructions drift, which its authors offer as a hypothesis, not as a cause. The drawing is schematic, and the values are illustrative.

A.6Patterns from earlier in the context

One mechanism helps explain why what stands earlier in a context can shape what comes later. Researchers have found attention heads, which they call induction heads, that "look back over the sequence for previous instances of the current token", find what came after it last time, and "predict that the same completion will occur again".21 In large models the matching is looser: similar patterns, not identical ones (PDF 2). The authors present "preliminary and indirect evidence" that such heads might account for much of what is called in-context learning, the way a model does better at a task as the context shows more of it (PDF 1), and they state that the case "is stronger for small models than for large ones" (PDF 3). It may be one reason why worked examples in a context can shape a model's writing more than rules do, a pattern that one single-case account of a six-month collaboration with a model reported.22 That link is a reading of the mechanism, not a finding.

A.7Searching by meaning

Many systems that give a model access to documents keep the documents outside the model, in a knowledge base, and, when a question comes in, place the passages that seem most relevant in the context. The search usually works by meaning rather than by matching words. Each passage is turned into a long series of numbers by a model trained for the purpose, an embedding of the whole passage, so that passages with related meanings lie near each other, like points in a space with very many dimensions, and, when a question comes in, it is turned into numbers in the same way, and the search returns the passages nearest to it. Where the practice speaks of what comes back from a knowledge base as resonating with a question, it is using an image for this nearness. What counts as near was learned from text, so the space carries the habits of that text: what that text tended to put together lies close, and what it kept apart lies far.

More on thisWhy "vector"?

The practice I work in calls its core technique of writing tension into what a model reads vectorization, borrowing the word for a direction with a strength (section 2.7 says more). Its vectors and the vectors inside a language model share a word, not a logic. In the practice, a vector is a written, provisional field of tendency, with poles (the pulls it moves between) and questions to ask of it. Inside a model, each token is represented as a long list of numbers, and by a hypothesis that researchers have found support for, many high-level concepts are represented as directions in the space those numbers make.23 No one picks these directions one by one, but they are not given by nature either: they come out of whose text was gathered and how it was filtered, how the model is built and how it was trained.

The two kinds meet only through text. A field written in a knowledge base reaches the model as tokens, which activate whatever the model has learned about their words; the practice never acts directly on the model's internal numbers, which closed models give no access to. So the practice can say what it wrote and what came back, not what happened in between, and it keeps to what it can answer for: the texts it maintains, and how their outputs are taken up.

A.8What follows for a priming ecology, and what does not

Four points follow; each says what the mechanism supports and where that support stops.

Everything in the context is tokens, and all of it enters the same weighted mixtures.

Instructions and material are read the same way. Products mark parts of the context by role, such as a provider's instructions and a user's messages, and providers train models to rank the roles (section 5.2 says more), but the mechanism itself has no separate channel for instructions. That is what prompt injection relies on: text planted in a document or a web page that the model treats as an instruction. One formal study concludes that, in architectures of this kind, "perfect prompt-injection prevention cannot be guaranteed within the shared representational pipeline itself".24 The authors add that this does not mean every defense is equally ineffective (1). For a priming ecology, it means that its own texts and any outside text it fetches arrive through the same channel, with only the ranking that training and the product have added to tell them apart, so a priming ecology that fetches outside text is open to prompt injection in the same way. A security layer outside the model can guarantee which actions an agent takes and where data goes, but the one described in section 5.2 makes no promise about what the model writes.

Re-supply fits the mechanism and promises nothing. Re-supply means that a priming ecology supplies its material again as the work goes on (section 5.4 says more). An entry fetched from the knowledge base later in a conversation stands closer to the point of writing if the product places it near the end of the context, and an instruction placed at the start of every answer is present at every step. Both put material where the model can attend to it. Neither guarantees that it does, or how much: the attention weights are computed afresh at each step, in each head, from what the queries and keys make of the whole context. And position cuts both ways, since the middle of a long context can be used worse than its ends. What I have seen in my practice is that re-supply helps keep a model from drifting, from sliding back toward its defaults, over a long piece of work. The nearest test, in the instruction-drift study described in A.5, found that repeating the system prompt more often raised stability but lowered accuracy on a separate question-answering test, in one model;25 what a priming ecology re-supplies, entries and notes and not one instruction, has not been tested as such.

A text that pulls in several directions fits the mechanism; the mechanism does not show that the pulls act as written. A fetched entry can be written so that several tendencies pull in different directions in it. Because attention is a budget shared out at every step, and because many heads share it out in different ways, one of those tendencies may draw much of the attention at one step while the others are attended to by other heads, or at later steps, or not at all. That is a reading of the mechanism, and it is the reasoning behind how the texts of a priming ecology are written (chapter 2). It is not a finding. The closest research is narrower: in one controlled study, familiar words such as apple and bird were made the nodes of a graph set up in the context, and with enough context the model's internal representations (the lists of numbers it works with between input and output) came to mirror that graph. The study also reports a case in which the context's structure was "present in the representations, but does not dominate them", and the model still used the context's structure for the task it was set.26

A large share of attention is not a measure of importance or of meaning. Attention weights are one intermediate quantity among many. They show what, in one head at one step, the model drew on; as A.4 said, that is one contribution among a great many that are mixed before a word is chosen. Nothing in the mechanism brings in what a text means to the people it concerns. That is why this text keeps in view what is supplied to the model and what comes back, does not read what happens between the two as the meaning of either, and leaves the reading of what comes back with people.

Notes (26)
  1. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 3. ↩
  2. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 210. ↩
  3. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 3. ↩
  4. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 208. ↩
  5. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page.Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. ↩
  6. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 3. ↩
  7. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 224. ↩
  8. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 223. ↩
  9. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 213. ↩
  10. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 5. ↩
  11. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 214. ↩
  12. Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 4. ↩
  13. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 224. ↩
  14. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 216.Vaswani, Ashish, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. "Attention Is All You Need." Advances in Neural Information Processing Systems 30 (NIPS 2017), 2017, pp. 5998–6008. Page cited is a PDF page. Page 3. ↩
  15. Prince, Simon J. D. Understanding Deep Learning. MIT Press, 2023. Page 227. ↩
  16. Liu, Nelson F., et al. "Lost in the Middle: How Language Models Use Long Contexts." Transactions of the Association for Computational Linguistics, vol. 12, 2024, pp. 157–73, https://doi.org/10.1162/tacl_a_00638. Quoted from the abstract; the figures were checked in the arXiv version (arXiv:2307.03172v3). ↩
  17. Xiao, Guangxuan, et al. "Efficient Streaming Language Models with Attention Sinks." International Conference on Learning Representations (ICLR 2024), 2024. arXiv:2309.17453. Quoted from the abstract. ↩
  18. Li, Kenneth, Tianle Liu, Naomi Bashkansky, David Bau, Fernanda Viégas, Hanspeter Pfister, and Martin Wattenberg. "Measuring and Controlling Instruction (In)Stability in Language Model Dialogs." Conference on Language Modeling (COLM 2024), 2024. arXiv:2402.10962. Page 6. ↩
  19. Liu, Nelson F., et al. "Lost in the Middle: How Language Models Use Long Contexts." Transactions of the Association for Computational Linguistics, vol. 12, 2024, pp. 157–73, https://doi.org/10.1162/tacl_a_00638. Quoted from the abstract; the figures were checked in the arXiv version (arXiv:2307.03172v3). Cited: figs. 3, 4 and 7. ↩
  20. Anthropic. "Exploring Model Welfare." Anthropic, 24 Apr. 2025, https://www.anthropic.com/research/exploring-model-welfare. Accessed 31 Oct. 2026. Page 3. ↩
  21. Olsson, Catherine, et al. "In-context Learning and Induction Heads." Transformer Circuits Thread, Anthropic, 8 Mar. 2022, https://transformer-circuits.pub/2022/in-context-learning-and-induction-heads/. Pages cited are those of a printed PDF copy. Cited: PDF 2. ↩
  22. Jiang, Ziyuan. "Caring for the System That Cares for Me: An Autoethnography of Designing Sustained Memory with a Stateless Conversational AI." Design and Artificial Intelligence, vol. 2, no. 2, 2026, article 100087, https://doi.org/10.1016/j.daai.2026.100087. Page 12. ↩
  23. Park, Kiho, Yo Joong Choe, and Victor Veitch. "The Linear Representation Hypothesis and the Geometry of Large Language Models." Proceedings of the 41st International Conference on Machine Learning (ICML 2024), 2024. arXiv:2311.03658v2. Pages cited are PDF pages. Pages 1, 5. ↩
  24. Pant, Dewank, Shruti Lohani, and Avijit Kumar. "On the Inseparability of Instructions and Data in Shared-Embedding Sequence Models." arXiv, June 2026, arXiv:2606.27567. Page 1. ↩
  25. Li, Kenneth, Tianle Liu, Naomi Bashkansky, David Bau, Fernanda Viégas, Hanspeter Pfister, and Martin Wattenberg. "Measuring and Controlling Instruction (In)Stability in Language Model Dialogs." Conference on Language Modeling (COLM 2024), 2024. arXiv:2402.10962. Pages 8–10. ↩
  26. Park, Core Francisco, Andrew Lee, Ekdeep Singh Lubana, Yongyi Yang, Maya Okawa, Kento Nishi, Martin Wattenberg, and Hidenori Tanaka. "ICLR: In-Context Learning of Representations." International Conference on Learning Representations (ICLR 2025), 2025. arXiv:2501.00070. Pages 1, 4. ↩

Glossary

Open the whole glossary at this entry