{
  "version": "https://jsonfeed.org/version/1",
  "title": "gruszka.dev",
  "home_page_url": "https://gruszka.dev/en",
  "feed_url": "https://gruszka.dev/en/tag-chatgpt.json",
  "description": "Things I would like to share",
  "items": [
    {
      "id": "https://gruszka.dev/en/linguistic-features-and-llm.html",
      "url": "https://gruszka.dev/en/linguistic-features-and-llm.html",
      "title": "Linguistic features - what you need to know before you understand how an LLM thinks",
      "content_html": "<p>LLMs (Large Language Models, i.e. ChatGPT, Claude, Gemini and friends) have been with us for a while now, and I decided to dig deeper into the topic, and one big question came up: <strong>but how does it even work that a model &quot;understands&quot; language?</strong> After all, underneath it's just &quot;math and statistics&quot;, right? Well... yes and no ;-)</p>\n<p>And then I stumbled into linguistics. And it turned out that to truly understand what an LLM does with language, you first need to understand what language is made of. And since a programmer trying to read about linguistics is a rather funny picture, I thought: <strong>I'll share it with you</strong> ;-)</p>\n<p>This is the <strong>first post in a series</strong> in which we'll survey different levels of language analysis and see how it all connects to LLMs. In today's post we'll build the foundation - we'll get to know the five main layers of language and see why each of them matters for language models.</p>\n<hr />\n<h2><a href=\"#language-is-like-an-onion---layer-upon-layer\" aria-hidden=\"true\" class=\"anchor\" id=\"language-is-like-an-onion---layer-upon-layer\"></a>Language is like an onion - layer upon layer</h2>\n<p>Before we get into the details, imagine language as a sort of... onion. Or a layer cake, if you prefer sweet metaphors :D</p>\n<p>Each layer is a different level on which language &quot;works&quot;. From the lowest - sounds - to the highest - what we <em>really</em> meant to say, even when we said something completely different.</p>\n<div class=\"mermaid-diagram\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"282.9914\" height=\"647\" viewBox=\"0 0 282.9914 647\"><rect x=\"0\" y=\"0\" width=\"282.9914\" height=\"647\" fill=\"#FFFFFF\"/><defs><marker id=\"arrow-0\" viewBox=\"0 0 10 10\" refX=\"5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker><marker id=\"arrow-start-0\" viewBox=\"0 0 10 10\" refX=\"4.5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 5 L 10 10 L 10 0 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker></defs><path id=\"edge-0\" class=\"edgePath\" data-edge-id=\"edge-0\" d=\"M 137.494,101.000 L 137.494,151.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(137.49 151.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-1\" class=\"edgePath\" data-edge-id=\"edge-1\" d=\"M 137.490,223.000 L 137.490,273.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(137.49 273.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-2\" class=\"edgePath\" data-edge-id=\"edge-2\" d=\"M 137.486,366.000 L 137.486,416.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(137.49 416.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-3\" class=\"edgePath\" data-edge-id=\"edge-3\" d=\"M 137.484,488.000 L 137.484,538.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(137.48 538.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><rect x=\"8.00\" y=\"8.00\" width=\"258.99\" height=\"93.00\" rx=\"3\" ry=\"3\" fill=\"#ff9999\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"137.50\" y=\"37.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"137.50\" dy=\"0.00\">🔊 Phonetics &amp; phonology</tspan><tspan x=\"137.50\" dy=\"21.00\">&lt;i&gt;sounds and the</tspan><tspan x=\"137.50\" dy=\"21.00\">system of sounds&lt;/i&gt;</tspan></text><rect x=\"16.65\" y=\"151.00\" width=\"241.69\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#ffcc99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"137.49\" y=\"180.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"137.49\" dy=\"0.00\">🧩 Morphology</tspan><tspan x=\"137.49\" dy=\"21.00\">&lt;i&gt;word structure&lt;/i&gt;</tspan></text><rect x=\"51.25\" y=\"273.00\" width=\"172.47\" height=\"93.00\" rx=\"3\" ry=\"3\" fill=\"#ffff99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"137.49\" y=\"302.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"137.49\" dy=\"0.00\">📐 Syntax</tspan><tspan x=\"137.49\" dy=\"21.00\">&lt;i&gt;sentence</tspan><tspan x=\"137.49\" dy=\"21.00\">structure&lt;/i&gt;</tspan></text><rect x=\"46.92\" y=\"416.00\" width=\"181.13\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#99ff99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"137.48\" y=\"445.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"137.48\" dy=\"0.00\">💡 Semantics</tspan><tspan x=\"137.48\" dy=\"21.00\">&lt;i&gt;meaning&lt;/i&gt;</tspan></text><rect x=\"51.25\" y=\"538.00\" width=\"172.47\" height=\"93.00\" rx=\"3\" ry=\"3\" fill=\"#9999ff\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"137.48\" y=\"567.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"137.48\" dy=\"0.00\">🎭 Pragmatics</tspan><tspan x=\"137.48\" dy=\"21.00\">&lt;i&gt;meaning in</tspan><tspan x=\"137.48\" dy=\"21.00\">context&lt;/i&gt;</tspan></text></svg></div>\n<p>Five layers, five ways in which language gets &quot;analyzed&quot;. And note - <strong>an LLM has to handle each of these levels</strong> to come across as a sensible conversational partner. Of course it doesn't do this consciously - but the structures it learns during training somehow &quot;catch&quot; these layers.</p>\n<div class=\"markdown-alert markdown-alert-note\">\n<p class=\"markdown-alert-title\">Note</p>\n<p><strong>The five layers of language in a nutshell:</strong></p>\n<ol>\n<li><strong>Phonetics &amp; phonology</strong> - sounds and how they're organized into a system</li>\n<li><strong>Morphology</strong> - how words are built from smaller pieces</li>\n<li><strong>Syntax</strong> - the rules of word order in a sentence</li>\n<li><strong>Semantics</strong> - the meaning of words and sentences</li>\n<li><strong>Pragmatics</strong> - how context changes the meaning of an utterance</li>\n</ol>\n</div>\n<p>OK, let's get to it. We start at the bottom of our onion ;-)</p>\n<hr />\n<h2><a href=\"#phonetics-and-phonology---the-sounds-an-llm-never-hears\" aria-hidden=\"true\" class=\"anchor\" id=\"phonetics-and-phonology---the-sounds-an-llm-never-hears\"></a>Phonetics and phonology - the sounds an LLM never hears</h2>\n<h3><a href=\"#what-is-phonetics\" aria-hidden=\"true\" class=\"anchor\" id=\"what-is-phonetics\"></a>What is phonetics?</h3>\n<p><strong>Phonetics</strong> studies speech sounds as physical phenomena. Put simply: how we produce sounds, how they travel through the air, and how we receive them.</p>\n<p>It has three branches:</p>\n<table>\n<thead>\n<tr>\n<th>Branch</th>\n<th>What it studies</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Articulatory</strong></td>\n<td>How the speech organs produce sounds</td>\n<td>Where is your tongue when you say &quot;sh&quot;?</td>\n</tr>\n<tr>\n<td><strong>Acoustic</strong></td>\n<td>The physical properties of sound waves</td>\n<td>Frequency, amplitude</td>\n</tr>\n<tr>\n<td><strong>Auditory</strong></td>\n<td>How the ear and brain receive sounds</td>\n<td>How the cochlea turns waves into a nerve signal</td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"#and-phonology\" aria-hidden=\"true\" class=\"anchor\" id=\"and-phonology\"></a>And phonology?</h3>\n<p><strong>Phonology</strong> is a level up. It's not interested in sounds as physical phenomena, but in <strong>how sounds are organized in a particular language</strong>.</p>\n<p>Key concept: the <strong>phoneme</strong> - the smallest unit of sound that distinguishes the meaning of words.</p>\n<p>A simple example in English:</p>\n<ul>\n<li><strong>pat</strong> vs <strong>bat</strong> - the words differ by one sound (/p/ vs /b/), and the meaning is completely different</li>\n<li><strong>rat</strong> vs <strong>mat</strong> - /r/ vs /m/ again changes everything</li>\n</ul>\n<p>Or in Polish:</p>\n<ul>\n<li><strong>kot</strong> (cat) vs <strong>lot</strong> (flight) - /k/ vs /l/ and we have a totally different word</li>\n</ul>\n<div class=\"markdown-alert markdown-alert-tip\">\n<p class=\"markdown-alert-title\">Tip</p>\n<p><strong>Experiment:</strong> Say &quot;cat&quot; out loud, once as a plain statement (&quot;My cat sleeps.&quot;), and once as a surprised question (&quot;Cat?!&quot; with raised eyebrows). The same word, but intonation, stress, and melody completely change what the listener &quot;hears&quot;. That is phonology in action - sounds + their organization in a system.</p>\n</div>\n<h3><a href=\"#why-does-this-matter-for-an-llm\" aria-hidden=\"true\" class=\"anchor\" id=\"why-does-this-matter-for-an-llm\"></a>Why does this matter for an LLM?</h3>\n<p>Right - <strong>an LLM gets text, not sound</strong>. It has never heard pronunciation. And yet...</p>\n<ul>\n<li>it knows that &quot;cat&quot; and &quot;hat&quot; rhyme (because it saw it in texts)</li>\n<li>it handles puns and wordplay based on sounds</li>\n<li>it can write rhyming poetry</li>\n</ul>\n<p>So the model somehow <strong>absorbs phonological information</strong> from text data alone. A bit like never having seen the ocean, but having read so many books about it that you can describe it ;-)</p>\n<p>But of course there are limitations. A text-based LLM can't distinguish homophones (words that sound the same but mean different things) based on phonetics - it handles them purely at the semantic level (more on that in a moment).</p>\n<p>And a fun fact: models like <strong>Whisper</strong> (speech-to-text from OpenAI) already connect phonetics with text. But that's a topic for a separate post in this series ;-)</p>\n<div class=\"markdown-alert markdown-alert-warning\">\n<p class=\"markdown-alert-title\">Warning</p>\n<p><strong>Paradox:</strong> An LLM has never heard a single sound, yet from training data it &quot;knows&quot; about rhymes, wordplay, and sound patterns. It's a bit like a person deaf from birth who can write rhyming poetry - because they've read millions of them.</p>\n</div>\n<hr />\n<h2><a href=\"#morphology---how-words-are-built-from-blocks\" aria-hidden=\"true\" class=\"anchor\" id=\"morphology---how-words-are-built-from-blocks\"></a>Morphology - how words are built from blocks</h2>\n<h3><a href=\"#what-is-morphology\" aria-hidden=\"true\" class=\"anchor\" id=\"what-is-morphology\"></a>What is morphology?</h3>\n<p><strong>Morphology</strong> studies the structure of words - how they're assembled from smaller, meaningful pieces called <strong>morphemes</strong>.</p>\n<p>A morpheme is the <strong>smallest unit of language that carries meaning</strong>. It can't be divided into anything smaller that would still carry meaning.</p>\n<p>An example from English, often used in textbooks:</p>\n<pre class=\"marmite-code\"><code class=\"marmite-code-inner\">unhappiness = un + happy + ness\n               ↑       ↑       ↑\n            &quot;not&quot;   &quot;happy&quot;   makes a noun\n</code></pre>\n<p>Or in Polish:</p>\n<pre class=\"marmite-code\"><code class=\"marmite-code-inner\">nieszczęśliwy = nie + szczęśliw + y\n                   ↑        ↑       ↑\n               &quot;not&quot;  &quot;happy/fortune&quot;  masculine gender\n</code></pre>\n<p>Or even more:</p>\n<pre class=\"marmite-code\"><code class=\"marmite-code-inner\">nieprzystojny = nie + przy + stoj + ny\n              &quot;not&quot; + &quot;at&quot; + &quot;stand&quot; + adjective suffix\n</code></pre>\n<p>Each of these pieces has its own meaning. Those are morphemes.</p>\n<h3><a href=\"#two-kinds-of-morphemes\" aria-hidden=\"true\" class=\"anchor\" id=\"two-kinds-of-morphemes\"></a>Two kinds of morphemes</h3>\n<table>\n<thead>\n<tr>\n<th>Type</th>\n<th>Description</th>\n<th>Examples</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Free</strong></td>\n<td>Can stand alone as a word</td>\n<td>cat, house, runs</td>\n</tr>\n<tr>\n<td><strong>Bound</strong></td>\n<td>Must be attached to another morpheme</td>\n<td>un-, -ness, -s, -ed</td>\n</tr>\n</tbody>\n</table>\n<p>And among bound morphemes we have <strong>affixes</strong>:</p>\n<ul>\n<li><strong>Prefixes</strong> (before the root): <em>un-</em>, <em>re-</em>, <em>pre-</em>, <em>dis-</em></li>\n<li><strong>Suffixes</strong> (after the root): <em>-ness</em>, <em>-ful</em>, <em>-ize</em>, <em>-ed</em></li>\n<li><strong>Infixes</strong> (inside the root): practically absent in English, but present in other languages! E.g. in Tagalog (Philippines): <em>sulat</em> (to write) -&gt; <em>s<strong>um</strong>ulat</em> (to write something) - the morpheme <em>-um-</em> is inserted into the middle of the root. Or think of the English <em>abso-bloody-lutely</em> ;-)</li>\n</ul>\n<h3><a href=\"#inflection-vs-derivation\" aria-hidden=\"true\" class=\"anchor\" id=\"inflection-vs-derivation\"></a>Inflection vs derivation</h3>\n<p>This is an important distinction:</p>\n<p><strong>Inflection</strong> - changes the grammatical form, but doesn't create a new word:</p>\n<ul>\n<li>house -&gt; house<strong>s</strong> (plural)</li>\n<li>run -&gt; ran (past tense)</li>\n</ul>\n<p><strong>Derivation</strong> (word formation) - creates a new word, often changing the part of speech:</p>\n<ul>\n<li>teach -&gt; <strong>teacher</strong> (verb -&gt; noun)</li>\n<li>house -&gt; <strong>household</strong> (noun -&gt; adjective/noun)</li>\n</ul>\n<div class=\"markdown-alert markdown-alert-warning\">\n<p class=\"markdown-alert-title\">Warning</p>\n<p><strong>Polish morphology is a nightmare for an LLM!</strong> The Polish language is highly inflectional - we have 7 cases, 2 numbers, 3 genders, verb aspects, and tons of exceptions. For comparison: in English, declining a noun means at most adding <em>-s</em>. In Polish? &quot;Dom, domu, domowi, dom, domem, domu, domie, domy, domow...&quot; and so on :D</p>\n</div>\n<h3><a href=\"#how-does-an-llm-handle-morphology\" aria-hidden=\"true\" class=\"anchor\" id=\"how-does-an-llm-handle-morphology\"></a>How does an LLM handle morphology?</h3>\n<p>Here's a fun fact. An LLM doesn't &quot;know&quot; what morphemes are. It uses <strong>BPE tokenization</strong> (Byte Pair Encoding), which splits text into tokens - but tokens are <strong>not the same</strong> as morphemes.</p>\n<div class=\"mermaid-diagram\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"542.85754\" height=\"335\" viewBox=\"0 0 542.85754 335\"><rect x=\"0\" y=\"0\" width=\"542.85754\" height=\"335\" fill=\"#FFFFFF\"/><defs><marker id=\"arrow-0\" viewBox=\"0 0 10 10\" refX=\"5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker><marker id=\"arrow-start-0\" viewBox=\"0 0 10 10\" refX=\"4.5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 5 L 10 10 L 10 0 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker></defs><rect x=\"8.00\" y=\"176.50\" width=\"518.86\" height=\"142.50\" rx=\"10\" ry=\"10\" fill=\"#F1F5F9\" stroke=\"#CBD5E1\" stroke-width=\"1\" /><text x=\"267.43\" y=\"205.50\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"267.43\" dy=\"0.00\">GPT-4o sees (BPE</tspan><tspan x=\"267.43\" dy=\"21.00\">tokenization):</tspan></text><rect x=\"8.00\" y=\"8.00\" width=\"492.90\" height=\"118.50\" rx=\"10\" ry=\"10\" fill=\"#F1F5F9\" stroke=\"#CBD5E1\" stroke-width=\"1\" /><text x=\"254.45\" y=\"35.50\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"254.45\" dy=\"0.00\">A linguist sees:</tspan></text><path id=\"edge-0\" class=\"edgePath\" data-edge-id=\"edge-0\" d=\"M 207.822,74.000 L 257.822,74.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(257.82 74.00) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-1\" class=\"edgePath\" data-edge-id=\"edge-1\" d=\"M 199.170,266.500 L 257.822,266.500\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(257.82 266.50) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><rect x=\"44.00\" y=\"48.50\" width=\"163.82\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"125.91\" y=\"77.50\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"125.91\" dy=\"0.00\">un-happiness</tspan></text><rect x=\"257.82\" y=\"48.50\" width=\"207.08\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#99ff99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"361.36\" y=\"77.50\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"361.36\" dy=\"0.00\">un + happy + ness</tspan></text><rect x=\"44.00\" y=\"241.00\" width=\"155.17\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"121.58\" y=\"270.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"121.58\" dy=\"0.00\">unhappiness</tspan></text><rect x=\"257.82\" y=\"241.00\" width=\"233.04\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#ff9999\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"374.34\" y=\"270.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"374.34\" dy=\"0.00\">un + h + app + iness</tspan></text></svg></div>\n<p>The BPE tokenizer splits text based on <strong>frequency of occurrence</strong> in the training data, not on linguistic structure. Sometimes that overlaps with morphemes, sometimes it doesn't.</p>\n<p>That means the model doesn't learn morphology &quot;directly&quot; - it learns it indirectly, through statistics. And somehow it works ;-)</p>\n<div class=\"markdown-alert markdown-alert-tip\">\n<p class=\"markdown-alert-title\">Tip</p>\n<p><strong>A challenge for you:</strong> Can you break these words into morphemes?</p>\n<ul>\n<li><em>unbelievable</em></li>\n<li><em>antidisestablishmentarianism</em></li>\n<li><em>reimplementation</em></li>\n</ul>\n</div>\n<hr />\n<h2><a href=\"#syntax---the-rules-of-the-sentence-arranging-game\" aria-hidden=\"true\" class=\"anchor\" id=\"syntax---the-rules-of-the-sentence-arranging-game\"></a>Syntax - the rules of the sentence-arranging game</h2>\n<h3><a href=\"#what-is-syntax\" aria-hidden=\"true\" class=\"anchor\" id=\"what-is-syntax\"></a>What is syntax?</h3>\n<p><strong>Syntax</strong> is the set of rules that determine how words are combined into sentences. Thanks to syntax we know that &quot;The cat sits on the mat&quot; is a valid sentence, and &quot;The cat the on mat sits&quot; is gibberish.</p>\n<p>Simple? Well... more or less ;-)</p>\n<h3><a href=\"#word-order\" aria-hidden=\"true\" class=\"anchor\" id=\"word-order\"></a>Word order</h3>\n<p>Different languages have different word-order rules:</p>\n<table>\n<thead>\n<tr>\n<th>Language</th>\n<th>Basic order</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>English</td>\n<td>SVO (Subject-Verb-Object)</td>\n<td>The cat sits on the mat</td>\n</tr>\n<tr>\n<td>Polish</td>\n<td>&quot;Flexible&quot; SVO, but...</td>\n<td>Kot siedzi na macie / Na macie siedzi kot / Siedzi kot na macie</td>\n</tr>\n<tr>\n<td>Japanese</td>\n<td>SOV</td>\n<td>猫がマットの上に座っている</td>\n</tr>\n<tr>\n<td>Latin</td>\n<td>Free (because endings say everything)</td>\n<td>Felix in tapete sedet</td>\n</tr>\n</tbody>\n</table>\n<p>Polish is nice because we have quite a lot of freedom in word order. While in English &quot;On the mat sits the cat&quot; sounds poetic or unnatural, for us it's a normal sentence ;-)</p>\n<h3><a href=\"#the-syntax-tree\" aria-hidden=\"true\" class=\"anchor\" id=\"the-syntax-tree\"></a>The syntax tree</h3>\n<p>Sentences have a hierarchical structure - words group into phrases, and phrases into larger phrases. You can draw it as a tree:</p>\n<div class=\"mermaid-diagram\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"791.7824\" height=\"479\" viewBox=\"0 0 791.7824 479\"><rect x=\"0\" y=\"0\" width=\"791.7824\" height=\"479\" fill=\"#FFFFFF\"/><defs><marker id=\"arrow-0\" viewBox=\"0 0 10 10\" refX=\"5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker><marker id=\"arrow-start-0\" viewBox=\"0 0 10 10\" refX=\"4.5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 5 L 10 10 L 10 0 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker></defs><path id=\"edge-0\" class=\"edgePath\" data-edge-id=\"edge-0\" d=\"M 223.401,59.000 L 223.401,68.625 Q 223.401,76.500 215.799,78.553 L 175.463,89.447 Q 167.860,91.500 167.860,99.375 L 167.860,109.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(167.86 109.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-1\" class=\"edgePath\" data-edge-id=\"edge-1\" d=\"M 343.582,59.000 L 343.582,68.625 Q 343.582,76.500 351.163,78.631 L 389.363,89.369 Q 396.945,91.500 396.945,99.375 L 396.945,109.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(396.94 109.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-2\" class=\"edgePath\" data-edge-id=\"edge-2\" d=\"M 104.330,160.000 L 104.330,170.286 Q 104.330,177.500 101.785,184.250 L 101.219,185.750 Q 98.674,192.500 98.674,199.714 L 98.674,210.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(98.67 210.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-3\" class=\"edgePath\" data-edge-id=\"edge-3\" d=\"M 424.479,160.000 L 424.479,169.625 Q 424.479,177.500 417.210,180.528 L 395.732,189.472 Q 388.462,192.500 388.462,200.375 L 388.462,210.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(388.46 210.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-4\" class=\"edgePath\" data-edge-id=\"edge-4\" d=\"M 504.072,160.000 L 504.072,169.625 Q 504.072,177.500 511.094,181.065 L 526.591,188.935 Q 533.612,192.500 533.612,200.375 L 533.612,210.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(533.61 210.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-5\" class=\"edgePath\" data-edge-id=\"edge-5\" d=\"M 541.823,261.000 L 541.823,270.625 Q 541.823,278.500 535.962,283.760 L 530.969,288.240 Q 525.108,293.500 525.108,301.375 L 525.108,311.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(525.11 311.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-6\" class=\"edgePath\" data-edge-id=\"edge-6\" d=\"M 629.612,261.000 L 629.612,270.625 Q 629.612,278.500 636.207,282.804 L 645.999,289.196 Q 652.594,293.500 652.594,301.375 L 652.594,311.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(652.59 311.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-7\" class=\"edgePath\" data-edge-id=\"edge-7\" d=\"M 676.678,362.000 L 676.678,412.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(676.68 412.00) rotate(90.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><rect x=\"35.51\" y=\"210.00\" width=\"120.56\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"95.79\" y=\"239.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"95.79\" dy=\"0.00\">The cat</tspan></text><rect x=\"616.51\" y=\"412.00\" width=\"120.56\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"676.79\" y=\"441.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"676.79\" dy=\"0.00\">the mat</tspan></text><rect x=\"8.00\" y=\"109.00\" width=\"198.43\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#99ff99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"107.21\" y=\"138.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"107.21\" dy=\"0.00\">NP (noun phrase)</tspan></text><rect x=\"577.35\" y=\"311.00\" width=\"198.43\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"676.57\" y=\"340.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"676.57\" dy=\"0.00\">NP (noun phrase)</tspan></text><rect x=\"448.67\" y=\"311.00\" width=\"77.44\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"487.39\" y=\"340.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"487.39\" dy=\"0.00\">on</tspan></text><rect x=\"443.46\" y=\"210.00\" width=\"276.29\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#ff9999\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"581.61\" y=\"239.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"581.61\" dy=\"0.00\">PP (prepositional phrase)</tspan></text><rect x=\"202.14\" y=\"8.00\" width=\"163.82\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#9999ff\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"284.05\" y=\"37.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#fff\"><tspan x=\"284.05\" dy=\"0.00\">S (sentence)</tspan></text><rect x=\"296.78\" y=\"210.00\" width=\"94.61\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"344.09\" y=\"239.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"344.09\" dy=\"0.00\">sits</tspan></text><rect x=\"357.26\" y=\"109.00\" width=\"198.43\" height=\"51.00\" rx=\"3\" ry=\"3\" fill=\"#ffcc99\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"456.48\" y=\"138.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#000\"><tspan x=\"456.48\" dy=\"0.00\">VP (verb phrase)</tspan></text></svg></div>\n<p>That's the simple sentence &quot;The cat sits on the mat&quot; and it already has its hierarchy! Now imagine sentences with subordinate clauses, participles, adverbials...</p>\n<h3><a href=\"#colorless-green-ideas-sleep-furiously\" aria-hidden=\"true\" class=\"anchor\" id=\"colorless-green-ideas-sleep-furiously\"></a>&quot;Colorless green ideas sleep furiously&quot;</h3>\n<p>This is a famous example from Noam Chomsky.</p>\n<p>The sentence is <strong>syntactically correct</strong> - it has a subject, a predicate, a proper structure. But <strong>semantically</strong> it's complete nonsense - ideas can't be green or sleep.</p>\n<p>And that's exactly the proof that <strong>syntax and semantics are two different levels</strong>. You can have perfect syntax and zero sense ;-)</p>\n<div class=\"markdown-alert markdown-alert-important\">\n<p class=\"markdown-alert-title\">Important</p>\n<p><strong>Syntax is an LLM's superpower.</strong> The model learns to predict the next token based on a huge amount of text data. In the process it absorbs syntactic patterns - it knows that after &quot;The cat sits on...&quot; we expect a noun, and after &quot;Quickly...&quot; a verb. This is the foundation of why an LLM generates grammatically correct sentences.</p>\n</div>\n<h3><a href=\"#quiz-correct-or-not\" aria-hidden=\"true\" class=\"anchor\" id=\"quiz-correct-or-not\"></a>Quiz: correct or not?</h3>\n<p>Test yourself - which sentences are syntactically correct?<sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n<ol>\n<li>The dog barks at the mailman.</li>\n<li>At the mailman barks the dog.</li>\n<li>Barks the dog at the mailman.</li>\n<li>The dog the mailman at barks.</li>\n<li>Does the dog bark at the mailman?</li>\n</ol>\n<hr />\n<h2><a href=\"#semantics---what-does-meaning-even-mean\" aria-hidden=\"true\" class=\"anchor\" id=\"semantics---what-does-meaning-even-mean\"></a>Semantics - what does &quot;meaning&quot; even mean?</h2>\n<h3><a href=\"#what-is-semantics\" aria-hidden=\"true\" class=\"anchor\" id=\"what-is-semantics\"></a>What is semantics?</h3>\n<p>If syntax asks &quot;how is this built?&quot;, semantics asks: <strong>&quot;what does it mean?&quot;</strong></p>\n<p>Semantics studies the meaning of words, phrases, and sentences. And right away it turns out this isn't simple at all.</p>\n<h3><a href=\"#polysemy---one-word-many-meanings\" aria-hidden=\"true\" class=\"anchor\" id=\"polysemy---one-word-many-meanings\"></a>Polysemy - one word, many meanings</h3>\n<p>A classic English example: <strong>bank</strong></p>\n<ul>\n<li>Bank - a financial institution (&quot;I deposited money at the bank&quot;)</li>\n<li>Bank - the side of a river (&quot;The river bank was muddy&quot;)</li>\n<li>Bank - a row of similar things (&quot;A bank of computers&quot;)</li>\n<li>Bank - to tilt an aircraft (&quot;The plane banked to the left&quot;)</li>\n</ul>\n<p>The same word, four completely different meanings. How does an LLM know which one is meant? <strong>From context.</strong> And that's exactly what it does well - because it has seen millions of sentences where &quot;bank&quot; appeared in different contexts.</p>\n<p>Or another classic - polysemy within a single sentence:</p>\n<blockquote>\n<p>&quot;I can can the canning of cans.&quot;</p>\n</blockquote>\n<p>The word &quot;can&quot; three times, three different functions: <strong>can</strong> (be able to), <strong>can</strong> (the verb, to put in a can), <strong>can</strong> (the noun, a container). Context changes everything ;-)</p>\n<h3><a href=\"#synonyms---are-big-large-and-huge-the-same\" aria-hidden=\"true\" class=\"anchor\" id=\"synonyms---are-big-large-and-huge-the-same\"></a>Synonyms - are &quot;big&quot;, &quot;large&quot;, and &quot;huge&quot; the same?</h3>\n<p>Almost. But not quite:</p>\n<ul>\n<li><strong>A big house</strong> - normal, just sizable</li>\n<li><strong>A large house</strong> - sounds a bit more formal</li>\n<li><strong>A huge house</strong> - now that's a mansion :D</li>\n</ul>\n<p>Semantics studies these subtle differences - both <strong>denotation</strong> (literal meaning) and <strong>connotation</strong> (associations, emotional coloring).</p>\n<h3><a href=\"#how-does-an-llm-understand-meaning\" aria-hidden=\"true\" class=\"anchor\" id=\"how-does-an-llm-understand-meaning\"></a>How does an LLM &quot;understand&quot; meaning?</h3>\n<p>Here enters the concept of <strong>word embeddings</strong>. In broad terms: each word is represented as a vector - a sequence of numbers - in a high-dimensional space. Words with similar meanings are &quot;close&quot; to each other in that space.</p>\n<p>The famous example you've probably seen:</p>\n<pre class=\"marmite-code\"><code class=\"marmite-code-inner\">vector(&quot;king&quot;) - vector(&quot;man&quot;) + vector(&quot;woman&quot;) ≈ vector(&quot;queen&quot;)\n</code></pre>\n<p>Meaning: the model &quot;knows&quot; that the relationship between &quot;king&quot; and &quot;man&quot; is analogous to the relationship between &quot;queen&quot; and &quot;woman&quot;. And it got that purely from data - nobody taught it that!</p>\n<p>We can even show this in code. Here's a simple example with the <code>gensim</code> library in Python:</p>\n<pre class=\"marmite-code\"><code class=\"marmite-code-inner language-python\"><a-k>from</a-k> <a-v>gensim</a-v>.<a-v>downloader</a-v> <a-k>import</a-k> <a-v>load</a-v>\n\n<a-v>model</a-v> <a-o>=</a-o> <a-f>load</a-f>(<a-s>&quot;glove-wiki-gigaword-50&quot;</a-s>)\n\n<a-v>result</a-v> <a-o>=</a-o> <a-v>model</a-v>.<a-pr>most_similar</a-pr>(\n    <a-v>positive</a-v><a-o>=</a-o>[<a-s>&quot;king&quot;</a-s>, <a-s>&quot;woman&quot;</a-s>],\n    <a-v>negative</a-v><a-o>=</a-o>[<a-s>&quot;man&quot;</a-s>],\n    <a-v>topn</a-v><a-o>=</a-o><a-n>3</a-n>\n)\n\n<a-f>print</a-f>(<a-v>result</a-v>)\n<a-c># [(&#39;queen&#39;, 0.85), ...]  -- in first place: queen!</a-c></code></pre>\n<div class=\"markdown-alert markdown-alert-tip\">\n<p class=\"markdown-alert-title\">Tip</p>\n<p><strong>If you want to test this yourself:</strong> install <code>gensim</code> (<code>pip install gensim</code>) and run the code above. Of course you'll need some RAM - the GloVe model isn't small. But the result is genuinely satisfying ;-)</p>\n</div>\n<h3><a href=\"#compositionality\" aria-hidden=\"true\" class=\"anchor\" id=\"compositionality\"></a>Compositionality</h3>\n<p>One of the most important concepts in semantics: <strong>the meaning of a sentence is the result of the meanings of the individual words + the rules for combining them.</strong></p>\n<p>So: &quot;The red cat sits on the mat&quot; = [red] + [cat] + [sits] + [on] + [the mat] + syntactic rules.</p>\n<p>Sounds trivial, but it's a powerful principle. Thanks to it we can understand an infinite number of sentences, even ones we've never heard before. And thanks to it an LLM can generate new, never-before-seen sentences that still make sense.</p>\n<div class=\"markdown-alert markdown-alert-warning\">\n<p class=\"markdown-alert-title\">Warning</p>\n<p><strong>But careful:</strong> &quot;I understood that you didn't understand that it wasn't understandable.&quot; - each word is simple, but the sentence as a whole requires analyzing it layer by layer. Compositionality is a powerful tool, but it has its limits.</p>\n</div>\n<hr />\n<h2><a href=\"#pragmatics---what-i-really-meant\" aria-hidden=\"true\" class=\"anchor\" id=\"pragmatics---what-i-really-meant\"></a>Pragmatics - what I really meant</h2>\n<h3><a href=\"#what-is-pragmatics\" aria-hidden=\"true\" class=\"anchor\" id=\"what-is-pragmatics\"></a>What is pragmatics?</h3>\n<p>And so we arrive at the most interesting layer (in my opinion). <strong>Pragmatics</strong> studies <strong>how context influences the meaning of an utterance</strong> - what we <em>really</em> want to say, often by saying something completely different.</p>\n<p>If semantics asks &quot;what does this mean?&quot;, pragmatics asks: <strong>&quot;what did the author mean in this particular situation?&quot;</strong></p>\n<h3><a href=\"#scenes-from-life\" aria-hidden=\"true\" class=\"anchor\" id=\"scenes-from-life\"></a>Scenes from life</h3>\n<p><strong>Scene 1: &quot;It's cold in here.&quot;</strong></p>\n<p>Semantically: information about the temperature in the room.\nPragmatically: <strong>&quot;Close the window!&quot;</strong> or <strong>&quot;Turn up the heating!&quot;</strong> or <strong>&quot;Give me a blanket.&quot;</strong></p>\n<p>Every one of you understands that when someone says &quot;It's cold in here&quot; while standing next to an open window - you don't ask about degrees Celsius, you just close the window.</p>\n<p><strong>Scene 2: &quot;Could you pass the salt?&quot;</strong></p>\n<p>Semantically: a question about your <em>ability</em> to pass the salt.\nPragmatically: <strong>a request to pass the salt.</strong></p>\n<p>Answering &quot;Yes, I could&quot; (and nothing more) is semantically correct, but pragmatically... well, you're being a bit rude ;-)</p>\n<p><strong>Scene 3: Irony</strong></p>\n<blockquote>\n<p>&quot;Well congratulations, you broke it again.&quot;</p>\n</blockquote>\n<p>Semantically: congratulations.\nPragmatically: <strong>irony, criticism, disappointment.</strong></p>\n<p>Does an LLM catch irony? Sometimes yes, sometimes no. It's still an open research problem.</p>\n<h3><a href=\"#speech-act-theory\" aria-hidden=\"true\" class=\"anchor\" id=\"speech-act-theory\"></a>Speech act theory</h3>\n<p>The philosopher J.L. Austin came up with something brilliant: <strong>utterances don't just describe reality, they also <em>do</em> things.</strong></p>\n<table>\n<thead>\n<tr>\n<th>Type of speech act</th>\n<th>Description</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Locutionary</strong></td>\n<td>The utterance itself</td>\n<td>You say &quot;I'm closing the window&quot;</td>\n</tr>\n<tr>\n<td><strong>Illocutionary</strong></td>\n<td>The intention of the utterance</td>\n<td>A promise to close the window</td>\n</tr>\n<tr>\n<td><strong>Perlocutionary</strong></td>\n<td>The effect on the listener</td>\n<td>The listener feels relieved</td>\n</tr>\n</tbody>\n</table>\n<p>Other examples of speech acts:</p>\n<ul>\n<li><strong>A promise:</strong> &quot;I promise I'll do it.&quot; - by saying it, you <em>perform</em> the act of promising</li>\n<li><strong>A declaration:</strong> &quot;I now pronounce you married.&quot; - someone must have the authority for it, but it works!</li>\n<li><strong>An apology:</strong> &quot;I'm sorry.&quot; - that's not a description of a state of affairs, it <em>is</em> the act of apologizing</li>\n</ul>\n<h3><a href=\"#grices-implicatures\" aria-hidden=\"true\" class=\"anchor\" id=\"grices-implicatures\"></a>Grice's implicatures</h3>\n<p>Paul Grice, another philosopher of language, noticed that conversation follows a <strong>cooperative principle</strong> - we say things that are relevant, true, clear, and on topic.</p>\n<p>When someone breaks that principle, we look for an <strong>implicature</strong> - a hidden meaning.</p>\n<p>Example:</p>\n<blockquote>\n<p>A: &quot;Are you going to the party?&quot;\nB: &quot;I have an exam tomorrow.&quot;</p>\n</blockquote>\n<p>B didn't answer &quot;yes&quot; or &quot;no&quot;. But from the context A understands: <strong>I'm not going, because I have to study.</strong> That's a conversational implicature.</p>\n<h3><a href=\"#how-does-an-llm-handle-pragmatics\" aria-hidden=\"true\" class=\"anchor\" id=\"how-does-an-llm-handle-pragmatics\"></a>How does an LLM handle pragmatics?</h3>\n<div class=\"markdown-alert markdown-alert-warning\">\n<p class=\"markdown-alert-title\">Warning</p>\n<p><strong>This is the hardest layer for an LLM.</strong> And that's not just my opinion - researchers all over the world are working on benchmarks that test the pragmatics of language models.</p>\n</div>\n<p>The problems:</p>\n<ul>\n<li><strong>Irony and sarcasm</strong> - the model often takes it literally</li>\n<li><strong>Implicatures</strong> - it doesn't always &quot;catch&quot; what's between the lines</li>\n<li><strong>Speech acts</strong> - it may not recognize whether someone is promising, asking, or threatening</li>\n<li><strong>Cultural context</strong> - what's polite in one culture is rude in another</li>\n</ul>\n<p>But on the other hand - GPT-4 and newer models are getting better and better. Why? Because <strong>the enormous amount of training data contains pragmatics in practice</strong> - dialogues from movies, books, internet forums. The model has &quot;seen&quot; millions of examples of irony, politeness, requests.</p>\n<div class=\"markdown-alert markdown-alert-tip\">\n<p class=\"markdown-alert-title\">Tip</p>\n<p><strong>An experiment for you:</strong> Open ChatGPT (or Claude, or whatever you have at hand) and run this short test:</p>\n<p>Tell the model:</p>\n<p><em>&quot;I just hammered my finger.&quot;</em></p>\n<p>Then, in a new conversation:</p>\n<p><em>&quot;Well congratulations, I hammered my finger again!&quot;</em></p>\n<p>See whether the model notices that in the second case &quot;congratulations&quot; is irony, or whether it starts calling an ambulance?</p>\n</div>\n<hr />\n<h2><a href=\"#summary---the-whole-onion-in-one-place\" aria-hidden=\"true\" class=\"anchor\" id=\"summary---the-whole-onion-in-one-place\"></a>Summary - the whole onion in one place</h2>\n<p>Here are our five layers, in a nutshell:</p>\n<table>\n<thead>\n<tr>\n<th>Layer</th>\n<th>What it studies</th>\n<th>Example</th>\n<th>How the LLM handles it</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Phonetics &amp; phonology</strong></td>\n<td>Sounds and the system of sounds</td>\n<td>/kat/ vs /hat/</td>\n<td>Never hears them, but &quot;knows&quot; from text data</td>\n</tr>\n<tr>\n<td><strong>Morphology</strong></td>\n<td>Word structure from morphemes</td>\n<td>un-happy-ness</td>\n<td>BPE tokenization != morphemes, but it works somehow</td>\n</tr>\n<tr>\n<td><strong>Syntax</strong></td>\n<td>Word order in a sentence</td>\n<td>The cat sits on the mat</td>\n<td>The model's superpower - handles grammar great</td>\n</tr>\n<tr>\n<td><strong>Semantics</strong></td>\n<td>Meaning of words and sentences</td>\n<td>&quot;bank&quot; - which one?</td>\n<td>Word embeddings + context</td>\n</tr>\n<tr>\n<td><strong>Pragmatics</strong></td>\n<td>Meaning in context</td>\n<td>&quot;It's cold&quot; = close the window</td>\n<td>The hardest layer, still an open problem</td>\n</tr>\n</tbody>\n</table>\n<div class=\"mermaid-diagram\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1209.4475\" height=\"211.5\" viewBox=\"0 0 1209.4475 211.5\"><rect x=\"0\" y=\"0\" width=\"1209.4475\" height=\"211.5\" fill=\"#FFFFFF\"/><defs><marker id=\"arrow-0\" viewBox=\"0 0 10 10\" refX=\"5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker><marker id=\"arrow-start-0\" viewBox=\"0 0 10 10\" refX=\"4.5\" refY=\"5\" markerUnits=\"userSpaceOnUse\" markerWidth=\"8\" markerHeight=\"8\" orient=\"auto\"><path d=\"M 0 5 L 10 10 L 10 0 z\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"1\" stroke-dasharray=\"1,0\"/></marker></defs><rect x=\"8.00\" y=\"8.00\" width=\"1185.45\" height=\"187.50\" rx=\"10\" ry=\"10\" fill=\"#F1F5F9\" stroke=\"#CBD5E1\" stroke-width=\"1\" /><text x=\"600.72\" y=\"37.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"600.72\" dy=\"0.00\">How an LLM processes</tspan><tspan x=\"600.72\" dy=\"21.00\">language</tspan></text><path id=\"edge-0\" class=\"edgePath\" data-edge-id=\"edge-0\" d=\"M 220.473,135.000 L 244.473,135.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(244.47 135.00) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-1\" class=\"edgePath\" data-edge-id=\"edge-1\" d=\"M 494.813,135.000 L 518.813,135.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(518.81 135.00) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-2\" class=\"edgePath\" data-edge-id=\"edge-2\" d=\"M 673.983,135.000 L 697.983,135.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(697.98 135.00) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><path id=\"edge-3\" class=\"edgePath\" data-edge-id=\"edge-3\" d=\"M 956.974,135.000 L 980.974,135.000\" fill=\"none\" stroke=\"#64748B\" stroke-width=\"2\"    stroke-linecap=\"round\" stroke-linejoin=\"round\" /><g transform=\"translate(980.97 135.00) rotate(0.00)\"><polygon points=\"0,0 -7.50,3.90 -7.50,-3.90\" fill=\"#64748B\" stroke=\"#64748B\" stroke-width=\"2\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/></g><rect x=\"48.00\" y=\"83.00\" width=\"172.47\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"134.24\" y=\"112.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"134.24\" dy=\"0.00\">Phonetics</tspan><tspan x=\"134.24\" dy=\"21.00\">❌ never hears</tspan></text><rect x=\"244.47\" y=\"72.50\" width=\"250.34\" height=\"93.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"369.64\" y=\"101.50\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"369.64\" dy=\"0.00\">Morphology</tspan><tspan x=\"369.64\" dy=\"21.00\">⚠️ through the lens of</tspan><tspan x=\"369.64\" dy=\"21.00\">tokens</tspan></text><rect x=\"980.97\" y=\"83.00\" width=\"172.47\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"1067.21\" y=\"112.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"1067.21\" dy=\"0.00\">Pragmatics</tspan><tspan x=\"1067.21\" dy=\"21.00\">❓ the hardest</tspan></text><rect x=\"518.81\" y=\"83.00\" width=\"155.17\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"596.40\" y=\"112.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"596.40\" dy=\"0.00\">Syntax</tspan><tspan x=\"596.40\" dy=\"21.00\">✅ very well</tspan></text><rect x=\"697.98\" y=\"83.00\" width=\"258.99\" height=\"72.00\" rx=\"3\" ry=\"3\" fill=\"#F8FAFC\" stroke=\"#94A3B8\" stroke-width=\"1\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><text x=\"827.48\" y=\"112.00\" text-anchor=\"middle\" font-family=\"Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,DejaVu Sans,Liberation Sans,sans-serif,Noto Color Emoji,Apple Color Emoji,Segoe UI Emoji\" font-size=\"14\" fill=\"#0F172A\"><tspan x=\"827.48\" dy=\"0.00\">Semantics</tspan><tspan x=\"827.48\" dy=\"21.00\">✅ well, with exceptions</tspan></text></svg></div>\n<h3><a href=\"#whats-next\" aria-hidden=\"true\" class=\"anchor\" id=\"whats-next\"></a>What's next?</h3>\n<p>In the next post we change perspective - instead of looking at the layers of language, we look at the very nature of signs and meaning:</p>\n<ul>\n<li><strong><a href=\"semiotics-and-llm.html\">Semiotics - why an LLM doesn't &quot;think&quot;, yet still means something</a></strong></li>\n</ul>\n<hr />\n<p>If you made it all the way here - <strong>thanks!</strong> ;-) I really appreciate that you took the time to read this monster.</p>\n<p>I hope I brought the topic a little closer to you. If anything is unclear - <strong>let me know in the comments</strong>, I'll try to explain. And if you have better examples (and you surely do!) - even more reason to let me know.</p>\n<p>Which layer surprised you the most? Which do you find the most interesting in the context of AI?</p>\n<p>See you in the next post!</p>\n<hr />\n<p><strong>Sources and interesting links:</strong></p>\n<p>If you want to go deeper, here are the materials I used when writing this post:</p>\n<ul>\n<li><a href=\"https://fiveable.me/introduction-study-language/unit-1/branches-linguistics/study-guide/Bbhz9eKIobWh0O9F\">Branches of linguistics - Fiveable</a> - a great overview of linguistics subfields with examples</li>\n<li><a href=\"https://fiveable.me/lists/levels-of-linguistic-analysis\">Levels of Linguistic Analysis - Fiveable</a> - a synthesis of the levels of language analysis</li>\n<li><a href=\"https://relay.libguides.com/science-of-teaching-reading-resource-guide/five-language-domains\">The Five Language Domains - Relay Graduate School</a> - a simple, didactic take on the five language domains</li>\n<li><a href=\"https://www.zenml.io/llmops-database/linguistic-informed-approach-to-production-llm-systems\">Linguistic-Informed Approach to Production LLM Systems - ZenML</a> - a bridge between linguistics and LLM practice</li>\n<li><a href=\"https://www.stat.lmu.de/soda/en/research/research-projects/evaluating-large-language-models-on-linguistic-competence/\">Evaluating Large Language Models on Linguistic Competence - LMU Munich</a> - how the linguistic competence of models is studied</li>\n<li><a href=\"https://arxiv.org/abs/2502.12378\">Pragmatics in the Era of LLMs: A Survey - arXiv</a> - a survey of research on pragmatics in LLMs</li>\n</ul>\n<section class=\"footnotes\" data-footnotes>\n<ol>\n<li id=\"fn-1\">\n<p>Quiz answers: sentences 1 and 5 are correct. Sentence 1 has standard SVO order. Sentence 5 is a grammatical question formed with the auxiliary &quot;does&quot;. Sentences 2 and 3 are understandable but sound archaic or poetic - English allows such inversions only in limited stylistic contexts, unlike Polish where flexible word order is the norm. Sentence 4 (&quot;The dog the mailman at barks&quot;) is syntactically incorrect - the word order is so jumbled it violates the rules of English grammar. <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n</li>\n</ol>\n</section>\n",
      "summary": "\"Five layers of language - phonetics, morphology, syntax, semantics, pragmatics - and how an LLM handles each of them.\"",
      "date_published": "2026-06-06T00:00:00-00:00",
      "image": "",
      "authors": [
        {
          "name": "Blazej Gruszka",
          "url": "https://www.linkedin.com/in/blazejgruszka/",
          "avatar": "https://github.com/bgruszka.png"
        }
      ],
      "tags": [
        "llm",
        "ai",
        "nlp",
        "linguistics",
        "language-models",
        "chatgpt"
      ],
      "language": "en"
    }
  ]
}