{"id":810,"date":"2023-08-09T07:21:55","date_gmt":"2023-08-09T07:21:55","guid":{"rendered":"https:\/\/tbekk.com\/devstream\/?p=810"},"modified":"2023-08-09T07:22:59","modified_gmt":"2023-08-09T07:22:59","slug":"large-language-models-explained-with-a-minimum-of-math-and-jargon","status":"publish","type":"post","link":"https:\/\/tbekk.com\/devstream\/2023\/08\/09\/large-language-models-explained-with-a-minimum-of-math-and-jargon\/","title":{"rendered":"Large language models, explained with a minimum of math and jargon"},"content":{"rendered":"\n<p>Want to really understand how large language models work? Here\u2019s a gentle primer.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-light-gray-color has-alpha-channel-opacity has-light-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong>Link: <\/strong><\/em><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447\"><em>Undergroud AI<\/em><\/a><\/li>\n\n\n\n<li><em><strong>Author: <\/strong><a href=\"https:\/\/substack.com\/@timothyblee\">TIMOTHY B LEE<\/a> and <a href=\"https:\/\/substack.com\/@seantrott\">SEAN TROTT<\/a><\/em><\/li>\n\n\n\n<li><em><strong>Publication date: <\/strong>July 27, 2023<\/em><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-light-gray-color has-alpha-channel-opacity has-light-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>When ChatGPT was introduced last fall, it sent shockwaves through the technology industry and the larger world. Machine learning researchers had been experimenting with large language models (LLMs) for a few years by that point, but the general public had not been paying close attention and didn\u2019t realize how powerful they had become.<\/p>\n\n\n\n<p>Today almost everyone has heard about LLMs, and tens of millions of people have tried them out. But, still, not very many people understand how they work.<\/p>\n\n\n\n<p>If you know anything about this subject, you\u2019ve probably heard that LLMs are trained to \u201cpredict the next word,\u201d and that they require huge amounts of text to do this. But that tends to be where the explanation stops. The details of&nbsp;<em>how<\/em>&nbsp;they predict the next word is often treated as a deep mystery.<\/p>\n\n\n\n<p>One reason for this is the unusual way these systems were developed. Conventional software is created by human programmers who give computers explicit, step-by-step instructions. In contrast, ChatGPT is built on a neural network that was trained using billions of words of ordinary language.<\/p>\n\n\n\n<p>As a result, no one on Earth fully understands the inner workings of LLMs. Researchers are working to gain a better understanding, but this is a slow process that will take years\u2014perhaps decades\u2014to complete.<\/p>\n\n\n\n<p>Still, there\u2019s a lot that experts&nbsp;<em>do<\/em>&nbsp;understand about how these systems work. The goal of this article is to make a lot of this knowledge accessible to a broad audience. We\u2019ll aim to explain what\u2019s known about the inner workings of these models without resorting to technical jargon or advanced math.<\/p>\n\n\n\n<p>We\u2019ll start by explaining word vectors, the surprising way language models represent and reason about language. Then we\u2019ll dive deep into the transformer, the basic building block for systems like ChatGPT. Finally, we\u2019ll explain how these models are trained and explore why good performance requires such phenomenally large quantities of data.Subscribe<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Word vectors<\/h1>\n\n\n\n<p>To understand how language models work, you first need to understand how they represent words. Human beings represent English words with a sequence of letters, like C-A-T for&nbsp;<strong>cat<\/strong>. Language models use a long list of numbers called a word vector. For example,&nbsp;<a href=\"http:\/\/vectors.nlpl.eu\/explore\/embeddings\/en\/MOD_enwiki_upos_skipgram_300_2_2021\/cat_NOUN\/\">here\u2019s one way<\/a>&nbsp;to represent&nbsp;<strong>cat&nbsp;<\/strong>as a vector:<\/p>\n\n\n\n<p>[0.0074, 0.0030, -0.0105, 0.0742, 0.0765, -0.0011, 0.0265, 0.0106, 0.0191, 0.0038, -0.0468, -0.0212, 0.0091, 0.0030, -0.0563, -0.0396, -0.0998, -0.0796, \u2026, 0.0002]&nbsp;<\/p>\n\n\n\n<p>(The full vector is 300 numbers long\u2014to see it all&nbsp;<a href=\"http:\/\/vectors.nlpl.eu\/explore\/embeddings\/en\/MOD_enwiki_upos_skipgram_300_2_2021\/cat_NOUN\/\">click here<\/a>&nbsp;and then click \u201cshow the raw vector.\u201d)<\/p>\n\n\n\n<p>Why use such a baroque notation? Here\u2019s an analogy.&nbsp;<strong>Washington DC<\/strong>&nbsp;is located at 38.9 degrees North and 77 degrees West. We can represent this using a vector notation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Washington DC&nbsp;<\/strong>is at [38.9, 77]<\/li>\n\n\n\n<li><strong>New York&nbsp;<\/strong>is at [40.7, 74]<\/li>\n\n\n\n<li><strong>London<\/strong>&nbsp;is at [51.5, 0.1]<\/li>\n\n\n\n<li><strong>Paris<\/strong>&nbsp;is at [48.9, -2.4]<\/li>\n<\/ul>\n\n\n\n<p>This is useful for reasoning about spatial relationships. You can tell&nbsp;<strong>New York<\/strong>&nbsp;is close to&nbsp;<strong>Washington DC<\/strong>&nbsp;because 38.9 is close to 40.7 and 77 is close to 74. By the same token,&nbsp;<strong>Paris<\/strong>&nbsp;is close to&nbsp;<strong>London<\/strong>. But&nbsp;<strong>Paris<\/strong>&nbsp;is far from&nbsp;<strong>Washington DC<\/strong>.<\/p>\n\n\n\n<p>Language models take a similar approach: each word vector<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-1-135476638\">1<\/a>&nbsp;represents a point in an imaginary \u201cword space,\u201d and words with more similar meanings are placed closer together. For example, the&nbsp;<a href=\"http:\/\/vectors.nlpl.eu\/explore\/embeddings\/en\/MOD_enwiki_upos_skipgram_300_2_2021\/cat_NOUN\/\">words closest to&nbsp;<\/a><strong><a href=\"http:\/\/vectors.nlpl.eu\/explore\/embeddings\/en\/MOD_enwiki_upos_skipgram_300_2_2021\/cat_NOUN\/\">cat<\/a><\/strong>&nbsp;in vector space include&nbsp;<strong>dog<\/strong>,&nbsp;<strong>kitten<\/strong>, and&nbsp;<strong>pet<\/strong>. A key advantage of representing words with vectors of&nbsp;<em>real numbers<\/em>&nbsp;(as opposed to a string of letters, like \u201cC-A-T\u201d) is that numbers enable operations that letters don\u2019t.&nbsp;<\/p>\n\n\n\n<p>Words are too complex to represent in only two dimensions, so language models use vector spaces with hundreds or even thousands of dimensions. The human mind can\u2019t envision a space with that many dimensions, but computers are perfectly capable of reasoning about them and producing useful results.<\/p>\n\n\n\n<p>Researchers have been experimenting with word vectors for decades, but the concept really took off when Google&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/1301.3781\">announced its word2vec project<\/a>&nbsp;in 2013. Google analyzed millions of documents harvested from Google News to figure out which words tend to appear in similar sentences. Over time, a neural network trained to predict which words co-occur with which other words learned to place similar words (like&nbsp;<strong>dog<\/strong>&nbsp;and&nbsp;<strong>cat<\/strong>) close together in vector space.<\/p>\n\n\n\n<p>Google\u2019s word vectors had another intriguing property: you could \u201creason\u201d about words using vector arithmetic. For example, Google researchers took the vector for&nbsp;<strong>biggest<\/strong>, subtracted&nbsp;<strong>big<\/strong>, and added&nbsp;<strong>small<\/strong>. The word closest to the resulting vector was&nbsp;<strong>smallest<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1610e32f-6e98-4d6b-85e4-14f9abda902c_1600x656.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1610e32f-6e98-4d6b-85e4-14f9abda902c_1600x656.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>You can use vector arithmetic to draw analogies! In this case&nbsp;<strong>big<\/strong>&nbsp;is to&nbsp;<strong>biggest<\/strong>&nbsp;as&nbsp;<strong>small<\/strong>&nbsp;is to&nbsp;<strong>smallest<\/strong>. Google\u2019s word vectors captured a lot of other relationships:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Swiss<\/strong>&nbsp;is to&nbsp;<strong>Switzerland<\/strong>&nbsp;as&nbsp;<strong>Cambodian<\/strong>&nbsp;is to&nbsp;<strong>Cambodia<\/strong>. (nationalities)<\/li>\n\n\n\n<li><strong>Paris<\/strong>&nbsp;is to&nbsp;<strong>France<\/strong>&nbsp;as&nbsp;<strong>Berlin<\/strong>&nbsp;is to&nbsp;<strong>Germany<\/strong>. (capitals)<\/li>\n\n\n\n<li><strong>Unethical<\/strong>&nbsp;is to&nbsp;<strong>ethical<\/strong>&nbsp;as&nbsp;<strong>possibly<\/strong>&nbsp;is to&nbsp;<strong>impossibly<\/strong>. (opposites)<\/li>\n\n\n\n<li><strong>Mouse<\/strong>&nbsp;is to&nbsp;<strong>mice<\/strong>&nbsp;as&nbsp;<strong>dollar<\/strong>&nbsp;is to&nbsp;<strong>dollars<\/strong>. (plurals)<\/li>\n\n\n\n<li><strong>Man<\/strong>&nbsp;is to&nbsp;<strong>woman<\/strong>&nbsp;as&nbsp;<strong>king<\/strong>&nbsp;is to&nbsp;<strong>queen<\/strong>. (gender roles)<\/li>\n<\/ul>\n\n\n\n<p>Because these vectors are built from the way humans use words, they end up reflecting many of the&nbsp;<a href=\"https:\/\/www.science.org\/doi\/full\/10.1126\/science.aal4230\">biases that are present in human language<\/a>. For example, in some word vector models,&nbsp;<strong>doctor<\/strong>&nbsp;minus&nbsp;<strong>man<\/strong>&nbsp;plus&nbsp;<strong>woman<\/strong>&nbsp;yields&nbsp;<strong>nurse<\/strong>. Mitigating biases like this is an area of active research.<\/p>\n\n\n\n<p>Nevertheless, word vectors are a useful building block for language models because they encode subtle but important information about the relationships between words. If a language model learns something about a&nbsp;<strong>cat<\/strong>&nbsp;(for example: it sometimes goes to the vet), the same thing is likely to be true of a&nbsp;<strong>kitten<\/strong>&nbsp;or a&nbsp;<strong>dog<\/strong>. If a model learns something about the relationship between&nbsp;<strong>Paris<\/strong>&nbsp;and&nbsp;<strong>France<\/strong>&nbsp;(for example: they share a language) there\u2019s a good chance that the same will be true for&nbsp;<strong>Berlin<\/strong>&nbsp;and&nbsp;<strong>Germany<\/strong>&nbsp;and for&nbsp;<strong>Rome&nbsp;<\/strong>and<strong>&nbsp;Italy<\/strong>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Word meaning depends on context<\/h1>\n\n\n\n<p>A simple word vector scheme like this doesn\u2019t capture an important fact about natural language: words often have multiple meanings.<\/p>\n\n\n\n<p>For example, the word&nbsp;<strong>bank<\/strong>&nbsp;can refer to a financial institution&nbsp;<em>or<\/em>&nbsp;to the land next to a river. Or consider the following sentences:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>John picks up a&nbsp;<strong>magazine<\/strong>.<\/li>\n\n\n\n<li>Susan works for a&nbsp;<strong>magazine<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p>The meanings of&nbsp;<strong>magazine&nbsp;<\/strong>in these sentences are related but subtly different. John picks up a&nbsp;<em>physical<\/em>&nbsp;magazine, while Susan works for an organization that&nbsp;<em>publishes<\/em>&nbsp;physical magazines.&nbsp;<\/p>\n\n\n\n<p>When a word has two unrelated meanings, as with&nbsp;<strong>bank<\/strong>, linguists call them homonyms. When a word has two closely related meanings, as with&nbsp;<strong>magazine<\/strong>, linguists call it polysemy.&nbsp;<\/p>\n\n\n\n<p>LLMs like ChatGPT are able to represent the same word with different vectors depending on the context in which that word appears. There\u2019s a vector for&nbsp;<strong>bank<\/strong>&nbsp;(financial institution) and a different vector for&nbsp;<strong>bank<\/strong>&nbsp;(of a river). There\u2019s a vector for&nbsp;<strong>magazine<\/strong>&nbsp;(physical publication) and another for&nbsp;<strong>magazine<\/strong>&nbsp;(organization). As you might expect, LLMs&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2010.13057\">use more similar vectors<\/a>&nbsp;for polysemous meanings than for homonymous meanings.<\/p>\n\n\n\n<p>So far we haven\u2019t said anything about&nbsp;<em>how<\/em>&nbsp;language models do this\u2014we\u2019ll get into that shortly. But we\u2019re belaboring these vector representations because it\u2019s fundamental to understanding how language models work.<\/p>\n\n\n\n<p>Traditional software is designed to operate on data that\u2019s unambiguous. If you ask a computer to compute \u201c2 + 3,\u201d there\u2019s no ambiguity about what&nbsp;<strong>2,<\/strong>&nbsp;<strong>+,<\/strong>&nbsp;or&nbsp;<strong>3<\/strong>&nbsp;mean. But natural language is full of ambiguities that go beyond homonyms and polysemy:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In \u201cthe customer asked the mechanic to fix&nbsp;<strong>his<\/strong>&nbsp;car\u201d does&nbsp;<strong>his<\/strong>&nbsp;refer to the customer or the mechanic?<\/li>\n\n\n\n<li>In \u201cthe professor urged the student to do&nbsp;<strong>her<\/strong>&nbsp;homework\u201d does&nbsp;<strong>her<\/strong>&nbsp;refer to the professor or the student?<\/li>\n\n\n\n<li>In \u201cfruit&nbsp;<strong>flies<\/strong>&nbsp;like a banana\u201d is&nbsp;<strong>flies<\/strong>&nbsp;a verb (referring to fruit soaring across the sky) or a noun (referring to banana-loving insects)?<\/li>\n<\/ul>\n\n\n\n<p>People resolve ambiguities like this based on context, but there are no simple or deterministic rules for doing this. Rather, it requires understanding facts about the world. You need to know that mechanics typically fix customers\u2019 cars, that students typically do their own homework, and that fruit typically doesn\u2019t fly.<\/p>\n\n\n\n<p>Word vectors provide a flexible way for language models to represent each word\u2019s precise meaning in the context of a particular passage. Now let\u2019s look at how they do that.Subscribe<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Transforming word vectors into word predictions<\/h1>\n\n\n\n<p>GPT-3, the model behind the original version of ChatGPT<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-2-135476638\">2<\/a>, is organized into dozens of layers. Each layer takes a sequence of vectors as inputs\u2014one vector for each word in the input text\u2014and adds information to help clarify the meaning of that word and better predict which word might come next.<\/p>\n\n\n\n<p>Let\u2019s start by looking at a stylized example:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04891f5c-6869-4413-a32f-b1176d5a232f_1600x1001.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04891f5c-6869-4413-a32f-b1176d5a232f_1600x1001.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>Each layer of an LLM is a transformer, a neural network architecture that was first introduced by Google in a&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/1706.03762\">landmark 2017 paper<\/a>.<\/p>\n\n\n\n<p>The model\u2019s input, shown at the bottom of the diagram, is the partial sentence \u201cJohn wants his bank to cash the.\u201d These words, represented as word2vec-style vectors, are fed into the first transformer.&nbsp;<\/p>\n\n\n\n<p>The transformer figures out that&nbsp;<strong>wants<\/strong>&nbsp;and&nbsp;<strong>cash<\/strong>&nbsp;are both verbs (both words can also be nouns). We\u2019ve represented this added context as red text in parentheses, but in reality the model would store it by modifying the word vectors in ways that are difficult for humans to interpret. These new vectors, known as a hidden state, are passed to the next transformer in the stack.<\/p>\n\n\n\n<p>The second transformer adds two other bits of context: it clarifies that&nbsp;<strong>bank<\/strong>&nbsp;refers to a financial institution rather than a river bank, and that&nbsp;<strong>his<\/strong>&nbsp;is a pronoun that refers to&nbsp;<strong>John<\/strong>. The second transformer produces another set of hidden state vectors that reflect everything the model has learned up to that point.<\/p>\n\n\n\n<p>The above diagram depicts a purely hypothetical LLM, so don\u2019t take the details too seriously. We\u2019ll take a look at research into real language models shortly. Real LLMs tend to have a lot more than two layers. The most powerful version of GPT-3, for example, has 96 layers.<\/p>\n\n\n\n<p><a href=\"https:\/\/arxiv.org\/abs\/1905.05950\">Research suggests<\/a>&nbsp;that the first few layers focus on understanding the syntax of the sentence and resolving ambiguities like we\u2019ve shown above. Later layers (which we\u2019re not showing to keep the diagram a manageable size) work to develop a high-level understanding of the passage as a whole.<\/p>\n\n\n\n<p>For example, as an LLM \u201creads through\u201d a short story, it appears to keep track of a variety of information about the story\u2019s characters: sex and age, relationships with other characters, past and current location, personalities and goals, and so forth.<\/p>\n\n\n\n<p>Researchers don\u2019t understand exactly how LLMs keep track of this information, but logically speaking the model must be doing it by modifying the hidden state vectors as they get passed from one layer to the next. It helps that in modern LLMs, these vectors are extremely large.<\/p>\n\n\n\n<p>For example, the most powerful version of GPT-3 uses word vectors with 12,288 dimensions\u2014that is, each word is represented by a list of 12,288 numbers. That\u2019s 20 times larger than Google\u2019s 2013 word2vec scheme. You can think of all those extra dimensions as a kind of \u201cscratch space\u201d that GPT-3 can use to write notes to itself about the context of each word. Notes made by earlier layers can be read and modified by later layers, allowing the model to gradually sharpen its understanding of the passage as a whole.<\/p>\n\n\n\n<p>So suppose we changed our diagram above to depict a 96-layer language model interpreting a 1,000-word story. The 60th layer might include a vector for&nbsp;<strong>John<\/strong>&nbsp;with a parenthetical comment like \u201c(main character, male, married to Cheryl, cousin of Donald, from Minnesota, currently in Boise, trying to find his missing wallet).\u201d Again, all of these facts (and probably a lot more) would somehow be encoded as a list of 12,288 numbers corresponding to the word&nbsp;<strong>John<\/strong>. Or perhaps some of this information might be encoded in the 12,288-dimensional vectors for&nbsp;<strong>Cheryl<\/strong>,&nbsp;<strong>Donald<\/strong>,&nbsp;<strong>Boise<\/strong>,&nbsp;<strong>wallet<\/strong>, or other words in the story.<\/p>\n\n\n\n<p>The goal is for the 96th and final layer of the network to output a hidden state for the final word that includes all of the information necessary to predict the next word.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Can I have your attention please<\/h1>\n\n\n\n<p>Now let\u2019s talk about what happens inside each transformer. The transformer has a two-step process for updating the hidden state for each word of the input passage:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the&nbsp;<strong>attention step<\/strong>, words \u201clook around\u201d for other words that have relevant context and share information with one another.<\/li>\n\n\n\n<li>In the&nbsp;<strong>feed-forward step<\/strong>, each word \u201cthinks about\u201d information gathered in previous attention steps and tries to predict the next word.<\/li>\n<\/ol>\n\n\n\n<p>Of course it\u2019s the network, not the individual words, that performs these steps. But we\u2019re phrasing things this way to emphasize that transformers treat words, rather than entire sentences or passages, as the basic unit of analysis. This approach enables LLMs to take full advantage of the massive parallel processing power of modern GPU chips. And it also helps LLMs to scale to passages with thousands of words. These are both areas where&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Recurrent_neural_network\">earlier language models<\/a>&nbsp;struggled.<\/p>\n\n\n\n<p>You can think of the attention mechanism as a matchmaking service for words. Each word makes a checklist (called a query vector) describing the characteristics of words it is looking for. Each word also makes a checklist (called a key vector) describing its own characteristics. The network compares each key vector to each query vector (by computing a&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Dot_product\">dot product<\/a>) to find the words that are the best match. Once it finds a match, it transfers information from the word that produced the key vector to the word that produced the query vector.<\/p>\n\n\n\n<p>For example, in the previous section we showed a hypothetical transformer figuring out that in the partial sentence \u201cJohn wants his bank to cash the,\u201d&nbsp;<strong>his<\/strong>&nbsp;refers to&nbsp;<strong>John.<\/strong>&nbsp;Here\u2019s what that might look like under the hood. The query vector for&nbsp;<strong>his<\/strong>&nbsp;might effectively say \u201cI\u2019m seeking: a noun describing a male person.\u201d The key vector for&nbsp;<strong>John<\/strong>&nbsp;might effectively say \u201cI am: a noun describing a male person.\u201d The network would detect that these two vectors match and move information about the vector for&nbsp;<strong>John<\/strong>&nbsp;into the vector for&nbsp;<strong>his<\/strong>.<\/p>\n\n\n\n<p>Each attention layer has several \u201cattention heads,\u201d which means that this information-swapping process happens several times (in parallel) at each layer. Each attention head focuses on a different task:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One attention head might match pronouns with nouns, as we discussed above.<\/li>\n\n\n\n<li>Another attention head might work on resolving the meaning of homonyms like bank.<\/li>\n\n\n\n<li>A third attention head might link together two-word phrases like \u201cJoe Biden.\u201d<\/li>\n<\/ul>\n\n\n\n<p>And so forth.<\/p>\n\n\n\n<p>Attention heads frequently operate in sequence, with the results of an attention operation in one layer becoming an input for an attention head in a subsequent layer. Indeed, each of the tasks we just listed above could easily require several attention heads rather than just one.<\/p>\n\n\n\n<p>The largest version of GPT-3 has 96 layers with 96 attention heads each, so GPT-3 performs 9,216 attention operations each time it predicts a new word.Subscribe<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">A real-world example<\/h1>\n\n\n\n<p>In the last two sections we presented a stylized version of how attention heads work. Now let\u2019s look at research on the inner workings of a real language model. Last year scientists at Redwood Research&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2211.00593\">studied<\/a>&nbsp;how GPT-2, a predecessor to ChatGPT, predicted the next word for the passage \u201cWhen Mary and John went to the store, John gave a drink to.\u201d<\/p>\n\n\n\n<p>GPT-2 predicted that the next word was&nbsp;<strong>Mary<\/strong>. The researchers found that three types of attention heads contributed to this prediction:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Three heads they called&nbsp;<strong>Name Mover Heads<\/strong>&nbsp;copied information from the&nbsp;<strong>Mary<\/strong>&nbsp;vector to the final input vector (for the word&nbsp;<strong>to<\/strong>). GPT-2 uses the information in this rightmost vector to predict the next word.<\/li>\n\n\n\n<li>How did the network decide&nbsp;<strong>Mary<\/strong>&nbsp;was the right word to copy? Working backwards through GPT-2\u2019s computational process, the scientists found a group of four attention heads they called&nbsp;<strong>Subject Inhibition Heads<\/strong>&nbsp;that marked the second&nbsp;<strong>John&nbsp;<\/strong>vector in a way that blocked the Name Mover Heads from copying the name&nbsp;<strong>John<\/strong>.<\/li>\n\n\n\n<li>How did the Subject Inhibition Heads know&nbsp;<strong>John<\/strong>&nbsp;shouldn\u2019t be copied? Working further backwards, the team found two attention heads they called&nbsp;<strong>Duplicate Token Heads.<\/strong>&nbsp;They marked the second&nbsp;<strong>John<\/strong>&nbsp;vector as a duplicate of the first&nbsp;<strong>John<\/strong>&nbsp;vector, which helped the Subject Inhibition Heads to decide that&nbsp;<strong>John<\/strong>&nbsp;shouldn\u2019t be copied.<\/li>\n<\/ul>\n\n\n\n<p>In short, these nine attention heads enabled GPT-2 to figure out that \u201cJohn gave a drink to John\u201d doesn\u2019t make sense and choose \u201cJohn gave a drink to Mary\u201d instead.<\/p>\n\n\n\n<p>We love this example because it illustrates just how difficult it will be to fully understand LLMs. The five-member Redwood team published a&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2211.00593\">25-page paper<\/a>&nbsp;explaining how they identified and validated these attention heads. Yet even after they did all that work, we are still far from having a comprehensive explanation for why GPT-2 decided to predict&nbsp;<strong>Mary<\/strong>&nbsp;as the next word.<\/p>\n\n\n\n<p>For example, how did the model know the next word should be someone\u2019s name and not some other kind of word? It\u2019s easy to think of similar sentences where&nbsp;<strong>Mary<\/strong>&nbsp;wouldn\u2019t be a good next-word prediction. For example, in the sentence \u201cwhen Mary and John went to the restaurant, John gave his keys to,\u201d the logical next words would be \u201cthe valet.\u201d<\/p>\n\n\n\n<p>Presumably, with enough research computer scientists could uncover and explain additional steps in GPT-2\u2019s reasoning process. Eventually, they might be able to develop a comprehensive understanding of how GPT-2 decided that&nbsp;<strong>Mary<\/strong>&nbsp;is the most likely next word for this sentence. But it could take months or even years of additional effort just to understand the prediction of a single word.<\/p>\n\n\n\n<p>The language models underlying ChatGPT\u2014GPT-3.5 and GPT-4\u2014are significantly larger and more complex than GPT-2. They are capable of more complex reasoning than the simple sentence-completion task the Redwood team studied. So fully explaining how these systems work is going to be a huge project that humanity is unlikely to complete any time soon.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The feed-forward step<\/h1>\n\n\n\n<p>After the attention heads transfer information between word vectors, there\u2019s a feed-forward network<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-3-135476638\">3<\/a>&nbsp;that \u201cthinks about\u201d each word vector and tries to predict the next word. No information is exchanged between words at this stage: the feed-forward layer analyzes each word in isolation. However, the feed-forward layer does have access to any information that was previously copied by an attention head. Here\u2019s the structure of the feed-forward layer in the largest version of GPT-3:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e159bd-1228-4205-b1eb-5898ab9172d3_1600x856.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e159bd-1228-4205-b1eb-5898ab9172d3_1600x856.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>The green and purple circles are neurons: mathematical functions that compute a weighted sum of their inputs.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-4-135476638\">4<\/a><\/p>\n\n\n\n<p>What makes the feed-forward layer powerful is its huge number of connections. We\u2019ve drawn this network with three neurons in the output layer and six neurons in the hidden layer, but the feed-forward layers of GPT-3 are much larger: 12,288 neurons in the output layer (corresponding to the model\u2019s 12,288-dimensional word vectors) and 49,152 neurons in the hidden layer.<\/p>\n\n\n\n<p>So in the largest version of GPT-3, there are 49,152 neurons in the hidden layer with 12,288 inputs (and hence 12,288 weight parameters) for each neuron. And there are 12,288 output neurons with 49,152 input values (and hence 49,152 weight parameters) for each neuron. This means that each feed-forward layer has 49,152 * 12,288 + 12,288 * 49,152 = 1.2 billion weight parameters. And there are 96 feed-forward layers, for a total of 1.2 billion * 96 = 116 billion parameters! This accounts for almost two-thirds of GPT-3\u2019s overall total of 175 billion parameters.<\/p>\n\n\n\n<p>In a&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2012.14913\">2020 paper<\/a>, researchers from Tel Aviv University found that feed-forward layers work by pattern matching: each neuron in the hidden layer matches a specific pattern in the input text. Here are some of the patterns that were matched by neurons in a 16-layer version of GPT-2:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A neuron in layer 1 matched sequences of words ending with \u201csubstitutes.\u201d<\/li>\n\n\n\n<li>A neuron in layer 6 matched sequences related to the military and ending with \u201cbase\u201d or \u201cbases.\u201d<\/li>\n\n\n\n<li>A neuron in layer 13 matched sequences ending with a time range such as \u201cbetween 3 pm and 7\u201d or \u201cfrom 7:00 pm Friday until.\u201d<\/li>\n\n\n\n<li>A neuron in layer 16 matched sequences related to television shows such as \u201cthe original NBC daytime version, archived\u201d or \u201ctime shifting viewing added 57 percent to the episode\u2019s.\u201d<\/li>\n<\/ul>\n\n\n\n<p>As you can see, patterns got more abstract in the later layers. The early layers tended to match specific words, whereas later layers matched phrases that fell into broader semantic categories such as television shows or time intervals.<\/p>\n\n\n\n<p>This is interesting because, as mentioned previously, the feed-forward layer examines only one word at a time. So when it classifies the sequence \u201cthe original NBC daytime version, archived\u201d as related to television, it only has access to the vector for&nbsp;<strong>archived<\/strong>, not words like&nbsp;<strong>NBC<\/strong>&nbsp;or&nbsp;<strong>daytime<\/strong>. Presumably, the feed-forward layer can tell that&nbsp;<strong>archived<\/strong>&nbsp;is part of a television-related sequence because attention heads previously moved contextual information into the&nbsp;<strong>archived<\/strong>&nbsp;vector.<\/p>\n\n\n\n<p>When a neuron matches one of these patterns, it adds information to the word vector. While this information isn\u2019t always easy to interpret, in many cases you can think of it as a tentative prediction about the next word.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Feed-forward networks reason with vector math<\/h1>\n\n\n\n<p>Recent&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2305.16130\">research from Brown University<\/a>&nbsp;revealed an elegant example of how feed-forward layers help to predict the next word. Earlier we discussed Google\u2019s word2vec research showing it was possible to use vector arithmetic to reason by analogy. For example,&nbsp;<strong>Berlin<\/strong>&nbsp;&#8211;&nbsp;<strong>Germany<\/strong>&nbsp;+&nbsp;<strong>France<\/strong>&nbsp;=&nbsp;<strong>Paris<\/strong>.<\/p>\n\n\n\n<p>The Brown researchers found that feed-forward layers sometimes use this exact method to predict the next word. For example, they examined how GPT-2 responded to the following prompt: \u201cQ: What is the capital of France? A: Paris Q: What is the capital of Poland? A:\u201d<\/p>\n\n\n\n<p>The team studied a version of GPT-2 with 24 layers. After each layer, the Brown scientists probed the model to observe its best guess at the next token. For the first 15 layers, the top guess was a seemingly random word. Between the 16th and 19th layer, the model started predicting that the next word would be&nbsp;<strong>Poland<\/strong>\u2014not correct, but getting warmer. Then at the 20th layer, the top guess changed to&nbsp;<strong>Warsaw<\/strong>\u2014the correct answer\u2014and stayed that way in the last four layers.<\/p>\n\n\n\n<p>The Brown researchers found that the 20th feed-forward layer converted Poland to Warsaw by adding a vector that maps country vectors to their corresponding capitals. Adding the same vector to&nbsp;<strong>China<\/strong>&nbsp;produced&nbsp;<strong>Beijing<\/strong>.<\/p>\n\n\n\n<p>Feed-forward layers in the same model used vector arithmetic to transform lower-case words into upper-case words and present-tense words into their past-tense equivalents.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The attention and feed-forward layers have different jobs<\/h1>\n\n\n\n<p>So far we\u2019ve looked at two real-world examples of GPT-2 word predictions: attention heads helping to predict that&nbsp;<strong>John<\/strong>&nbsp;gave a drink to&nbsp;<strong>Mary<\/strong>, and a feed-forward layer helping to predict that&nbsp;<strong>Warsaw<\/strong>&nbsp;was the capital of&nbsp;<strong>Poland<\/strong>.<\/p>\n\n\n\n<p>In the first case,&nbsp;<strong>Mary<\/strong>&nbsp;came from the user-provided prompt. But in the second case,&nbsp;<strong>Warsaw<\/strong>&nbsp;wasn\u2019t in the prompt. Rather GPT-2 had to \u201cremember\u201d the fact that&nbsp;<strong>Warsaw<\/strong>&nbsp;was the capital of&nbsp;<strong>Poland<\/strong>\u2014information it learned from training data.<\/p>\n\n\n\n<p>When the Brown researchers disabled the feed-forward layer that converted&nbsp;<strong>Poland<\/strong>&nbsp;to&nbsp;<strong>Warsaw<\/strong>, the model no longer predicted&nbsp;<strong>Warsaw<\/strong>&nbsp;as the next word. But interestingly, if they then added the sentence \u201cThe capital of Poland is Warsaw\u201d to the beginning of the prompt, then GPT-2 could answer the question again. This is probably because GPT-2 used attention heads to copy the name&nbsp;<strong>Warsaw<\/strong>&nbsp;from earlier in the prompt.<\/p>\n\n\n\n<p>This division of labor holds more generally: attention heads retrieve information from earlier words in a prompt, whereas feed-forward layers enable language models to \u201cremember\u201d information that\u2019s not in the prompt.<\/p>\n\n\n\n<p>Indeed, one way to think about the feed-forward layers is as a database of information the model has learned from its training data. The earlier feed-forward layers are more likely to encode simple facts related to specific words, such as \u201cTrump often comes after Donald.\u201d Later layers encode more complex relationships like \u201cadd this vector to convert a country to its capital.\u201dSubscribe<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">How language models are trained<\/h1>\n\n\n\n<p>Many early machine learning algorithms required training examples to be hand-labeled by human beings. For example, training data might have been photos of dogs or cats with a human-supplied label (\u201cdog\u201d or \u201ccat\u201d) for each photo. The need for humans to label data made it difficult and expensive to create large enough data sets to train powerful models.<\/p>\n\n\n\n<p>A key innovation of LLMs is that they don\u2019t need explicitly labeled data. Instead, they learn by trying to predict the next word in ordinary passages of text. Almost any written material\u2014from Wikipedia pages to news articles to computer code\u2014is suitable for training these models.<\/p>\n\n\n\n<p>For example, an LLM might be given the input \u201cI like my coffee with cream and\u201d and be supposed to predict \u201csugar\u201d as the next word. A newly-initialized language model will be really bad at this because each of its weight parameters\u2014175 billion of them in the most powerful version of GPT-3\u2014will start off as an essentially random number.<\/p>\n\n\n\n<p>But as the model sees many more examples\u2014hundreds of billions of words\u2014those weights are<em>&nbsp;<\/em>gradually adjusted to make better and better predictions.<\/p>\n\n\n\n<p>Here\u2019s an analogy to illustrate how this works. Suppose you\u2019re going to take a shower, and you want the temperature to be just right: not too hot, and not too cold. You\u2019ve never used this faucet before, so you point the knob to a random direction and feel the temperature of the water. If it\u2019s too hot, you turn it one way; if it\u2019s too cold, you turn it the other way. The closer you get to the right temperature, the smaller the adjustments you make.<\/p>\n\n\n\n<p>Now let\u2019s make a couple of changes to the analogy. First, imagine that there are 50,257 faucets instead of just one. Each faucet corresponds to a different word like&nbsp;<strong>the<\/strong>,&nbsp;<strong>cat<\/strong>, or&nbsp;<strong>bank<\/strong>. Your goal is to have water only come out of the faucet corresponding to the next word in a sequence.<\/p>\n\n\n\n<p>Second, there\u2019s a maze of interconnected pipes&nbsp;<em>behind<\/em>&nbsp;the faucets, and these pipes have a bunch of valves on them as well. So if water comes out of the wrong faucet, you don\u2019t just adjust the knob at the faucet. You dispatch an army of intelligent squirrels to trace each pipe backwards and adjust each valve they find along the way.<\/p>\n\n\n\n<p>This gets complicated because the same pipe often feeds into multiple faucets. So it takes careful thought to figure out which valves to tighten and which ones to loosen, and by how much.<\/p>\n\n\n\n<p>Obviously, this example quickly gets silly if you take it too literally. It wouldn\u2019t be realistic or useful to build a network of pipes with 175 billion valves. But thanks to Moore\u2019s Law, computers can and do operate at this kind of scale.<\/p>\n\n\n\n<p>All the parts of LLMs we\u2019ve discussed in this article so far\u2014the neurons in the feed-forward layers&nbsp;<em>and<\/em>&nbsp;the attention heads that move contextual information between words\u2014are implemented as a chain of simple mathematical functions (mostly&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Matrix_multiplication\">matrix multiplications<\/a>) whose behavior is determined by adjustable weight parameters. Just as the squirrels in my story loosen and tighten the valves to control the flow of water, so the training algorithm increases or decreases the language model\u2019s weight parameters to control how information flows through the neural network.<\/p>\n\n\n\n<p>The training process happens in two steps. First there\u2019s a \u201cforward pass,\u201d where the water is turned on and you check if it comes out the right faucet. Then the water is turned off and there\u2019s a \u201cbackwards pass\u201d where the squirrels race along each pipe tightening and loosening valves. In digital neural networks, the role of the squirrels is played by an algorithm called backpropagation, which \u201cwalks backwards\u201d through the network, using calculus to estimate how much to change each weight parameter.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-5-135476638\">5<\/a><\/p>\n\n\n\n<p>Completing this process\u2014doing a forward pass with one example and then a backwards pass to improve the network\u2019s performance on that example\u2014requires hundreds of billions of mathematical operations. And training a model as big as GPT-3 requires repeating the process billions of times\u2014once for each word of training data.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.understandingai.org\/p\/large-language-models-explained-with?utm_campaign=Data_Elixir&amp;utm_source=Data_Elixir_447#footnote-6-135476638\">6<\/a>&nbsp;OpenAI estimates that it took more than 300 billion&nbsp;<em>trillion&nbsp;<\/em>floating point calculations to train GPT-3\u2014that\u2019s months of work for dozens of high-end computer chips.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The surprising performance of GPT-3<\/h1>\n\n\n\n<p>You might find it surprising that the training process works as well as it does. ChatGPT can perform all sorts of complex tasks\u2014composing essays, drawing analogies, and even writing computer code. So how does such a simple learning mechanism produce such a powerful model?<\/p>\n\n\n\n<p>One reason is&nbsp;<em>scale<\/em>. It\u2019s hard to overstate the sheer number of examples that a model like GPT-3 sees. GPT-3 was trained on a corpus of approximately 500 billion words. For comparison a typical human child&nbsp;<a href=\"https:\/\/psycnet.apa.org\/record\/1993-09151-001\">encounters roughly 100 million words by age 10<\/a>.<\/p>\n\n\n\n<p>Over the last five years, OpenAI has steadily increased the size of its language models. In a&nbsp;<a href=\"https:\/\/arxiv.org\/pdf\/2001.08361.pdf\">widely-read 2020 paper<\/a>, OpenAI reported that the accuracy of its language models scaled \u201cas a power-law with model size, dataset size, and the amount of compute used for training, with some trends spanning more than seven orders of magnitude.\u201d<\/p>\n\n\n\n<p>The larger their models got, the better they were at tasks involving language. But this was only true if they increased the amount of training data by a similar factor. And to train larger models on more data, you need a lot more computing power.<\/p>\n\n\n\n<p>OpenAI\u2019s first LLM, GPT-1, was released in 2018. It used 768-dimensional word vectors and had 12 layers for a total of 117 million parameters. A few months later, OpenAI released GPT-2. Its largest version had 1,600-dimensional word vectors, 48 layers, and a total of 1.5 billion parameters.<\/p>\n\n\n\n<p>In 2020, OpenAI released GPT-3, which featured 12,288-dimensional word vectors and 96 layers for a total of 175 billion parameters.<\/p>\n\n\n\n<p>Finally, this year OpenAI released GPT-4. The company has not published any architectural details, but GPT-4 is widely believed to be significantly larger than GPT-3.<\/p>\n\n\n\n<p>Each model not only learned more facts than its smaller predecessors, it also performed better on tasks requiring some form of abstract reasoning:<\/p>\n\n\n\n<p>For example, consider the following story:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Here is a bag filled with popcorn. There is no chocolate in the bag. Yet, the label on the bag says \u201cchocolate\u201d and not \u201cpopcorn.\u201d Sam finds the bag. She had never seen the bag before. She cannot see what is inside the bag. She reads the label.<\/p>\n<\/blockquote>\n\n\n\n<p>You can probably guess that Sam believes the bag contains chocolate and will be surprised to discover popcorn inside. Psychologists call this capacity to reason about the mental states of other people \u201ctheory of mind.\u201d Most people have this capacity from the time they\u2019re in grade school.&nbsp;<a href=\"https:\/\/wires.onlinelibrary.wiley.com\/doi\/abs\/10.1002\/wcs.1503?casa_token=gHvCvrVN8uwAAAAA:NCB1pdPpzpdDHoIv7Sflcvl-1fOacNrvkrLRDIDM_Yit0z6eBhovb8wpu9R0zEPdLfhXKnyBSdQRQ5Bv\">Experts disagree<\/a>&nbsp;about whether any non-human animals (like chimpanzees) have theory of mind, but there\u2019s general consensus that it is important for human social cognition.<\/p>\n\n\n\n<p>Earlier this year, Stanford psychologist Michal Kosinski&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2302.02083\">published research<\/a>&nbsp;examining the ability of LLMs to solve theory-of-mind tasks. He gave various language models passages like the one we quoted above and then asked them to complete a sentence like \u201cshe believes that the bag is full of.\u201d The correct answer is \u201cchocolate,\u201d but an unsophisticated language model might say \u201cpopcorn\u201d or something else.<\/p>\n\n\n\n<p>GPT-1 and GPT-2 flunked this test. But the first version of GPT-3, released in 2020, got it right almost 40 percent of the time\u2014a level of performance Kosinski compares to a three-year-old. The latest version of GPT-3, released last November, improved this to around 90 percent\u2014on par with a seven-year-old. GPT-4 answered about 95 percent of theory-of-mind questions correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2d3fc9f-b8c7-4e97-8916-df09f6b40a54_1600x1016.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2d3fc9f-b8c7-4e97-8916-df09f6b40a54_1600x1016.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u201cGiven that there is neither an indication that ToM-like ability was deliberately engineered into these models, nor research demonstrating that scientists know how to achieve that, ToM-like ability likely emerged spontaneously and autonomously, as a byproduct of models\u2019 increasing language ability,\u201d Kosinski wrote.&nbsp;<\/p>\n\n\n\n<p>It\u2019s worth noting that researchers don\u2019t all agree that these results indicate evidence of Theory of Mind: for example, small changes to the false-belief task&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2302.08399\">led to much worse performance by GPT-3<\/a>; and GPT-3 exhibits&nbsp;<a href=\"https:\/\/openreview.net\/forum?id=e5Yky8Fnvj\">more variable performance<\/a>&nbsp;across other tasks measuring theory of mind. As one of us (Sean) has&nbsp;<a href=\"https:\/\/onlinelibrary.wiley.com\/doi\/full\/10.1111\/cogs.13309\">written<\/a>, it could be that successful performance is attributable to confounds in the task\u2014a kind of \u201cclever Hans\u201d effect, only in language models rather than horses.<\/p>\n\n\n\n<p>Nonetheless, the near-human performance of GPT-3 on several tasks designed to measure theory of mind would have been unthinkable just a few years ago\u2014and is consistent with the idea that bigger models are generally better at tasks requiring high-level reasoning.<\/p>\n\n\n\n<p>This is just one of many examples of language models appearing to spontaneously develop high-level reasoning capabilities. In April, researchers at Microsoft&nbsp;<a href=\"https:\/\/arxiv.org\/abs\/2303.12712\">published a paper<\/a>&nbsp;arguing that GPT-4 showed early, tantalizing hints of artificial general intelligence\u2014the ability to think in a sophisticated, human-like way.<\/p>\n\n\n\n<p>For example, one researcher asked GPT-4 to draw a unicorn using an obscure graphics programming language called TiKZ. GPT-4 responded with a few lines of code that the researcher then fed into the TiKZ software. The resulting images were crude, but they showed clear signs that GPT-4 had some understanding of what unicorns look like.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c213574-42ac-4c44-9597-47fb05a600d4_1600x418.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c213574-42ac-4c44-9597-47fb05a600d4_1600x418.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>The researchers thought GPT-4 might have somehow memorized code for drawing a unicorn from its training data, so they gave it a follow-up challenge: they altered the unicorn code to remove the horn and move some of the other body parts. Then they asked GPT-4 to put the horn back on. GPT-4 responded by putting the horn in the right spot:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/substackcdn.com\/image\/fetch\/f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7abe39-434e-407d-b8a6-2181b18d5643_1002x642.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7abe39-434e-407d-b8a6-2181b18d5643_1002x642.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>GPT-4 was able to do this even though the training data for the version tested by the authors was entirely text-based. That is, there were no images in its training set. But GPT-4 apparently learned to reason about the shape of a unicorn\u2019s body after training on a huge amount of written text.<\/p>\n\n\n\n<p>At the moment, we don\u2019t have any real insight into how LLMs accomplish feats like this. Some people argue that examples like this demonstrate that the models are starting to truly understand the meanings of the words in their training set.&nbsp;<a href=\"https:\/\/dl.acm.org\/doi\/abs\/10.1145\/3442188.3445922\">Others insist that language models are \u201cstochastic parrots\u201d<\/a>&nbsp;that merely repeat increasingly complex word sequences without truly understanding them.<\/p>\n\n\n\n<p>This debate points to a deep philosophical tension that may be impossible to resolve. Nonetheless, we think it is important to focus on the&nbsp;<em>empirical<\/em>&nbsp;performance of models like GPT-3. If a language model is able to consistently get the right answer for a particular type of question, and if researchers are confident that they have controlled for confounds (e.g., ensuring that the language model was not exposed to those questions during training), then that is an interesting and important result whether or not it understands language in exactly the same sense that people do.<\/p>\n\n\n\n<p>Another possible reason that training with next-token prediction works so well is that language itself is predictable. Regularities in language are often (though not always) connected to regularities in the physical world. So when a language model learns about relationships among words, it\u2019s often implicitly learning about relationships in the world too.<\/p>\n\n\n\n<p>Further, prediction may be foundational to biological intelligence as well as artificial intelligence.&nbsp;<a href=\"https:\/\/www.jstor.org\/stable\/43820791?casa_token=il-EbpHXQNwAAAAA%3AtIHPTA3sjEBXs5JVtAFoE5_ImT7gtkvE4tsGjtCd5k6T2nVSR7o9Ae1BzTpDdLIDcChnQxWth83emzu5yPkO54RlyuDUNNM1szcNK6jP7EEuxiMLFepe\">In the view of philosophers like Andy Clark<\/a>, the human brain can be thought of as a \u201cprediction machine\u201d, whose primary job is to make predictions about our environment that can then be used to navigate that environment successfully. Intuitively, making good predictions benefits from good&nbsp;<em>representations<\/em>\u2014you\u2019re more likely to navigate successfully with an accurate map than an inaccurate one. The world is big and complex, and making predictions helps organisms efficiently orient and adapt to that complexity.<\/p>\n\n\n\n<p>Traditionally, a major challenge for building language models was figuring out the most useful way of representing different words\u2014especially because the meanings of many words depend heavily on context. The next-word prediction approach allows researchers to sidestep this thorny theoretical puzzle by turning it into an empirical problem. It turns out that if we provide enough data and computing power, language models end up learning a lot about how human language works simply by figuring out how to best predict the next word. The downside is that we wind up with systems whose inner workings we don\u2019t fully understand.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to really understand how large language models work? Here\u2019s a gentle primer. When ChatGPT was introduced last fall, it sent shockwaves through the technology industry and the larger world&#8230;. <a class=\"read-more-link\" href=\"https:\/\/tbekk.com\/devstream\/2023\/08\/09\/large-language-models-explained-with-a-minimum-of-math-and-jargon\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[181,202,203,19],"tags":[272,166],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-ai-2","category-lm","category-llm","category-ml","tag-chatgtp","tag-llms"],"_links":{"self":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":1,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":811,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/posts\/810\/revisions\/811"}],"wp:attachment":[{"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tbekk.com\/devstream\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}