Chapterبەش 1 · Lectureوانە 1.3

How a Language Model Writes: Tokens, Probabilities and the Context Windowمۆدێلی زمان چۆن دەنووسێت: تۆکنەکان، ئەگەرەکان و پەنجەرەی کۆنتێکست

How text becomes tokens (byte-pair encoding, vocabularies, why Kurdish costs more), the next-token loop and what happens inside a transformer, choosing the next token (greedy decoding, sampling, temperature and top-p, and why the newest models no longer let you set them), and the context window: working memory, stateless requests, context rot and limits. Small Python programs you can run.

دەق چۆن دەبێت بە (، ، بۆچی کوردی گرانترە)، خولی داهاتوو و ئەوەی لە ناو ڕوو دەدات، هەڵبژاردنی داهاتوو (، ، و ⁦top-p⁩ و بۆچی نوێترین مۆدێلەکان چیتر ڕێگە نادەن دایانبنێیت) و : بیرگەی کارکردن، ، و سنوورەکان. چەند بەرنامەیەکی بچووکی Python کە دەتوانیت کاریان پێ بکەیت.

21 min read21 خولەک خوێندنەوە · 15 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain what a token is and how byte-pair encoding builds a tokenizer's vocabulary.
  • Explain why the same text usually needs more tokens in Kurdish than in English, and what that costs.
  • Describe the next-token loop and the role of embeddings, self-attention and layers at concept level.
  • Turn scores into probabilities in Python and compare greedy decoding, sampling, temperature and top-p.
  • Check whether a request fits a context window, and explain stateless requests and context rot.
  • ڕوون بکەیتەوە چییە و چۆن دروست دەکات.
  • ڕوون بکەیتەوە بۆچی هەمان دەق زۆرجار بە کوردی زیاتری لە ئینگلیزی دەوێت و ئەمە چی تێدەچێت.
  • خولی داهاتوو و ڕۆڵی ، و بە شێوەیەکی بیرۆکەیی وەسف بکەیت.
  • بە Python نمرەکان بکەیت بە و ، ، و ⁦top-p⁩ بەراورد بکەیت.
  • بپشکنیت ئایا لە جێی دەبێتەوە و و ڕوون بکەیتەوە.

A reply, one piece at a timeوەڵامێک، پارچە پارچە

When Aram asks a chatbot a question, the answer does not appear all at once. It grows on the screen, a few letters at a time. Each piece is a token: a word, part of a word, a space with a word, or a punctuation mark. A language model writes by choosing one token, then the next, then the next, until the answer is finished.

کاتێک ئارام پرسیارێک لە دەکات، وەڵامەکە بە یەکجار دەرناکەوێت. لەسەر شاشەکە پارچە پارچە گەورە دەبێت. هەر پارچەیەک : وشەیەک، بەشێک لە وشەیەک، بۆشاییەک لەگەڵ وشەیەک یان نیشانەیەکی خاڵبەندی. بەم شێوەیە دەنووسێت: هەڵدەبژێرێت، پاشان یەکێکی تر، پاشان یەکێکی تر، تا وەڵامەکە تەواو دەبێت.

This lesson opens the box: how text becomes tokens, how the model scores every possible next token, why the same question can get different answers, and how much text a model can look at in one go (its context window). The Python examples use lists, dictionaries and functions; no install and no API key are needed. Counting which word follows which is taught in Language models, small and large; here we start from the model's scores.

ئەم وانەیە سندوقەکە دەکاتەوە: دەق چۆن دەبێت بە ، چۆن نمرە دەداتە هەموو گونجاوی داهاتوو، بۆچی هەمان پرسیار لەوانەیە وەڵامی جیاواز وەربگرێت و لە یەک کاتدا چەند دەق دەبینێت (). نموونەکانی Python ، و بەکار دەهێنن؛ نە دامەزراندن پێویستە نە . ژماردنی ئەوەی کام وشە دوای کام وشە دێت لە مۆدێلەکانی زمان، بچووک و گەورە فێر کراوە؛ لێرە لە نمرەکانی دەست پێ دەکەین.

An animation of a chat window. Aram asks: What is a token? The chatbot's answer appears one coloured box at a time: A, token, is, a, small, piece, of, text, full stop. A blinking cursor follows the newest box. The last frame says: 9 tokens, each one chosen after the one before it.
An animation of a chat window. Aram asks: What is a token? The chatbot's answer appears one coloured box at a time: A, token, is, a, small, piece, of, text, full stop. A blinking cursor follows the newest box. The last frame says: 9 tokens, each one chosen after the one before it.
The answer grows one token at a time.وەڵامەکە بە گەورە دەبێت.CêIT

Tokens: the pieces a model readsتۆکنەکان: ئەو پارچانەی مۆدێل دەیانخوێنێتەوە

A model does not read letters as we do. A program called a tokenizer first cuts the text into tokens and gives each token an id number from the model's vocabulary: the fixed list of every token it knows. A common word is usually one token. A longer or rarer word is cut into pieces: unbelievable may become un + believ + able, and «کتێبەکانمان» (our books) may become «کتێب» + «ەکان» + «مان». A verb such as «دەکاتەوە» may become «دەکات» + «ەوە».

وەک ئێمە پیت ناخوێنێتەوە. بەرنامەیەکی سەرەتا دەقەکە دەکات بە و هەر ژمارەیەکی ناسنامە لە وەردەگرێت: لیستی جێگیری هەموو ئەو دەیانناسێت. وشەیەکی باو زۆرجار یەک . وشەیەکی درێژتر یان دەگمەنتر دەکرێت بە پارچە: unbelievable لەوانەیە ببێت بە un + believ + able و «کتێبەکانمان» لەوانەیە ببێت بە «کتێب» + «ەکان» + «مان». کردارێکی وەک «دەکاتەوە» لەوانەیە ببێت بە «دەکات» + «ەوە».

After this step the model never sees letters, only a list of numbers. Spaces and signs count too: a full stop is usually a token of its own. GPT-2 (2019) had a vocabulary of 50,257 tokens; newer models have even more. Every company trains its own tokenizer, and even one company's change: Anthropic's tokenizer since Claude Opus 4.7 gives about 30 % more tokens for the same text than the one before.

دوای ئەم هەنگاوە هەرگیز پیت نابینێت، تەنیا لیستێک ژمارە. بۆشایی و نیشانەکانیش دەژمێردرێن: خاڵ زۆرجار سەربەخۆیە. ⁦GPT-2 (2019)⁩ ⁦50,257⁩ تۆکنی هەبوو؛ نوێتر زیاتریان هەیە. هەر کۆمپانیایەک بەرنامەی خۆی ڕادەهێنێت و تەنانەت هی یەک کۆمپانیاش دەگۆڕێت: بەرنامەی Anthropic لە ⁦Claude Opus 4.7⁩ـەوە بۆ هەمان دەق نزیکەی ⁦30 %⁩ زیاتر دەدات لە هی پێشووتر.

Three rows of coloured boxes with an id number under each box. The English word unbelievable is cut into un (403), believ (25317) and able (481). The Kurdish word کتێبەکانمان, our books, is cut into کتێب (8812), ەکان (1290) and مان (734), read from right to left. The sentence Tea is ready. becomes Tea (17166), space+is (374), space+ready (5644) and a full stop (13). Note: the model receives only the numbers; pieces and ids are examples and every tokenizer cuts differently.سێ ڕیز چوارگۆشەی ڕەنگاوڕەنگ و ژمارەیەکی ناسنامە لە ژێر هەر یەکەیاندا. وشەی ئینگلیزیی unbelievable دەکرێت بە un (403)، believ (25317) و able (481). وشەی کوردیی «کتێبەکانمان» دەکرێت بە «کتێب» (8812)، «ەکان» (1290) و «مان» (734)، لە ڕاستەوە بۆ چەپ. ڕستەی Tea is ready. دەبێت بە Tea (17166)، بۆشایی+is (374)، بۆشایی+ready (5644) و خاڵ (13). تێبینی: مۆدێلەکە تەنیا ژمارەکان وەردەگرێت؛ پارچە و ژمارەکان نموونەن و هەر بەرنامەیەکی تۆکنکردن بە شێوەیەکی جیاواز دەیبڕێت.
The model receives id numbers, not letters (example pieces and ids). ژمارەی ناسنامە وەردەگرێت، نەک پیت (پارچە و ژمارەکان نموونەن).CêIT

How a tokenizer learns its pieces: byte-pair encodingبەرنامەی تۆکنکردن چۆن پارچەکانی فێر دەبێت: کۆدکردنی جووتەبایت

Most tokenizers learn their vocabulary with byte-pair encoding (BPE), an old compression idea that Sennrich, Haddow and Birch brought to language models in 2015. The recipe is short:

زۆربەی بەرنامەکانی بە ⁦(BPE)⁩ فێر دەبن، کە بیرۆکەیەکی کۆنی پەستاندنە و Sennrich، Haddow و Birch لە ساڵی ⁦2015⁩دا هێنایانە ناو . ڕێگاکە کورتە:

  1. Start with single characters (or bytes).

    بە تاکە پیت (یان ) دەست پێ بکە.

  2. Count every pair of neighbours in a large training text.

    هەموو جووتێکی دراوسێ لە دەقێکی گەورەی ڕاهێناندا بژمێرە.

  3. Join the most frequent pair into one new token and add it to the vocabulary.

    زۆرترین جووتی دووپاتە بکە بە یەک نوێ و بیخەرە ناو .

  4. Repeat, thousands of times.

    دووپاتەی بکەرەوە، هەزاران جار.

Two ladders of merges learned from the training text "the student reads the book . the teacher reads the lesson ." repeated 5 times. The word the: start t h e </w>; merge 1 h+e gives t he </w>; merge 2 t+he gives the </w>; merge 3 gives the</w>. The word reads: start r e a d s </w>; merges 4 e+a, 5 r+ea, 6 rea+d, 7 read+s and 8 reads+</w> join it into one token. Bottom: after 30 merges, the, reads, teacher and book are one token each, and the new word lessons becomes lesson + s.دوو پەیژە لەو بەیەکگەیاندنانەی لە دەقی ڕاهێنانی «the student reads the book . the teacher reads the lesson .» (5 جار) فێر بوون. وشەی the: سەرەتا t h e </w>؛ جاری 1 h+e دەبێت بە t he </w>؛ جاری 2 t+he دەبێت بە the </w>؛ جاری 3 دەبێت بە the</w>. وشەی reads: سەرەتا r e a d s </w>؛ جارەکانی 4 e+a، 5 r+ea، 6 rea+d، 7 read+s و 8 reads+</w> دەیکەن بە یەک تۆکن. خوارەوە: دوای 30 جار، the، reads، teacher و book هەر یەکە تۆکنێکە و وشە نوێیەکەی lessons دەبێت بە lesson + s.
BPE joins the most frequent neighbours, again and again. زۆرترین دراوسێی دووپاتە بە یەک دەگەیەنێت، جار لە دوای جار.CêIT
A toy BPE tokenizer: learn 30 merges, then tokenizeبەرنامەیەکی بچووکی کۆدکردنی جووتەبایت: ⁦30⁩ جار فێربوون، پاشان تۆکنکردنtoy_bpe.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
from collections import Counter

def merge_pair(pieces, pair):
    """Join the two pieces of `pair` wherever they stand side by side."""
    out, i = [], 0
    while i < len(pieces):
        if i + 1 < len(pieces) and (pieces[i], pieces[i + 1]) == pair:
            out.append(pieces[i] + pieces[i + 1])
            i += 2
        else:
            out.append(pieces[i])
            i += 1
    return out

def train(text, rounds):
    words = [list(w) + ["</w>"] for w in text.split()]   # "</w>" = end of a word
    merges = []
    for _ in range(rounds):
        pairs = Counter()
        for w in words:
            pairs.update(zip(w, w[1:]))
        if not pairs:
            break
        best = max(pairs, key=pairs.get)          # the most frequent neighbour pair
        merges.append(best)
        words = [merge_pair(w, best) for w in words]
    return merges

def tokenize(text, merges):
    tokens = []
    for word in text.split():
        pieces = list(word) + ["</w>"]
        for pair in merges:                        # replay the merges in order
            pieces = merge_pair(pieces, pair)
        tokens += pieces
    return tokens

training_text = "the student reads the book . the teacher reads the lesson . " * 5
merges = train(training_text, 30)
print("first 5 merges:", merges[:5])

for sentence in ["the student reads the lessons",
                 "the students read",
                 "قوتابییەکە وانەکان دەخوێنێتەوە"]:
    tokens = tokenize(sentence, merges)
    print(len(tokens), "tokens:", tokens)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 16

Each word becomes a list of letters plus </w>, an end-of-word mark (the 2015 paper used the same sign).

هەر وشەیەک دەبێت بە لیستێک پیت لەگەڵ </w>، نیشانەی کۆتایی وشە (وتارەکەی ⁦2015⁩ هەمان نیشانەی بەکار هێنا).

Lineدێڕی 19-24

zip(w, w[1:]) gives every pair of neighbours; Counter counts them; max(..., key=pairs.get) takes the most frequent.

zip(w, w[1:]) هەموو جووتێکی دراوسێ دەدات؛ Counter دەیانژمێرێت؛ max(..., key=pairs.get) زۆرترینیان دەبات.

Lineدێڕی 32-34

To tokenize new text, the learned merges are replayed in the same order.

بۆ دەقی نوێ، ئەو بەیەکگەیاندنانەی فێر بوون بە هەمان ڕیز دووپاتە دەکرێنەوە.

The unseen words lessons and students are still written with known pieces (lesson + s). The Kurdish sentence «قوتابییەکە وانەکان دەخوێنێتەوە» (the student reads the lessons) found no learned pair, so every letter became its own token: 31 tokens against 7. In the output each Kurdish word reads from right to left, as usual.

وشە نەبینراوەکانی lessons و students هێشتا بە پارچە ناسراوەکان دەنووسرێن (lesson + s). ڕستە کوردییەکەی «قوتابییەکە وانەکان دەخوێنێتەوە» هیچ جووتێکی فێربووی نەدۆزییەوە، بۆیە هەر پیتێک بوو بە سەربەخۆ: ⁦31⁩ بەرامبەر 7. لە دەرخستەکەدا هەر وشەیەکی کوردی وەک هەمیشە لە ڕاستەوە بۆ چەپ دەخوێنرێتەوە.

Why Kurdish needs more tokensبۆچی کوردی تۆکنی زیاتری دەوێت

A tokenizer learns from its training text, and most of that text is English. So English words become whole tokens, while Kurdish words are cut into many small pieces. Petrov and colleagues (2023) compared real tokenizers and found that the same text can need up to 15 times more tokens in one language than in another. Kurdish letters also take more space: in UTF-8, the usual way to store text (UTF-8: one to four bytes), an English letter is 1 byte and a Kurdish letter is 2 bytes. A tokenizer that works on bytes and has learned no Kurdish pieces may even need two tokens for one Kurdish letter.

بەرنامەی لە دەقی ڕاهێنانەکەی فێر دەبێت و زۆربەی ئەو دەقە ئینگلیزییە. بۆیە وشە ئینگلیزییەکان دەبن بە تەواو، بەڵام وشە کوردییەکان دەکرێن بە چەندین پارچەی بچووک. Petrov و هاوکارانی ⁦(2023)⁩ بەرنامە ڕاستەقینەکانی بەراورد کرد و بۆیان دەرکەوت کە هەمان دەق لەوانەیە لە زمانێکدا تا ⁦15⁩ هێندە زیاتری پێویست بێت لە زمانێکی تر. پیتی کوردی جێگەی زیاتریش دەگرێت: لە ⁦UTF-8⁩، ڕێگە باوەکەی هەڵگرتنی دەق (⁦UTF-8⁩: یەک تا چوار بایت)، پیتێکی ئینگلیزی 1 و پیتێکی کوردی 2 . بەرنامەیەکی کە لەسەر کار دەکات و هیچ پارچەیەکی کوردی فێر نەبووە لەوانەیە بۆ یەک پیتی کوردی دوو پێویست بێت.

Letters and UTF-8 bytesپیت و بایتەکانی ⁦UTF-8⁩bytes.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(len("hello"), len("hello".encode("utf-8")))
print(len("سڵاو"), len("سڵاو".encode("utf-8")))
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

«سڵاو» has 4 letters but 8 bytes: every Kurdish letter is 2 bytes in UTF-8.

«سڵاو» 4 پیتی هەیە بەڵام 8 : هەر پیتێکی کوردی لە ⁦UTF-8⁩دا 2 .

More tokens mean a higher price, a slower answer and less room in the context window. Rules of thumb exist only for English and differ by company: Google says a Gemini token is about 4 characters and 100 tokens are about 60–80 English words; Anthropic says 1 million tokens are about 555,000 English words on Claude's newest tokenizer (as of November 2026). For Kurdish, count with the provider's own free token counter (Token optimization).

زیاتر واتە نرخی زیاتر، وەڵامی هێواشتر و جێگەی کەمتر لە . یاسای نزیکەیی تەنیا بۆ ئینگلیزی هەن و لە کۆمپانیایەکەوە بۆ کۆمپانیایەکی تر جیاوازن: Google دەڵێت Gemini نزیکەی 4 پیتە و ⁦100⁩ نزیکەی ⁦60–80⁩ وشەی ئینگلیزییە؛ Anthropic دەڵێت 1 ملیۆن لەسەر نوێترین بەرنامەی Claude نزیکەی ⁦555,000⁩ وشەی ئینگلیزییە (لە مانگی ⁦11⁩ی ⁦2026⁩دا). بۆ کوردی، بە ژمێرەری بێبەرانبەری خودی دابینکەرەکە بیژمێرە (باشترینکردنی تۆکن).

Two bars from the toy tokenizer of the last screen, trained on English only: the student reads the lessons needs 7 tokens; قوتابییەکە وانەکان دەخوێنێتەوە needs 31. Below, UTF-8 bytes per letter: lesson has 6 letters and 6 bytes; وانە has 4 letters and 8 bytes. A blue box: with real tokenizers (Petrov et al., 2023) the same text can need up to 15 times more tokens in one language than another. Bottom: more tokens mean a higher price, a slower answer and less room in the context window.دوو ستوونی ئاسۆیی لە بەرنامە بچووکەکەی تۆکنکردن لە شاشەی پێشوو، کە تەنیا لەسەر ئینگلیزی ڕاهێنراوە: the student reads the lessons 7 تۆکنی دەوێت؛ «قوتابییەکە وانەکان دەخوێنێتەوە» 31. لە خوارەوە، بایتەکانی UTF-8 بۆ هەر پیتێک: lesson 6 پیت و 6 بایتە؛ «وانە» 4 پیت و 8 بایتە. چوارگۆشەیەکی شین: لە بەرنامە ڕاستەقینەکاندا (Petrov و هاوکارانی، 2023) هەمان دەق لەوانەیە لە زمانێکدا تا 15 هێندە تۆکنی زیاتری پێویست بێت. خوارەوە: تۆکنی زیاتر واتە نرخی زیاتر، وەڵامی هێواشتر و جێگەی کەمتر لە پەنجەرەی کۆنتێکستدا.
The same sentence costs more tokens in Kurdish.هەمان ڕستە بە کوردی زیاتر دەخوات.CêIT

The next-token loopخولی تۆکنی داهاتوو

Once the text is a list of token ids, writing is a loop:

کاتێک دەقەکە بوو بە لیستێک ژمارەی ناسنامەی ، نووسین دەبێت بە :

  1. Readخوێندنەوە

    The model takes all the tokens so far: the instructions, the question and its own answer up to now.

    هەموو تا ئێستا وەردەگرێت: ڕێنماییەکان، پرسیارەکە و وەڵامی خۆی تا ئەم ساتە.

  2. Scoreنمرەدان

    It gives every token in its vocabulary a score: how well it fits next.

    نمرەیەک دەداتە هەموو : چەند بۆ دواتر دەگونجێت.

  3. Probabilitiesئەگەرەکان

    The softmax function turns the scores into probabilities between 0 and 1 that add up to 1 (in Python below).

    نمرەکان دەکات بە لە نێوان 0 و 1دا کە کۆیان 1ـە (بە Python لە خوارەوە).

  4. Pickهەڵبژاردن

    One token is chosen, usually one of the most likely.

    هەڵدەبژێردرێت، زۆرجار یەکێک لە ئەگەرترینەکان.

  5. Add and repeatزیادکردن و دووپاتەکردنەوە

    The token joins the text and the loop starts again, until the model picks a special end token or reaches the length limit.

    دەچێتە سەر دەقەکە و دیسان دەست پێ دەکاتەوە، تا تایبەتی کۆتایی هەڵدەبژێرێت یان دەگاتە سنووری درێژی.

Take a Kurdish saying. After «دڵۆپ دڵۆپ دەبێتە» (drop by drop becomes …), a model trained on Kurdish text gives «دەریا» (sea) the highest probability, because that is how the saying usually goes. It does not know the saying; it has seen what usually comes next. In the same way, after «ئازاد بیر دەکاتەوە لە ژیریی دەستکرد» (Azad thinks about artificial intelligence) the next token might be «و» 22 %, «کە» 18 %, «چونکە» 15 % or «بەڵام» 10 % (invented numbers).

پەندێکی کوردی وەربگرە. دوای «دڵۆپ دڵۆپ دەبێتە»، کە لەسەر دەقی کوردی ڕاهێنرابێت بەرزترین دەداتە «دەریا»، چونکە پەندەکە زۆرجار وا دەڕوات. پەندەکە نازانێت؛ بینیویەتی زۆرجار چی دوای ئەوە دێت. بە هەمان شێوە، دوای «ئازاد بیر دەکاتەوە لە ژیریی دەستکرد» لەوانەیە داهاتوو «و» بێت ⁦22 %⁩، «کە» ⁦18 %⁩، «چونکە» ⁦15 %⁩ یان «بەڵام» ⁦10 %⁩ (ژمارەی نموونەیی).

An animation in six frames. The text so far is دڵۆپ دڵۆپ دەبێتە. A strip of five steps lights up in turn: 1 read, 2 score, 3 probabilities, 4 pick, 5 add and repeat. Bars show invented probabilities for the next token: دەریا (sea) 62 %, ڕووبار (river) 17 %, لافاو (flood) 12 %, ئاو (water) 6 %. دەریا is picked and added; the text becomes دڵۆپ دڵۆپ دەبێتە دەریا, shown as token boxes with the newest one in green. The loop runs again: a full stop gets 71 %, and the last frame shows دڵۆپ دڵۆپ دەبێتە دەریا. and says: until it picks a special end token or reaches the length limit.
An animation in six frames. The text so far is دڵۆپ دڵۆپ دەبێتە. A strip of five steps lights up in turn: 1 read, 2 score, 3 probabilities, 4 pick, 5 add and repeat. Bars show invented probabilities for the next token: دەریا (sea) 62 %, ڕووبار (river) 17 %, لافاو (flood) 12 %, ئاو (water) 6 %. دەریا is picked and added; the text becomes دڵۆپ دڵۆپ دەبێتە دەریا, shown as token boxes with the newest one in green. The loop runs again: a full stop gets 71 %, and the last frame shows دڵۆپ دڵۆپ دەبێتە دەریا. and says: until it picks a special end token or reaches the length limit.
Read, score, pick, add, repeat: one token per turn of the loop.خوێندنەوە، نمرەدان، هەڵبژاردن، زیادکردن، دووپاتە: لە هەر سووڕێکی یەک .CêIT

Inside the model: embeddings, attention and layersناو مۆدێلەکە: ئیمبەدینگ، سەرنجی خۆیی و چینەکان

What happens between read and score? Today's language models are transformers (Vaswani and others, 2017; why they replaced older networks is in RNNs and transformers). Each token id first becomes an embedding, a long list of numbers (next lesson). Then the numbers pass through many layers. In each layer:

لە نێوان خوێندنەوە و نمرەداندا چی ڕوو دەدات؟ ئەمڕۆ ن (Vaswani و هاوکارانی، ⁦2017⁩؛ بۆچی جێگەی تۆڕە کۆنەکانیان گرتەوە لە تۆڕی دەماریی گەڕاوە و ترانسفۆرمەردا هاتووە). هەر ژمارەیەکی ناسنامەی سەرەتا دەبێت بە ، لیستێکی درێژی ژمارە (وانەی داهاتوو). پاشان ژمارەکان بە چەندین تێدەپەڕن. لە هەر :

  • Self-attention: every token looks back at the tokens before it and decides which ones matter for its meaning. In «ئازاد بیر دەکاتەوە لە ژیریی دەستکرد», «دەکاتەوە» pays most attention to «ئازاد» (who is thinking?) and «دەستکرد» to «ژیریی» (artificial what?).
  • A small feed-forward network then adds more meaning to each token on its own.
  • Normalisation keeps the numbers in a steady range, so the many layers work well together.
  • : هەر سەیری ئەو پێش خۆی دەکات و بڕیار دەدات کامیان بۆ واتاکەی گرنگن. لە «ئازاد بیر دەکاتەوە لە ژیریی دەستکرد»دا، «دەکاتەوە» زۆرترین سەرنج دەداتە «ئازاد» (کێ بیر دەکاتەوە؟) و «دەستکرد» سەرنج دەداتە «ژیریی» (چی دەستکرد؟).
  • پاشان تۆڕێکی بچووکی ⁦feed-forward⁩ واتای زیاتر بە هەر دەدات بە تەنیا.
  • ژمارەکان لە مەودایەکی جێگیردا دەهێڵێتەوە، بۆ ئەوەی پێکەوە باش کار بکەن.

Big models repeat this block in dozens of layers. After the last layer come the scores for the next token. A model that writes looks only backwards, at earlier tokens, because the later ones do not exist yet. To watch a small GPT-style model do all of this in 3D, open Brendan Bycroft's LLM Visualization (bbycroft.net/llm).

گەورە ئەم بلۆکە لە دەیان دووپاتە دەکاتەوە. دوای دوایین نمرەکانی داهاتوو دێنە دەرەوە. کە دەنووسێت تەنیا سەیری دواوە دەکات، سەیری پێشوو، چونکە ئەوانەی دواتر هێشتا نین. بۆ ئەوەی ببینیت بچووکی وەک GPT هەموو ئەمانە بە سێ ڕەهەند دەکات، LLM Visualizationـی Brendan Bycroft بکەرەوە (⁦bbycroft.net/llm⁩).

Top: the six tokens ئازاد، بیر، دەکاتەوە، لە، ژیریی، دەستکرد in boxes from right to left, with English glosses Azad, thought, does (= thinks), about, intelligence, artificial. A thick green arc goes from دەکاتەوە back to ئازاد with the weight 0.8, and an orange arc from دەستکرد back to ژیریی with 0.7. Bottom: a pipeline from token ids to embeddings, then self-attention and feed-forward inside a dashed box marked one layer, repeated many times, then next-token probabilities. Note: the attention numbers are an example; real models have many attention heads and dozens of layers.سەرەوە: شەش تۆکنەکەی ئازاد، بیر، دەکاتەوە، لە، ژیریی، دەستکرد لە ناو چوارگۆشەدا لە ڕاستەوە بۆ چەپ. کەوانەیەکی سەوزی ئەستوور لە «دەکاتەوە»ـوە بۆ «ئازاد» دەگەڕێتەوە بە کێشی 0.8 و کەوانەیەکی پرتەقاڵی لە «دەستکرد»ـەوە بۆ «ژیریی» بە 0.7. خوارەوە: ڕێڕەوێک لە ژمارەی تۆکنەکانەوە بۆ ئیمبەدینگەکان، پاشان سەرنجی خۆیی و feed-forward لە ناو چوارگۆشەیەکی پچڕپچڕدا کە نووسراوە یەک چین، چەندین جار دووپاتە دەبێتەوە، پاشان ئەگەری تۆکنی داهاتوو. تێبینی: ژمارەکانی سەرنج نموونەن؛ مۆدێلەکان ڕاستەقینە چەندین سەری سەرنج و دەیان چینیان هەیە.
Attention links each token to the earlier tokens that give it meaning. هەر بەو پێشووەوە دەبەستێتەوە کە واتای پێ دەدەن.CêIT

Choosing the next token: greedy or by chance?هەڵبژاردنی تۆکنی داهاتوو: چاوچنۆکانە یان بە هەڵکەوت؟

The model gives probabilities; a separate rule chooses the token. Two simple rules:

دەدات؛ یاسایەکی جیا هەڵدەبژێرێت. دوو یاسای سادە:

  • Greedy decoding: always take the most likely token. The same input always gives the same output, but long texts become dull and start to repeat themselves.
  • Sampling: choose by chance, using the probabilities as weights, like drawing a ticket from a bag with 66 tickets saying sugar, 24 lemon, 9 milk and 1 salt. Likely tokens win most of the time, but not always.
  • : هەمیشە ئەگەرترین وەربگرە. هەمان هەمیشە هەمان دەدات، بەڵام دەقە درێژەکان بێتام دەبن و دەست دەکەن بە دووپاتەبوونەوە.
  • : بە هەڵکەوت هەڵبژێرە و وەک کێش بەکار بهێنە، وەک دەرهێنانی پسوولەیەک لە کیسەیەک کە ⁦66⁩ پسوولەی sugar، ⁦24⁩ lemon، 9 milk و 1 saltـی تێدایە. ئەو ئەگەریان زیاترە زۆربەی جار دەبەنەوە، بەڵام نەک هەمیشە.

Chat apps usually sample, so asking the same question twice can give two different answers; both may be good, and both may be wrong. Here is the idea in Python, with invented scores for the next word of Tea in Erbil is served with …:

ئەپەکانی گفتوگۆ زۆرجار دەکەن، بۆیە دوو جار پرسینی هەمان پرسیار لەوانەیە دوو وەڵامی جیاواز بدات؛ لەوانەیە هەردووکیان باش بن و لەوانەیە هەردووکیان هەڵە بن. ئەمە بیرۆکەکەیە بە Python، بە نمرەی نموونەیی بۆ وشەی داهاتووی Tea in Erbil is served with … (چای هەولێر لەگەڵ … دەدرێت):

Scores → probabilities, then greedy or samplingنمرە ← ئەگەر، پاشان چاوچنۆکانە یان نموونەگیریnext_token.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import math
import random

# Scores a model might give the next word of "Tea in Erbil is served with ..."
scores = {"sugar": 3.0, "lemon": 2.0, "milk": 1.0, "salt": -1.0}

def probabilities(scores, temperature=1.0):
    """Turn scores into probabilities (the softmax function)."""
    top = max(scores.values())
    powers = {w: math.exp((s - top) / temperature) for w, s in scores.items()}
    total = sum(powers.values())
    return {w: p / total for w, p in powers.items()}

for t in (0.5, 1.0, 2.0):
    probs = probabilities(scores, t)
    print(f"T={t}:", "  ".join(f"{w} {p:.2f}" for w, p in probs.items()))

probs = probabilities(scores)
print("greedy:", max(probs, key=probs.get))

random.seed(5)
words, weights = list(probs), list(probs.values())
print("sampled:", random.choices(words, weights=weights, k=8))
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 9-12

The softmax: raise e to each score, then divide by the total so the probabilities add up to 1. Subtracting the largest score first changes nothing in the result but keeps math.exp from overflowing (see Common mistakes).

: e بەرز بکەرەوە بۆ توانی هەر نمرەیەک، پاشان دابەشی بکە بەسەر کۆکەدا بۆ ئەوەی کۆی ببێت بە 1. دەرکردنی گەورەترین نمرە پێشتر هیچ لە ئەنجامەکە ناگۆڕێت، بەڵام ڕێ لە math.exp دەگرێت (بڕوانە هەڵە باوەکان).

Lineدێڕی 18-19

Greedy decoding: max with key=probs.get returns the word with the biggest probability.

: max لەگەڵ key=probs.get ئەو وشەیە دەگەڕێنێتەوە کە گەورەترین هەیە.

Lineدێڕی 21-23

Sampling: random.choices draws 8 words with the probabilities as weights. random.seed(5) makes the draw repeatable, so you get exactly this output (the random module).

: random.choices 8 وشە دەردەهێنێت و وەک کێش بەکار دەهێنێت. random.seed(5) دەرهێنانەکە دووپاتەکراوە دەکات، بۆیە ڕێک ئەم دەرخستەیە وەردەگریت (مۆدیولی random).

The probabilities of the next word of Tea in Erbil is served with …: sugar 0.66, lemon 0.24, milk 0.09, salt 0.01. Left panel, greedy decoding, always the top token: sugar eight times, the same every time, can become repetitive. Right panel, sampling, drawn by chance with these weights: sugar, lemon, lemon, milk, lemon, milk, sugar, sugar; varied, likely words win most often.ئەگەری وشەی داهاتووی Tea in Erbil is served with …: sugar 0.66، lemon 0.24، milk 0.09، salt 0.01. بەشی چەپ، هەڵبژاردنی چاوچنۆکانە، هەمیشە بەرزترین تۆکن: هەشت جار sugar، هەموو جارێک وەک یەک، لەوانەیە دووپاتە ببێتەوە. بەشی ڕاست، نموونەگیری، بە هەڵکەوت بەپێی ئەم کێشانە: sugar، lemon، lemon، milk، lemon، milk، sugar، sugar؛ جۆراوجۆر، وشە ئەگەردارەکان زۆرتر دەبەنەوە.
Greedy always picks the favourite; sampling sometimes picks another likely word. هەمیشە دڵخوازترین هەڵدەبژێرێت؛ هەندێک جار وشەیەکی تری ئەگەردار هەڵدەبژێرێت.CêIT

Temperature and top-pپلەی گەرمی و ⁦top-p⁩

Before the softmax, the scores can be divided by a number called the temperature. A low temperature (0.5) makes the favourite even stronger: sugar gets 87 %. A high temperature (2) flattens the chances: sugar drops to 47 % and even salt gets 6 %. Low means safe and repetitive; high means varied and risky. Top-p sampling is a second filter: keep only the most likely tokens whose probabilities add up to p, then sample among them. With p = 0.8, sugar (0.66) and lemon (0.24) already reach 0.8, so milk and salt can never be chosen.

پێش ، دەکرێت نمرەکان دابەش بکرێن بەسەر ژمارەیەکدا کە پێی دەگوترێت . نزم ⁦(0.5)⁩ دڵخوازەکە بەهێزتر دەکات: sugar ⁦87 %⁩ وەردەگرێت. بەرز ⁦(2)⁩ دەرفەتەکان یەکسانتر دەکات: sugar دادەبەزێت بۆ ⁦47 %⁩ و تەنانەت salt ⁦6 %⁩ وەردەگرێت. نزم واتە سەلامەت و دووپاتە؛ بەرز واتە جۆراوجۆر و مەترسیدار. فلتەرێکی دووەمە: تەنیا ئەگەرترین بهێڵەرەوە کە کۆی دەگاتە p، پاشان لە نێوانیاندا بکە. بە p = ⁦0.8⁩، sugar ⁦(0.66)⁩ و lemon ⁦(0.24)⁩ پێکەوە دەگەنە ⁦0.8⁩، بۆیە milk و salt هەرگیز هەڵنابژێردرێن.

Three bar charts of the same four words. T = 0.5 (low: safe, repetitive): sugar 87 %, lemon 12 %, milk 2 %, salt 0 %. T = 1 (the model's own scores): sugar 66 %, lemon 24 %, milk 9 %, salt 1 %. T = 2 (high: varied, risky): sugar 47 %, lemon 29 %, milk 17 %, salt 6 %. Scores: sugar 3, lemon 2, milk 1, salt −1 (invented); each chart adds up to 100 %.سێ چارتی ستوونی بۆ هەمان چوار وشە. T = 0.5 (نزم: سەلامەت، دووپاتە): sugar 87 %، lemon 12 %، milk 2 %، salt 0 %. T = 1 (نمرەکانی خودی مۆدێلەکە): sugar 66 %، lemon 24 %، milk 9 %، salt 1 %. T = 2 (بەرز: جۆراوجۆر، مەترسیدار): sugar 47 %، lemon 29 %، milk 17 %، salt 6 %. نمرەکان (نموونەیی): sugar 3، lemon 2، milk 1، salt −1؛ کۆی هەر چارتێک دەکاتە سەدا سەد.
Low temperature sharpens the favourite; high temperature spreads the chances. نزم دڵخوازەکە تیژتر دەکات؛ بەرز دەرفەتەکان بڵاو دەکاتەوە.CêIT

The context window: the model's working memoryپەنجەرەی کۆنتێکست: بیرگەی کارکردنی مۆدێل

A model can look at only a limited amount of text in one request: its context window, counted in tokens. Everything must fit inside it: the app's hidden instructions (the system prompt), the conversation so far, any attached files, the new question and the answer the model writes. Anthropic's documentation calls it the model's working memory, different from the huge training data it learned from.

لە یەک تەنیا دەتوانێت سەیری بڕێکی سنووردار دەق بکات: ، کە بە دەپێورێت. هەموو شتێک دەبێت تێیدا جێی ببێتەوە: ڕێنماییە شاراوەکانی (هەوێنی سیستەم)، گفتوگۆکە تا ئێستا، هەر فایلێکی هاوپێچ، پرسیارە نوێیەکە و ئەو وەڵامەی دەینووسێت. بەڵگەنامەکانی Anthropic پێی دەڵێن بیرگەی کارکردنـی ، کە جیاوازە لەو گەورەیەی لێی فێر بووە.

Windows have grown fast. GPT-2 (2019) could see 1,024 tokens. In November 2026 the main Claude and Gemini models see 1 million tokens and the GPT-6 family 1.05 million; one answer can be up to 128,000 tokens on Claude and GPT. On Claude's newest tokenizer, 1 million tokens are about 555,000 English words: several long books.

خێرا گەورە بوون. ⁦GPT-2 (2019)⁩ دەیتوانی ⁦1,024⁩ ببینێت. لە مانگی ⁦11⁩ی ⁦2026⁩دا گرنگترین Claude و ⁦Gemini 1⁩ ملیۆن دەبینن و خێزانی ⁦GPT-6 1.05⁩ ملیۆن؛ یەک وەڵام دەتوانێت لە Claude و GPTـدا تا ⁦128,000⁩ بێت. لەسەر نوێترین بەرنامەی Claude، 1 ملیۆن نزیکەی ⁦555,000⁩ وشەی ئینگلیزییە: چەند کتێبێکی درێژ.

Everyday analogyنموونەیەک لە ژیانی ڕۆژانەوە

A context window is like a classroom whiteboard: the teacher can use only what is written on it now. Last week's lesson is not there unless someone writes it again; when the board is full, something must be wiped.

وەک تەختەی پۆلێکە: مامۆستا تەنیا دەتوانێت ئەوە بەکار بهێنێت کە ئێستا لەسەر تەختەکە نووسراوە. وانەی هەفتەی ڕابردوو لەوێ نییە مەگەر کەسێک دووپاتە بینووسێتەوە و کاتێک تەختەکە پڕ دەبێت، دەبێت شتێک بسڕدرێتەوە.

Where the analogy stops workingسنووری ئەم نموونەیە

A teacher reads the whole board equally well; a model reads a very long context less carefully (long contexts).

مامۆستا هەموو تەختەکە بە یەکسانی دەخوێنێتەوە. لە کۆنتێکستێکی زۆر درێژدا کەمتر بە وردی سەرنج دەدات (کۆنتێکستی درێژ).

A long bar marked context window: about 1,000,000 tokens on the main models (November 2026). It is split into a thin system prompt, the conversation so far, an attached file, the new question, a dashed part kept for the answer, and some free space. Below, in a grey box: NOT in the window: the training data the model learned from long before; the model knows that only through its weights and cannot read it now.ستوونێکی درێژ کە لەسەری نووسراوە پەنجەرەی کۆنتێکست: نزیکەی 1,000,000 تۆکن لە مۆدێلە سەرەکییەکاندا (مانگی 11ی 2026). دابەش کراوە بۆ هەوێنێکی سیستەم باریک، گفتوگۆ تا ئێستا، فایلێکی هاوپێچ، پرسیاری نوێ، بەشێکی پچڕپچڕ بۆ وەڵام و هەندێک جێگەی بەتاڵ. لە خوارەوە، لە چوارگۆشەیەکی خۆڵەمێشیدا: لە پەنجەرەی کۆنتێکستدا نییە: ئەو دراوەی ڕاهێنانەی مۆدێلەکە زۆر پێشتر لێی فێر بووە؛ مۆدێلەکە تەنیا لە ڕێگەی کێشەکانییەوە ئەوە دەزانێت و ئێستا ناتوانێت بیخوێنێتەوە.
Everything in one request shares the same window.هەموو شتێکی یەک هەمان بەش دەکەن.CêIT

The context window: the model's working memoryپەنجەرەی کۆنتێکست: بیرگەی کارکردنی مۆدێل

Does it fit? A budget check in Pythonجێی دەبێتەوە؟ پشکنینی بودجە بە Python

Karwan wants Shilan's helper to answer questions about a 300-page book. Before he sends it, he estimates the tokens. The rule of thumb is rough, but it shows the idea: everything sent plus room for the answer must stay under the window.

کاروان دەیەوێت یاریدەدەرەکەی شیلان وەڵامی پرسیار لەبارەی کتێبێکی ⁦300⁩ لاپەڕەیی بداتەوە. پێش ناردن، مەزەندە دەکات. یاسا نزیکەییەکە وردی نییە، بەڵام بیرۆکەکە پیشان دەدات: هەموو ئەوەی دەنێردرێت لەگەڵ جێگەی وەڵام دەبێت لە ژێر بمێنێتەوە.

Will the request fit in the context window?ئایا داواکارییەکە لە پەنجەرەی کۆنتێکستدا جێی دەبێتەوە؟context_budget.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
WINDOW = 1_000_000      # tokens the model can see at once (main models, November 2026)
MAX_OUTPUT = 32_000     # tokens kept free for the answer
CHARS_PER_TOKEN = 4     # Google's rule of thumb for English text on Gemini

def fits(parts):
    used = sum(chars // CHARS_PER_TOKEN for chars in parts.values())
    total = used + MAX_OUTPUT
    print(f"{used:,} + {MAX_OUTPUT:,} for the answer = {total:,} of {WINDOW:,}")
    return total <= WINDOW

book = 300 * 1_800                  # 300 pages, about 1,800 characters each
request = {"instructions": 2_000, "book": book, "question": 400}
print("one book fits:", fits(request))

request["book"] = 10 * book         # a shelf of ten such books
print("ten books fit:", fits(request))
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

A rough English rule. Claude's newest tokenizer gives about 2.5 characters per token, so the same book counts more tokens there (exercise 3).

یاسایەکی نزیکەیی بۆ ئینگلیزی. نوێترین بەرنامەی Claude بۆ هەر نزیکەی ⁦2.5⁩ پیت دەدات، بۆیە هەمان کتێب لەوێ زیاتر دەژمێرێت (ڕاهێنانی ⁦3⁩).

Lineدێڕی 6

sum(...) adds the estimated tokens of every part; // is whole-number division.

sum(...) ژمارەی مەزەندەکراوی هەموو بەشەکان کۆ دەکاتەوە؛ // دابەشکردنی ژمارەی تەواوە.

Example only (not run): Claude's own token counterتەنیا نموونە (کار پێ نەکراوە): ژمێرەری تۆکنی خودی Claudecount_tokens.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import anthropic

client = anthropic.Anthropic()
response = client.messages.count_tokens(
    model="claude-opus-5-5",
    system="You answer questions about one book.",
    messages=[{"role": "user", "content": "Who is the main character?"}],
)
print(response.json())

No memory between requestsهیچ بیرگەیەک لە نێوان داواکارییەکاندا نییە

The model itself remembers nothing from one request to the next: the API is stateless. So how does a chat continue? The app keeps the conversation and sends all of it again with every new message: turn 1 sends the first question; turn 2 sends question 1, answer 1 and question 2; and so on. Each turn is longer than the last, which is why long chats get slower and cost more (Token optimization).

خودی هیچ شتێک لە بۆ داهاتوو لەبیر ناکات: . کەواتە گفتوگۆ چۆن بەردەوام دەبێت؟ گفتوگۆکە هەڵدەگرێت و لەگەڵ هەر نامەیەکی نوێدا هەمووی دووپاتە دەنێرێتەوە: نۆرەی 1 پرسیاری یەکەم دەنێرێت؛ نۆرەی 2 پرسیاری 1، وەڵامی 1 و پرسیاری 2 دەنێرێت؛ بەم شێوەیە. هەر نۆرەیەک لە نۆرەی پێشوو درێژترە، بۆیە گفتوگۆ درێژەکان هێواشتر دەبن و تێچوویان زیاتر دەبێت (باشترینکردنی تۆکن).

When an app says it remembers you, the app has saved notes about you and quietly puts them into the context of new chats. The model's weights did not change; it learned nothing about you.

کاتێک دەڵێت تۆی لە بیرە، تێبینیی لەبارەی تۆ پاشەکەوت کردووە و بە بێدەنگی دەیانخاتە ناو کۆنتێکستی گفتوگۆ نوێکانەوە. نەگۆڕاون؛ هیچ شتێکی لەبارەی تۆ فێر نەبووە.

An animation of a staircase of requests. Turn 1 sends S and Q1 to the model. Turn 2 sends S, Q1, A1 and Q2. Turn 3 sends S, Q1, A1, Q2, A2 and Q3. The model box says: remembers nothing between requests. Legend: S = system prompt, Q = question, A = answer; every turn is longer: more tokens, more time, more cost. The last frame adds a new chat that sends saved notes, S and Q1, and says: memory in an app means saved notes put into the new chat; the model is unchanged.
An animation of a staircase of requests. Turn 1 sends S and Q1 to the model. Turn 2 sends S, Q1, A1 and Q2. Turn 3 sends S, Q1, A1, Q2, A2 and Q3. The model box says: remembers nothing between requests. Legend: S = system prompt, Q = question, A = answer; every turn is longer: more tokens, more time, more cost. The last frame adds a new chat that sends saved notes, S and Q1, and says: memory in an app means saved notes put into the new chat; the model is unchanged.
The app re-sends the whole conversation every turn. لە هەر نۆرەیەکدا هەموو گفتوگۆکە دووپاتە دەنێرێتەوە.CêIT

When the window is long, or fullکاتێک پەنجەرەی کۆنتێکست درێژ یان پڕ دەبێت

A bigger window does not mean the model reads everything equally well. Anthropic's documentation warns that as the number of tokens grows, accuracy and recall get worse, and calls this context rot. So give the model the parts that matter, not everything you have; the next lesson shows how to fetch the right parts (RAG).

گەورەتر واتای ئەوە نییە کە هەموو شتێک بە یەکسانی باش دەخوێنێتەوە. بەڵگەنامەکانی Anthropic ئاگادار دەکەنەوە کە هەتا ژمارەی زیاد بکات، وردی و بیرهێنانەوە خراپتر دەبن و پێی دەڵێن . بۆیە ئەو بەشانەی گرنگن بدە بە ، نەک هەموو ئەوەی هەتە؛ وانەی داهاتوو پیشان دەدات چۆن بەشە دروستەکان بهێنیت (RAG).

And when it is full? On the Claude API, as of November 2026:

ئەی کاتێک پڕ دەبێت؟ لە Claude APIـدا، لە مانگی ⁦11⁩ی ⁦2026⁩دا:

  • The input alone is too long → the request is refused with a 400 error (prompt is too long).
  • The answer reaches the end of the window → it stops with the stop reason model_context_window_exceeded.
  • The answer reaches the max_tokens you set → it stops with max_tokens. A stopped answer is cut off, not finished.
  • بەتەنیا زۆر درێژە ← بە هەڵەی ⁦400⁩ ڕەت دەکرێتەوە (prompt is too long).
  • وەڵامەکە دەگاتە کۆتایی ← دەوەستێت بە هۆکاری وەستانی model_context_window_exceeded.
  • وەڵامەکە دەگاتە ئەو max_tokensـەی داتناوە ← بە max_tokens دەوەستێت. وەڵامێکی وەستاو بڕاوە، نەک تەواو.

Chat apps hide this from you: some drop the oldest messages first, others replace them with a short summary (context compaction).

ئەپەکانی گفتوگۆ ئەمە لە تۆ دەشارنەوە: هەندێکیان سەرەتا کۆنترین نامەکان فڕێ دەدەن و هەندێکی تر کورتەیەکی کورتیان لەبری دادەنێن (پوختکردنەوەی کۆنتێکست).

Three panels for the Claude API, November 2026. One: the input alone is longer than the limit line, so the request is refused with a 400 error, prompt is too long. Two: the input plus the answer reach the limit line, so the answer stops: window full, model_context_window_exceeded. Three: the answer reaches a dashed max_tokens line before the window is full, so it stops cut off and unfinished, stop reason max_tokens.سێ بەش بۆ Claude API، مانگی 11ی 2026. یەکەم: نێوخستە بەتەنیا لە هێڵی سنوور درێژترە، بۆیە داواکارییەکە بە هەڵەی 400 ڕەت دەکرێتەوە، prompt is too long. دووەم: نێوخستە لەگەڵ وەڵامەکە دەگەنە هێڵی سنوور، بۆیە وەڵامەکە دەوەستێت: پڕ بوو، model_context_window_exceeded. سێیەم: وەڵامەکە پێش پڕبوونی پەنجەرەی کۆنتێکست دەگاتە هێڵێکی پچڕپچڕی max_tokens، بۆیە بڕاو و ناتەواو دەوەستێت، هۆکاری وەستان max_tokens.
Three ways a request meets a limit.سێ ڕێگە کە دەگاتە سنوورێک.CêIT

Common mistakesهەڵە باوەکان

A programming mistake: computing the softmax with math.exp(score) directly. Real scores can be large, and e to the power 1,000 is too big for a Python float:

هەڵەیەکی بەرنامەسازی: ژماردنی ڕاستەوخۆ بە math.exp(score). نمرە ڕاستەقینەکان لەوانەیە گەورە بن و e بە توانی ⁦1,000⁩ بۆ floatـی Python زۆر گەورەیە:

Wrong: e to the power of a big scoreهەڵە: e بە توانی نمرەیەکی گەورەoverflow.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import math

scores = {"sugar": 1000.0, "lemon": 999.0}
powers = {w: math.exp(s) for w, s in scores.items()}
print(powers)
Right: subtract the largest score firstدروست: سەرەتا گەورەترین نمرە دەربکەoverflow_fixed.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import math

scores = {"sugar": 1000.0, "lemon": 999.0}
top = max(scores.values())
powers = {w: math.exp(s - top) for w, s in scores.items()}
total = sum(powers.values())
print({w: round(p / total, 2) for w, p in powers.items()})
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-5

After subtracting 1,000, the scores are 0 and −1, so math.exp gives 1 and 0.37. The probabilities are the same as before; only the overflow is gone.

دوای دەرکردنی ⁦1,000⁩، نمرەکان دەبن بە 0 و ⁦−1⁩، بۆیە math.exp 1 و ⁦0.37⁩ دەدات. وەک پێشوون؛ تەنیا نەماوە.

Exercisesڕاهێنانەکان

ExerciseڕاهێنانTokenize by handتۆکنکردن بە دەست

Use the 30 merges that toy_bpe.py learned (the words the, reads, teacher, student and book are whole tokens with </w>; read, student, teacher and lesson also exist without it). Tokenize the teachers read the book. How many tokens? Check with the program.

ئەو ⁦30⁩ بەیەکگەیاندنە بەکار بهێنە کە toy_bpe.py فێریان بوو (وشەکانی the، reads، teacher، student و book لەگەڵ </w> تەواون؛ read، student، teacher و lesson بەبێ ئەویش هەن). the teachers read the book بکە بە . چەند ؟ بە بیپشکنە.

Show answerوەڵامەکە پیشان بدە

8 tokens: the</w> teacher s </w> read </w> the</w> book</w>. teachers is new, so it is written as the known piece teacher plus s; read without s never got its end mark joined, so </w> stays separate. The program prints ['the</w>', 'teacher', 's', '</w>', 'read', '</w>', 'the</w>', 'book</w>'].

8 : the</w> teacher s </w> read </w> the</w> book</w>. teachers نوێیە، بۆیە بە پارچە ناسراوەکەی teacher لەگەڵ s دەنووسرێت؛ read بەبێ s هەرگیز نیشانەی کۆتایی پێوە نەلکاوە، بۆیە </w> جیا دەمێنێتەوە. ['the</w>', 'teacher', 's', '</w>', 'read', '</w>', 'the</w>', 'book</w>'] چاپ دەکات.

ExerciseڕاهێنانScores to probabilitiesنمرە بۆ ئەگەر

After «دڵۆپ دڵۆپ دەبێتە» a model gives the scores دەریا 2, ڕووبار 1 and لافاو 0. Compute the probabilities at temperature 1 and at temperature 2 (use e ≈ 2.718; round to two decimals). Which choice changes more?

دوای «دڵۆپ دڵۆپ دەبێتە» ئەم نمرانە دەدات: دەریا 2، ڕووبار 1 و لافاو 0. لە 1 و 2دا بژمێرە (e ≈ ⁦2.718⁩؛ بۆ دوو ژمارەی دوای فاریزە نزیکی بکەرەوە). کام هەڵبژاردن زیاتر دەگۆڕێت؟

Show answerوەڵامەکە پیشان بدە
T=1:e2=7.39, e1=2.72, e0=1, total=11.11⇒0.67, 0.24, 0.09T=2:e1=2.72, e0.5=1.65, e0=1, total=5.37⇒0.51, 0.31, 0.19\begin{aligned} T=1:&\quad e^{2}=7.39,\ e^{1}=2.72,\ e^{0}=1,\ \text{total}=11.11 \Rightarrow 0.67,\ 0.24,\ 0.09 \\ T=2:&\quad e^{1}=2.72,\ e^{0.5}=1.65,\ e^{0}=1,\ \text{total}=5.37 \Rightarrow 0.51,\ 0.31,\ 0.19 \end{aligned}

دەریا falls from 67 % to 51 %; لافاو more than doubles, from 9 % to 19 %. A higher temperature spreads the chances. (Checked with python3.13.)

دەریا لە ⁦67 %⁩ـەوە دادەبەزێت بۆ ⁦51 %⁩؛ لافاو زیاتر لە دوو هێندە دەبێت، لە ⁦9 %⁩ـەوە بۆ ⁦19 %⁩. بەرزتر دەرفەتەکان بڵاو دەکاتەوە. (بە ⁦python3.13⁩ پشکنراوە.)

ExerciseڕاهێنانDoes the book fit on Claude?ئایا کتێبەکە لە Claudeـدا جێی دەبێتەوە؟

In context_budget.py, set CHARS_PER_TOKEN = 2.5 (about right for Claude's newest tokenizer). (a) How many tokens does one 300-page book need now? (b) With 32,000 tokens kept for the answer, how many such books fit in 1,000,000 tokens with 4 characters per token, and how many with 2.5?

لە context_budget.pyـدا CHARS_PER_TOKEN = 2.5 دابنێ (نزیکەی ڕاستە بۆ نوێترین بەرنامەی ⁦Claude). (a⁩) کتێبێکی ⁦300⁩ لاپەڕەیی ئێستا چەند دەوێت؟ ⁦(b)⁩ بە هێشتنەوەی ⁦32,000⁩ بۆ وەڵام، چەند کتێبی لەو جۆرە لە ⁦1,000,000⁩ جێیان دەبێتەوە بە 4 پیت بۆ هەر و چەند بە ⁦2.5⁩؟

Show answerوەڵامەکە پیشان بدە

(a) 540,000 ÷ 2.5 = 216,000 tokens for the book (plus 960 for the instructions and question). (b) With 4 characters per token a book is 135,000 tokens: 7 books fit (945,000 + 600 + 32,000 = 977,600), 8 do not. With 2.5 a book is 216,000 tokens: only 4 fit (864,000 + 960 + 32,000 = 896,960). The same text costs more on a tokenizer that makes smaller pieces, so always count with the model you will use.

⁦(a) 540,000 ÷ 2.5 = 216,000⁩ بۆ کتێبەکە (لەگەڵ ⁦960⁩ بۆ ڕێنمایی و پرسیار). ⁦(b)⁩ بە 4 پیت بۆ هەر ، کتێبێک ⁦135,000⁩ : 7 کتێب جێیان دەبێتەوە ⁦(945,000 + 600 + 32,000 = 977,600)⁩، 8 نا. بە ⁦2.5⁩ کتێبێک ⁦216,000⁩ : تەنیا 4 جێیان دەبێتەوە ⁦(864,000 + 960 + 32,000 = 896,960)⁩. هەمان دەق لەسەر بەرنامەیەکی کە پارچەی بچووکتر دروست دەکات تێچووی زیاترە، بۆیە هەمیشە بەو دەژمێرە کە بەکاری دەهێنیت.

ExerciseڕاهێنانHow much does turn 3 send?نۆرەی 3 چەند دەنێرێت؟

Shilan's helper has a 100-token system prompt. Each customer question is 50 tokens and each answer 200 tokens. The API is stateless, so every turn re-sends everything. How many input tokens does turn 3 send, and how many input tokens do the three turns send together?

یاریدەدەرەکەی شیلان ⁦100⁩ تۆکنی هەیە. هەر پرسیارێکی کڕیار ⁦50⁩ و هەر وەڵامێک ⁦200⁩ . ، بۆیە هەر نۆرەیەک هەموو شتێک دووپاتە دەنێرێتەوە. نۆرەی 3 چەند دەنێرێت و هەر سێ نۆرەکە پێکەوە چەند؟

Show answerوەڵامەکە پیشان بدە

Turn 1: 100 + 50 = 150. Turn 2: 100 + 50 + 200 + 50 = 400. Turn 3: 100 + 50 + 200 + 50 + 200 + 50 = 650. Together 150 + 400 + 650 = 1,200 input tokens, for only 150 tokens of new questions. This is why long chats get expensive.

نۆرەی ⁦1: 100 + 50 = 150⁩. نۆرەی ⁦2: 100 + 50 + 200 + 50 = 400⁩. نۆرەی ⁦3: 100 + 50 + 200 + 50 + 200 + 50 = 650⁩. پێکەوە ⁦150 + 400 + 650 = 1,200⁩ ، بۆ تەنیا ⁦150⁩ پرسیاری نوێ. بۆیە گفتوگۆ درێژەکان گران دەبن.

Summaryپوختە

  • A tokenizer cuts text into tokens and gives each an id from a fixed vocabulary; byte-pair encoding learns the pieces by joining the most frequent pairs.
  • Kurdish usually needs more tokens than English (up to 15× between languages; 2-byte letters), so it costs more and fills the window sooner.
  • Writing is a loop: read all tokens → score every token → softmax → pick → add → repeat. Inside, transformer layers use self-attention and feed-forward networks.
  • Greedy decoding always takes the top token; sampling draws by chance; temperature and top-p shape the chances. In November 2026 the newest Claude, Gemini and GPT models set this for you.
  • The context window (about 1 million tokens on the main models, November 2026) holds everything in one request, including the answer; the API is stateless, so the app re-sends the conversation; long contexts suffer from context rot.
  • بەرنامەی دەق دەکات بە و ژمارەیەکی ناسنامە لە جێگیر دەداتە هەریەکەیان؛ پارچەکان بە بەیەکگەیاندنی زۆرترین جووتی دووپاتە فێر دەبێت.
  • کوردی زۆرجار زیاتری لە ئینگلیزی دەوێت (تا ⁦15⁩ هێندە لە نێوان زمانەکاندا؛ پیتی 2 بایتی)، بۆیە گرانترە و زووتر پڕ دەکات.
  • نووسین : هەموو بخوێنەوە ← نمرە بدە بە هەموویان ← ← هەڵبژێرە ← زیادی بکە ← دووپاتە. لە ناوەوە، و تۆڕی ⁦feed-forward⁩ بەکار دەهێنن.
  • هەمیشە بەرزترین وەردەگرێت؛ بە هەڵکەوت دەردەهێنێت؛ و ⁦top-p⁩ دەرفەتەکان دادەڕێژن. لە مانگی ⁦11⁩ی ⁦2026⁩دا نوێترین Claude، Gemini و GPT ئەمە بۆ تۆ دادەنێن.
  • (نزیکەی 1 ملیۆن لە مۆدێلە سەرەکییەکاندا، مانگی ⁦11⁩ی ⁦2026⁩) هەموو شتێکی یەک لەخۆ دەگرێت، وەڵامەکەشی؛ ، بۆیە گفتوگۆکە دووپاتە دەنێرێتەوە؛ کۆنتێکستی درێژ تووشی دەبێت.

Next: how the model turns tokens into meaning, and how the same idea powers search by meaning and answers from your own documents: Meaning as numbers.

داهاتوو: چۆن دەکات بە واتا و چۆن هەمان بیرۆکە گەڕان بەپێی واتا و وەڵامدانەوە لە بەڵگەنامەکانی خۆتەوە دەجووڵێنێت: مانا وەک ژمارە.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Meaning as Numbers: Vectors and Embeddingsمانا وەک ژمارە: ئاڕاستەبڕەکان و ئیمبەدینگەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.