[{"data":1,"prerenderedAt":1000,"buildId":1001},["ShallowReactive",2],{"ai-article-full-en":3},{"path":4,"url":5,"title":6,"description":7,"published":8,"publishedIso":8,"publishedLong":9,"updated":8,"updatedIso":8,"updatedLong":9,"wasUpdated":10,"parts":11,"nodes":68,"learningPaths":991},"blog\u002Fai","\u002Fblog\u002Fai\u002F","How modern language models work","From text to tokens, attention, sampling, retrieval and tools: how a large language model turns a prompt into an answer, and what it does not do along the way.","2026-10-02","October 2, 2026",false,[12,21,33,43,49,59],{"id":13,"title":14,"nodeIds":15},"part-1","From text to vectors",[16,17,18,19,20],"text","tokenization","token-ids","embeddings","position",{"id":22,"title":23,"nodeIds":24},"part-2","Inside the transformer",[25,26,27,28,29,30,31,32],"contextual-representations","transformer-layers","attention","qkv","dense-attention","sparse-attention","context-window","kv-cache",{"id":34,"title":35,"nodeIds":36},"part-3","Choosing the next token",[37,38,39,40,41,42],"logits","softmax","sampling","sampling-controls","discarded-candidates","search-and-verification",{"id":44,"title":45,"nodeIds":46},"part-4","Running a model yourself",[47,48],"quantization","local-inference",{"id":50,"title":51,"nodeIds":52},"part-5","Bringing in outside information",[53,54,55,56,57,58],"rag","retrieval-vs-attention","external-memory","tool-use","mcp","code-retrieval",{"id":60,"title":61,"nodeIds":62},"part-6","Learning, and what the words mean",[63,64,65,66,67],"training","hallucination","synthetic-data","self-improvement","agi",[69,95,125,150,180,210,237,268,293,324,353,379,413,444,470,496,526,552,581,612,645,678,709,735,764,795,822,853,884,913,940,966],{"id":16,"order":70,"partId":71,"title":72,"summary":73,"concepts":74,"searchTerms":79,"learningObjectives":85,"misconceptions":88,"buildsOn":90,"seeAlso":91,"body":94},1,null,"Text","A language model never reads letters directly: before it can do anything, text has to become a sequence of integers.",[16,75,76,77,78],"input","unicode","bytes","preprocessing",[80,81,82,83,84],"characters","letters","utf-8","how does an llm read text","input text",[86,87],"Explain why a neural network cannot consume text as written","Name the steps between a string and the model's first computation",[89],"A language model reads the letters of a prompt the way a person does.",[],[92],{"id":17,"title":93},"Tokenization","\u003Cp>A computer stores text as bytes: Unicode characters encoded, usually, as\nUTF-8. A neural network does not compute with bytes or letters. It computes\nwith numbers arranged in vectors and matrices, and the only thing it can do\nwith an input is multiply and add it.\u003C\u002Fp>\n\u003Cp>So between the prompt you type and the first calculation inside the model\nthere is a fixed, mechanical pipeline. The text is normalised, split into\n\u003Ca href=\"#tokenization\">tokens\u003C\u002Fa>, and each token is replaced by an integer\n\u003Ca href=\"#token-ids\">ID\u003C\u002Fa>. Those integers are the model’s entire view of your text.\u003C\u002Fp>\n\u003Cp>Nothing in that pipeline is learned while you use the model, and nothing in\nit understands anything. It is closer to a dictionary lookup than to reading.\u003C\u002Fp>\n\u003Cp>This has consequences that surprise people. A model that receives \u003Ccode>straw\u003C\u002Fcode>\nand \u003Ccode>berry\u003C\u002Fcode> as two IDs has no direct view of the letters inside them, so\n“how many r’s are in strawberry” asks about something the model only knows\nindirectly, from patterns it absorbed during training.\u003C\u002Fp>\n",{"id":17,"order":96,"partId":71,"title":93,"summary":97,"concepts":98,"searchTerms":104,"learningObjectives":112,"misconceptions":115,"buildsOn":117,"seeAlso":119,"body":124},2,"Text is split into units from a fixed vocabulary: whole words, pieces of words, or raw bytes.",[17,99,100,101,102,103],"token","vocabulary","subword","byte pair encoding","wordpiece",[105,106,107,108,109,110,111],"tokenizer","tokens","bpe","sentencepiece","subwords","word pieces","how many tokens",[113,114],"Describe how a subword tokenizer splits common and rare words","Explain why token counts differ between models",[116],"One token is one word.",[118],{"id":16,"title":72},[120,122],{"id":18,"title":121},"Token IDs",{"id":31,"title":123},"Context windows","\u003Cp>A tokenizer splits text into units drawn from a fixed vocabulary, typically\ntens of thousands to a few hundred thousand entries. Modern tokenizers work\non \u003Cstrong>subwords\u003C\u002Fstrong>: common words get a single token, while rare words are built\nfrom several pieces. Byte pair encoding (BPE), WordPiece and Unigram are the\ncommon algorithms; byte-level variants fall back to individual bytes, so any\ninput at all can be encoded.\u003C\u002Fp>\n\u003Cp>The vocabulary is chosen before the model is trained, from statistics of a\nlarge text sample, and it never changes afterwards. The model learns to work\nwith whatever pieces the tokenizer produces.\u003C\u002Fp>\n\u003Cp>This is the actual output of the WordPiece tokenizer behind this article’s\n\u003Ca href=\"\u002Fblog\u002Fai\u002Fask\u002F\">Ask\u003C\u002Fa> view. \u003Ccode>##\u003C\u002Fcode> marks a piece that continues the previous one:\u003C\u002Fp>\n\u003Cpre class=\"hl-code\">\u003Ccode>&quot;Why doesn&#039;t a larger context window replace RAG?&quot;\nwhy | doesn | &#039; | t | a | larger | context | window | replace | rag | ?\n\n&quot;transformers hallucinate unfathomably&quot;\ntransformers | hall | ##uc | ##inate | un | ##fat | ##hom | ##ably\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Tokens are not words. Punctuation and word fragments are tokens too, and a\ndifferent model’s tokenizer would split the same sentence differently, which\nis why token counts and per-token prices are only comparable within one model\nfamily.\u003C\u002Fp>\n",{"id":18,"order":126,"partId":71,"title":121,"summary":127,"concepts":128,"searchTerms":133,"learningObjectives":140,"misconceptions":142,"buildsOn":144,"seeAlso":146,"body":149},3,"Each token is replaced by its position in the vocabulary. The number is an index, and carries no meaning of its own.",[129,130,131,132],"token id","vocabulary index","special tokens","integer",[134,135,136,137,138,139],"token ids","input ids","vocab index","bos","eos","end of sequence token",[141],"Explain why token IDs are indices rather than quantities",[143],"Tokens with nearby IDs have similar meanings.",[145],{"id":17,"title":93},[147],{"id":19,"title":148},"Embeddings","\u003Cp>Once text is split, each token is looked up in the vocabulary and replaced by\nits index. The sequence of these integers is what the model actually\nreceives.\u003C\u002Fp>\n\u003Cp>The numbers are labels, not quantities. Token 2,000 is no more similar to\ntoken 2,001 than to token 9. Nothing in the model ever does arithmetic on the\nIDs themselves; their only use is to select a row from the\n\u003Ca href=\"#embeddings\">embedding table\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Vocabularies also contain \u003Cstrong>special tokens\u003C\u002Fstrong> that never appear as ordinary\ntext: markers for the start and end of a sequence, separators, and in chat\nmodels the markers that delimit system, user and assistant turns. A model\nstops generating when it produces its end-of-sequence token, because it was\ntrained to emit one where text ends.\u003C\u002Fp>\n",{"id":19,"order":151,"partId":71,"title":148,"summary":152,"concepts":153,"searchTerms":159,"learningObjectives":165,"misconceptions":168,"buildsOn":170,"seeAlso":172,"body":179},4,"Token IDs select rows of a learned table of vectors: the model's starting point for each token, not its final word on meaning.",[154,155,156,157,158],"embedding","embedding table","vector","static embedding","embedding model",[160,161,162,163,164],"word vectors","vector representation","semantic vectors","embedding matrix","meaning of words",[166,167],"Describe what an embedding table is and how it is used","Distinguish a token's input embedding from its contextual representation",[169],"An embedding is a fixed definition of what a word means.",[171],{"id":18,"title":121},[173,175,177],{"id":25,"title":174},"Context-dependent representations",{"id":53,"title":176},"Retrieval-augmented generation",{"id":54,"title":178},"Retrieval versus attention","\u003Cp>The model’s first layer is a table with one row per vocabulary entry. Each\nrow is a vector of a few hundred to several thousand numbers, and a token ID\nsimply selects its row. The values in the table are learned during training,\nalong with everything else.\u003C\u002Fp>\n\u003Cp>Training tends to place tokens that are used in similar ways near each other,\nwhich is why embeddings are often described as encoding meaning. For this\ntable, that description goes too far. The input embedding for \u003Ccode>bank\u003C\u002Fcode> is the\nsame row whether the sentence is about a river or an account: it is a\ncontext-free starting point. What a token means in a particular sentence is\nonly worked out as its vector is transformed by the layers above, using the\ntokens around it. That is the subject of\n\u003Ca href=\"#contextual-representations\">contextual representations\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>The word \u003Cstrong>embedding\u003C\u002Fstrong> is also used for something related but separate: an\nembedding \u003Cstrong>model\u003C\u002Fstrong> that turns a whole passage into one vector, so passages can\nbe compared by similarity. That is how \u003Ca href=\"#rag\">retrieval\u003C\u002Fa> usually finds\nrelevant text.\u003C\u002Fp>\n\u003Cp>The \u003Ca href=\"\u002Fblog\u002Fai\u002Fask\u002F\">Ask\u003C\u002Fa> view of this article uses the simplest kind: a static\nembedding table, where a passage’s vector is the average of its tokens’ rows.\nNo context and no layers, so it runs in a browser without a machine-learning\nruntime. It is also why Ask combines it with plain keyword matching: a static\ntable cannot tell which sense of a word you meant.\u003C\u002Fp>\n",{"id":20,"order":181,"partId":71,"title":182,"summary":183,"concepts":184,"searchTerms":189,"learningObjectives":196,"misconceptions":199,"buildsOn":201,"seeAlso":203,"body":209},5,"Positional information","Attention on its own ignores word order, so position has to be injected. Most current models do it by rotating queries and keys (RoPE).",[185,20,186,187,188],"positional encoding","word order","rotary position embedding","rope",[190,191,192,193,194,195],"positional embeddings","sinusoidal","alibi","relative position","token order","rotary embeddings",[197,198],"Explain why a transformer needs positional information","Contrast absolute position embeddings with rotary embeddings",[200],"Every model adds a position vector to each token embedding.",[202],{"id":19,"title":148},[204,206,208],{"id":27,"title":205},"Self-attention",{"id":28,"title":207},"Queries, keys and values",{"id":31,"title":123},"\u003Cp>\u003Ca href=\"#attention\">Self-attention\u003C\u002Fa> compares tokens with each other, but nothing in\nthat comparison depends on where they are. Without extra information, “dog\nbites man” and “man bites dog” would give the model the same tokens in a\ndifferent order, and it would have no way to tell them apart.\u003C\u002Fp>\n\u003Cp>Early transformers fixed this by \u003Cstrong>adding\u003C\u002Fstrong> a position vector to each token’s\nembedding: fixed sinusoidal patterns in the original Transformer, a learned\ntable of positions in BERT and GPT-2.\u003C\u002Fp>\n\u003Cp>Most current large models use \u003Cstrong>rotary position embeddings\u003C\u002Fstrong> (RoPE) instead.\nNothing is added to the embedding. Inside every attention layer, query and\nkey vectors are rotated by an angle that depends on their position, so the\nscore between two tokens ends up depending on how far apart they are. Other\nschemes, such as ALiBi, add a distance-based penalty to attention scores\ndirectly.\u003C\u002Fp>\n\u003Cp>The choice matters for \u003Ca href=\"#context-window\">context length\u003C\u002Fa>: a model handles\npositions well mostly within the range it was trained on, and many\nlong-context techniques work by adjusting how RoPE behaves beyond that range.\u003C\u002Fp>\n",{"id":25,"order":211,"partId":71,"title":174,"summary":212,"concepts":213,"searchTerms":218,"learningObjectives":224,"misconceptions":227,"buildsOn":229,"seeAlso":232,"body":236},6,"As vectors pass through the network, each token's representation is rewritten using the tokens around it.",[214,215,216,217],"contextual representation","hidden state","residual stream","contextual embedding",[219,220,221,222,223],"hidden states","activations","word sense","polysemy","meaning in context",[225,226],"Explain how the same token ends up with different vectors in different sentences","Describe where contextual representations exist and how long they last",[228],"The meaning of a word in context is looked up from a stored table.",[230,231],{"id":19,"title":148},{"id":20,"title":182},[233,235],{"id":26,"title":234},"Transformer layers",{"id":27,"title":205},"\u003Cp>The vector a token starts with is the same in every sentence. The vector it\nhas after the first layer is not. Each layer mixes in information from other\npositions and transforms the result, so by the middle of the network the\nvector at the position of \u003Ccode>bank\u003C\u002Fcode> is different in “river bank” and “bank\naccount”. These intermediate vectors are called hidden states, and together\nthey form what is often called the \u003Cstrong>residual stream\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Cp>This is where anything resembling meaning in context lives. Research that\nprobes these vectors finds they encode things like grammatical role, which\nentity a pronoun refers to, and facts associated with a name. None of that\nwas looked up; it was computed from the input by fixed weights.\u003C\u002Fp>\n\u003Cp>Contextual representations are not stored anywhere permanently. They are\ncomputed fresh for each input and discarded when the request ends. The only\npart of them kept around during a single generation is the attention state in\nthe \u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>At the top of the network, the representation at the last position is what\nthe model uses to score possible next tokens: the \u003Ca href=\"#logits\">logits\u003C\u002Fa>.\u003C\u002Fp>\n",{"id":26,"order":238,"partId":71,"title":234,"summary":239,"concepts":240,"searchTerms":248,"learningObjectives":256,"misconceptions":259,"buildsOn":261,"seeAlso":263,"body":267},7,"A transformer is a stack of blocks. Each one lets tokens exchange information (attention), then transforms every token on its own (an MLP).",[241,242,243,244,245,246,247],"transformer","layer","transformer block","feed-forward network","mlp","residual connection","mixture of experts",[249,250,251,252,253,254,255],"decoder only","architecture","ffn","layer norm","moe","how many layers","parameters",[257,258],"Name the two sublayers of a transformer block and what each does","Explain why the same weights can process inputs of any length",[260],"Each layer of the model handles a different word of the input.",[262],{"id":25,"title":174},[264,265],{"id":27,"title":205},{"id":63,"title":266},"Inference versus training","\u003Cp>A large language model is a stack of dozens of transformer blocks, often\nsomewhere between 30 and 100 or more. Each block reads the residual stream,\ncomputes something, and adds its result back, so information accumulates\nrather than being replaced.\u003C\u002Fp>\n\u003Cp>Every block has two parts:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Attention\u003C\u002Fstrong> moves information between positions. It is the only place\nwhere one token’s representation can be influenced by another’s. See\n\u003Ca href=\"#attention\">self-attention\u003C\u002Fa>.\u003C\u002Fli>\n\u003Cli>A \u003Cstrong>feed-forward network\u003C\u002Fstrong> (MLP) then transforms each position separately,\nwith the same weights at every position. Much of what a model has absorbed\nabout the world appears to be stored in these weights.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Normalisation steps keep the numbers in a stable range between the two.\u003C\u002Fp>\n\u003Cp>The weights of each block are fixed after training and shared across\npositions, which is why one model can process a prompt of five tokens or five\nthousand: the same computation is applied at every position. Chat models are\n\u003Cstrong>decoder-only\u003C\u002Fstrong> transformers with a causal mask, meaning each position can\nonly attend to positions before it.\u003C\u002Fp>\n\u003Cp>Many recent large models replace the single MLP with a \u003Cstrong>mixture of experts\u003C\u002Fstrong>:\nseveral MLPs, of which a small router picks a few for each token. The model\nhas more parameters in total, but each token only uses a fraction of them.\u003C\u002Fp>\n",{"id":27,"order":269,"partId":71,"title":205,"summary":270,"concepts":271,"searchTerms":276,"learningObjectives":281,"misconceptions":284,"buildsOn":286,"seeAlso":288,"body":292},8,"Each token's representation gathers information from other positions in the context, weighted by how relevant the model computes them to be.",[272,27,273,274,275],"self-attention","attention head","attention weights","causal mask",[277,278,279,280],"attention mechanism","multi-head attention","attention is all you need","how does attention work",[282,283],"Explain what attention computes for one position","State the scope of what attention can reach",[285],"Attention lets the model look things up beyond what is in its context.",[287],{"id":26,"title":234},[289,290,291],{"id":28,"title":207},{"id":54,"title":178},{"id":31,"title":123},"\u003Cp>Attention is how a transformer moves information between positions. For each\nposition, it computes a weight for every position it is allowed to look at,\nthen takes a weighted average of information from those positions. In a\ndecoder-only model the allowed positions are the current one and everything\nbefore it.\u003C\u002Fp>\n\u003Cp>The weights are computed fresh for every input. That is the important\ndifference from the rest of the network: the MLP weights are fixed numbers,\nbut how much “it” draws from “the cat” versus “the mat” is decided at run\ntime, from the content itself. How those weights are computed is the subject\nof \u003Ca href=\"#qkv\">queries, keys and values\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Each layer runs several attention \u003Cstrong>heads\u003C\u002Fstrong> in parallel, each with its own\nlearned projections, so different heads can track different relations:\nthe previous token, the subject of the sentence, a matching bracket.\u003C\u002Fp>\n\u003Cp>Attention only ever operates over what is in the\n\u003Ca href=\"#context-window\">context window\u003C\u002Fa>. It has no access to documents, databases\nor earlier conversations unless something has put them there as tokens. That\nis a job for \u003Ca href=\"#retrieval-vs-attention\">retrieval\u003C\u002Fa>, which is a different\nmechanism.\u003C\u002Fp>\n",{"id":28,"order":294,"partId":71,"title":207,"summary":295,"concepts":296,"searchTerms":303,"learningObjectives":310,"misconceptions":313,"buildsOn":315,"seeAlso":317,"body":323},9,"Each token is projected into a query (what it looks for), a key (what it can be matched on) and a value (what it passes along).",[297,298,299,28,300,301,302],"query","key","value","dot product","scaled dot-product attention","grouped-query attention",[304,305,306,307,308,309],"q k v","query key value","attention formula","gqa","multi-query attention","attention scores",[311,312],"Write down scaled dot-product attention and explain each term","Explain why keys and values are what gets cached",[314],"Attention selects one matching token, like a database lookup.",[316],{"id":27,"title":205},[318,320,321],{"id":32,"title":319},"KV cache",{"id":20,"title":182},{"id":38,"title":322},"Probabilities and softmax","\u003Cp>Inside an attention head, each token’s current vector is multiplied by three\nlearned matrices, producing three new vectors:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>a \u003Cstrong>query\u003C\u002Fstrong>: what this position is looking for;\u003C\u002Fli>\n\u003Cli>a \u003Cstrong>key\u003C\u002Fstrong>: what this position can be matched on;\u003C\u002Fli>\n\u003Cli>a \u003Cstrong>value\u003C\u002Fstrong>: what this position contributes if it is attended to.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>The score between position \u003Cmath>\u003Cmi>i\u003C\u002Fmi>\u003C\u002Fmath> and position \u003Cmath>\u003Cmi>j\u003C\u002Fmi>\u003C\u002Fmath> is the dot product of\n\u003Cmath>\u003Cmi>i\u003C\u002Fmi>\u003C\u002Fmath>’s query with \u003Cmath>\u003Cmi>j\u003C\u002Fmi>\u003C\u002Fmath>’s key, divided by the square root of the key length to\nkeep the numbers in a stable range. A \u003Ca href=\"#softmax\">softmax\u003C\u002Fa> turns each row of\nscores into weights that sum to one, and the output for \u003Cmath>\u003Cmi>i\u003C\u002Fmi>\u003C\u002Fmath> is the weighted\nsum of the values:\u003C\u002Fp>\n\u003Cp>\u003Cmath display=\"block\">\u003Cmi>Attention\u003C\u002Fmi>\u003Cmo>(\u003C\u002Fmo>\u003Cmi>Q\u003C\u002Fmi>\u003Cmo>,\u003C\u002Fmo>\u003Cmi>K\u003C\u002Fmi>\u003Cmo>,\u003C\u002Fmo>\u003Cmi>V\u003C\u002Fmi>\u003Cmo>)\u003C\u002Fmo>\u003Cmo>=\u003C\u002Fmo>\u003Cmi>softmax\u003C\u002Fmi>\u003Cmrow>\u003Cmo>(\u003C\u002Fmo>\u003Cmfrac>\u003Cmrow>\u003Cmi>Q\u003C\u002Fmi>\u003Cmsup>\u003Cmi>K\u003C\u002Fmi>\u003Cmi>T\u003C\u002Fmi>\u003C\u002Fmsup>\u003C\u002Fmrow>\u003Cmsqrt>\u003Cmsub>\u003Cmi>d\u003C\u002Fmi>\u003Cmi>k\u003C\u002Fmi>\u003C\u002Fmsub>\u003C\u002Fmsqrt>\u003C\u002Fmfrac>\u003Cmo>)\u003C\u002Fmo>\u003C\u002Fmrow>\u003Cmi>V\u003C\u002Fmi>\u003C\u002Fmath>\u003C\u002Fp>\n\u003Cp>The database vocabulary is only an analogy. Every key matches every query to\nsome degree, and the output is a blend, not a single selected record.\u003C\u002Fp>\n\u003Cp>Keys and values depend only on a token and the tokens before it, never on\nlater ones, so once computed they can be reused. That is what the\n\u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa> stores. \u003Cstrong>Grouped-query attention\u003C\u002Fstrong> lets several query\nheads share one set of keys and values, which shrinks that cache\nconsiderably.\u003C\u002Fp>\n",{"id":29,"order":325,"partId":71,"title":326,"summary":327,"concepts":328,"searchTerms":333,"learningObjectives":341,"misconceptions":344,"buildsOn":346,"seeAlso":348,"body":352},10,"Dense attention","In full (dense) attention every token can attend to every earlier token, so the work grows with the square of the sequence length.",[329,330,331,332],"dense attention","full attention","quadratic cost","flashattention",[334,335,336,337,338,339,340],"quadratic complexity","n squared","attention cost","flash attention","global attention","why is attention expensive","long documents",[342,343],"Explain why attention cost grows quadratically with length","Distinguish exact optimisations like FlashAttention from approximations",[345],"FlashAttention is an approximation of attention.",[347],{"id":28,"title":207},[349,351],{"id":30,"title":350},"Sparse and sliding-window attention",{"id":31,"title":123},"\u003Cp>In the standard design, every position attends to every position before it.\nFor a sequence of \u003Cmath>\u003Cmi>n\u003C\u002Fmi>\u003C\u002Fmath> tokens that is roughly \u003Cmath>\u003Cmsup>\u003Cmi>n\u003C\u002Fmi>\u003Cmn>2\u003C\u002Fmn>\u003C\u002Fmsup>\u003Cmo>\u002F\u003C\u002Fmo>\u003Cmn>2\u003C\u002Fmn>\u003C\u002Fmath> query-key scores per\nhead, per layer. Double the length of the input and the attention work\nroughly quadruples, while the rest of the network’s work only doubles.\u003C\u002Fp>\n\u003Cp>For short prompts this hardly matters. For hundreds of thousands of tokens it\ndominates, and it is one of the reasons \u003Ca href=\"#context-window\">context windows\u003C\u002Fa>\nhave limits at all.\u003C\u002Fp>\n\u003Cp>A lot of engineering goes into making dense attention cheaper \u003Cstrong>without\nchanging its result\u003C\u002Fstrong>. FlashAttention, for example, computes exactly the same\noutput, but in tiles that stay in the GPU’s fast on-chip memory instead of\nwriting the whole score matrix out and reading it back. That is an\nimplementation detail, not an approximation.\u003C\u002Fp>\n\u003Cp>Changing which positions may attend to which, so that less work is done in\nthe first place, is a different idea: \u003Ca href=\"#sparse-attention\">sparse attention\u003C\u002Fa>.\u003C\u002Fp>\n",{"id":30,"order":354,"partId":71,"title":350,"summary":355,"concepts":356,"searchTerms":362,"learningObjectives":368,"misconceptions":371,"buildsOn":373,"seeAlso":375,"body":378},11,"Some attention layers restrict each token to a window or pattern of positions, trading direct reach for lower cost. It all happens inside the model.",[357,358,359,360,361],"sparse attention","sliding-window attention","local attention","attention pattern","receptive field",[363,359,364,365,366,367],"sliding window","longformer","bigbird","block sparse","windowed attention",[369,370],"Describe sliding-window attention and how information still travels beyond the window","Explain why sparse attention is not a form of retrieval",[372],"Sparse attention fetches the relevant parts of a long document, like search.",[374],{"id":29,"title":326},[376,377],{"id":54,"title":178},{"id":31,"title":123},"\u003Cp>Sparse attention changes the rule of \u003Ca href=\"#dense-attention\">dense attention\u003C\u002Fa>\nthat every token may attend to every earlier one. In \u003Cstrong>sliding-window\u003C\u002Fstrong>\nattention, each token attends only to the most recent few thousand\npositions. Other designs combine a local window with a few global tokens,\nuse fixed strided or block patterns, or select positions dynamically.\u003C\u002Fp>\n\u003Cp>A token outside the window is not lost. Each layer passes information\nforward by up to one window, so stacking layers lets information travel much\nfurther, indirectly. Several open models alternate local-window layers with\nfull-attention layers to get most of the saving while keeping some direct\nlong-range reach.\u003C\u002Fp>\n\u003Cp>Sparse attention is entirely internal to the transformer. It decides which\npositions \u003Cstrong>already in the context\u003C\u002Fstrong> each token may look at, and it is fixed\nby the architecture. It does not search a document collection, and it does\nnot bring anything new into the context. That is what\n\u003Ca href=\"#retrieval-vs-attention\">retrieval\u003C\u002Fa> does, outside the model.\u003C\u002Fp>\n",{"id":31,"order":380,"partId":71,"title":123,"summary":381,"concepts":382,"searchTerms":388,"learningObjectives":396,"misconceptions":399,"buildsOn":403,"seeAlso":406,"body":412},12,"The context window is the most tokens a model can process at once: prompt, documents, tool results and its own output together.",[383,384,385,386,387],"context window","context length","context","long context","prompt",[389,390,391,392,393,394,395],"context size","token limit","max tokens","128k","1 million tokens","lost in the middle","larger context window",[397,398],"Define the context window precisely","Explain why a larger context window does not remove the need for retrieval",[400,401,402],"The context window is a slice of the model's embeddings.","Everything inside the context window is used equally well.","A large enough context window makes retrieval unnecessary.",[404,405],{"id":27,"title":205},{"id":17,"title":93},[407,408,409,410],{"id":32,"title":319},{"id":53,"title":176},{"id":54,"title":178},{"id":55,"title":411},"External memory","\u003Cp>The context window is a limit on sequence length: the largest number of\ntokens the model can process in one pass. It is not a region of memory inside\nthe model, and not a slice of its embeddings. It is simply the input,\nmeasured in tokens.\u003C\u002Fp>\n\u003Cp>Everything the model can take into account has to be inside it: the system\nprompt, the conversation so far, any documents or tool results that were\npasted in, and every token the model has generated in this response. When a\nconversation outgrows it, something has to be dropped or summarised.\u003C\u002Fp>\n\u003Cp>The limit comes from several places at once: the lengths the model was\ntrained on, how its \u003Ca href=\"#position\">positional scheme\u003C\u002Fa> extends, the\n\u003Ca href=\"#dense-attention\">quadratic cost\u003C\u002Fa> of attention, and the memory needed for\nthe \u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Windows have grown from a few thousand tokens to hundreds of thousands and\nmore. That helps, but it does not make retrieval obsolete. Models measurably\nuse information less reliably when it is buried in the middle of a very long\ninput. Every token in the window costs time and money on every request. And\nmost importantly, a window only holds what someone put into it: a document\ncollection of millions of pages still has to be searched, and choosing what\nto place in the context is what \u003Ca href=\"#rag\">RAG\u003C\u002Fa> is for.\u003C\u002Fp>\n",{"id":32,"order":414,"partId":71,"title":319,"summary":415,"concepts":416,"searchTerms":421,"learningObjectives":427,"misconceptions":431,"buildsOn":434,"seeAlso":437,"body":443},13,"During generation, keys and values already computed for earlier tokens are kept and reused, so each new token only computes its own.",[417,418,419,420],"kv cache","key-value cache","prefix caching","inference memory",[32,422,423,424,425,426],"key value cache","prompt caching","paged attention","why is generation slow","cache",[428,429,430],"Explain what the KV cache stores and why it speeds up generation","Estimate how KV cache memory grows with context length","State what the KV cache does not contain",[432,433],"The KV cache stores alternative completions the model considered.","The KV cache is a form of long-term memory or learning.",[435,436],{"id":28,"title":207},{"id":31,"title":123},[438,440,442],{"id":41,"title":439},"What happens to the tokens not chosen",{"id":39,"title":441},"Decoding and sampling",{"id":63,"title":266},"\u003Cp>A model generates text one token at a time, and each new token attends to\nevery token before it. Without a cache, every step would recompute the\n\u003Ca href=\"#qkv\">keys and values\u003C\u002Fa> for the entire prefix, again and again.\u003C\u002Fp>\n\u003Cp>Because a token’s keys and values never change once computed, the inference\nengine stores them: for every layer, and for every position processed so far.\nEach new step computes the query, key and value for the one new token,\nappends its key and value to the cache, and attends over the stored ones.\u003C\u002Fp>\n\u003Cp>The cache grows linearly with the context. Its size is roughly\u003C\u002Fp>\n\u003Cp>\u003Cmath display=\"block\">\u003Cmn>2\u003C\u002Fmn>\u003Cmo>×\u003C\u002Fmo>\u003Cmtext>layers\u003C\u002Fmtext>\u003Cmo>×\u003C\u002Fmo>\u003Cmtext>kv heads\u003C\u002Fmtext>\u003Cmo>×\u003C\u002Fmo>\u003Cmtext>head size\u003C\u002Fmtext>\u003Cmo>×\u003C\u002Fmo>\u003Cmtext>tokens\u003C\u002Fmtext>\u003Cmo>×\u003C\u002Fmo>\u003Cmtext>bytes per number\u003C\u002Fmtext>\u003C\u002Fmath>\u003C\u002Fp>\n\u003Cp>which for long contexts can exceed the size of the model weights.\nGrouped-query attention, quantised caches and paged memory management all\nexist to keep it in check.\u003C\u002Fp>\n\u003Cp>What the cache holds is precise: the attention state for the exact sequence\nthat was actually processed, meaning the prompt plus the tokens that were\nactually chosen. Candidate tokens that were not sampled were never fed back\nin, so no keys or values exist for them. The cache is not a store of\n\u003Ca href=\"#discarded-candidates\">alternatives\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Nor is it learning. The cache lives for one request, or is kept briefly to\nreuse a shared prefix such as a long system prompt across requests, which is\nwhat “prompt caching” usually refers to. The model’s weights are untouched\nthroughout.\u003C\u002Fp>\n",{"id":37,"order":445,"partId":71,"title":446,"summary":447,"concepts":448,"searchTerms":453,"learningObjectives":459,"misconceptions":461,"buildsOn":463,"seeAlso":466,"body":469},14,"Logits","The final representation at the last position is turned into one score per vocabulary entry: the logits.",[37,449,450,451,452],"unembedding","language modeling head","next-token prediction","score",[454,455,456,457,458],"lm head","output layer","next token scores","logit","next token prediction",[460],"Describe how a hidden state becomes a score for every token in the vocabulary",[462],"Logits are probabilities.",[464,465],{"id":25,"title":174},{"id":26,"title":234},[467,468],{"id":38,"title":322},{"id":39,"title":441},"\u003Cp>After the last layer, the vector at the final position is multiplied by one\nmore matrix, the \u003Cstrong>unembedding\u003C\u002Fstrong> or language-modelling head, which has one\ncolumn per vocabulary entry. The result is a list of tens of thousands of\nnumbers, one per possible next token. These are the logits.\u003C\u002Fp>\n\u003Cp>Logits are raw scores. They can be negative, they do not sum to anything in\nparticular, and only their differences matter: adding the same constant to\nall of them changes nothing about which token is preferred.\u003C\u002Fp>\n\u003Cp>During training the model produces logits at every position at once, and\neach is compared with the token that really came next. During generation only\nthe last position’s logits are needed, because only the next token is being\nchosen. Turning these scores into probabilities is the job of\n\u003Ca href=\"#softmax\">softmax\u003C\u002Fa>.\u003C\u002Fp>\n",{"id":38,"order":471,"partId":71,"title":322,"summary":472,"concepts":473,"searchTerms":478,"learningObjectives":484,"misconceptions":487,"buildsOn":489,"seeAlso":491,"body":495},15,"Softmax turns the logits into a probability distribution over the entire vocabulary.",[38,474,475,476,477],"probability distribution","probability","normalization","calibration",[479,480,481,482,483],"probabilities","next token probability","exponential","logprobs","confidence",[485,486],"Compute softmax for a small list of logits","Explain why a high probability is not the same as a correct answer",[488],"A token with high probability is likely to be factually correct.",[490],{"id":37,"title":446},[492,494],{"id":40,"title":493},"Temperature, top-k and top-p",{"id":28,"title":207},"\u003Cp>Softmax exponentiates each logit and divides by the sum, so every token gets\na positive probability and all of them add up to one:\u003C\u002Fp>\n\u003Cp>\u003Cmath display=\"block\">\u003Cmsub>\u003Cmi>p\u003C\u002Fmi>\u003Cmi>i\u003C\u002Fmi>\u003C\u002Fmsub>\u003Cmo>=\u003C\u002Fmo>\u003Cmfrac>\u003Cmsup>\u003Cmi>e\u003C\u002Fmi>\u003Cmsub>\u003Cmi>z\u003C\u002Fmi>\u003Cmi>i\u003C\u002Fmi>\u003C\u002Fmsub>\u003C\u002Fmsup>\u003Cmrow>\u003Cmsub>\u003Cmo>∑\u003C\u002Fmo>\u003Cmi>j\u003C\u002Fmi>\u003C\u002Fmsub>\u003Cmsup>\u003Cmi>e\u003C\u002Fmi>\u003Cmsub>\u003Cmi>z\u003C\u002Fmi>\u003Cmi>j\u003C\u002Fmi>\u003C\u002Fmsub>\u003C\u002Fmsup>\u003C\u002Fmrow>\u003C\u002Fmfrac>\u003C\u002Fmath>\u003C\u002Fp>\n\u003Cp>It keeps the order of the logits and exaggerates the gaps between them: a\nlogit two points higher than another becomes about seven times as probable.\nEvery token in the vocabulary, however unlikely, keeps a probability above\nzero.\u003C\u002Fp>\n\u003Cp>The distribution describes what tends to come next in text like the context,\nas learned in training. It is not a calibrated measure of truth. A fluent,\nconfident continuation and a correct one are different things, which is part\nof why models can state falsehoods with high probability.\u003C\u002Fp>\n\u003Cp>The same function appears inside \u003Ca href=\"#qkv\">attention\u003C\u002Fa>, where it turns query-key\nscores into weights. Same arithmetic, different job.\u003C\u002Fp>\n",{"id":39,"order":497,"partId":71,"title":441,"summary":498,"concepts":499,"searchTerms":504,"learningObjectives":514,"misconceptions":517,"buildsOn":519,"seeAlso":521,"body":525},16,"Generation is a loop: choose one token from the distribution, append it to the input, run the model again.",[500,39,501,502,503],"decoding","autoregressive generation","greedy decoding","beam search",[505,506,507,508,509,510,511,512,513],"generation loop","argmax","next token","how does an llm generate text","autoregressive","streaming","random","randomly","pick words",[515,516],"Describe the autoregressive generation loop","Explain why decoding settings belong to the inference software rather than the model",[518],"The model writes a whole answer at once and then displays it word by word.",[520],{"id":38,"title":322},[522,523,524],{"id":40,"title":493},{"id":41,"title":439},{"id":32,"title":319},"\u003Cp>The model only ever predicts one next token. Generating a reply is a loop\naround that:\u003C\u002Fp>\n\u003Col>\n\u003Cli>Run the model on the current sequence and get a distribution for the next\ntoken.\u003C\u002Fli>\n\u003Cli>Choose one token from it.\u003C\u002Fli>\n\u003Cli>Append that token to the sequence and go back to step 1.\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Cp>The loop stops when the model produces its end-of-sequence token or a length\nlimit is reached. This is why replies stream out token by token: each one\nreally does exist only after the step that chose it.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Greedy\u003C\u002Fstrong> decoding always takes the most probable token. \u003Cstrong>Sampling\u003C\u002Fstrong> draws a\ntoken at random according to the probabilities, usually after reshaping them\nwith \u003Ca href=\"#sampling-controls\">temperature, top-k or top-p\u003C\u002Fa>. \u003Cstrong>Beam search\u003C\u002Fstrong> keeps\nseveral partial sequences and extends the best few; it is common in\ntranslation and rarely used for chat models.\u003C\u002Fp>\n\u003Cp>The decoding strategy is part of the inference software, not of the model’s\nweights. The same model can produce noticeably different text under\ndifferent settings.\u003C\u002Fp>\n",{"id":40,"order":527,"partId":71,"title":493,"summary":528,"concepts":529,"searchTerms":535,"learningObjectives":543,"misconceptions":545,"buildsOn":547,"seeAlso":549,"body":551},17,"Temperature reshapes the distribution; top-k and top-p cut off its unlikely tail before a token is drawn.",[530,531,532,533,534],"temperature","top-k","top-p","nucleus sampling","min-p",[536,537,538,539,540,541,542],"top p","top k","nucleus","creativity","randomness","deterministic output","temperature 0",[544],"Describe the effect of temperature, top-k and top-p on the next-token distribution",[546],"Raising the temperature makes the model think more creatively.",[548],{"id":39,"title":441},[550],{"id":38,"title":322},"\u003Cp>These settings act on the final distribution, just before a token is drawn:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Temperature\u003C\u002Fstrong> divides every logit by a number \u003Cmath>\u003Cmi>T\u003C\u002Fmi>\u003C\u002Fmath> before\n\u003Ca href=\"#softmax\">softmax\u003C\u002Fa>. Below 1 the distribution gets sharper and the likely\ntokens dominate; as \u003Cmath>\u003Cmi>T\u003C\u002Fmi>\u003C\u002Fmath> approaches 0 it approaches greedy decoding. Above\n1 it flattens, and unlikely tokens are chosen more often.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Top-k\u003C\u002Fstrong> keeps only the \u003Cmath>\u003Cmi>k\u003C\u002Fmi>\u003C\u002Fmath> most probable tokens and renormalises.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Top-p\u003C\u002Fstrong>, or nucleus sampling, keeps the smallest set of tokens whose\nprobabilities add up to at least \u003Cmath>\u003Cmi>p\u003C\u002Fmi>\u003C\u002Fmath>, so the cut adapts to how spread out\nthe distribution is.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Min-p\u003C\u002Fstrong> keeps tokens whose probability is at least some fraction of the\ntop token’s.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>None of these change what the model computed. They change which of its\ncandidates are eligible and how often each is picked. “More creative” output\nat a high temperature is the same model drawing more often from the tail of\nthe same distribution.\u003C\u002Fp>\n\u003Cp>Even at temperature 0, output is not always perfectly repeatable in practice,\nbecause of how floating-point work is batched and parallelised on\naccelerators.\u003C\u002Fp>\n",{"id":41,"order":553,"partId":71,"title":439,"summary":554,"concepts":555,"searchTerms":560,"learningObjectives":569,"misconceptions":572,"buildsOn":574,"seeAlso":577,"body":580},18,"Next-token candidates that were not chosen are normally discarded. The model does not keep them as alternative lines of reasoning.",[556,557,558,482,559],"rejected candidates","alternative completions","single sequence","speculative decoding",[561,562,563,564,565,566,567,568],"does the model consider alternatives","branches","other answers","parallel reasoning","unchosen tokens","tokens not chosen","not picked","rejected tokens",[570,571],"Explain why ordinary decoding produces exactly one sequence","Distinguish implicit alternatives in a distribution from explicitly generated alternatives",[573],"During generation the model explores several answers in parallel and keeps the best one.",[575,576],{"id":39,"title":441},{"id":32,"title":319},[578],{"id":42,"title":579},"Multiple samples, search and verification","\u003Cp>At every step the model produces a probability for every token in its\nvocabulary, and the decoding loop picks one. What happens to the rest is\nsimple: nothing. They are not fed back into the model, so no hidden states\nand no \u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa> entries are ever computed for them. The sequence\ncontinues along the chosen path only.\u003C\u002Fp>\n\u003Cp>An API can return the top few probabilities at each step, often called\nlogprobs, but that is a report about one distribution, not a set of\nalternative continuations.\u003C\u002Fp>\n\u003Cp>So “the model considered several answers and rejected them” is misleading for\nordinary generation. At each step there was a distribution; after it, there\nis one token and one sequence. A model can only weigh alternatives in a way\nthat persists if it writes them out as text, which is what reasoning models\ndo when they try an approach, check it and back up, all within one generated\nsequence.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Speculative decoding\u003C\u002Fstrong> looks like an exception but is not. A small draft\nmodel proposes several tokens, and the large model verifies them in one\npass, keeping the ones it agrees with. Rejected drafts are thrown away, and\nthe result follows the large model’s distribution. It is a speed trick, not a\nsearch over answers.\u003C\u002Fp>\n\u003Cp>Exploring alternatives deliberately is possible, but it is done by the system\naround the model: \u003Ca href=\"#search-and-verification\">multiple samples and verification\u003C\u002Fa>.\u003C\u002Fp>\n",{"id":42,"order":582,"partId":71,"title":579,"summary":583,"concepts":584,"searchTerms":591,"learningObjectives":599,"misconceptions":602,"buildsOn":604,"seeAlso":606,"body":611},19,"Systems can explore alternatives deliberately: generate several candidates, search over partial solutions, and check the results. It is an outer loop around generation.",[585,586,587,588,589,590],"best-of-n","self-consistency","verification","tree search","test-time compute","reward model",[592,593,594,595,596,597,598],"multiple samples","majority vote","verifier","reasoning models","thinking","test time compute","generate and test",[600,601],"Describe best-of-n sampling and self-consistency","Explain why multi-candidate search is an outer loop rather than part of token generation",[603],"Running more candidates at inference time trains the model.",[605],{"id":41,"title":439},[607,609],{"id":65,"title":608},"Self-training and synthetic data",{"id":56,"title":610},"Tool use","\u003Cp>If one sample can be wrong, generate several. That simple idea has many\nforms:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Best-of-n\u003C\u002Fstrong>: sample \u003Cmath>\u003Cmi>n\u003C\u002Fmi>\u003C\u002Fmath> complete answers and pick one with a scoring model\nor a check.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Self-consistency\u003C\u002Fstrong>: sample several reasoning paths and take the answer most\nof them agree on.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Search\u003C\u002Fstrong>: treat partial solutions as nodes in a tree, extend the promising\nones and abandon the rest.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Verification\u003C\u002Fstrong>: run the unit tests, check the proof, execute the query, and\nkeep what passes.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Each candidate is a separate generation, with its own context and its own\nKV cache, although a shared prompt prefix can be cached once. The\nalternatives exist because the inference system asked for them, not because\nthe model kept its \u003Ca href=\"#discarded-candidates\">discarded candidates\u003C\u002Fa>. Spending\nmore computation this way, at answer time rather than in training, is often\ncalled \u003Cstrong>test-time compute\u003C\u002Fstrong>.\u003C\u002Fp>\n\u003Cp>None of this changes the model. Candidates that pass a verifier can later be\ncollected and used to train a better model, but that happens afterwards, in a\nseparate process: see \u003Ca href=\"#synthetic-data\">synthetic data\u003C\u002Fa>.\u003C\u002Fp>\n",{"id":47,"order":613,"partId":71,"title":614,"summary":615,"concepts":616,"searchTerms":622,"learningObjectives":633,"misconceptions":636,"buildsOn":638,"seeAlso":641,"body":644},20,"Quantization","Quantization stores a model's weights in fewer bits, such as 8 or 4 instead of 16, trading a little accuracy for a model that is smaller and faster to read.",[47,617,618,619,620,621],"quantisation","int8","4-bit","precision","model compression",[623,624,625,626,627,628,629,630,631,632],"gguf","q4","q8","fp16","bf16","awq","gptq","smaller model","compress a model","bits per weight",[634,635],"Estimate the memory a model's weights need at a given precision","Explain what per-block scales do and why quality usually survives 8 and 4 bits",[637],"A quantized model is a smaller model trained separately from the original.",[639,640],{"id":26,"title":234},{"id":32,"title":319},[642,643],{"id":19,"title":148},{"id":63,"title":266},"\u003Cp>A model’s weights are numbers, billions of them, and each is normally stored\nin 16 bits. \u003Cstrong>Quantization\u003C\u002Fstrong> stores each one in fewer bits instead: 8, 4,\nsometimes less. The memory the weights need is close to\u003C\u002Fp>\n\u003Cp>\u003Cmath display=\"block\">\u003Cmtext>parameters\u003C\u002Fmtext>\u003Cmo>×\u003C\u002Fmo>\u003Cmfrac>\u003Cmtext>bits per weight\u003C\u002Fmtext>\u003Cmn>8\u003C\u002Fmn>\u003C\u002Fmfrac>\u003Cmtext>&nbsp;bytes\u003C\u002Fmtext>\u003C\u002Fmath>\u003C\u002Fp>\n\u003Cp>so an 8-billion-parameter model takes about 16 GB at 16 bits, 8 GB at 8 bits\nand a little over 4 GB at 4 bits.\u003C\u002Fp>\n\u003Cp>Fewer bits means fewer distinct values, so every weight is rounded to the\nnearest one that can be represented. To keep that rounding small, weights\nare grouped, by row or in blocks of a few dozen, and each group stores its\nown \u003Cstrong>scale\u003C\u002Fstrong>: the group’s largest value maps to the top of the small\ninteger range and everything else is rounded relative to it. A large weight\nin one group then cannot crush the precision of every other group.\u003C\u002Fp>\n\u003Cp>It is the same model, rounded. No training happens and nothing new is\nlearned: a quantized model is an approximation of the original weights, not a\nsmaller model trained to imitate it. That second thing exists too, and is\ncalled distillation. At 8 bits the difference is usually hard to measure; at\n4 bits it is small for most tasks; below about 3 bits quality drops\nnoticeably, and smaller models suffer from it sooner than large ones.\u003C\u002Fp>\n\u003Cp>Weights are not the only thing that can be quantized. The\n\u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa> can be stored in fewer bits too, which matters for\nlong contexts. The embedding model behind this article’s\n\u003Ca href=\"\u002Fblog\u002Fai\u002Fask\u002F\">Ask\u003C\u002Fa> view is stored as 8-bit integers with one scale per\nrow; against the original 32-bit numbers, the average similarity between each\nrow and its rounded copy is 0.99997.\u003C\u002Fp>\n",{"id":48,"order":646,"partId":71,"title":647,"summary":648,"concepts":649,"searchTerms":656,"learningObjectives":666,"misconceptions":669,"buildsOn":671,"seeAlso":674,"body":677},21,"Running a model on your own hardware","Whether a model runs locally is mostly a question of memory: it must hold the weights and the KV cache, and generation speed is set by how fast those weights can be read.",[650,651,652,653,654,655],"local inference","self-hosted model","memory bandwidth","vram","tokens per second","prefill and decode",[657,658,659,660,661,662,663,664,665],"run llm locally","llama.cpp","ollama","gpu memory","how much ram do i need","why is my local model slow","apple silicon","cpu inference","self-hosting",[667,668],"Estimate whether a model fits in a machine's memory","Explain why generation speed follows memory bandwidth rather than processor speed",[670],"Faster processor cores are what make a local model generate faster.",[672,673],{"id":47,"title":614},{"id":32,"title":319},[675,676],{"id":26,"title":234},{"id":63,"title":266},"\u003Cp>To run a model, a machine needs room for three things: the weights, the\n\u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa> for the context in use, and some working memory for\nthe runtime. The weights are fixed by the model and its\n\u003Ca href=\"#quantization\">quantization\u003C\u002Fa>; the cache grows with the context. A 4-bit\n8-billion-parameter model fits comfortably in 8 GB; the same model with a\nlong context may not.\u003C\u002Fp>\n\u003Cp>Inference has two phases with different limits. \u003Cstrong>Prefill\u003C\u002Fstrong> reads the\nprompt, and all of its tokens can be processed at once, so it is limited by\nhow much arithmetic the hardware can do. \u003Cstrong>Decode\u003C\u002Fstrong> then generates one token\nat a time, and every token needs a pass through all of the weights. For a\nsingle user, that pass is mostly waiting for memory, not computing, so a\nrough ceiling is\u003C\u002Fp>\n\u003Cp>\u003Cmath display=\"block\">\u003Cmtext>tokens per second\u003C\u002Fmtext>\u003Cmo>≈\u003C\u002Fmo>\u003Cmfrac>\u003Cmtext>memory bandwidth\u003C\u002Fmtext>\u003Cmtext>bytes of weights read per token\u003C\u002Fmtext>\u003C\u002Fmfrac>\u003C\u002Fmath>\u003C\u002Fp>\n\u003Cp>A machine that reads 100 GB\u002Fs, running a 5 GB model, tops out near 20 tokens\na second however fast its cores are. This is why GPUs, with several times the\nmemory bandwidth of a desktop CPU, generate faster, why quantization speeds\ngeneration up as well as shrinking the download, and why machines with fast\nmemory shared between CPU and GPU run large models well.\u003C\u002Fp>\n\u003Cp>A \u003Ca href=\"#transformer-layers\">mixture-of-experts\u003C\u002Fa> model bends the rule: all of\nits experts must be in memory, but each token reads only the few the router\npicks, so it generates faster than its total size suggests.\u003C\u002Fp>\n\u003Cp>Running locally keeps every prompt on the machine and costs nothing per\ntoken. What it gives up is size: the largest models need far more memory than\none machine usually has, and a provider can batch many users’ requests through\neach read of the weights, which a single person cannot.\u003C\u002Fp>\n",{"id":53,"order":679,"partId":71,"title":176,"summary":680,"concepts":681,"searchTerms":687,"learningObjectives":695,"misconceptions":698,"buildsOn":700,"seeAlso":703,"body":708},22,"RAG searches an external collection at request time and places the most relevant passages in the context before the model answers.",[682,53,683,684,685,686],"retrieval-augmented generation","retrieval","vector search","chunking","reranking",[688,689,690,691,692,693,694],"retrieval augmented generation","vector database","semantic search","knowledge base","grounding","citations","document search",[696,697],"Walk through the steps of a RAG pipeline","Name the main ways a RAG system fails",[699],"RAG teaches the model new facts by updating it.",[701,702],{"id":31,"title":123},{"id":19,"title":148},[704,705,706],{"id":54,"title":178},{"id":55,"title":411},{"id":58,"title":707},"Codebase-aware retrieval","\u003Cp>A model knows only what it absorbed in training plus what is in its\n\u003Ca href=\"#context-window\">context\u003C\u002Fa>. Retrieval-augmented generation adds a step\nbefore generation that decides what else should be in that context:\u003C\u002Fp>\n\u003Col>\n\u003Cli>Ahead of time, split a document collection into passages (“chunks”) and\nindex them, usually by computing an \u003Ca href=\"#embeddings\">embedding\u003C\u002Fa> for each and\noften with a keyword index as well.\u003C\u002Fli>\n\u003Cli>When a question arrives, embed it the same way and find the passages\nwhose vectors are most similar, optionally re-scoring the best few with a\nmore expensive model.\u003C\u002Fli>\n\u003Cli>Insert those passages into the prompt, and let the model generate with\nthem in view.\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Cp>That gives a model access to private, recent or very large collections\nwithout retraining anything, and lets it cite its sources. The model’s\nweights are not changed at all.\u003C\u002Fp>\n\u003Cp>RAG fails in recognisable ways. If retrieval misses the passage that\nmatters, the model answers without it, often fluently. If it retrieves\nnear-misses, they can distract or mislead. Most of the work in a good RAG\nsystem is in the retrieval, not the generation.\u003C\u002Fp>\n\u003Cp>The \u003Ca href=\"\u002Fblog\u002Fai\u002Fask\u002F\">Ask\u003C\u002Fa> view of this article is the retrieval half of this\npipeline, without the generating half: it embeds your question in your\nbrowser and returns the closest sections, which you then read yourself.\u003C\u002Fp>\n",{"id":54,"order":710,"partId":71,"title":178,"summary":711,"concepts":712,"searchTerms":715,"learningObjectives":721,"misconceptions":724,"buildsOn":727,"seeAlso":731,"body":734},23,"Attention mixes information among tokens already in the context. Retrieval decides which outside information gets into the context at all.",[683,27,713,714],"similarity search","context selection",[716,717,718,719,720],"difference between attention and retrieval","is attention retrieval","does a bigger context window replace rag","long context vs rag","retrieval vs long context",[722,723],"Contrast attention and retrieval by where they run and what they operate on","Explain why sparse attention and long contexts do not replace retrieval",[725,726],"Attention and retrieval are the same thing at different scales.","A long enough context window makes retrieval unnecessary.",[728,729,730],{"id":27,"title":205},{"id":30,"title":350},{"id":53,"title":176},[732,733],{"id":31,"title":123},{"id":55,"title":411},"\u003Cp>Both mechanisms compare vectors and favour the most similar, which is why\nthey are easy to confuse. They do different jobs.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Attention\u003C\u002Fstrong> runs inside the model, in every layer, for every token. Its\nqueries and keys are the model’s own internal states, computed with weights\nlearned during training. Its scope is exactly the current context window:\nnothing more, nothing less.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Retrieval\u003C\u002Fstrong> usually runs outside the model, before or between generation\nsteps. It is a separate system: a search index, an embedding model and a\nstore of documents. Its scope is whatever collection it indexes, which can\nbe far larger than any context window. Its output is text that gets placed\ninto the context, where attention can then use it.\u003C\u002Fp>\n\u003Cp>So \u003Ca href=\"#sparse-attention\">sparse attention\u003C\u002Fa> is not retrieval: it narrows what a\ntoken may look at among tokens already present. And a bigger context window\ndoes not replace retrieval: it raises the ceiling on how much can be placed\nin context, but something still has to choose what goes there, and with a\nlarge collection it cannot be everything.\u003C\u002Fp>\n\u003Cp>A few research architectures build retrieval into the model itself, letting\nit look up neighbours in a large external store during the forward pass.\nEven there, the lookup over the store is a separate step from ordinary\nattention over the context.\u003C\u002Fp>\n",{"id":55,"order":736,"partId":71,"title":411,"summary":737,"concepts":738,"searchTerms":744,"learningObjectives":751,"misconceptions":754,"buildsOn":756,"seeAlso":759,"body":763},24,"Anything a system should remember beyond one context window has to be stored outside the model and read back in as tokens.",[739,740,741,742,743],"memory","external memory","long-term memory","persistence","agent memory",[745,746,747,748,749,750],"does the model remember","chat memory","remember previous conversations","notes","scratchpad","vector store",[752,753],"Explain why a model has no memory across requests by itself","Describe how memory features are built from storage and retrieval",[755],"A chat assistant remembers you because the model learned from your earlier conversations.",[757,758],{"id":31,"title":123},{"id":53,"title":176},[760,761,762],{"id":32,"title":319},{"id":63,"title":266},{"id":56,"title":610},"\u003Cp>During ordinary use a model’s weights do not change, and its context is\ndiscarded when a request ends. Left to itself, it remembers nothing from one\nconversation to the next.\u003C\u002Fp>\n\u003Cp>Memory features are built around the model instead. The application saves\nsomething, such as a summary of a conversation, a note the model was asked to\nkeep, or the files an agent wrote, and later retrieves the relevant parts and\nplaces them back into the context. The model “remembers” only by reading.\u003C\u002Fp>\n\u003Cp>The storage can be anything: a text file, a database table, a vector index.\nThe hard parts are the same as in \u003Ca href=\"#rag\">RAG\u003C\u002Fa>: deciding what is worth\nsaving, finding the right piece later, and keeping stored facts accurate as\nthings change.\u003C\u002Fp>\n\u003Cp>This is different from the \u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa>, which only lasts for one\nrequest, and from \u003Ca href=\"#training\">training\u003C\u002Fa>, which changes weights in a separate\nprocess. Coding agents rely on external memory constantly: task lists,\nnotes, and the repository itself, re-read through\n\u003Ca href=\"#tool-use\">tools\u003C\u002Fa> whenever needed.\u003C\u002Fp>\n",{"id":56,"order":765,"partId":71,"title":610,"summary":766,"concepts":767,"searchTerms":773,"learningObjectives":780,"misconceptions":783,"buildsOn":785,"seeAlso":788,"body":794},25,"A model can emit a structured request to call a tool. Software outside the model runs it and feeds the result back into the context.",[768,769,770,771,772],"tool use","function calling","tool call","agent","agent loop",[769,774,775,776,777,778,779],"tools","agents","agentic","api calls","run code","plugins",[781,782],"Describe the loop between a model and the application that runs its tool calls","Explain where tool execution and permissions actually live",[784],"The model itself executes the code or API calls it requests.",[786,787],{"id":39,"title":441},{"id":31,"title":123},[789,791,792,793],{"id":57,"title":790},"Model Context Protocol (MCP)",{"id":53,"title":176},{"id":58,"title":707},{"id":55,"title":411},"\u003Cp>When an application describes some tools in the prompt, such as a name, a\npurpose and the arguments each takes, a model trained for it can respond\nwith a structured call instead of prose: in effect, “call \u003Ccode>search\u003C\u002Fcode> with\nthese arguments”.\u003C\u002Fp>\n\u003Cp>The model executes nothing. The application around it parses the request,\ndecides whether it is allowed, runs it, and appends the result to the\ncontext as more tokens. Then generation continues, now with the result in\nview. Permissions, sandboxing and logging all live in that application,\nnever in the model.\u003C\u002Fp>\n\u003Cp>An \u003Cstrong>agent\u003C\u002Fstrong> is this loop repeated: generate, call a tool, read the result,\ngenerate again, until the task is done. \u003Ca href=\"#rag\">Retrieval\u003C\u002Fa> is often just one\nof the tools, alongside running code, reading files or calling an API.\u003C\u002Fp>\n\u003Cp>How tools are described to the model and connected to the application varies\nbetween vendors. \u003Ca href=\"#mcp\">MCP\u003C\u002Fa> is one attempt to standardise the connection\nside.\u003C\u002Fp>\n",{"id":57,"order":796,"partId":71,"title":790,"summary":797,"concepts":798,"searchTerms":804,"learningObjectives":810,"misconceptions":813,"buildsOn":816,"seeAlso":818,"body":821},26,"MCP is an open protocol for exposing tools, data and prompts to AI applications. It standardises the connection, not the retrieval.",[799,57,800,801,802,803],"model context protocol","protocol","mcp server","mcp client","json-rpc",[801,805,806,807,808,809],"what is mcp","is mcp rag","connectors","integrations","anthropic mcp",[811,812],"Describe the parts of an MCP connection and what a server can expose","Explain why MCP is not itself retrieval or memory",[814,815],"MCP is a kind of RAG.","MCP gives the model direct access to systems.",[817],{"id":56,"title":610},[819,820],{"id":53,"title":176},{"id":58,"title":707},"\u003Cp>The Model Context Protocol, introduced by Anthropic in late 2024 and now\nimplemented by many applications, is a standard way to connect AI\napplications to outside capabilities. A \u003Cstrong>host\u003C\u002Fstrong> application, such as a chat\napp or an editor, runs MCP \u003Cstrong>clients\u003C\u002Fstrong> that talk to MCP \u003Cstrong>servers\u003C\u002Fstrong>. A server can\noffer:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>tools\u003C\u002Fstrong>: functions the model may ask to call;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>resources\u003C\u002Fstrong>: data the application can read and place in context;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>prompts\u003C\u002Fstrong>: reusable templates.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Messages are JSON-RPC, carried over standard input and output for local\nservers or over HTTP for remote ones. The benefit is reuse: an integration\nwritten once as an MCP server works in every host that speaks the protocol.\u003C\u002Fp>\n\u003Cp>MCP is plumbing. It is not a model, not a memory and not RAG. A server \u003Cstrong>can\u003C\u002Fstrong>\nexpose a search tool, and then a retrieval step happens through MCP; but the\nprotocol only carries the request and the result. Ranking, indexing and\nrelevance all belong to whatever the server does, and the model still only\nsees what ends up in its context. Everything said about\n\u003Ca href=\"#tool-use\">tool use\u003C\u002Fa> still applies: the host decides what runs.\u003C\u002Fp>\n",{"id":58,"order":823,"partId":71,"title":707,"summary":824,"concepts":825,"searchTerms":832,"learningObjectives":840,"misconceptions":843,"buildsOn":845,"seeAlso":848,"body":852},27,"Coding agents find the relevant parts of a repository with search tools, such as text search, symbol indexes, embeddings or code graphs, and read them into context.",[826,827,828,829,830,831],"code search","codebase retrieval","code knowledge graph","symbol index","language server","grep",[833,834,835,836,837,838,839],"coding agent","repository","repo","ripgrep","code graph","how do coding agents understand a codebase","lsp",[841,842],"List the main ways an agent searches a codebase and when each works best","Explain why exact identifiers favour lexical search",[844],"A coding agent reads and understands the whole repository at once.",[846,847],{"id":53,"title":176},{"id":56,"title":610},[849,850,851],{"id":57,"title":790},{"id":55,"title":411},{"id":54,"title":178},"\u003Cp>A repository rarely fits in a context window, and most of it is irrelevant\nto any given task. So a coding agent does what a developer new to the code\nwould do: it searches, reads, and searches again. The usual instruments:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Text search\u003C\u002Fstrong>, grep and its descendants: exact and fast, ideal for a known\nidentifier or error message.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>File listings\u003C\u002Fstrong>: the shape of the project, from its directory structure.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Symbol indexes\u003C\u002Fstrong> and language servers: where something is defined, and\neverything that refers to it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Embedding search\u003C\u002Fstrong> over chunks of code and documentation, for questions\nphrased in concepts rather than names.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Code knowledge graphs\u003C\u002Fstrong>: precomputed relations such as calls, imports and\nownership, queried as a tool and often exposed over \u003Ca href=\"#mcp\">MCP\u003C\u002Fa>.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>The agent chooses which to use, reads the results into context, and lets\nattention do the reasoning from there. Each tool is a different kind of\n\u003Ca href=\"#rag\">retrieval\u003C\u002Fa>, and they complement each other: an exact identifier such\nas a function name is found reliably by text search and easily blurred by\nsemantic similarity. The \u003Ca href=\"\u002Fblog\u002Fai\u002Fask\u002F\">Ask\u003C\u002Fa> view of this article uses the same\nidea, letting exact keyword matches outrank vague semantic ones.\u003C\u002Fp>\n",{"id":63,"order":854,"partId":71,"title":266,"summary":855,"concepts":856,"searchTerms":863,"learningObjectives":870,"misconceptions":873,"buildsOn":876,"seeAlso":879,"body":883},28,"Training changes a model's weights. Inference, meaning ordinary use, runs fixed weights and changes nothing in the model.",[63,857,858,859,860,861,862],"inference","pretraining","fine-tuning","weights","in-context learning","gradient descent",[864,865,866,867,868,869],"does chatgpt learn from my conversations","does the model learn while chatting","rlhf","backpropagation","post-training","weights update",[871,872],"Distinguish what changes during training from what changes during inference","Explain in-context learning without weight updates",[874,875],"A model learns from each conversation as it happens.","In-context learning updates the model's weights.",[877,878],{"id":26,"title":234},{"id":39,"title":441},[880,881,882],{"id":65,"title":608},{"id":55,"title":411},{"id":32,"title":319},"\u003Cp>\u003Cstrong>Training\u003C\u002Fstrong> is where a model’s weights come from. In pretraining, the model\npredicts the next token across an enormous body of text; each prediction is\ncompared with the real next token, and gradient descent nudges every weight\nslightly in the direction that would have made the right token more likely.\n\u003Cstrong>Post-training\u003C\u002Fstrong> then shapes behaviour: supervised fine-tuning on example\nconversations, learning from human or AI preference judgements, and\nreinforcement learning on tasks whose answers can be checked.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Inference\u003C\u002Fstrong> is everything that happens when the model is used. It runs the\nnetwork forward only. No error is measured, no gradients are computed, and\nthe weights are read but never written. Inside a conversation, what changes\nis the context and the \u003Ca href=\"#kv-cache\">KV cache\u003C\u002Fa>, and both are discarded\nafterwards.\u003C\u002Fp>\n\u003Cp>Models can still adapt to a prompt: show one a few examples of a format and\nit follows the format. This \u003Cstrong>in-context learning\u003C\u002Fstrong> is computation over the\ncontext by fixed weights, not training. Remove the examples and the\nbehaviour goes with them.\u003C\u002Fp>\n\u003Cp>Whether a provider later uses conversations as training data is a matter of\npolicy, and if it happens, it happens in a separate training run that\nproduces a new model, not inside the conversation.\u003C\u002Fp>\n",{"id":64,"order":885,"partId":71,"title":886,"summary":887,"concepts":888,"searchTerms":891,"learningObjectives":899,"misconceptions":902,"buildsOn":905,"seeAlso":908,"body":912},29,"Hallucination","A model can state something false as fluently as something true, because it generates likely text and has no store of facts to check against.",[64,889,890,477,692],"confabulation","factual errors",[892,893,894,895,896,897,898],"why does ai make things up","made up citations","fake references","is the model lying","wrong answers","how to reduce hallucinations","confidently wrong",[900,901],"Explain why fluent output is no evidence that it is correct","Name the main ways systems reduce hallucination, and what each depends on",[903,904],"A model looks facts up in an internal database, and a hallucination is the wrong row coming back.","When a model hallucinates, it knows the answer is false and says it anyway.",[906,907],{"id":63,"title":266},{"id":39,"title":441},[909,910,911],{"id":53,"title":176},{"id":42,"title":579},{"id":56,"title":610},"\u003Cp>A model answers by generating the tokens that are likely to follow the\ncontext, one at a time. \u003Ca href=\"#training\">Training\u003C\u002Fa> made text that resembles its\ntraining data likely, and true statements are common in that data, so the\nlikely continuation is often the true one. But nothing in generation checks\nit. When the model has not absorbed the fact, the likely continuation is\nstill something that \u003Cem>looks\u003C\u002Fem> like an answer: a plausible name, a\nreasonable-sounding date, a citation in the right format to a paper that does\nnot exist.\u003C\u002Fp>\n\u003Cp>There is no lookup to fail. What a model knows is spread across its weights,\nnot kept as records, so there is no row that comes back empty and no “not\nfound” to report. Saying “I don’t know” is itself just another continuation,\nand it is only chosen when training made it the likely one in that kind of\ncontext.\u003C\u002Fp>\n\u003Cp>Nor is it lying. Models do carry some internal signal of how uncertain they\nare, and training can teach them to act on it, but the signal is imperfect,\nand a fluent wrong answer is produced by the same process as a fluent right\none. Errors are most common for things that appeared rarely in training:\nobscure people, exact numbers, quotations, recent events.\u003C\u002Fp>\n\u003Cp>The fixes all work by putting a check outside the model’s memory:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Grounding\u003C\u002Fstrong>: \u003Ca href=\"#rag\">retrieve\u003C\u002Fa> the relevant text and answer from it,\nwhich helps exactly as much as retrieval finds the right passage;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Tools\u003C\u002Fstrong>: \u003Ca href=\"#tool-use\">look it up, calculate it or run it\u003C\u002Fa> rather than\nrecall it;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Verification\u003C\u002Fstrong>: \u003Ca href=\"#search-and-verification\">check\u003C\u002Fa> the answer, by tests,\nby citations that can be opened, or by sampling several times and\ndistrusting answers that disagree;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Training\u003C\u002Fstrong> that rewards declining to answer over guessing.\u003C\u002Fli>\n\u003C\u002Ful>\n",{"id":65,"order":914,"partId":71,"title":608,"summary":915,"concepts":916,"searchTerms":922,"learningObjectives":928,"misconceptions":931,"buildsOn":933,"seeAlso":936,"body":939},30,"Model outputs that have been filtered, checked or ranked can become training data for a later model: a learning loop outside generation.",[917,918,919,920,921],"synthetic data","self-training","distillation","rejection sampling","model collapse",[923,924,925,926,927],"training on model outputs","ai generated training data","self improvement loop","bootstrapping","data flywheel",[929,930],"Describe a generate, verify and train loop","Explain why verification quality limits self-training",[932],"A model improves itself every time it generates and checks an answer.",[934,935],{"id":63,"title":266},{"id":42,"title":579},[937],{"id":66,"title":938},"Recursive self-improvement","\u003Cp>Generated text can be training data. Some common patterns:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>Generate many solutions to problems with checkable answers, keep the ones\nthat pass, and fine-tune on those.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Distillation\u003C\u002Fstrong>: train a smaller model on the outputs of a larger one.\u003C\u002Fli>\n\u003Cli>Have a model critique or rank responses, and use the rankings as\npreference data.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>All of these are an outer loop with a clear sequence: generate, using\ninference; evaluate, with tests, verifiers or other models; select; then\ntrain, which is the only step where weights change, producing a new model.\nThe \u003Ca href=\"#search-and-verification\">multi-candidate search\u003C\u002Fa> of the inference step\nand the learning of the training step are different stages, often run at\ndifferent times on different machines.\u003C\u002Fp>\n\u003Cp>The loop is only as good as its filter. If verification is weak, errors get\ntrained in and reinforced. Repeatedly training on unfiltered generated text\nhas been shown to narrow a model’s output and lose the rarer parts of the\noriginal data, sometimes called \u003Cstrong>model collapse\u003C\u002Fstrong>. Where answers can be\nchecked mechanically, as in mathematics and code, the loop works far better\nthan where they cannot.\u003C\u002Fp>\n",{"id":66,"order":941,"partId":71,"title":938,"summary":942,"concepts":943,"searchTerms":948,"learningObjectives":954,"misconceptions":957,"buildsOn":959,"seeAlso":961,"body":965},31,"The idea that an AI system could improve its own capabilities, including its ability to improve itself. A research concept, not a current mechanism.",[944,945,946,947],"recursive self-improvement","intelligence explosion","automated ai research","feedback loop",[949,950,951,952,953],"singularity","self improving ai","ai improving ai","takeoff","seed ai",[955,956],"State the recursive self-improvement hypothesis","Identify which parts of today's training loops resemble it, and which do not",[958],"Current models rewrite their own weights to become smarter while they run.",[960],{"id":65,"title":608},[962,964],{"id":67,"title":963},"AGI, and why definitions vary",{"id":63,"title":266},"\u003Cp>The hypothesis is old: a system able to improve the system that produces it\ncould make each improvement come faster than the last. In 1965 the\nstatistician I. J. Good called the possible result an “intelligence\nexplosion”.\u003C\u002Fp>\n\u003Cp>Pieces of today’s practice point in that direction. Models generate and\nfilter \u003Ca href=\"#synthetic-data\">their own training data\u003C\u002Fa>, write code for machine\nlearning experiments, and help evaluate other models. But every one of those\nloops still runs through training jobs, compute budgets and evaluations that\npeople design and launch, and no model changes its own weights while it\nruns.\u003C\u002Fp>\n\u003Cp>Whether such loops could become autonomous and compounding, or would run into\nlimits of data, compute, or the ability to verify that a change really is an\nimprovement, is an open research question. The honest summary is that the\nconcept is well defined and seriously studied, and the mechanism does not\nexist in deployed systems today.\u003C\u002Fp>\n",{"id":67,"order":967,"partId":71,"title":963,"summary":968,"concepts":969,"searchTerms":974,"learningObjectives":981,"misconceptions":984,"buildsOn":986,"seeAlso":988,"body":990},32,"Artificial general intelligence has no single agreed definition, so any claim about it depends on which definition is being used.",[970,67,971,972,973],"artificial general intelligence","definition","generality","benchmarks",[975,976,977,978,979,980],"what is agi","when will agi arrive","human level ai","superintelligence","general intelligence","asi",[982,983],"Compare several definitions of AGI","Evaluate an AGI claim by identifying the definition and the measurement behind it",[985],"AGI is a well-defined threshold that a model either passes or does not.",[987],{"id":66,"title":938},[989],{"id":63,"title":266},"\u003Cp>“Artificial general intelligence” is used in at least four quite different\nsenses:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Human-level breadth\u003C\u002Fstrong>: performing at or above human level across most\ncognitive tasks, not only one domain.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Learning ability\u003C\u002Fstrong>: acquiring new skills as efficiently as a person does,\nfrom little data.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Economic\u003C\u002Fstrong>: doing most economically valuable work. OpenAI’s charter uses\na version of this, describing systems that “outperform humans at most\neconomically valuable work”.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Graded\u003C\u002Fstrong>: frameworks that drop the single threshold and rate systems by\nlevels of performance and generality instead.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>The disagreement is not just pedantry. “General” and “intelligence” are both\ncontested words, the definitions point to different measurements\n(benchmark scores, job tasks, autonomy, learning speed), and organisations\nhave commercial and contractual reasons to prefer one or another.\u003C\u002Fp>\n\u003Cp>So the useful question about any AGI claim is not yes or no, but: which\ndefinition, measured how? A system can satisfy one definition comfortably\nwhile clearly failing another.\u003C\u002Fp>\n",[992,996],{"id":993,"title":994,"nodes":995},"llm-generation","How an LLM generates text",[17,19,20,27,32,37,39],{"id":997,"title":998,"nodes":999},"coding-agents","How AI coding agents understand a repository",[31,54,53,55,56,57,58],1795596271922,"0da95fdd-5522-4f9d-b2e6-bcb75a6c8f49"]