Lecture 02 · Words and Tokens

المحاضرة 02 · الكلمات والرموز (Tokens)

Tokenization and BPE

التقطيع (Tokenization) وBPE

Slides 37–52الشرائح 37–52 P1 MUST

How raw text becomes the units a model actually sees, and how to run byte-pair encoding by hand on the lecture's own toy corpus without guessing.

كيف يتحول النص الخام إلى الوحدات التي يراها النموذج فعلاً، وكيف تنفّذ byte-pair encoding يدوياً على corpus المحاضرة الصغير دون تخمين.

Highest exam risk on this lectureأعلى خطر في الاختبار في هذه المحاضرة

The likely question is not "what is BPE". It is "here is a small corpus, perform two merges and give the resulting vocabulary". That is a procedure, and you will be marked on the counts. The full worked run of the lecture's own example is below with every pair count shown. Do that run yourself once on paper before the exam and this page is finished with you.

السؤال المتوقع ليس "what is BPE"، بل "here is a small corpus, perform two merges and give the resulting vocabulary". هذا إجراء، والدرجة تُمنح على صحة العدّ. التنفيذ الكامل لمثال المحاضرة موجود أدناه مع كل عدّ لكل زوج. نفّذه بنفسك مرة واحدة على ورقة قبل الامتحان، وتكون هذه الصفحة قد أدّت مهمتها.

The second likely question is the one people lose marks on by not noticing it was asked: training learns the merge list, encoding applies it. They are different operations.

والسؤال المتوقع الثاني هو الذي يخسر فيه الناس درجات لأنهم لم يلاحظوا أنه سُئل: training يتعلّم قائمة الـ merges، وencoding يطبّقها. عمليتان مختلفتان.

What tokenization is, slide 37

ما التقطيع، الشريحة 37

A model cannot consume a string. It consumes a sequence of discrete items drawn from a fixed, finite inventory. Tokenization is the step that turns raw text into that sequence.

النموذج لا يستهلك نصاً، بل تسلسلاً من عناصر منفصلة مأخوذة من مخزون ثابت ومحدود. وtokenization هي الخطوة التي تحوّل النص الخام إلى ذلك التسلسل.

The slide's definition: tokenization converts raw text into a sequence of tokens, the units a model or NLP pipeline operates on. And tokens can be words, characters, or subwords.

تعريف الشريحة: tokenization يحوّل النص الخام إلى تسلسل من tokens، وهي الوحدات التي يعمل عليها النموذج أو خط معالجة NLP. والـ tokens قد تكون كلمات أو حروفاً أو subwords.

So there is a design choice to make, and the slide gives four criteria for making it:

إذن هناك قرار تصميمي يجب اتخاذه، وتعطي الشريحة أربعة معايير لاتخاذه:

CriterionالمعيارWhat it asksماذا يسألWho wins on itمن يفوز فيه
Coverageالتغطية (Coverage)few or no unknown tokensقليل من الـ tokens المجهولة أو لا شيء منهاcharacters and bytesالحروف والـ bytes
Compactnessالإيجاز (Compactness)shorter sequences, faster processingتسلسلات أقصر ومعالجة أسرعwordsالكلمات
Meaningfulnessالدلالة (Meaningfulness)units correlate with meaning and contextالوحدات ترتبط بالمعنى والسياقwordsالكلمات
Cross-lingual applicabilityالصلاحية عبر اللغات (Cross-lingual applicability)works across writing systemsتعمل عبر أنظمة الكتابةcharacters and bytesالحروف والـ bytes

يسرد الجدول المعايير الأربعة من الشريحة 37 ومن يفوز بكل واحد: Coverage أي التغطية بلا tokens مجهولة، وتفوز بها الحروف والـ bytes؛ وCompactness أي تسلسلات أقصر، وتفوز بها الكلمات؛ وMeaningfulness أي وحدات مرتبطة بالمعنى، وتفوز بها الكلمات؛ وCross-lingual applicability أي العمل عبر أنظمة الكتابة، وتفوز بها الحروف والـ bytes. اقرأ العمود الأخير وستجد أن لا خيار واحد يفوز بالأربعة.

Notice that no single option wins all four. Coverage and cross-lingual reach pull toward small units; compactness and meaningfulness pull toward large ones. The slide prints the tension as a spectrum:

لاحظ أن لا خيار واحد يفوز بالمعايير الأربعة. التغطية والمدى بين اللغات تجذبان نحو وحدات صغيرة، والاختصار والمعنى يجذبان نحو وحدات كبيرة. وتطبع الشريحة هذا التوتر على شكل طيف متصل:

Characters ↔ Subwords ↔ Words

يمتد الطيف من الحروف (Characters) في طرف إلى الكلمات (Words) في الطرف الآخر، والـ Subwords في الوسط بينهما.

Subwords sit in the middle on purpose. Everything else on this page is a consequence of that one picture.

الـ subwords تقع في الوسط عن قصد، وكل ما بقي في هذه الصفحة نتيجة لهذه الصورة الواحدة.

Word tokenization, slide 38

التقطيع على مستوى الكلمات، الشريحة 38

Why words feel natural

لماذا تبدو الكلمات طبيعية

The main challenges

التحديات الرئيسية

The OOV problem is the fatal one. A fixed word vocabulary has to be closed at some size, and anything outside it collapses to a single <UNK> token. The model then cannot distinguish one unseen word from any other unseen word, no matter how transparent the word is. A model that has seen renew and -ing thousands of times still cannot read renewing if that exact string missed the cut.

مشكلة OOV هي القاتلة. أي vocabulary للكلمات يجب إغلاقه عند حجم معين، وكل ما خرج عنه ينهار إلى token واحد هو <UNK>. فلا يستطيع النموذج بعدها أن يميّز كلمة مجهولة من أخرى، مهما كانت بنيتها واضحة. ونموذج رأى renew و-ing آلاف المرات لا يستطيع قراءة renewing إذا لم تدخل تلك السلسلة بعينها في القائمة.

When words are still preferred

متى تبقى الكلمات مفضّلة

The slide does not dismiss word tokenization. It keeps it for tasks that need explicit word boundaries or interpretability: some POS tagging and parsing settings, and lexicon-driven systems. If your method looks a word up in a dictionary, you need the word.

لا ترفض الشريحة word tokenization، بل تبقيها للمهام التي تحتاج حدود كلمات صريحة أو قابلية تفسير: بعض حالات POS tagging وparsing، والأنظمة المعتمدة على المعاجم. فإذا كانت طريقتك تبحث عن الكلمة في قاموس، فأنت تحتاج الكلمة كاملة.

Character tokenization, slide 39

التقطيع على مستوى الحروف، الشريحة 39

Why characters are attractive

لماذا الحروف جذابة

The main drawbacks

العيوب الرئيسية

When characters are preferred

متى تُفضّل الحروف

Noisy text (OCR output, typo-heavy input), extremely low-resource settings, or very specialized tasks.

النص المشوّش (مخرجات OCR، والمدخلات المليئة بالأخطاء الإملائية)، والحالات شديدة الفقر في الموارد، أو المهام المتخصصة جداً.

The drawback that really hurts is the first one. If one English word is about five characters, then character tokenization makes every sequence roughly five times longer. For an architecture whose cost grows faster than linearly in sequence length, that is not a small tax.

العيب الذي يؤلم فعلاً هو الأول. إذا كانت الكلمة الإنجليزية الواحدة خمسة حروف تقريباً، فإن character tokenization يجعل كل تسلسل أطول بخمس مرات تقريباً. وفي معمارية تنمو تكلفتها أسرع من الخطي مع طول التسلسل، هذه ضريبة ليست صغيرة.

Subword tokenization, slide 40

التقطيع إلى أجزاء فرعية (Subword)، الشريحة 40

The compromise. Keep pieces big enough to carry meaning and small enough that you can build anything out of them.

هذا هو الحل الوسط: أبقِ القطع كبيرة بما يكفي لتحمل معنى، وصغيرة بما يكفي لتبني منها أي شيء.

Why subwords help

لماذا تساعد الأجزاء الفرعية

That third bullet is the whole reason subwords won. An unseen word is no longer a dead end. It gets split into pieces the model has seen, and the model can make something of it.

النقطة الثالثة هي سبب انتصار الـ subwords بالكامل. فالكلمة المجهولة لم تبقَ طريقاً مسدوداً، بل تُقسَّم إلى قطع رآها النموذج من قبل، فيستطيع أن يصنع منها شيئاً.

Morpheme-based subwords

أجزاء فرعية مبنية على المورفيمات

The obvious idea is to cut at morpheme boundaries, since morphemes carry meaning. The slide concedes this seems natural, then says why it is not what modern systems do: morpheme segmentation is hard and ambiguous. It names the reasons: allomorphy, non-concatenative morphology, and clitics. Useful in some applications, but not the most common approach in modern language models.

الفكرة البديهية هي القطع عند حدود الـ morphemes، لأنها تحمل المعنى. وتعترف الشريحة أن هذا يبدو طبيعياً، ثم تذكر لماذا لا تفعله الأنظمة الحديثة: تقطيع الـ morphemes صعب وغامض. وتسمّي الأسباب: allomorphy، وnon-concatenative morphology، والـ clitics. مفيد في بعض التطبيقات، لكنه ليس المنهج الأشيع في النماذج اللغوية الحديثة.

Non-concatenative morphology is worth a second look if you have Arabic in your head, because it is Arabic's root-and-pattern system that the term describes. You cannot segment كتاب and كاتب into a prefix plus a stem; the root letters are interleaved with the pattern. Any segmenter built on "cut the string into contiguous pieces" is defeated before it starts.

يستحق non-concatenative morphology وقفة ثانية إن كانت العربية في ذهنك، فنظام الجذر والوزن العربي هو ما يصفه المصطلح بالضبط. لا تستطيع تقطيع كتاب أو كاتب إلى سابقة وجذع، لأن حروف الجذر متشابكة مع الوزن. وأي مقطّع مبني على فكرة قطع السلسلة إلى قطع متجاورة مهزوم قبل أن يبدأ.

Language-agnostic subwords

أجزاء فرعية مستقلة عن اللغة

So instead of encoding linguistic knowledge, modern tokenizers learn frequent subword units from data. The slide names BPE (byte-pair encoding) and related methods, and gives the reason they are popular: they work across languages and they reduce OOV while staying efficient.

فبدلاً من ترميز المعرفة اللغوية، تقوم المقطّعات الحديثة بـ تعلّم وحدات subword متكررة من البيانات. وتسمّي الشريحة BPE (byte-pair encoding) والطرق القريبة منه، وتذكر سبب شعبيتها: تعمل عبر اللغات، وتقلّل OOV مع بقاء الكفاءة.

Nobody tells BPE what a morpheme is. It finds whatever is frequent. Sometimes the result lines up with a morpheme and sometimes it does not, and the method does not care.

لا أحد يخبر BPE ما هو الـ morpheme. هو يجد ما هو متكرر فقط. وقد يتوافق الناتج مع morpheme أحياناً وقد لا يتوافق، والطريقة لا تهتم.

The three granularities, compared

المستويات الثلاثة، مقارنةً

WordالكلمةSubwordالجزء الفرعي (Subword)Characterالحرف
Typical vocabulary sizeحجم المفردات المعتادhundreds of thousands, unboundedمئات الآلاف، وغير محدود30k to 100k (slide 48)من 30k إلى 100k (الشريحة 48)tens to a few hundred, 256 for bytesمن عشرات إلى بضع مئات، و256 للـ bytes
Sequence lengthطول التسلسلshortestالأقصرmoderateمتوسطlongest, roughly 5× word length in Englishالأطول، نحو 5× طول الكلمات في الإنجليزية
Unknown wordsالكلمات المجهولةyes, <UNK> is unavoidableنعم، <UNK> لا مفر منهalmost none, unseen words get composedلا تكاد توجد، فالكلمات غير المرئية تُركَّبnoneلا توجد
Does a token carry meaning?هل يحمل الـ token معنى؟yes, directlyنعم، مباشرةoften, a piece is a stem or an affixغالباً، فالقطعة جذع أو لاصقةno, meaning is spread outلا، المعنى موزع
Across writing systemsعبر أنظمة الكتابةbreaks where there are no spacesينكسر حيث لا توجد مسافاتworks, learned from the dataيعمل، لأنه مُتعلَّم من البياناتworks everywhereيعمل في كل مكان
Embedding matrix costكلفة مصفوفة الـ embeddingenormousهائلةmanageableمعقولةtinyضئيلة
Best used forأفضل استخدامPOS tagging, parsing, lexicon-driven systemsوسم أقسام الكلام (POS tagging)، والإعراب (parsing)، والأنظمة القائمة على المعاجمmodern language modelsنماذج اللغة الحديثةOCR and typo-heavy text, very low-resource settingsالنصوص الممسوحة ضوئياً (OCR) والكثيرة الأخطاء، والبيئات شحيحة الموارد جداً

يقارن الجدول الحبيبات الثلاث (Word وSubword وCharacter) على سبعة أسطر: حجم الـ vocabulary المعتاد، وطول التسلسل، والكلمات المجهولة، وهل يحمل الـ token معنى، والعمل عبر أنظمة الكتابة، وتكلفة مصفوفة الـ embedding، وأفضل استخدام. اقرأه عموداً عموداً لا سطراً سطراً، والعمود الأوسط هو الحل العملي.

Read the table by column and the middle one is unremarkable on every row. That is the point. Subwords are not best at anything; they are never disastrous at anything either.

اقرأ الجدول عمودياً وستجد العمود الأوسط عادياً في كل سطر، وهذا هو المقصود بالضبط: الـ subwords ليست الأفضل في أي شيء، لكنها ليست كارثية في أي شيء كذلك.

the same string, three granularities word renewing 1 token, shortest sequence but unseen words become UNK subword renew ing 2 tokens, moderate vocabulary unseen words get composed character r e n e w i n g 8 tokens, tiny vocabulary no unknowns, but long and slow going down the page: vocabulary shrinks, sequence grows, meaning per token drops
Three ways to cut one string. Every row is the same text. The tradeoff is monotone: smaller units mean a smaller vocabulary and better coverage, but longer sequences and less meaning packed into each token.
ثلاث طرق لقطع سلسلة واحدة. كل صف هو النص نفسه. والمقايضة رتيبة: الوحدات الأصغر تعني مفردات أصغر وتغطية أفضل، لكنها تعني تسلسلات أطول ومعنى أقل في كل token.

يعرض الرسم كلمة renewing مقطّعة بثلاث حبيبات. سطر word: صندوق واحد، أقصر تسلسل، لكن الكلمة المجهولة تصبح UNK. سطر subword: صندوقان هما renew وing، وvocabulary متوسط، والكلمات المجهولة تُركَّب. سطر character: ثمانية صناديق، وvocabulary ضئيل بلا مجهول، لكنه طويل وبطيء. اقرأه من أعلى لأسفل: الـ vocabulary يصغر، والتسلسل يطول، والمعنى في كل token يقل.

Byte-pair encoding, slide 41

ترميز أزواج البايتات (Byte-pair encoding)، الشريحة 41

BPE is widely used in modern language models. The slide makes one structural point before anything else, and it is the point the exam tests:

BPE مستخدم على نطاق واسع في النماذج اللغوية الحديثة. وتطرح الشريحة نقطة بنيوية واحدة قبل أي شيء آخر، وهي النقطة التي يختبرها الامتحان:

the BPE algorithm has two parts: a trainer, and an encoder

ينص المربع على أن خوارزمية BPE لها جزآن: مدرّب (trainer) ومرمّز (encoder). ثبّت هذا التقسيم قبل أي تفصيل.

The trainer looks at a corpus and produces an ordered list of merges plus a vocabulary. It runs once, offline. The encoder takes that list and applies it to new text. It runs every time you feed the model anything, and it never counts, learns or changes anything.

الـ trainer ينظر إلى corpus ويُنتج قائمة مرتّبة من الـ merges مع vocabulary، ويعمل مرة واحدة وخارج الخط. والـ encoder يأخذ تلك القائمة ويطبّقها على نص جديد، ويعمل كل مرة تغذّي النموذج بأي شيء، ولا يعدّ ولا يتعلّم ولا يغيّر شيئاً أبداً.

Training, in the slide's three bullets:

التدريب، في نقاط الشريحة الثلاث:

  1. Start with a basic symbol inventory: characters, or bytes.

    ابدأ بمخزون رموز أساسي: حروف، أو bytes.

  2. Iteratively merge the most frequent adjacent symbol pair.

    ادمج تكرارياً أكثر زوج رموز متجاورين تكراراً.

  3. The merges create a vocabulary of common substrings, which are your subwords.

    الـ merges تُنشئ vocabulary من السلاسل الفرعية الشائعة، وهذه هي الـ subwords عندك.

Read bullet 2 slowly. The thing being counted is a pair of neighbours, not a single symbol. The most frequent symbol in English is e; BPE never merges e with itself for that reason. It merges whichever two-symbol sequence occurs most often side by side.

اقرأ النقطة الثانية ببطء. المعدود هو زوج من الجارَين، لا رمز واحد. أكثر رمز تكراراً في الإنجليزية هو e، ولهذا السبب لا يدمج BPE أبداً e مع نفسه. هو يدمج التسلسل المكوّن من رمزين الذي يظهر متجاوراً أكثر من غيره.

The algorithm, slide 42

الخوارزمية، الشريحة 42

Slide 42 prints the pseudocode. Transcribed:

تطبع الشريحة 42 الكود الوهمي، وهذا نسخه:

function BYTE-PAIR ENCODING(strings C, number of merges k) returns vocab V

  V <- all unique characters in C          # initial set of tokens is characters
  for i = 1 to k do                        # merge tokens k times
      tL, tR <- Most frequent pair of adjacent tokens in C
      tNEW  <- tL + tR                     # make new token by concatenating
      V     <- V + tNEW                    # update the vocabulary
      Replace each occurrence of tL, tR in C with tNEW   # and update the corpus
  return V

يُقرأ الكود الوهمي هكذا: الدخل هو السلاسل C وعدد الـ merges وهو k، والخرج vocab V. ابدأ بـ V يساوي كل الحروف الفريدة في C، ثم كرّر k مرة: جد أكثر زوج tokens متجاورين تكراراً وسمّه tL, tR، وألصقهما في رمز جديد tNEW، وأضف tNEW إلى V، واستبدل كل ظهور للزوج في C بـ tNEW. وفي النهاية أعد V.

Four facts fall straight out of the pseudocode and each one kills a common wrong answer:

أربع حقائق تسقط مباشرة من الكود الوهمي، وكل واحدة منها تقتل جواباً خاطئاً شائعاً:

1. count every adjacent pair weighted by word frequency 2. pick the most frequent pair the pair, never a single symbol 3. merge it everywhere rewrite the whole corpus 4. add the new symbol to V and append the merge to the list repeat k times k is chosen by you, not discovered by the algorithm start: every character is its own symbol · finish: vocabulary = starting symbols + k merges
Training is this loop and nothing else. Count pairs on the current corpus, merge the winner, record it, go round again. Step 3 is what makes round i+1 different from round i, because the counts are always taken on the rewritten corpus.
التدريب هو هذه الحلقة ولا شيء غيرها. عُدّ الأزواج في الـ corpus الحالي، وادمج الفائز، وسجّله، ثم أعد الدورة. الخطوة 3 هي ما يجعل الجولة i+1 مختلفة عن الجولة i، لأن العدّ يُؤخذ دائماً على الـ corpus بعد إعادة كتابته.

يرسم الشكل حلقة التدريب في أربع خطوات متتابعة: الأولى عُدّ كل زوج متجاور، موزوناً بتكرار الكلمة. والثانية اختر أكثر الأزواج تكراراً، الزوج لا رمزاً واحداً. والثالثة ادمجه في كل مكان، أي أعد كتابة الـ corpus كله. والرابعة أضف الرمز الجديد إلى V وألحق الـ merge بالقائمة. ثم ارجع إلى الخطوة الأولى وكرّر k مرة، وk تختاره أنت ولا تكتشفه الخوارزمية. البداية: كل حرف رمز بنفسه. النهاية: الـ vocabulary يساوي رموز البداية زائد k.

Memory hookخطاف للذاكرة

Count pairs, merge the winner, repeat. Six words, and that is the entire training algorithm.

عُدّ الأزواج، ادمج الفائز، كرّر. ثلاث كلمات، وهي خوارزمية التدريب كاملة.

Two words to stop the two biggest errors: pairs, not symbols. And recount every round, because you merged the corpus underneath yourself.

وكلمتان توقفان أكبر خطأين: أزواج، لا رموز. وأعد العدّ كل دورة، لأنك دمجت الـ corpus من تحتك.

For the two halves: the trainer counts, the encoder replays. If you are counting anything, you are training. If you are not counting anything, you are encoding.

وللنصفين: المدرّب يعدّ، والمرمّز يعيد التشغيل. فإن كنت تعدّ أي شيء فأنت تدرّب، وإن كنت لا تعدّ شيئاً فأنت ترمّز.

The lecture's worked example, slides 43 to 46

مثال المحاضرة المحلول، الشرائح 43 إلى 46

Four slides animating one run. The corpus is:

أربع شرائح تحرّك تنفيذاً واحداً. والـ corpus هو:

set new new renew reset renew

يطبع المربع الـ corpus الصغير: ست كلمات هي set new new renew reset renew. احفظها، فكل التنفيذ أدناه مبني عليها.

Slide 43 says to start with characters and a space or end-of-word marker, and writes the corpus as the single string set_new_new_renew_reset_renew. So the marker here is a leading space symbol, written _ below. Note the consequence: set is the first word in the corpus and therefore has no marker, while the other words carry one. That is why the slide's table shows s e t on one line and _ r e s e t on another even though they are the same word type. Keep them separate, the slide does.

تقول الشريحة 43 ابدأ بالحروف مع مسافة أو علامة نهاية كلمة، وتكتب الـ corpus كسلسلة واحدة هي set_new_new_renew_reset_renew. فالعلامة هنا رمز مسافة سابق للكلمة، ويُكتب _ أدناه. ولاحظ النتيجة: set هي أول كلمة في الـ corpus فلا تحمل علامة، بينما تحمل الكلمات الأخرى علامة. ولهذا يُظهر جدول الشريحة s e t في سطر و_ r e s e t في سطر آخر، رغم أنهما نوع الكلمة نفسه. أبقِهما منفصلين كما تفعل الشريحة.

Some textbooks instead append an end-of-word marker written </w>. Same idea, opposite side. Follow whichever convention the question gives you.

بعض الكتب تضيف علامة نهاية كلمة تُكتب </w> بدلاً من ذلك. الفكرة نفسها، لكن في الجهة المقابلة. اتبع الاتفاق الذي يعطيك إياه السؤال.

Workedمثال محلول

The complete run, slides 43 to 46, with every pair count computed. _ is the space marker and the left column is how many times that word form occurs.

التنفيذ الكامل، الشرائح 43 إلى 46، مع حساب كل عدّ لكل زوج. الرمز _ هو علامة المسافة، والعمود الأيسر هو عدد مرات ظهور صيغة الكلمة. والحلقة في كل دورة واحدة: عُدّ كل زوج رموز متجاورين، وادمج أكثر الأزواج تكراراً، وأضف الرمز المدموج إلى الـ vocabulary، وكرّر k مرة.

Round 0: the starting state (slide 43).

الدورة 0: الحالة الابتدائية (الشريحة 43).

corpus                          vocabulary
 2    _ n e w                    _, e, n, r, s, t, w
 2    _ r e n e w
 1    s e t
 1    _ r e s e t

check the frequencies against "set new new renew reset renew":
  new   appears twice   -> 2
  renew appears twice   -> 2
  set   appears once    -> 1   (no leading marker, it starts the corpus)
  reset appears once    -> 1
vocabulary size = 7 symbols

يعرض المقطع الحالة الابتدائية: أربعة سطور من الـ corpus مع تكرار كل سطر، فـ _ n e w بتكرار 2، و_ r e n e w بتكرار 2، وs e t بتكرار 1، و_ r e s e t بتكرار 1. والـ vocabulary هو الرموز السبعة _, e, n, r, s, t, w. والتكرارات مأخوذة من عدّ الكلمات في الـ corpus الأصلي، وset بلا علامة لأنها تبدأ الـ corpus.

Round 1: count the pairs. Each pair contributes the frequency of the line it sits on.

الدورة 1: عُدّ الأزواج. كل زوج يساهم بتكرار السطر الذي يقع فيه.

PairالزوجWhere it occursأين يظهرCountالعدد
n ein _ n e w (2) and in _ r e n e w (2)في _ n e w (2) وفي _ r e n e w (2)2 + 2 = 4
e win _ n e w (2) and in _ r e n e w (2)في _ n e w (2) وفي _ r e n e w (2)2 + 2 = 4
_ rin _ r e n e w (2) and in _ r e s e t (1)في _ r e n e w (2) وفي _ r e s e t (1)2 + 1 = 3
r ein _ r e n e w (2) and in _ r e s e t (1)في _ r e n e w (2) وفي _ r e s e t (1)2 + 1 = 3
_ nin _ n e w (2)2
e nin _ r e n e w (2)2
s ein s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)1 + 1 = 2
e tin s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)1 + 1 = 2
e sin _ r e s e t (1)1

يسرد الجدول كل أزواج الدورة 1 وعدّاتها: (n e) و(e w) عند 4، ثم (_ r) و(r e) عند 3، ثم (_ n) و(e n) و(s e) و(e t) عند 2، و(e s) عند 1. وطريقة القراءة: اجمع تكرار كل سطر يظهر فيه الزوج، فالعمود الأوسط يبيّن أين ظهر والعمود الأخير يبيّن الجمع.

the maximum is 4, and TWO pairs reach it: (n e) and (e w).
the slide breaks the tie in favour of (n e).

MERGE 1:  n + e  ->  ne

يقرر المقطع الفائز: الحد الأقصى 4، وزوجان يبلغانه هما (n e) و(e w)، والشريحة تفصل التعادل لصالح (n e). فالـ merge الأول هو n + e وينتج ne.

State after merge 1 (this is slide 44).

الحالة بعد الـ merge الأول (وهذه الشريحة 44).

corpus                          vocabulary
 2    _ ne w                     _, e, n, r, s, t, w, ne
 2    _ r e ne w
 1    s e t
 1    _ r e s e t
vocabulary size = 8

يعرض المقطع الـ corpus بعد الدمج: _ ne w و_ r e ne w وs e t و_ r e s e t. والـ vocabulary صار ثمانية رموز بإضافة ne، والرموز السبعة الأصلية باقية كلها.

Round 2: recount on the new corpus. ne is now a single symbol, so pairs involving it are pairs involving the whole thing.

الدورة 2: أعد العدّ على الـ corpus الجديد. صار ne رمزاً واحداً، فالأزواج التي تضمّه تضمّه كاملاً لا جزءاً منه.

PairالزوجWhere it occursأين يظهرCountالعدد
ne win _ ne w (2) and in _ r e ne w (2)في _ ne w (2) وفي _ r e ne w (2)2 + 2 = 4
_ rin _ r e ne w (2) and in _ r e s e t (1)في _ r e ne w (2) وفي _ r e s e t (1)2 + 1 = 3
r ein _ r e ne w (2) and in _ r e s e t (1)في _ r e ne w (2) وفي _ r e s e t (1)2 + 1 = 3
_ nein _ ne w (2)2
e nein _ r e ne w (2)2
s ein s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)2
e tin s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)2
e sin _ r e s e t (1)1

جدول الدورة 2: (ne w) عند 4 وهو الفائز، ثم (_ r) و(r e) عند 3، ثم (_ ne) و(e ne) و(s e) و(e t) عند 2، و(e s) عند 1. ولاحظ أن (n e) اختفى من الجدول تماماً، لأنه صار رمزاً واحداً لا زوجاً.

the maximum is 4, reached only by (ne w). no tie this time.

MERGE 2:  ne + w  ->  new

يقرر المقطع: الحد الأقصى 4 ويبلغه (ne w) وحده، فلا تعادل هذه المرة. فالـ merge الثاني هو ne + w وينتج new.

State after merge 2 (this is slide 45).

الحالة بعد الـ merge الثاني (وهذه الشريحة 45).

corpus                          vocabulary
 2    _ new                      _, e, n, r, s, t, w, ne, new
 2    _ r e new
 1    s e t
 1    _ r e s e t
vocabulary size = 9

صار الـ corpus هو _ new و_ r e new وs e t و_ r e s e t، والـ vocabulary تسعة رموز بإضافة new.

Note that the first line is now a single symbol plus its marker. The word new has become one token.

لاحظ أن السطر الأول صار رمزاً واحداً مع علامته، فكلمة new صارت token واحداً.

Round 3: recount again.

الدورة 3: أعد العدّ مرة أخرى.

PairالزوجWhere it occursأين يظهرCountالعدد
_ rin _ r e new (2) and in _ r e s e t (1)في _ r e new (2) وفي _ r e s e t (1)2 + 1 = 3
r ein _ r e new (2) and in _ r e s e t (1)في _ r e new (2) وفي _ r e s e t (1)2 + 1 = 3
_ newin _ new (2)في _ new (2)2
e newin _ r e new (2)في _ r e new (2)2
s ein s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)2
e tin s e t (1) and in _ r e s e t (1)في s e t (1) وفي _ r e s e t (1)2
e sin _ r e s e t (1)1

جدول الدورة 3: (_ r) و(r e) عند 3، ثم (_ new) و(e new) و(s e) و(e t) عند 2، و(e s) عند 1. واختفى (ne w) لأنه صار رمزاً واحداً، ونزل الحد الأقصى من 4 إلى 3.

the maximum is 3, and again TWO pairs reach it: (_ r) and (r e).
the slide breaks the tie in favour of (_ r), the leftmost one again.

MERGE 3:  _ + r  ->  _r

يقرر المقطع: الحد الأقصى 3، وزوجان يبلغانه هما (_ r) و(r e)، والشريحة تفصل التعادل لصالح (_ r)، وهو الأيسر مرة أخرى. فالـ merge الثالث هو _ + r وينتج _r.

State after merge 3 (intermediate, not drawn separately on a slide).

الحالة بعد الـ merge الثالث (حالة وسطية، لا تُرسم في شريحة مستقلة).

corpus                          vocabulary
 2    _ new                      _, e, n, r, s, t, w, ne, new, _r
 2    _r e new
 1    s e t
 1    _r e s e t
vocabulary size = 10

صار الـ corpus هو _ new و_r e new وs e t و_r e s e t، والـ vocabulary عشرة رموز بإضافة _r.

Round 4: recount one more time.

الدورة 4: أعد العدّ مرة أخيرة.

PairالزوجWhere it occursأين يظهرCountالعدد
_r ein _r e new (2) and in _r e s e t (1)في _r e new (2) وفي _r e s e t (1)2 + 1 = 3
_ newin _ new (2)في _ new (2)2
e newin _r e new (2)في _r e new (2)2
s ein s e t (1) and in _r e s e t (1)في s e t (1) وفي _r e s e t (1)2
e tin s e t (1) and in _r e s e t (1)في s e t (1) وفي _r e s e t (1)2
e sin _r e s e t (1)1

جدول الدورة 4: (_r e) عند 3 وهو الفائز، ثم (_ new) و(e new) و(s e) و(e t) عند 2، و(e s) عند 1. ولاحظ أن (r e) صار (_r e)، لأن r اندمج مع العلامة التي قبله.

the maximum is 3, reached only by (_r e). no tie.

MERGE 4:  _r + e  ->  _re

يقرر المقطع: الحد الأقصى 3 ويبلغه (_r e) وحده، فلا تعادل. فالـ merge الرابع هو _r + e وينتج _re.

Final state after merge 4 (this is slide 46).

الحالة النهائية بعد الـ merge الرابع (وهذه الشريحة 46).

corpus                          vocabulary
 2    _ new                      _, e, n, r, s, t, w, ne, new, _r, _re
 2    _re new
 1    s e t
 1    _re s e t
vocabulary size = 11   =   7 starting symbols + 4 merges

الحالة النهائية: الـ corpus هو _ new و_re new وs e t و_re s e t، والـ vocabulary أحد عشر رمزاً، أي 7 رموز ابتدائية زائد 4 من الـ merges. وهذه هي معادلة الحجم التي يُسأل عنها.

Slide 46 shows this exact state, which means the deck performs merges 3 and 4 on the same slide. The vocabulary it prints is _, e, n, r, s, t, w, ne, new, _r, _re, so both _r and _re are there and the intermediate state above is what sits between them.

تُظهر الشريحة 46 هذه الحالة بالضبط، ومعنى ذلك أن العرض ينفّذ الـ merge الثالث والرابع في شريحة واحدة. والـ vocabulary الذي تطبعه هو _, e, n, r, s, t, w, ne, new, _r, _re، فكلا _r و_re موجودان، والحالة الوسطية أعلاه هي ما يقع بينهما.

One thing to notice about the result: BPE learned the token _re, which is the English prefix re-. Nobody told it that. It fell out of counting adjacent pairs. That is the whole promise of a language-agnostic subword learner, demonstrated on six words.

شيء يستحق الملاحظة في النتيجة: تعلّم BPE الـ token المسمّى _re، وهو السابقة الإنجليزية re-. لم يخبره أحد بذلك، بل سقط من عدّ الأزواج المتجاورة. وهذا هو وعد متعلّم الـ subword المستقل عن اللغة، مُبرهناً على ست كلمات.

The merge list, in order

قائمة الدمج، بالترتيب

This ordered list is the actual output of training. The vocabulary is derivable from it; the order is not recoverable from the vocabulary, which is why the list is what gets saved.

هذه القائمة المرتّبة هي الناتج الفعلي للتدريب. الـ vocabulary يمكن استنتاجه منها، لكن الترتيب لا يمكن استرجاعه من الـ vocabulary، ولهذا القائمة هي ما يُحفَظ.

StepالخطوةPair mergedالزوج المدموجNew symbolالرمز الجديدCount that wonالعدد الفائزWas there a tie?هل كان هناك تعادل؟
1n + ene4yes, tied with (e w) at 4نعم، تعادل مع (e w) عند 4
2ne + wnew4noلا
3_ + r_r3yes, tied with (r e) at 3نعم، تعادل مع (r e) عند 3
4_r + e_re3no

يسرد الجدول الـ merges الأربعة بترتيبها: الأول n + e ينتج ne بعدّ 4 مع تعادل، والثاني ne + w ينتج new بعدّ 4 بلا تعادل، والثالث _ + r ينتج _r بعدّ 3 مع تعادل، والرابع _r + e ينتج _re بعدّ 3 بلا تعادل. هذا الترتيب هو ما تحفظه وتعيد تشغيله عند الـ encoding.

Both ties go to the pair that appears earlier when you scan the corpus left to right. Real implementations fix a deterministic tie-break rule so that training is reproducible, and the lecture's choice is consistent with reading left to right. If an exam corpus gives you a tie, state your rule and apply it consistently; the examiner is looking for the procedure, not a secret convention.

التعادلان كلاهما يذهب إلى الزوج الذي يظهر أولاً عند مسح الـ corpus من اليسار إلى اليمين. والتطبيقات الحقيقية تثبّت قاعدة حتمية لفصل التعادل حتى يكون التدريب قابلاً للتكرار، واختيار المحاضرة متوافق مع القراءة من اليسار إلى اليمين. فإذا أعطاك الامتحان corpus فيه تعادل، فاذكر قاعدتك وطبّقها باتساق، لأن المصحح يبحث عن الإجراء لا عن اتفاق سري.

The vocabulary growing, merge by merge

المفردات تنمو، دمجاً بعد دمج

Starting symbols stay in the vocabulary forever. Each round adds exactly one entry.

رموز البداية تبقى في الـ vocabulary إلى الأبد، وكل دورة تضيف مدخلاً واحداً بالضبط.

Start, 7 symbols

البداية، 7 رموز

_enrstw

After merge 1, 8 symbols

بعد الـ merge الأول، 8 رموز

_enrstwne

After merge 2, 9 symbols

بعد الـ merge الثاني، 9 رموز

_enrstwnenew

After merge 3, 10 symbols

بعد الـ merge الثالث، 10 رموز

_enrstwnenew_r

After merge 4, 11 symbols. This is slide 46.

بعد الـ merge الرابع، 11 رمزاً. وهذه هي الشريحة 46.

_enrstwnenew_r_re

BPE encoding, slide 47

الترميز بـ BPE (encoding)، الشريحة 47

Different operation. You now have a merge list and you are handed a new string. The slide's recipe:

عملية مختلفة. عندك الآن قائمة merges وأُعطيت سلسلة جديدة. ووصفة الشريحة:

  1. Start with characters or bytes.

    ابدأ بالحروف أو الـ bytes.

  2. Apply the learned merges in order, greedily.

    طبّق الـ merges المتعلَّمة بالترتيب، وبطمع.

  3. Output the resulting subword sequence. Most words end up as a single token.

    أخرج تسلسل الـ subwords الناتج. وأكثر الكلمات تنتهي إلى token واحد.

And the reason this matters: it ensures deterministic encoding under a fixed merge list. The same string always produces the same tokens, on every machine, forever.

وسبب أهمية هذا: إنه يضمن deterministic encoding تحت قائمة merges ثابتة. فالسلسلة نفسها تُنتج الـ tokens نفسها، على كل جهاز، إلى الأبد.

Nothing here counts anything. There is no corpus, no frequency, no learning. You walk down the merge list once, from merge 1 to merge k, and at each step you replace every occurrence of that pair.

لا شيء هنا يعدّ شيئاً. لا corpus، ولا تكرار، ولا تعلّم. أنت تمشي في قائمة الـ merges مرة واحدة، من الـ merge الأول إلى الـ merge رقم k، وفي كل خطوة تستبدل كل ظهور لذلك الزوج.

Workedمثال محلول

Encoding with the merge list learned above: 1. n+e→ne   2. ne+w→new   3. _+r→_r   4. _r+e→_re

الترميز باستخدام قائمة الـ merges المتعلَّمة أعلاه، بترتيبها: n+e ثم ne+w ثم _+r ثم _r+e.

EXAMPLE A   encode " renew"   (a word that was in the training corpus)

  start as characters      _ r e n e w
  merge 1  n+e -> ne       _ r e ne w
  merge 2  ne+w -> new     _ r e new
  merge 3  _+r -> _r       _r e new
  merge 4  _r+e -> _re     _re new

  OUTPUT:  _re  new        2 tokens

  this matches line 2 of the slide 46 corpus. it should: encoding a
  training word reproduces the state training left it in.

المثال A يرمّز " renew"، وهي كلمة كانت في corpus التدريب. ابدأ حروفاً _ r e n e w، فالـ merge الأول يعطي _ r e ne w، والثاني يعطي _ r e new، والثالث يعطي _r e new، والرابع يعطي _re new. فالناتج _re new أي 2 tokens، وهو مطابق للسطر الثاني من corpus الشريحة 46، لأن ترميز كلمة تدريبية يعيد إنتاج الحالة التي تركها التدريب.

EXAMPLE B   encode " reset"

  start as characters      _ r e s e t
  merge 1  n+e -> ne       no "n e" anywhere.  no change.
  merge 2  ne+w -> new     no "ne" symbol.     no change.
  merge 3  _+r -> _r       _r e s e t
  merge 4  _r+e -> _re     _re s e t

  OUTPUT:  _re  s  e  t    4 tokens

  note merges 1 and 2 did nothing. you still had to check them,
  and you still had to check them FIRST.

المثال B يرمّز " reset". ابدأ _ r e s e t. الـ merge الأول لا يجد n e فلا تغيير، والثاني لا يجد رمز ne فلا تغيير، والثالث يعطي _r e s e t، والرابع يعطي _re s e t. فالناتج _re s e t أي 4 tokens. والدرس: الـ merge الأول والثاني لم يفعلا شيئاً، لكن كان عليك فحصهما، وفحصهما أولاً.

EXAMPLE C   encode " newer"   (never seen in training)

  start as characters      _ n e w e r
  merge 1  n+e -> ne       _ ne w e r
  merge 2  ne+w -> new     _ new e r
  merge 3  _+r -> _r       is there "_ r"? no, "_" is followed by "new".
                           no change.
  merge 4  _r+e -> _re     no "_r" symbol.  no change.

  OUTPUT:  _  new  e  r    4 tokens

  an unseen word still encodes, with no UNK. the known piece "new"
  survives as one token and the leftovers fall back to characters.
  this is the "compose unseen words from subpieces" promise, working.

المثال C يرمّز " newer"، وهي كلمة لم تُرَ في التدريب. ابدأ _ n e w e r، فالـ merge الأول يعطي _ ne w e r، والثاني يعطي _ new e r، والثالث يبحث عن _ r فلا يجده لأن العلامة يتبعها new، والرابع لا يجد رمز _r أصلاً. فالناتج _ new e r أي 4 tokens. الكلمة المجهولة رُمّزت بلا UNK إطلاقاً: القطعة المعروفة new بقيت token واحداً، والبقية رجعت حروفاً. هذا هو وعد تركيب الكلمات المجهولة من قطع فرعية، وهو يعمل.

WHY THE ORDER MATTERS

  merge 4 (_r + e) can only fire if merge 3 already created "_r".
  run them in the other order and merge 4 finds nothing, merge 3
  then produces "_r", and you finish with "_r e new" instead of
  "_re new". different tokens, different embeddings, different model
  input. the list is ordered, and you replay it front to back.

يبيّن المقطع لماذا الترتيب مهم: الـ merge الرابع (_r + e) لا يمكن أن يعمل إلا إذا كان الثالث قد أنشأ _r أولاً. فإذا شغّلتهما بالعكس، لم يجد الرابع شيئاً، ثم أنتج الثالث _r، فتنتهي بـ _r e new بدلاً من _re new. tokens مختلفة، وembeddings مختلفة، ومدخل نموذج مختلف. القائمة مرتّبة، وتعيد تشغيلها من أولها إلى آخرها.

Training versus encoding

التدريب مقابل الترميز

BPE trainingتدريب BPEBPE encodingترميز BPE
Inputالإدخالa corpus, plus a chosen kcorpus، مع k مختارone new string, plus the merge listسلسلة جديدة واحدة، مع قائمة الدمج
Outputالمخرَجan ordered merge list and a vocabularyقائمة دمج مرتبة ومفرداتa sequence of tokensتسلسل من الـ tokens
Does it count pair frequencies?هل يعدّ تكرارات الأزواج؟yes, that is the core of itنعم، فهذا جوهرهno, neverلا، أبداً
Does it learn anything?هل يتعلم شيئاً؟yesنعمno, it replaysلا، إنه يعيد التشغيل
How are merges chosen?كيف تُختار عمليات الدمج؟by frequency, recounted each roundبالتكرار، ويُعاد العدّ في كل جولةnot chosen, they are applied in the stored orderلا تُختار، بل تُطبّق بالترتيب المخزّن
How often does it run?كم مرة يعمل؟once, offlineمرة واحدة، دون اتصال (offline)on every input, foreverعلى كل إدخال، دائماً
Is the result deterministic?هل النتيجة حتمية؟yes, given a fixed tie-break ruleنعم، بشرط قاعدة ثابتة لكسر التعادلyes, that is the stated goal on slide 47نعم، وهذا هو الهدف المعلن في الشريحة 47

يقابل الجدول بين BPE training وBPE encoding في سبعة أسطر: الدخل، والخرج، وهل يعدّ تكرار الأزواج (نعم، وهو جوهره، مقابل لا أبداً)، وهل يتعلّم شيئاً (نعم مقابل لا، هو يعيد التشغيل)، وكيف تُختار الـ merges (بالتكرار مع إعادة عدّ كل دورة، مقابل بالترتيب المحفوظ)، وكم مرة يعمل (مرة واحدة خارج الخط، مقابل كل مدخل إلى الأبد)، وهل الناتج حتمي. اقرأ العمودين متقابلين، فهذا هو السؤال المتوقع.

Trapفخ

Counting pairs during encoding. Encoding has no frequencies. If a question gives you a merge list and a string and you start tallying, you have answered a training question that was not asked.

عدّ الأزواج أثناء الـ encoding. الـ encoding لا تكرارات فيه. فإذا أعطاك السؤال قائمة merges وسلسلة وبدأت تعدّ، فقد أجبت سؤال تدريب لم يُسأل.

Merging the most frequent symbol. BPE merges the most frequent adjacent pair. In round 1 above, e occurs 9 times across the corpus (1 in set, 1 in each of the two news, 2 in each of the two renews, 2 in reset) and is never merged with itself. The winner was n e at 4.

دمج أكثر رمز تكراراً. BPE يدمج أكثر زوج متجاور تكراراً. في الدورة 1 أعلاه يظهر e تسع مرات في الـ corpus ولا يُدمج مع نفسه أبداً، والفائز كان n e عند 4.

Recounting on the original corpus. After a merge the corpus is rewritten, and round 2 counts pairs on the rewritten version. In round 2, n e no longer exists as a pair at all; it is one symbol ne.

إعادة العدّ على الـ corpus الأصلي. بعد كل merge يُعاد كتابة الـ corpus، والدورة 2 تعدّ الأزواج على النسخة المُعاد كتابتها. وفي الدورة 2 لم يبق n e زوجاً أصلاً، بل صار رمزاً واحداً هو ne.

Applying merges in frequency order at encoding time. They go in learned order, which is the order they were discovered. Merge 4 above literally cannot fire before merge 3.

تطبيق الـ merges بترتيب التكرار وقت الـ encoding. هي تُطبّق بالترتيب المتعلَّم، أي ترتيب اكتشافها. والـ merge الرابع أعلاه لا يمكنه حرفياً أن يعمل قبل الثالث.

Forgetting that characters stay in the vocabulary. The pseudocode only ever adds. n, e and w are all still in the final vocabulary alongside new.

نسيان أن الحروف تبقى في الـ vocabulary. الكود الوهمي يضيف فقط. فالرموز n وe وw كلها ما زالت في الـ vocabulary النهائي إلى جانب new.

Counting the final vocabulary wrong. It is starting symbols plus k, one per merge. Seven plus four is eleven here, and slide 46 prints eleven.

حساب الـ vocabulary النهائي خطأ. هو رموز البداية زائد k، واحد لكل merge. سبعة زائد أربعة يساوي أحد عشر هنا، والشريحة 46 تطبع أحد عشر.

BPE in practice, slide 48

BPE عملياً، الشريحة 48

The pre-tokenizer matters more than it sounds. Without it, BPE could merge straight across a space in round one and learn tokens that span words. The pre-tokenizer puts up walls that merges may not cross. Hold that thought, because slide 51 is about deliberately taking the walls down.

الـ pre-tokenizer أهم مما يبدو. فبدونه قد يدمج BPE عبر المسافة في الدورة الأولى ويتعلّم tokens تمتد عبر كلمتين. والـ pre-tokenizer يبني أسواراً لا يجوز للـ merges أن تعبرها. أمسك هذه الفكرة، فالشريحة 51 عن إسقاط الأسوار بشكل مقصود.

BPE versus WordPiece versus unigram

BPE مقابل WordPiece مقابل unigram

The slide names the three without defining them. The distinction worth carrying into the exam is what decides the next step, and which direction the algorithm moves.

تسمّي الشريحة الثلاثة دون تعريفها. والتمييز الذي يستحق أن تحمله إلى الامتحان هو ما الذي يقرر الخطوة التالية، وفي أي اتجاه تتحرك الخوارزمية.

BPEBPEWordPieceWordPieceUnigramUnigram
Directionالاتجاهbottom up, starts from characters and mergesمن الأسفل إلى الأعلى، يبدأ من الحروف ويدمجbottom up, starts from characters and mergesمن الأسفل إلى الأعلى، يبدأ من الحروف ويدمجtop down, starts from a large candidate vocabulary and prunesمن الأعلى إلى الأسفل، يبدأ من مفردات مرشحة كبيرة ويقلّم
Selection criterionمعيار الاختيارraw frequency of the adjacent pairالتكرار الخام للزوج المتجاورa likelihood score, roughly how much merging improves the model rather than raw countدرجة احتمالية (likelihood)، أي تقريباً كم يحسّن الدمج النموذج بدلاً من العدد الخامremove the pieces whose removal costs the least likelihoodإزالة القطع التي تكلّف إزالتها أقل قدر من الاحتمالية
What it producesماذا ينتجan ordered merge listقائمة دمج مرتبةan ordered merge listقائمة دمج مرتبةa vocabulary with a probability per piece, no merge orderمفردات مع احتمال لكل قطعة، بلا ترتيب دمج
Segmentation of a new stringتقطيع سلسلة جديدةreplay the merges in orderإعادة تشغيل عمليات الدمج بالترتيبreplay the merges in orderإعادة تشغيل عمليات الدمج بالترتيبchoose the highest-probability segmentation, so several segmentations are possibleاختيار التقطيع الأعلى احتمالاً، فعدة تقطيعات ممكنة
Associated withمرتبط بـGPT familyعائلة GPTBERT familyعائلة BERTSentencePiece, T5SentencePiece وT5

يقابل الجدول بين BPE وWordPiece وUnigram في خمسة أسطر: الاتجاه، فـ BPE وWordPiece من الأسفل للأعلى بالدمج، وUnigram من الأعلى للأسفل بالتقليم. ومعيار الاختيار: التكرار الخام، مقابل درجة احتمالية، مقابل أقل خسارة احتمالية عند الحذف. والناتج: قائمة merges مرتّبة، مقابل vocabulary باحتمال لكل قطعة وبلا ترتيب. ثم كيف تُقطَّع سلسلة جديدة، وأخيراً العائلة المرتبطة بكل واحد: GPT، وBERT، وSentencePiece مع T5.

The one-line separation: BPE picks by count, WordPiece picks by likelihood gain, unigram deletes instead of merging.

الفصل في سطر واحد: BPE يختار بالعدّ، وWordPiece يختار بمقدار الربح الاحتمالي، وunigram يحذف بدلاً من أن يدمج.

Byte-level BPE, slide 49

BPE على مستوى البايت، الشريحة 49

Same algorithm, different starting inventory. Run the merges over UTF-8 bytes instead of Unicode characters.

الخوارزمية نفسها، لكن بمخزون بداية مختلف: شغّل الـ merges على UTF-8 bytes بدلاً من Unicode characters.

Character-level BPEBPE على مستوى الحروفByte-level BPEBPE على مستوى البايت
Base inventoryالمخزون الأساسيevery distinct character in the training corpusكل حرف مميز في corpus التدريبall 256 byte values, fixed in advanceقيم البايت الـ 256 كلها، محددة مسبقاً
Size of base inventoryحجم المخزون الأساسيunbounded, depends on the corpusغير محدود، ويعتمد على الـ corpusexactly 256256 بالضبط
A character the corpus never containedحرف لم يحوه الـ corpus قطout of vocabulary, becomes <UNK>خارج المفردات، يصبح <UNK>impossible, its bytes are already in the inventoryمستحيل، فبايتاته موجودة أصلاً في المخزون
New scripts, emoji, mojibake, typosخطوط كتابة جديدة، وإيموجي، ونص مشوّه الترميز (mojibake)، وأخطاء مطبعيةmay failقد يفشلalways representableقابل للتمثيل دائماً
Are the tokens readable?هل الـ tokens مقروءة؟yes, a token is a substringنعم، الـ token سلسلة جزئيةoften not, a token can be a fragment of a multi-byte characterغالباً لا، فقد يكون الـ token جزءاً من حرف متعدد البايتات

يقابل الجدول بين character-level BPE وbyte-level BPE: مخزون البداية، وهو كل حرف مميز في الـ corpus مقابل قيم الـ bytes الـ 256 كلها مثبتة مسبقاً. وحجم المخزون، غير محدود مقابل 256 بالضبط. وحرف لم يرد في الـ corpus، يصبح <UNK> مقابل مستحيل أن يحدث. ثم الخطوط الجديدة والرموز التعبيرية والنصوص المشوّشة. وأخيراً هل الـ tokens قابلة للقراءة، نعم مقابل غالباً لا.

The slide's pros are: no OOV characters, works for any script, robust to noisy text. Its single con is: tokens may be less interpretable.

مزايا الشريحة هي: لا OOV في الحروف، ويعمل مع أي نظام كتابة، ومقاوم للنص المشوّش. وعيبه الوحيد: الـ tokens قد تكون أقل قابلية للتفسير.

That con is concrete. From the previous page, the Arabic letter م is the two bytes D9 85. A byte-level tokenizer starts by treating D9 and 85 as two unrelated symbols, and only learns that they belong together because they co-occur constantly. Until that merge is learned, half a letter is a token. Nothing about that is human-readable, and it is the price of never failing on an input.

هذا العيب ملموس. من الصفحة السابقة، الحرف العربي م يساوي الـ bytes D9 85. والمقطّع على مستوى الـ bytes يبدأ بمعاملة D9 و85 كرمزين لا علاقة بينهما، ولا يتعلّم أنهما ينتميان لبعضهما إلا لأنهما يتجاوران باستمرار. وقبل تعلّم ذلك الـ merge، يكون نصف حرف هو token كامل. لا شيء من هذا مقروء للبشر، وهو ثمن ألّا تفشل أبداً على أي مدخل.

Memory hookخطاف للذاكرة

Byte-level BPE is about coverage, not speed. There are only 256 bytes, so the base vocabulary is complete before training starts, so an unknown character is not a thing that can exist. Say "no OOV" when you see "byte-level" and you will be right every time.

byte-level BPE يتعلّق بالتغطية، لا بالسرعة. هناك 256 قيمة byte فقط، فمخزون البداية مكتمل قبل أن يبدأ التدريب، فالحرف المجهول شيء لا يمكن أن يوجد أصلاً. قل "لا OOV" كلما رأيت "byte-level" وستكون محقاً كل مرة.

And the matching cost: complete coverage, unreadable tokens. One benefit, one price.

والثمن المقابل: تغطية كاملة، وtokens غير مقروءة. فائدة واحدة، وثمن واحد.

Multilingual tokenization, slide 50

التقطيع متعدد اللغات، الشريحة 50

Three statements, and they build on each other:

ثلاث عبارات، وكل واحدة تُبنى على التي قبلها:

The mechanism is just BPE's rule turned on a multilingual corpus. Merges are awarded by frequency. If 90 percent of your training text is English, then English character pairs win nearly every round, and nearly every learned subword is an English subword. A fixed vocabulary budget of, say, 50k entries gets spent mostly on one language.

الآلية هي قاعدة BPE نفسها مطبّقة على corpus متعدد اللغات. فالـ merges تُمنح بالتكرار. وإذا كان 90 بالمئة من نص تدريبك إنجليزياً، فأزواج الحروف الإنجليزية تفوز بكل دورة تقريباً، وتصبح كل subword متعلَّمة تقريباً إنجليزية. وميزانية vocabulary ثابتة قدرها 50k مدخل مثلاً تُصرف في معظمها على لغة واحدة.

The languages that lost the auction then have to be spelled out in small pieces, because the big pieces that would have covered them were never learned. Their sequences get longer for the same content.

واللغات التي خسرت المزاد تُهجَّأ بقطع صغيرة، لأن القطع الكبيرة التي كانت ستغطيها لم تُتعلَّم أبداً. فتطول تسلسلاتها للمحتوى نفسه.

That is not just an aesthetic complaint. Longer sequences mean:

وهذه ليست شكوى جمالية فقط. فالتسلسلات الأطول تعني:

  1. More compute and more latency for the same sentence.

    حساباً أكثر وزمن استجابة أطول للجملة نفسها.

  2. More money, since API pricing is per token.

    مالاً أكثر، لأن تسعير الـ API يكون بالـ token.

  3. Less content fits in a fixed context window.

    محتوى أقل يسع في نافذة سياق ثابتة.

  4. Harder learning, because the meaning is spread over more positions, which is the same drawback character tokenization had on slide 39.

    تعلّماً أصعب، لأن المعنى موزّع على مواضع أكثر، وهو العيب نفسه الذي كان لـ character tokenization في الشريحة 39.

Which is why the slide's third bullet says fairness, not just efficiency. Speakers of under-represented languages get a worse, slower, more expensive model from the identical system.

ولهذا تقول النقطة الثالثة في الشريحة fairness، أي العدالة، لا الكفاءة فقط. فالناطقون باللغات قليلة التمثيل يحصلون على نموذج أسوأ وأبطأ وأغلى من النظام نفسه بعينه.

The slide does not print token counts, so do not quote any in an exam as if it did. But the underlying asymmetry is visible at the byte level, which is a thing you can compute yourself:

لا تطبع الشريحة أعداد tokens، فلا تنقل أي رقم في الامتحان كأنها طبعته. لكن اللاتماثل الكامن مرئي على مستوى الـ bytes، وهو شيء تستطيع حسابه بنفسك:

"Natural Language Processing"      27 characters, 27 UTF-8 bytes
                                   every character is ASCII, 1 byte each

"معالجة اللغات الطبيعية"           22 characters, 42 UTF-8 bytes
                                   every Arabic letter sits in the
                                   U+0080 to U+07FF range, so 2 bytes each

fewer characters, but more than half again as many bytes.

يقارن المقطع عبارتين. الإنجليزية "Natural Language Processing" فيها 27 حرفاً و27 من الـ bytes، لأن كل حرف ASCII بـ byte واحد. والعربية "معالجة اللغات الطبيعية" فيها 22 حرفاً لكن 42 من الـ bytes، لأن كل حرف عربي يقع في المدى U+0080 إلى U+07FF، أي 2 bytes لكل حرف. الخلاصة: حروف أقل، لكن bytes أكثر بأكثر من النصف.

So before a single merge is learned, a byte-level tokenizer already starts العربية at roughly double the symbol count per letter. Merges can claw that back, but only if the training corpus contained enough Arabic to make Arabic pairs win rounds. That is the whole argument on slide 50, in one sentence.

إذن قبل أن يُتعلَّم merge واحد، يبدأ المقطّع على مستوى الـ bytes بالعربية عند ضعف عدد الرموز لكل حرف تقريباً. والـ merges يمكنها استعادة بعض ذلك، لكن فقط إذا احتوى corpus التدريب عربية كافية لتفوز الأزواج العربية بدورات. وهذه هي حجة الشريحة 50 كاملة، في جملة واحدة.

SuperBPE, slide 51

SuperBPE، الشريحة 51

Remember the pre-tokenizer from slide 48 that stops merges crossing a space. SuperBPE's idea is to let some tokenizers merge across spaces in later stages.

تذكّر الـ pre-tokenizer من الشريحة 48 الذي يمنع الـ merges من عبور المسافة. وفكرة SuperBPE هي السماح لبعض المقطّعات بـ الدمج عبر المسافات في المراحل المتأخرة.

"Later stages" is doing work in that first bullet. You train normally first, so the ordinary within-word subwords get learned, and only then do you lift the space restriction for a second stage. The big multiword tokens get built on top of a normal vocabulary rather than instead of one.

عبارة "later stages" تحمل ثقلاً في النقطة الأولى. أنت تدرّب بشكل عادي أولاً، فتُتعلَّم الـ subwords العادية داخل الكلمات، وبعد ذلك فقط ترفع قيد المسافة لمرحلة ثانية. فتُبنى الـ tokens الكبيرة متعددة الكلمات فوق vocabulary عادي، لا بدلاً منه.

The slide's figure tokenizes one sentence both ways. Counted off the figure:

يقطّع شكل الشريحة جملة واحدة بالطريقتين، وهذا العدّ مأخوذ من الشكل:

Tokenizerالمُقطِّع (Tokenizer)Segmentation of "By the way, I am a fan of the Milky Way."تقطيع "By the way, I am a fan of the Milky Way."Tokensعدد الـ Tokens
BPEBy | the | way | , | I | am | a | fan | of | the | Milky | Way | .13
SuperBPEBy the way | , | I am | a | fan | of the | Milky Way | .8

يقابل الجدول تقطيع الجملة "By the way, I am a fan of the Milky Way." بالطريقتين: BPE يعطي 13 token، كل كلمة وكل علامة ترقيم على حدة. وSuperBPE يعطي 8 فقط، لأنه يجمع By the way وI am وof the وMilky Way كل واحدة منها في token واحد.

Thirteen tokens down to eight on one sentence, with the merged units being exactly the phrases that always travel together: By the way, of the, Milky Way.

من ثلاثة عشر token إلى ثمانية في جملة واحدة، والوحدات المدموجة هي بالضبط العبارات التي تسافر معاً دائماً: By the way، وof the، وMilky Way.

Now the tradeoff. If Milky Way is a single atomic token, the model's representation of it is no longer built out of Milky and Way. For this phrase that is arguably correct, since the galaxy has little to do with milk. But the same mechanism applies to phrases where the parts do matter, and there the model loses the ability to compose. That is what "may reduce compositionality" means: you traded the ability to build meaning from parts for fewer positions to process.

الآن المقابل. إذا كان Milky Way token واحداً ذرياً، فتمثيل النموذج له لم يُبنَ من Milky وWay. ولهذه العبارة قد يكون ذلك صحيحاً، فالمجرة لا علاقة لها باللبن. لكن الآلية نفسها تنطبق على عبارات تهم أجزاؤها فعلاً، وهناك يفقد النموذج القدرة على التركيب. وهذا معنى "may reduce compositionality": بدّلت القدرة على بناء المعنى من أجزائه بمواضع أقل للمعالجة.

Design checklist, slide 52

قائمة قرارات التصميم، الشريحة 52

The closing slide is a list of decisions you have to make when you build a tokenizer. Each one is a plausible short-answer prompt.

الشريحة الختامية قائمة بالقرارات التي يجب اتخاذها عند بناء مقطّع، وكل قرار منها سؤال قصير محتمل.

DecisionالقرارThe question the slide asksالسؤال الذي تطرحه الشريحةWhat it affectsما يؤثر فيه
Pre-tokenizationالتقطيع المسبق (Pre-tokenization)split on whitespace? keep spaces as tokens?هل نقسم على المسافات؟ هل نُبقي المسافات tokens؟whether merges can cross word boundaries, which is exactly what SuperBPE changesهل يمكن لعمليات الدمج أن تعبر حدود الكلمات، وهذا بالضبط ما يغيّره SuperBPE
Normalizationالتطبيع (Normalization)Unicode normalization, lowercasing, stripping accents?تطبيع Unicode، والتحويل إلى أحرف صغيرة، وحذف علامات التشكيل؟whether visually identical strings become the same token, slide 33's problemهل تصبح السلاسل المتطابقة بصرياً الـ token نفسه، وهي مشكلة الشريحة 33
Special tokensالـ tokens الخاصة<BOS>, <EOS>, <UNK>, <PAD>sequence boundaries, batching, and the fallback for anything unrepresentableحدود التسلسل، والتجميع في دفعات (batching)، والبديل الاحتياطي لأي شيء لا يمكن تمثيله
Numbers, URLs, emojisالأعداد والروابط والإيموجيhow are they handled?كيف تُعالج؟these fragment badly under a naive tokenizer; digit handling is why some models are bad at arithmeticهذه تتفتت بشدة تحت مُقطِّع ساذج؛ ومعالجة الأرقام هي سبب ضعف بعض النماذج في الحساب
Multilingual coverage and biasالتغطية متعددة اللغات والتحيزwhich languages, in what proportion?أي اللغات، وبأي نسبة؟who gets short sequences and who gets over-segmented, slide 50من يحصل على تسلسلات قصيرة ومن يُقطَّع أكثر من اللازم، الشريحة 50

يسرد الجدول خمسة قرارات من الشريحة 52 وما يؤثر عليه كل منها: Pre-tokenization، أي هل تقسّم على المسافات وهل تبقي المسافات tokens، ويحدد هل تعبر الـ merges حدود الكلمات. وNormalization، ويحدد هل تصبح السلاسل المتطابقة بصرياً token واحداً. وSpecial tokens، ويحدد حدود التسلسل والتجميع والبديل. والأرقام والـ URLs والرموز التعبيرية، وهي تتفتت بشكل سيئ. والتغطية متعددة اللغات والتحيّز.

The four special tokens are worth being able to name cold: beginning of sequence, end of sequence, unknown, padding. Note that a byte-level tokenizer still carries <UNK> as a slot, it just never has cause to emit it.

الـ tokens الخاصة الأربعة تستحق أن تسمّيها من الذاكرة: بداية التسلسل، ونهاية التسلسل، والمجهول، والحشو. ولاحظ أن المقطّع على مستوى الـ bytes ما زال يحمل <UNK> كخانة، لكنه لا يجد أبداً سبباً لإخراجه.

Trapفخ

"A bigger vocabulary is strictly better." It is a tradeoff with three sides. A bigger vocabulary shortens sequences, which is good. It also grows the embedding matrix and the output softmax linearly, which costs memory and compute. And it pushes rare words toward being stored as single memorized tokens instead of being composed from pieces, which is worse generalization, not better. That is why slide 48 calls vocabulary size a design choice rather than something to maximize.

"A bigger vocabulary is strictly better." هذه مفاضلة بثلاثة أوجه. الـ vocabulary الأكبر يقصّر التسلسلات، وهذا جيد. وهو يكبّر مصفوفة الـ embedding وsoftmax الخرج خطياً، وهذا يكلّف ذاكرة وحساباً. وهو يدفع الكلمات النادرة لأن تُحفظ tokens مفردة بدل أن تُركَّب من قطع، وهذا تعميم أسوأ لا أفضل. ولهذا تسمي الشريحة 48 حجم الـ vocabulary قراراً تصميمياً لا شيئاً يُعظَّم.

"Tokenizer choice is language-neutral." Slide 50 says the opposite in three bullets. The same sentence costs far more tokens in some languages than others, and that is a consequence of whose text dominated the training corpus.

"Tokenizer choice is language-neutral." تقول الشريحة 50 العكس في ثلاث نقاط. الجملة نفسها تكلّف tokens أكثر بكثير في بعض اللغات من غيرها، وهذا نتيجة لمن سيطر نصه على corpus التدريب.

"Subwords are morphemes." Slide 40 explicitly separates them. BPE finds frequent substrings. It landed on _re in the worked example, which happens to be a real prefix, but that was frequency, not linguistics, and the method has no concept of meaning.

"Subwords are morphemes." تفصل الشريحة 40 بينهما صراحة. BPE يجد سلاسل فرعية متكررة. وقد وقع على _re في المثال المحلول، وهي سابقة حقيقية فعلاً، لكن ذلك كان تكراراً لا لغويات، والطريقة لا تعرف المعنى إطلاقاً.

"Character tokenization has no downsides since it has no OOV." Slide 39 lists three downsides: very long sequences, meaning spread thin, and slower processing. The no-OOV guarantee is real and it is not free.

"Character tokenization has no downsides since it has no OOV." تسرد الشريحة 39 ثلاثة عيوب: تسلسلات طويلة جداً، ومعنى موزّع رقيق، ومعالجة أبطأ. وضمان عدم وجود OOV حقيقي، لكنه ليس مجانياً.

Thirty-second recap

خلاصة في ثلاثين ثانية

tokens can be words, characters or subwordsالـ tokens قد تكون كلمات أو حروفاً أو أجزاء فرعية coverage, compactness, meaningfulness, cross-lingualالتغطية، والإيجاز، والدلالة، والصلاحية عبر اللغات words: huge vocab, OOVالكلمات: مفردات ضخمة، وOOV characters: no OOV, very long sequencesالحروف: لا OOV، وتسلسلات طويلة جداً subwords: the practical middleالأجزاء الفرعية: الوسط العملي BPE = trainer + encoderBPE = مُدرِّب + مُرمِّز count pairs, merge the winner, repeatعُدّ الأزواج، وادمج الفائز، وكرّر merge the most frequent adjacent PAIRادمج الزوج المتجاور الأكثر تكراراً recount after every mergeأعد العدّ بعد كل دمج final vocab = starting symbols + kالمفردات النهائية = رموز البداية + k encoding replays merges in learned orderالترميز يعيد تشغيل عمليات الدمج بالترتيب المُتعلَّم worked example merges: ne, new, _r, _reعمليات الدمج في المثال المحلول: ne, new, _r, _re 7 + 4 = 11 symbols at the end7 + 4 = 11 رمزاً في النهاية BPE by count, WordPiece by likelihood, unigram prunesBPE بالعدد، وWordPiece بالاحتمالية، وunigram يقلّم byte-level BPE: 256 bytes, so no OOV everBPE على مستوى البايت: 256 بايت، فلا OOV أبداً shared vocabs favour high-resource languagesالمفردات المشتركة تحابي اللغات الغنية بالموارد SuperBPE merges across spaces, 13 tokens to 8SuperBPE يدمج عبر المسافات، من 13 token إلى 8 vocab size 30k to 100k is a design choiceحجم المفردات من 30k إلى 100k قرار تصميمي

Check yourself

اختبر نفسك

You are training BPE on the lecture's corpus. After the first merge the state is 2: _ ne w, 2: _ r e ne w, 1: s e t, 1: _ r e s e t. Which pair is merged next, and with what count?

أنت تدرّب BPE على corpus المحاضرة. بعد الـ merge الأول صارت الحالة 2: _ ne w، و2: _ r e ne w، و1: s e t، و1: _ r e s e t. أي زوج يُدمج تالياً، وبأي عدّ؟

Count pairs on the current state, weighting each by its line frequency. ne w appears in _ ne w (frequency 2) and in _ r e ne w (frequency 2), so 2 + 2 = 4, which beats (r e) and (_ r) at 3. A is the most tempting wrong answer because (r e) really does occur and really does total 3; it just loses. B is the "merge the most frequent symbol" error, and BPE never merges a single symbol with nothing. Slide 45 confirms the result: the next state shows new in the vocabulary.

الجواب C. عُدّ الأزواج على الحالة الحالية، ووازن كل زوج بتكرار سطره. الزوج ne w يظهر في _ ne w بتكرار 2 وفي _ r e ne w بتكرار 2، فالمجموع 4، وهو يتجاوز (r e) و(_ r) عند 3. والجواب A هو الأكثر إغراءً لأن (r e) يظهر فعلاً ومجموعه 3 فعلاً، لكنه يخسر. وB هو خطأ "ادمج أكثر رمز تكراراً"، وBPE لا يدمج رمزاً واحداً مع لا شيء. والشريحة 45 تؤكد النتيجة: الحالة التالية تُظهر new في الـ vocabulary.

The merge list learned on the toy corpus is, in order: n+e→ne, ne+w→new, _+r→_r, _r+e→_re. Encode the unseen word " newer".

قائمة الـ merges المتعلَّمة على الـ corpus الصغير، بالترتيب، هي: n+e ثم ne+w ثم _+r ثم _r+e. رمّز الكلمة غير المرئية " newer".

Start as characters _ n e w e r. Merge 1 gives _ ne w e r, merge 2 gives _ new e r. Merge 3 looks for _ followed by r, and the _ here is followed by new, so it does not fire. Merge 4 needs a _r symbol that does not exist. Result: 4 tokens. C is the error the whole subword idea exists to prevent: an unseen word is composed from known pieces, not replaced. D is tempting if you think merges only apply to training words, but merges apply to any string that contains the pair.

الجواب B. ابدأ حروفاً _ n e w e r. الـ merge الأول يعطي _ ne w e r، والثاني يعطي _ new e r. والثالث يبحث عن _ يتبعها r، لكن _ هنا يتبعها new، فلا يعمل. والرابع يحتاج رمز _r وهو غير موجود. فالنتيجة 4 tokens. والجواب C هو الخطأ الذي وُجدت فكرة الـ subword كلها لمنعه: الكلمة المجهولة تُركَّب من قطع معروفة ولا تُستبدل. وD مغرٍ إن ظننت أن الـ merges تنطبق على كلمات التدريب فقط، لكنها تنطبق على أي سلسلة تحتوي الزوج.

What is the difference between BPE training and BPE encoding?

ما الفرق بين BPE training وBPE encoding؟

Slide 41 splits BPE into a trainer and an encoder, and slide 47 describes encoding as applying the learned merges in order, greedily, with no counting. C is the most tempting distractor because both operations touch text and both involve merges, but only training looks at frequencies, and encoding has no notion of a corpus at all. B is wrong on both halves: encoding is greedy too, and the global-search idea belongs to unigram models, not BPE.

الجواب D. تقسّم الشريحة 41 الـ BPE إلى trainer وencoder، وتصف الشريحة 47 الـ encoding بأنه تطبيق الـ merges المتعلَّمة بالترتيب وبطمع، بلا أي عدّ. والجواب C هو أقوى مشتّت لأن العمليتين تمسّان نصاً وفيهما merges، لكن التدريب وحده ينظر إلى التكرارات، والـ encoding لا يعرف مفهوم corpus إطلاقاً. وB خاطئ في نصفيه: الـ encoding طمّاع أيضاً، وفكرة البحث الشامل تنتمي لنماذج unigram لا لـ BPE.

In the worked example, the starting symbol inventory had 7 symbols and the deck performs 4 merges. How large is the final vocabulary, and why?

في المثال المحلول، كان مخزون الرموز الابتدائي 7 رموز، والعرض ينفّذ 4 من الـ merges. ما حجم الـ vocabulary النهائي، ولماذا؟

The pseudocode line is V <- V + tNEW, which only adds, so the size is starting symbols plus k = 7 + 4 = 11, and slide 46 prints exactly 11 entries. C is the common misreading: the corpus is rewritten in place, but the vocabulary is not. Keeping the original characters is what guarantees that any string over those characters can still be spelled out, so losing them would reintroduce OOV.

الجواب A. سطر الكود الوهمي هو V <- V + tNEW، وهو يضيف فقط، فالحجم هو رموز البداية زائد k، أي 7 + 4 = 11، والشريحة 46 تطبع أحد عشر مدخلاً بالضبط. والجواب C هو القراءة الخاطئة الشائعة: الـ corpus يُعاد كتابته في مكانه، لكن الـ vocabulary لا. والإبقاء على الحروف الأصلية هو ما يضمن أن أي سلسلة من تلك الحروف يمكن تهجئتها، ففقدانها يعيد OOV من جديد.

Why does byte-level BPE exist?

لماذا يوجد byte-level BPE؟

Slide 49 lists the pros as no OOV characters, works for any script, and robust to noisy text, all of which follow from the base inventory being a complete, finite 256. A is the most tempting wrong answer because "bytes" sounds like a low-level performance optimization; it is not, it is a coverage guarantee. B is backwards: a non-ASCII character is 2 to 4 bytes, so the byte sequence is longer, not shorter. D inverts the slide's single stated con, which is that byte tokens may be less interpretable.

الجواب C. تسرد الشريحة 49 المزايا بأنها لا OOV في الحروف، والعمل مع أي نظام كتابة، ومقاومة النص المشوّش، وكلها تتبع من كون مخزون البداية كاملاً ومحدوداً عند 256. والجواب A هو الأكثر إغراءً لأن كلمة bytes تبدو كتحسين أداء منخفض المستوى، وهي ليست كذلك، بل ضمان تغطية. وB معكوس: الحرف غير ASCII من 2 إلى 4 bytes، فتسلسل الـ bytes أطول لا أقصر. وD يقلب العيب الوحيد المذكور في الشريحة، وهو أن الـ tokens قد تكون أقل قابلية للتفسير.

Slide 50 says shared multilingual vocabularies favor high-resource languages. What is the mechanism, and why does the slide call it a fairness issue?

تقول الشريحة 50 إن الـ vocabularies المشتركة متعددة اللغات تنحاز للغات غنية الموارد. ما الآلية، ولماذا تسمّيها الشريحة مسألة عدالة؟

BPE selects purely by pair frequency, so a corpus that is mostly one language spends its fixed vocabulary budget on that language and the rest must be spelled out in small pieces. The slide's own phrase is "over-segmented (longer sequences)", and it concludes that tokenizer design affects fairness and performance. D is tempting because morphological richness is real, but it blames the language instead of the design choice, and the slide is pointing at the design choice. A is simply false: UTF-8 encodes every script.

الجواب B. يختار BPE بتكرار الأزواج وحده، فالـ corpus الذي معظمه لغة واحدة يصرف ميزانية الـ vocabulary الثابتة على تلك اللغة، والبقية تُهجَّأ بقطع صغيرة. وعبارة الشريحة نفسها هي over-segmented (longer sequences)، وتخلص إلى أن تصميم المقطّع يؤثر على العدالة والأداء. والجواب D مغرٍ لأن الغنى الصرفي حقيقي، لكنه يلوم اللغة بدل القرار التصميمي، والشريحة تشير إلى القرار التصميمي. وA خاطئ ببساطة: UTF-8 يرمّز كل أنظمة الكتابة.

A colleague proposes raising the subword vocabulary from 32k to 250k entries, arguing that bigger is strictly better. What is wrong with that?

يقترح زميل رفع vocabulary الـ subword من 32k إلى 250k مدخل، بحجة أن الأكبر أفضل حتماً. ما الخطأ في ذلك؟

Slide 48 calls vocabulary size a design choice, typically 30k to 100k, precisely because the effects pull in opposite directions. A is tempting because the sequence-shortening benefit is real and easy to see; the costs are the parts that are easy to forget. C is backwards: larger vocabularies reduce OOV pressure, and in a byte-level setup OOV is impossible at any size. B is false, since BPE can keep merging as long as adjacent pairs remain.

الجواب D. تسمي الشريحة 48 حجم الـ vocabulary قراراً تصميمياً، وعادة بين 30k و100k، تحديداً لأن الآثار تتجاذب في اتجاهين متضادين. والجواب A مغرٍ لأن فائدة تقصير التسلسل حقيقية وظاهرة، والتكاليف هي الجزء الذي يُنسى. وC معكوس: الـ vocabularies الأكبر تخفّف ضغط OOV، وفي إعداد على مستوى الـ bytes يكون OOV مستحيلاً عند أي حجم. وB خاطئ، لأن BPE يستطيع المواصلة ما دامت هناك أزواج متجاورة.