Lecțiile acestui traseu sunt publicate deocamdată doar în engleză, așa că lecția de mai jos apare în engleză. Restul — module, quiz și materiale — funcționează la fel.
How Language Models Work
Vei putea să:
You can explain next-token prediction, tokens, sampling and the context window, and estimate whether a document fits in a model and what it costs to send.
Ask a chatbot the same question twice and you may get two different answers. Ask it to count the letter "r" in a long word and it may miscount. Talk to it for an hour and it may lose track of something you said at the start. None of these is a bug in the usual sense. All three follow from how a language model works, and once you know the mechanism you can predict them.
One job: predict the next token
A language model does one thing. Given a piece of text, it gives a probability for every possible next piece. The product picks one, adds it to the text, and asks again. A whole answer is that loop run a few hundred times.
The model learned to do this by reading an enormous amount of text and repeatedly guessing what came next. To guess well it had to pick up grammar, facts, styles and patterns of reasoning, because all of them help prediction. Nobody programmed those in.
Tokens
The pieces are called tokens. A token is a common word or a fragment of one. In English a token is about four characters, or roughly three-quarters of a word, so 100 tokens is about 75 words. Other languages and unusual words usually take more tokens for the same meaning.
The model receives token numbers, not letters. That is why counting letters, reversing a word or doing exact arithmetic on long numbers is unreliable unless the model works step by step or calls a tool such as a calculator.
Choosing a token: why answers vary
The model's output is a list of probabilities. The product then draws one token by weighted chance, which is called sampling. A setting named temperature controls how adventurous the draw is. At a low temperature the most likely token nearly always wins. At a higher one, less likely tokens get a chance.
This is why the same prompt gives different answers, and why "regenerate" is a legitimate tool when you want another idea. It also means one good answer does not prove the next will be good.
The context window
Everything the model can use while answering sits in its context window:
- hidden instructions from the company that made the product
- the conversation so far
- any files you attached, and the results of any search or tool
- the answer it is writing
The window is measured in tokens. Depending on the model it holds from tens of thousands to a million or more. The model has no other memory. When a conversation outgrows the window, the product drops or summarises the oldest part. Even inside the window, material in a very long input is used less reliably than the same material in a short one.
Worked example: will the book fit?
You want to ask questions about a 300-page report.
- 300 pages × about 300 words = 90,000 words.
- 90,000 ÷ 0.75 = 120,000 tokens.
- A model with a 200,000-token window can take it and still has 80,000 tokens for your questions and its answers.
Models are priced per million tokens. At an illustrative price of $3 per million input tokens, sending the report once costs 0.12 × $3 = $0.36. In a chat the whole conversation is sent again with every new message. Ten questions can therefore mean ten readings of the report, unless the provider stores it between messages at a discount.
Try it now (5 minutes)
Open a tokenizer tool and paste one sentence in English. Note the token count. Paste the same sentence translated into another language you know and compare. Then try a long invented word and watch it split into fragments.
On aiqbench
Which model is worth it? sets each model's capability against its price per token, and every model's own page shows its context size. Repeat the book calculation with a real price and a real window.
What to remember
- A language model predicts the next token, again and again. An answer is a chain of those predictions.
- A token is about three-quarters of an English word. The model sees tokens, not letters.
- The next token is drawn by weighted chance, so answers vary.
- The context window is the model's only memory. What is outside it does not exist for the model.
Materiale selectate
1.4hMunca de profunzime se întâmplă aici — lecția este briefingul tău.
În direct pe aiqbench
Subiectul acestei lecții în restul site-ului, astăzi.
În știri, ultimele 30 de zile
- Build a PDF Chatbot for Your Website with Gradio and Hugging Face ZeroGPUTowards Data Science ·
- From chatbots to AI agents: Banco Guayaquil’s next chapter in bankingSiliconANGLE ·
- When Does Fine-Tuning Overtake Prompting? An Accuracy and Cost Analysis of Small Language Models on Narrow TasksarXiv ·
Testează-ți cunoștințele
5 întrebări în 100 de secunde, pe o pagină separată. Citește mai întâi tot ce este mai sus.
Testează-ți cunoștințele →Misiunea modulului
20–25 minTake a real document from your work. Estimate its tokens from the word count. Check your estimate by pasting a 300-word sample into a tokenizer, once in English and once in another language. Work out whether the whole document fits in one model's window, and what one reading costs at that model's current price.
Cum arată un răspuns bun
- The document's word count, your token estimate, and a measured 300-word sample, with the difference between estimate and measurement.
- The sample measured in English and in one other language.
- A yes or no on whether the whole document fits one named model's window, with the numbers.
- The cost of one reading, with the price you used and where you found it.
Se încarcă lucrarea ta…