Majid Al-RaimiTokenization units and byte-pair encodingوحدات التقسيم وترميز أزواج البايتات (BPE)

ICS 582Lecture 02المحاضرة 02Part 06الجزء 06

Tokenization units and byte-pair encodingوحدات التقسيم وترميز أزواج البايتات (BPE)

Words, characters or subwords as the unit of text, the tradeoffs among them, and the BPE algorithm that learns a subword vocabulary by merging frequent pairs, traced by hand on a toy corpus.الكلمات أو الحروف أو الوحدات الجزئية (subwords) كوحدة للنص، والموازنات بينها، وخوارزمية BPE التي تتعلم مفردات جزئية بدمج الأزواج المتكررة، مع تتبعها يدويا على مدونة صغيرة.

Conceptsالمفاهيم
5
Slidesالشرائح
38-48
Readingمدة القراءة
30 min30 دقيقة
Understoodما فهمته
0/5 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Every model you train or evaluate in this course fixes a tokenizer before it sees a single example. That choice decides the vocabulary size, the sequence length, the cost per token, and whether an Arabic clitic such as wa- or the article al- ends up as a clean unit or as a fragment glued to whatever follows it.

This part first asks what a good tokenization is trying to achieve, then compares the three obvious units (words, characters, subwords) against those goals. The second half is the byte-pair encoding algorithm that modern language models use to learn subwords from data: how it trains, a full hand trace on the toy corpus from the slides with every pair count shown, and how the learned merges are replayed on new text. Tracing BPE by hand is a standard exam exercise, and reading a merge list is what you will do when you debug a Hugging Face tokenizer on Arabic text in your research.

كل نموذج تدرّبه أو تقيّمه في هذا المقرر يثبّت مقطِّعًا (tokenizer) قبل أن يرى مثالًا واحدًا. هذا الاختيار يحدد حجم المفردات، وطول التسلسل، وتكلفة كل وحدة (token)، وما إذا كانت لاحقة عربية مثل wa- (و) أو أداة التعريف al- (الـ) ستنتهي وحدة نظيفة مستقلة أم قطعة ملتصقة بما يليها.

يسأل هذا الجزء أولًا: ما الذي يحاول التقطيع الجيد تحقيقه؟ ثم يقارن الوحدات الثلاث البديهية (الكلمات والحروف والوحدات الفرعية) بهذه الأهداف. النصف الثاني مخصص لخوارزم byte-pair encoding الذي تستخدمه النماذج اللغوية الحديثة لتعلّم الوحدات الفرعية من البيانات: كيف يتدرّب، وتتبّع يدوي كامل على المدوّنة الصغيرة من الشرائح مع إظهار عدد كل زوج، وكيف تُعاد الدمجات المُتعلَّمة على نص جديد. تتبّع BPE يدويًا تمرين امتحاني معتاد، وقراءة قائمة الدمجات هي ما ستفعله عندما تصحّح مقطِّع Hugging Face على نص عربي في بحثك.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Name the four properties a tokenization balances and place words, characters and subwords on the coverage versus compactness spectrum.تسمية الخصائص الأربع التي يوازن بينها التقطيع (tokenization)، ووضع الكلمات والحروف والوحدات الفرعية (subwords) على طيف التغطية مقابل الإيجاز.
  2. Write the BPE training pseudocode from memory and explain the role of k.كتابة الشيفرة الزائفة (pseudocode) لتدريب BPE من الذاكرة، وشرح دور k.
  3. Run BPE by hand for k merges on a small corpus, showing pair counts, stating the tie rule, and listing the vocabulary and final corpus.تنفيذ BPE يدويًا لعدد k من الدمجات على مدوّنة صغيرة، مع إظهار عدّ الأزواج، وذكر قاعدة كسر التعادل، وسرد المفردات والمدوّنة النهائية.
  4. Encode an unseen word by replaying the merge list in order and explain why order matters.ترميز كلمة لم تظهر في التدريب بإعادة تطبيق قائمة الدمجات بترتيبها، وشرح لماذا يهمّ الترتيب.
  5. Explain how a leading space marker versus an end-of-word marker changes the learned units.شرح كيف يغيّر وسم المسافة البادئ، مقارنةً بوسم نهاية الكلمة، الوحداتِ التي يتعلمها الخوارزم.

Take the six-word string that the rest of this part will keep returning to: set new new renew reset renew. Split it at spaces and you have one token per word. Split it into characters, keeping a marker for each space, and you have one token per character. Split it with the subword vocabulary this part will learn and you get something in between.

خذ السلسلة ذات الكلمات الست التي سيعود إليها هذا الجزء مرارًا: set new new renew reset renew. قسّمها عند المسافات فتحصل على وحدة لكل كلمة. قسّمها إلى حروف مع الإبقاء على وسم لكل مسافة فتحصل على وحدة لكل حرف. قسّمها بمفردات الوحدات الفرعية التي سيتعلمها هذا الجزء فتحصل على شيء بينهما.

SplitالتقسيمTokens Nعدد الوحدات NDistinct typesالأنواع المميزةVocabulary |V|المفردات |V|
Wordsكلمات664444
Characters with markerحروف مع وسم المسافة29297777
BPE, k = 4BPE، k = 41515661111
The same six-word string under three tokenizationsالسلسلة نفسها ذات الكلمات الست تحت ثلاثة أنواع من التقطيع

Same text, three very different values of N and |V|. That is the whole subject of Tokenization in one example. Tokenization converts raw text into a sequence of tokens, the units that a model or a pipeline operates on, and the choice of unit fixes three things at once: the Vocabulary the model must learn embeddings for, the length of every input, and what the model can represent at all. Earlier parts of this lecture treated the unit as given and asked what a word is. This part reverses the question: given that we may pick the unit, what should we optimise for?

النص نفسه، وثلاث قيم مختلفة جدًا لـ N و|V|. هذا هو موضوع tokenization كله في مثال واحد. يحوّل التقطيع النص الخام إلى تسلسل من tokens، وهي الوحدات التي يعمل عليها النموذج أو خط المعالجة، واختيار الوحدة يثبّت ثلاثة أشياء دفعة واحدة: المفردات (vocabulary) التي يجب أن يتعلم النموذج تضمينات (embeddings) لها، وطول كل مدخل، وما يستطيع النموذج تمثيله أصلًا. الأجزاء السابقة من هذه المحاضرة عاملت الوحدة على أنها معطاة وسألت: ما الكلمة؟ هذا الجزء يعكس السؤال: إذا كان لنا أن نختار الوحدة، فما الذي ينبغي أن نحسّنه؟

Four properties a tokenization balancesأربع خصائص يوازن بينها التقطيع

Coverageالتغطية (Coverage)
How rarely new text contains a token the vocabulary cannot represent. Characters and bytes win outright; words lose.مدى ندرة احتواء نص جديد على وحدة لا تستطيع المفردات تمثيلها. الحروف والبايتات تفوز بلا منازع، والكلمات تخسر.
Compactnessالإيجاز (Compactness)
How short the token sequence is for a given text. Words win; characters lose by a factor of four to six.مدى قِصَر تسلسل الوحدات لنص معيّن. الكلمات تفوز، والحروف تخسر بعامل يتراوح بين أربعة وستة.
Meaningfulnessالدلالة (Meaningfulness)
How well one token lines up with one unit of meaning. Words win; characters carry almost none on their own.مدى توافق الوحدة الواحدة مع وحدة معنى واحدة. الكلمات تفوز، والحروف لا تحمل بمفردها أي معنى تقريبًا.
Cross-lingual applicabilityالصلاحية عبر اللغات (Cross-lingual applicability)
Whether the same scheme works for Arabic, Chinese and English alike. Data-driven subwords and bytes win; whitespace words fail for scripts without spaces.هل يعمل المخطط نفسه مع العربية والصينية والإنجليزية على حد سواء. الوحدات الفرعية المدفوعة بالبيانات والبايتات تفوز، والكلمات المقسومة عند المسافات تفشل مع الكتابات التي لا مسافات فيها.

The four criteria pull in different directions, which is why no single unit wins. Coverage asks how often new text contains something the vocabulary cannot represent, the out-of-vocabulary problem from the Zipf and Heaps part: with word tokens the answer is always, because Heaps' law says the word vocabulary never closes. Compactness asks how many tokens the model must process; every token costs attention, memory and, in a hosted API, money. Meaningfulness asks whether one token corresponds to one unit of meaning, which makes downstream tasks such as tagging and parsing easier. Cross-lingual applicability asks whether the same scheme works for Chinese, which has no spaces, and for Arabic, whose clitics glue several words into one whitespace token.

المعايير الأربعة تشدّ في اتجاهات مختلفة، ولهذا لا تفوز وحدة واحدة. التغطية (coverage) تسأل: كم مرة يحتوي نص جديد على شيء لا تستطيع المفردات تمثيله؟ وهذه مشكلة out-of-vocabulary من جزء Zipf وHeaps: مع وحدات الكلمات يكون الجواب دائمًا، لأن Heaps' law ينص على أن مفردات الكلمات لا تنغلق أبدًا. الإيجاز (compactness) يسأل: كم وحدة يجب أن يعالجها النموذج؟ فكل وحدة تكلّف انتباهًا (attention) وذاكرة، وفي واجهة API مستضافة تكلّف مالًا. الدلالة (meaningfulness) تسأل: هل تقابل الوحدة الواحدة وحدة معنى واحدة؟ وهذا يسهّل المهام اللاحقة مثل الوسم والإعراب (tagging، parsing). الصلاحية عبر اللغات تسأل: هل يعمل المخطط نفسه مع الصينية التي لا مسافات فيها، ومع العربية التي تلصق لواحقها (clitics) عدة كلمات في وحدة مسافية واحدة؟

There is also a quieter reason to care. Jurafsky and Martin note that a standardised tokenization is essential for replicability: a perplexity or an F1 score only means something if the units are the same, so the tokenizer is part of the experimental protocol, not a preprocessing detail (SLP3, chapter 2).

وهناك سبب أهدأ للاهتمام. يشير Jurafsky وMartin إلى أن التقطيع الموحَّد ضروري لقابلية تكرار التجارب: قيمة perplexity أو F1 لا تعني شيئًا إلا إذا كانت الوحدات نفسها، لذلك المقطِّع جزء من البروتوكول التجريبي وليس تفصيلًا من تفاصيل المعالجة المسبقة (SLP3، الفصل 2).

Recall

Name the four properties a good tokenization balances, and say which one word tokens fail on.سمِّ الخصائص الأربع التي يوازن بينها التقطيع الجيد، وقل أيّها تفشل فيه وحدات الكلمات.

Coverage (few or no unknown tokens), compactness (short sequences), meaningfulness (units correlate with meaning) and cross-lingual applicability. Word tokens fail on coverage: the word vocabulary never closes, so new text always brings out-of-vocabulary words.
التغطية (وحدات مجهولة قليلة أو معدومة)، والإيجاز (تسلسلات قصيرة)، والدلالة (الوحدات ترتبط بالمعنى)، والصلاحية عبر اللغات. تفشل وحدات الكلمات في التغطية: مفردات الكلمات لا تنغلق أبدًا، لذلك يأتي النص الجديد دائمًا بكلمات خارج المفردات (OOV).

Take the word renewed. As a word token it is one unit, but only if it appeared in training; if it did not, it is an unknown. As characters it is 7 letters, eight tokens with the leading space marker, none of which means anything alone. With the subword vocabulary learned later in this part it is four tokens, _re new e d, and the model has seen every one of them before even though it has never seen the word. Those three outcomes are the three granularities, and each buys something by paying for something else.

خذ الكلمة renewed. كوحدة كلمة هي وحدة واحدة، لكن فقط إذا ظهرت في التدريب؛ وإن لم تظهر فهي مجهولة. كحروف هي 7 أحرف، أي ثماني وحدات مع space marker البادئ، ولا يعني أيٌّ منها شيئًا بمفرده. ومع مفردات الوحدات الفرعية التي سنتعلمها لاحقًا في هذا الجزء تصبح أربع وحدات، _re new e d، وقد رأى النموذج كل واحدة منها من قبل رغم أنه لم يرَ الكلمة قط. هذه النتائج الثلاث هي مستويات الدقة (granularity) الثلاثة، وكل منها يكسب شيئًا بدفع ثمن شيء آخر.

The same string as 29 character tiles, 15 subword tiles or 6 word tiles. The bar under each row is its token count. The vocabulary each scheme needs on a real corpus runs the other way, dozens of characters against tens of thousands of subwords and an open-ended set of words, which a six-word corpus is too small to show.السلسلة نفسها في صورة 29 قطعة حرفية أو 15 قطعة فرعية أو 6 قطع كلمات. الشريط تحت كل صف هو عدد وحداته. أما حجم المفردات الذي يحتاجه كل مخطط على مدوّنة حقيقية فيسير في الاتجاه المعاكس: عشرات الحروف مقابل عشرات الآلاف من الوحدات الفرعية ومجموعة مفتوحة بلا حدّ من الكلمات، وهذا ما لا تكفي مدوّنة من ست كلمات لإظهاره.
WordsالكلماتCharactersالحروفSubwordsالوحدات الفرعية
Vocabulary sizeحجم المفرداتVery large and open-ended; grows with the corpus under Heaps' lawضخم جدًا ومفتوح بلا حد، وينمو مع المدوّنة وفق Heaps' lawTiny: the letters of a script, or 256 byte valuesصغير جدًا: حروف الكتابة، أو 256 قيمة للبايتFixed by design, typically 32k to 200k unitsثابت بالتصميم، عادةً من 32k إلى 200k وحدة
Sequence lengthطول التسلسلShortest: one token per wordالأقصر: وحدة واحدة لكل كلمةLongest: one token per characterالأطول: وحدة واحدة لكل حرفIn between: frequent words stay whole, rare words splitبينهما: الكلمات المتكررة تبقى كاملة، والنادرة تنقسم
Out-of-vocabularyخارج المفردات (OOV)Yes: rare words, misspellings, new namesنعم: الكلمات النادرة والأخطاء الإملائية والأسماء الجديدةNone: every string is spelled from the base symbolsلا شيء: كل سلسلة تُكتب من الرموز الأساسيةAlmost none: unseen words are composed from piecesتقريبًا لا شيء: الكلمات غير المرئية تُركَّب من قطع
MeaningfulnessالدلالةHighest; aligns with lexicons and syntaxالأعلى، تتوافق مع المعاجم والتركيب النحويSpread across many tokens; the model must learn to reassemble itموزّعة على وحدات كثيرة، ويجب أن يتعلم النموذج إعادة تجميعهاOften morpheme-like, but only by accident of frequencyغالبًا شبيهة بالصرفيمات، لكن فقط بمصادفة التكرار
Best useأفضل استخدامPOS tagging, parsing, lexicon-driven systems that need explicit word boundariesوسم أقسام الكلام (POS tagging) والإعراب النحوي والأنظمة المعتمدة على المعاجم التي تحتاج حدودًا صريحة للكلماتNoisy OCR or typo-heavy text, very low-resource languages, specialised tasksنص OCR المليء بالضوضاء أو كثير الأخطاء الطباعية، واللغات شديدة الندرة في الموارد، والمهام المتخصصةModern language models and machine translationالنماذج اللغوية الحديثة والترجمة الآلية
Words, characters and subwords on the four criteriaالكلمات والحروف والوحدات الفرعية على المعايير الأربعة

Words: meaningful, but the vocabulary never closesالكلمات: ذات معنى، لكن المفردات لا تنغلق أبدًا

Word tokens are the natural first choice. They are meaningful, they line up with dictionaries and with the lexicons that rule-based systems consult, and tasks that need explicit word boundaries, such as part-of-speech tagging, syntactic parsing and lexicon-driven pipelines, are built around them. The problems are the ones the first four parts of this lecture already exposed. "Word" is ambiguous across languages: punctuation, contractions, compounds, clitics and scripts without spaces all give different answers. And the vocabulary is enormous and open-ended. Heaps' law says |V| keeps growing with N, so however large the training corpus, test text brings rare and unseen words, and every one of them is an OOV token the model must lump into a single UNK symbol.

وحدات الكلمات هي الخيار الأول الطبيعي. فهي ذات معنى، وتتوافق مع القواميس ومع المعاجم التي ترجع إليها الأنظمة القائمة على القواعد، والمهام التي تحتاج حدودًا صريحة للكلمات، مثل وسم أقسام الكلام (POS tagging) والإعراب النحوي وخطوط المعالجة المعتمدة على المعاجم، مبنية حولها. المشكلات هي نفسها التي كشفتها الأجزاء الأربعة الأولى من هذه المحاضرة. مفهوم "الكلمة" ملتبس بين اللغات: علامات الترقيم والاختصارات المدمجة (contractions) والكلمات المركبة واللواحق والكتابات التي بلا مسافات كلها تعطي إجابات مختلفة. ثم إن المفردات ضخمة ومفتوحة بلا حد. ينص Heaps' law على أن |V| يستمر في النمو مع N، فمهما كبرت مدوّنة التدريب يأتي نص الاختبار بكلمات نادرة وغير مرئية، وكل واحدة منها وحدة OOV يجب على النموذج أن يجمعها في رمز UNK واحد.

Characters: nothing is unknown, but everything is longالحروف: لا شيء مجهول، لكن كل شيء طويل

Go to the other extreme and tokenize into characters. The vocabulary is tiny, a few dozen letters for Latin script or, at byte level, exactly 256 values. There is no OOV at all, because any string is spelled from the base symbols, and the tokenizer is robust to spelling variants, typos and OCR noise since a damaged word still shares most of its characters with the clean one. The price is paid in sequence length and in meaning. The 6-word string became 29 tokens, roughly five times longer, and attention cost grows with the square of that length. Two words that sit a sentence apart become dozens of positions apart, so a model with a fixed context window sees less of the surrounding text and must learn dependencies across far longer distances. Meaning is spread across many tokens, so the model must spend capacity learning to reassemble words before it can learn anything about them, which makes training slower. Characters are the right call for noisy text, for extremely low-resource languages where no subword vocabulary can be trusted, and for specialised tasks such as transliteration where the character really is the unit.

اذهب إلى الطرف الآخر وقطّع إلى حروف. المفردات صغيرة جدًا: بضع عشرات من الحروف للكتابة اللاتينية، أو بالضبط 256 قيمة على مستوى البايت. لا توجد OOV إطلاقًا، لأن أي سلسلة تُكتب من الرموز الأساسية، والمقطِّع متين أمام اختلافات الإملاء والأخطاء الطباعية وضوضاء OCR، لأن الكلمة المشوّهة تشترك مع السليمة في معظم حروفها. الثمن يُدفع في طول التسلسل وفي المعنى. السلسلة ذات الكلمات 6 صارت 29 وحدة، أي أطول بخمس مرات تقريبًا، وتكلفة الانتباه تنمو مع مربع هذا الطول. كلمتان تفصل بينهما جملة تصبحان على بُعد عشرات المواضع، فيرى نموذج ذو نافذة سياق ثابتة قدرًا أقل من النص المحيط، ويجب أن يتعلم اعتماديات عبر مسافات أطول بكثير. والمعنى موزّع على وحدات كثيرة، فيُنفق النموذج سعته في تعلّم إعادة تجميع الكلمات قبل أن يتعلم أي شيء عنها، وهذا يبطئ التدريب. الحروف هي الخيار الصحيح للنص المليء بالضوضاء، وللغات شديدة الندرة في الموارد حيث لا يمكن الوثوق بأي مفردات فرعية، وللمهام المتخصصة مثل النقحرة (transliteration) حيث يكون الحرف هو الوحدة فعلًا.

Subwords: the middle ground modern models useالوحدات الفرعية: الحل الوسط الذي تستخدمه النماذج الحديثة

Subword tokenization keeps a vocabulary smaller than a word vocabulary and produces sequences shorter than a character sequence, and its decisive property is the third row of the table: an unseen word is composed from pieces that were seen. The GPT-2 paper describes byte-pair encoding as a practical middle ground that interpolates between word-level inputs for frequent symbol sequences and character-level inputs for infrequent ones (Radford et al., 2019). Frequent words stay whole, rare words shatter into recognisable parts, and nothing is ever unknown.

Subword tokenization يحافظ على مفردات أصغر من مفردات الكلمات، وينتج تسلسلات أقصر من تسلسلات الحروف، وخاصيته الحاسمة هي الصف الثالث في الجدول: الكلمة غير المرئية تُركَّب من قطع سبق رؤيتها. تصف ورقة GPT-2 الـ byte-pair encoding بأنه حل وسط عملي يتدرّج بين مدخلات على مستوى الكلمة للتسلسلات الرمزية المتكررة ومدخلات على مستوى الحرف للنادرة (Radford et al., 2019). الكلمات المتكررة تبقى كاملة، والكلمات النادرة تتفتت إلى أجزاء يمكن التعرف عليها، ولا شيء يكون مجهولًا أبدًا.

There are two ways to decide what the pieces are. The linguistically natural way is to cut at morphemes, since morphemes carry meaning by definition. But the morphology parts of this lecture showed why that is hard: allomorphy changes the shape of a morpheme by context, non-concatenative morphology interleaves an Arabic root with a pattern rather than concatenating anything, and clitics blur the boundary between word and affix. Morpheme segmentation needs a linguist, or a model, per language, and it remains ambiguous even then. It is useful in some applications but it is not the common approach in modern language models. The language-agnostic way is to learn frequent substrings from data with no linguistic knowledge at all. That is what byte-pair encoding does, and Jurafsky and Martin name BPE and unigram language modelling as the two families widely used in modern language models (SLP3, section 2.4). They work across languages, reduce OOV and stay efficient, which is why the rest of this part is about one of them.

هناك طريقتان لتحديد ما هي القطع. الطريقة الطبيعية لغويًا هي القطع عند الصرفيمات (morphemes)، لأن الصرفيمات تحمل المعنى بالتعريف. لكن أجزاء الصرف في هذه المحاضرة أظهرت لماذا هذا صعب: التبدّل الصرفي (allomorphy) يغيّر شكل الصرفيم حسب السياق، وnon-concatenative morphology يداخل الجذر العربي مع الوزن بدلًا من وصل شيء بشيء، واللواحق تطمس الحد بين الكلمة والزائدة. تقسيم الصرفيمات يحتاج لغويًا، أو نموذجًا، لكل لغة، ويبقى ملتبسًا حتى مع ذلك. هو مفيد في بعض التطبيقات لكنه ليس النهج الشائع في النماذج اللغوية الحديثة. الطريقة المستقلة عن اللغة هي تعلّم السلاسل الفرعية المتكررة من البيانات دون أي معرفة لغوية على الإطلاق. هذا ما يفعله byte-pair encoding، ويذكر Jurafsky وMartin أن BPE وunigram language modelling هما العائلتان المستخدمتان على نطاق واسع في النماذج اللغوية الحديثة (SLP3، القسم 2.4). تعملان عبر اللغات، وتقللان OOV، وتبقيان فعّالتين، ولهذا خُصّص بقية هذا الجزء لإحداهما.

Quick checkاختبار سريع

Which statement about tokenization granularity is correct?أي عبارة عن مستوى دقة التقطيع صحيحة؟

Recall

Give one reason to prefer characters over words, and one reason to prefer subwords over both.أعطِ سببًا واحدًا لتفضيل الحروف على الكلمات، وسببًا واحدًا لتفضيل الوحدات الفرعية على كليهما.

Characters have no OOV and a tiny vocabulary, and they are robust to typos and OCR noise, so they suit noisy or very low-resource text. Subwords keep a fixed mid-sized vocabulary with sequences far shorter than characters and still compose unseen words from pieces, so they get most of the coverage benefit at a fraction of the length.
الحروف بلا OOV ومفرداتها صغيرة جدًا، وهي متينة أمام الأخطاء الطباعية وضوضاء OCR، لذلك تناسب النص المليء بالضوضاء أو شديد الندرة في الموارد. الوحدات الفرعية تحافظ على مفردات ثابتة متوسطة الحجم مع تسلسلات أقصر بكثير من الحروف، وما زالت تركّب الكلمات غير المرئية من قطع، فتحصل على معظم فائدة التغطية بجزء صغير من الطول.

Here is the smallest corpus that shows the whole idea, borrowed from Jurafsky and Martin: the ten-character string A B D C A B E C A B with the vocabulary {A, B, C, D, E}. Look for the pair of adjacent symbols that occurs most often. It is A B, three times. Replace every A B with a new symbol AB and add it to the vocabulary. Now look again.

إليك أصغر مدوّنة تُظهر الفكرة كلها، مأخوذة من Jurafsky وMartin: السلسلة ذات الحروف العشرة A B D C A B E C A B مع المفردات {A, B, C, D, E}. ابحث عن زوج الرموز المتجاورة الأكثر تكرارًا. إنه A B، ثلاث مرات. استبدل كل A B برمز جديد AB وأضفه إلى المفردات. ثم انظر مجددًا.

Worked exampleمثال محلول

Two merges on a ten-character corpusدمجتان على مدوّنة من عشرة حروف

  1. Merge (A, B)دمج (A, B)

    The corpus becomes AB D C AB E C AB, seven symbols instead of ten, and the vocabulary grows to six: {A, B, C, D, E, AB}.
    تصبح المدوّنة AB D C AB E C AB، سبعة رموز بدلًا من عشرة، وتكبر المفردات إلى ستة: {A, B, C, D, E, AB}.
  2. Merge (C, AB)دمج (C, AB)

    The most frequent adjacent pair is now C AB, twice. The corpus becomes AB D CAB E CAB, five symbols, and the vocabulary grows to seven with CAB.
    الزوج المتجاور الأكثر تكرارًا الآن هو C AB، مرتين. تصبح المدوّنة AB D CAB E CAB، خمسة رموز، وتكبر المفردات إلى سبعة بإضافة CAB.
  3. Two mergesدمجتان

    Vocabulary 5 to 7, corpus 10 to 5 symbols. Each merge adds exactly one vocabulary entry and shortens the corpus by the number of non-overlapping occurrences of the pair it replaces (for pairs of two different symbols, simply the pair count).
    المفردات من 5 إلى 7، والمدوّنة من 10 إلى 5 رموز. كل دمج يضيف عنصرًا واحدًا بالضبط إلى المفردات ويقصّر المدوّنة بعدد مرات الظهور غير المتداخلة للزوج الذي يستبدله (وللأزواج المكوّنة من رمزين مختلفين، هذا ببساطة عدد الزوج).

That loop is the entire training algorithm of byte-pair encoding. The slide's pseudocode, which is Figure 2.6 of SLP3 adapted from Bostrom and Durrett (2020), reads as follows. Start with V equal to the set of unique characters (or bytes) in the Corpus C. Then repeat k times: find the most frequent pair of adjacent tokens tL, tR in C, form the new token tNEW = tL + tR by concatenation, add it to V, and replace every occurrence of tL tR in C with tNEW. Return V. One iteration of the loop is a Merge.

هذه الحلقة هي خوارزم التدريب الكامل لـ byte-pair encoding. الشيفرة الزائفة في الشريحة، وهي الشكل 2.6 في SLP3 المقتبس من Bostrom and Durrett (2020)، تقول ما يلي. ابدأ بـ V مساوية لمجموعة الحروف (أو البايتات) الفريدة في corpus C. ثم كرّر k مرة: جد زوج الوحدات المتجاورة الأكثر تكرارًا tL, tR في C، وكوّن الوحدة الجديدة tNEW = tL + tR بالوصل، وأضفها إلى V، واستبدل كل ظهور لـ tL tR في C بـ tNEW. أعِد V. التكرار الواحد للحلقة يسمى merge (دمج).

∣Vfinal∣=∣Vinitial∣+k|V_{\text{final}}| = |V_{\text{initial}}| + k
Each merge adds exactly one entry, so k fixes the vocabulary sizeكل دمج يضيف مدخلًا واحدًا بالضبط، لذلك تحدد k حجم المفردات

Sennrich, Haddow and Birch, who introduced BPE for neural machine translation, state the consequence plainly: the final symbol vocabulary size is equal to the size of the initial vocabulary plus the number of merge operations, and the number of merges is the only hyperparameter of the algorithm (Sennrich et al., 2016). In the toy example k is 2 or 4. In practice Jurafsky and Martin describe tens of thousands of merges on a very large corpus to produce vocabularies of 50,000, 100,000 or even 200,000 tokens, and GPT-2's vocabulary is 50,257 entries (Radford et al., 2019).

يذكر Sennrich وHaddow وBirch، الذين قدّموا BPE للترجمة الآلية العصبية، النتيجة صراحة: حجم مفردات الرموز النهائي يساوي حجم المفردات الأولية زائد عدد عمليات الدمج، وعدد الدمجات هو المعامل الفائق (hyperparameter) الوحيد للخوارزم (Sennrich et al., 2016). في المثال الصغير k يساوي 2 أو 4. أما عمليًا فيصف Jurafsky وMartin عشرات الآلاف من الدمجات على مدوّنة ضخمة جدًا لإنتاج مفردات من 50,000 أو 100,000 أو حتى 200,000 وحدة، ومفردات GPT-2 فيها 50,257 عنصرًا (Radford et al., 2019).

Two practical details shape the counting. First, merges never cross word boundaries. Sennrich's implementation says it does not consider pairs that cross word boundaries for efficiency, so the corpus is stored as a table of distinct words with their counts, and a pair inside a word that occurs twice in the corpus is counted twice. That is exactly why the slides list the toy corpus as four rows with counts rather than as running text. Second, the base symbols can be characters or bytes. GPT-2 works on UTF-8 bytes because a Unicode Code point vocabulary would start at over 130,000 entries, whereas byte-level BPE starts at exactly 256 and, since every byte is in the vocabulary, there can never be an unknown token (Radford et al., 2019; SLP3, section 2.4).

تفصيلان عمليان يشكّلان طريقة العدّ. أولًا، الدمجات لا تعبر حدود الكلمات أبدًا. ينص تطبيق Sennrich على أنه لا يأخذ في الحسبان الأزواج التي تعبر حدود الكلمات من أجل الكفاءة، لذلك تُخزَّن المدوّنة جدولًا من الكلمات المميزة مع أعدادها، والزوج داخل كلمة تظهر مرتين في المدوّنة يُعدّ مرتين. ولهذا بالضبط تعرض الشرائح المدوّنة الصغيرة أربعة صفوف مع أعدادها بدلًا من نص متصل. ثانيًا، يمكن أن تكون الرموز الأساسية حروفًا أو بايتات. يعمل GPT-2 على بايتات UTF-8 لأن مفردات من code points Unicode كانت ستبدأ بأكثر من 130,000 عنصر، بينما يبدأ byte-level BPE بـ 256 بالضبط، ولأن كل بايت موجود في المفردات لا يمكن أن تظهر وحدة مجهولة أبدًا (Radford et al., 2019؛ SLP3، القسم 2.4).

Four brackets close in the order the trainer learned them, then the character row gives way to four tokens. Merged pieces are accent, leftover characters teal.تنغلق أربعة أقواس بالترتيب الذي تعلّمه المدرِّب، ثم يفسح صف الحروف المجال لأربع وحدات. القطع المدموجة بلون التمييز، والحروف المتبقية باللون الأخضر المزرق.

Where the algorithm came from, and its two halvesمن أين جاء الخوارزم، ونصفاه

The name is older than NLP. Philip Gage published byte pair encoding in 1994 as a data compression method: find the most frequently occurring pair of adjacent bytes in the data, replace all instances with a byte that was not in the original data, and repeat until no further compression is possible (Gage, 1994). Sennrich and colleagues adapted it for word segmentation, and two things changed. The units became characters rather than bytes, and the stopping rule became a fixed k rather than exhaustion, so the merges are no longer a throwaway table for one file but a reusable vocabulary shared by every text the model will ever see.

الاسم أقدم من NLP. نشر Philip Gage خوارزم byte pair encoding عام 1994 طريقةً لضغط البيانات: جد زوج البايتات المتجاورة الأكثر تكرارًا في البيانات، واستبدل كل ظهوراته ببايت لم يكن في البيانات الأصلية، وكرّر حتى لا يعود الضغط ممكنًا (Gage, 1994). كيّفه Sennrich وزملاؤه لتقسيم الكلمات، وتغيّر أمران. صارت الوحدات حروفًا بدلًا من بايتات، وصارت قاعدة التوقف عددًا ثابتًا k بدلًا من الاستنفاد، فلم تعد الدمجات جدولًا يُرمى بعد ملف واحد، بل مفردات قابلة لإعادة الاستخدام يتشاركها كل نص سيراه النموذج.

That reuse is why BPE has two parts. The trainer runs once, over the training corpus, and produces the vocabulary together with the ordered list of merges it performed. The encoder runs every time new text arrives and applies that list. The two must never be confused, and the last concept of this part is devoted to the encoder. The simulator below is the trainer: step through the merges and watch the pair table decide each one, then encode a word of your own in its lower panel; the encoder concept returns to that panel on its own.

إعادة الاستخدام هذه هي سبب وجود جزأين لـ BPE. المدرِّب (trainer) يعمل مرة واحدة على مدوّنة التدريب، وينتج المفردات مع القائمة المرتبة للدمجات التي نفّذها. المرمِّز (encoder) يعمل في كل مرة يصل فيها نص جديد ويطبّق تلك القائمة. يجب ألا يُخلط بينهما أبدًا، والمفهوم الأخير في هذا الجزء مخصص للمرمِّز. المحاكي أدناه هو المدرِّب: تقدّم عبر الدمجات وراقب جدول الأزواج يقرر كل واحدة، ثم رمّز كلمة من اختيارك في لوحته السفلية؛ ويعود مفهوم المرمِّز إلى تلك اللوحة بشكل مستقل.

SimulatorمحاكيBPE merge stepper: train on a corpus, then encode a new wordمتتبع دمج BPE: درّب على مدونة، ثم رمِّز كلمة جديدة
Next: merge 1التالي: الدمج رقم 1
Merges kعمليات الدمج k0applied
Vocabularyالمفردات7entries7 initial + 07 أولية + 0
Corpusالمدونة29symbolsfrom 29من 29
Shorter byأقصر بمقدار0%
Corpus after 0 mergesالمدونة بعد 0 عمليات دمج
  • 2_new
  • 2_renew
  • 1set
  • 1_reset
Vocabulary (7)المفردات (7)
_enrstw

Grey chips are the initial symbols, teal chips are learned merges in the order they were learned, and the accent chip is the newest.الرقاقات الرمادية هي الرموز الأولية، والرقاقات الخضراء المزرقة هي عمليات الدمج المتعلَّمة بترتيب تعلُّمها، والرقاقة باللون المميز هي الأحدث.

Pair counts deciding merge 1أعداد الأزواج التي تحسم الدمج رقم 1
RankالرتبةPairالزوجCountالعددFirst seen atأول ظهور عندNoteملاحظة
1(n, e)4position 1الموضع 1winner, tie broken by ruleالفائز، وحُسم التعادل بالقاعدة
2(e, w)4position 2الموضع 2tie at the maximumتعادل عند القيمة القصوى
3(_, r)3position 4الموضع 4
4(r, e)3position 5الموضع 5
5(_, n)2position 0الموضع 0
6(e, n)2position 6الموضع 6
7(s, e)2position 10الموضع 10
8(e, t)2position 11الموضع 11
9(e, s)1position 15الموضع 15
  1. charactersالمحارف_renewed
  2. outputالناتج_ r e n e w e d (8 tokens)(8 رموز)

The encoder never counts anything. It replays the merge list top to bottom; a merge whose pair does not occur in the word is skipped.المرمِّز لا يعدّ أي شيء. إنه يعيد تطبيق قائمة الدمج من أعلاها إلى أسفلها، ويتخطى كل دمج لا يظهر زوجه في الكلمة.

Quick checkاختبار سريع

In one BPE training step, what exactly does the trainer merge?في خطوة تدريب واحدة من BPE، ما الذي يدمجه المدرِّب بالضبط؟

Recall

State the difference between the BPE trainer and the BPE encoder in one sentence each.اذكر الفرق بين مدرِّب BPE ومرمِّز BPE في جملة واحدة لكل منهما.

The trainer counts adjacent pair frequencies on the training corpus and produces a vocabulary plus an ordered merge list. The encoder splits new text into characters or bytes and replays that merge list in order without counting anything.
المدرِّب يعدّ تكرارات الأزواج المتجاورة على مدوّنة التدريب وينتج مفردات مع قائمة دمجات مرتبة. المرمِّز يقسّم النص الجديد إلى حروف أو بايتات ويعيد تطبيق قائمة الدمجات تلك بترتيبها دون أن يعدّ أي شيء.

Now run the BPE trainer by hand on the slide Corpus, set new new renew reset renew, for k = 4. This is the same example as the current SLP3 draft (example 2.11 in section 2.4), so the tables here match both the slides and the book symbol for symbol. The slides show the corpus and the Vocabulary after each Merge but never the pair counts that decided it, so those are worked out in full below.

الآن شغّل مدرِّب BPE يدويًا على corpus الشريحة، set new new renew reset renew، لعدد k = 4. هذا هو المثال نفسه في مسودة SLP3 الحالية (المثال 2.11 في القسم 2.4)، لذلك تطابق الجداول هنا الشرائح والكتاب رمزًا برمز. تعرض الشرائح المدوّنة وvocabulary بعد كل merge، لكنها لا تعرض أبدًا أعداد الأزواج التي حسمته، لذلك نحسبها كاملة أدناه.

First the setup. Every word except the first carries a leading space marker, drawn as an open box on the slides and written _ here. The first word, set, starts the string, so it has none. Grouping equal words gives four rows with counts: 2 × _ n e w, 2 × _ r e n e w, 1 × s e t and 1 × _ r e s e t. The initial vocabulary is the seven symbols _, e, n, r, s, t, w, and the corpus holds 2 × 4 + 2 × 6 + 3 + 6 = 29 symbols. Pair counts are weighted by row count: a pair that occurs once inside _ n e w counts 2.

أولًا الإعداد. كل كلمة ما عدا الأولى تحمل space marker بادئًا، يُرسم مربعًا مفتوحًا في الشرائح ونكتبه _ هنا. الكلمة الأولى، set، تبدأ السلسلة فلا وسم لها. تجميع الكلمات المتساوية يعطي أربعة صفوف مع أعدادها: 2 × _ n e w و2 × _ r e n e w و1 × s e t و1 × _ r e s e t. المفردات الأولية هي الرموز السبعة _, e, n, r, s, t, w، والمدوّنة تحوي 2 × 4 + 2 × 6 + 3 + 6 = 29 رمزًا. أعداد الأزواج موزونة بعدد الصف: الزوج الذي يظهر مرة واحدة داخل _ n e w يُعدّ 2.

Worked exampleمثال محلول

Four merges on set new new renew reset renewأربع دمجات على set new new renew reset renew

  1. Merge 1: count every adjacent pairالدمج 1: عُدّ كل زوج متجاور

    PairالزوجCountالعددNoteملاحظة
    (n, e)(n, e)44winner: tied with (e, w), seen first in the corpusالفائز: متعادل مع (e, w)، وظهر أولًا في المدوّنة
    (e, w)(e, w)44tie at the maximumتعادل عند الحد الأقصى
    (_, r)(_, r)33
    (r, e)(r, e)33
    (_, n)(_, n)22
    (e, n)(e, n)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    (n, e) occurs once in _ n e w (count 2) and once in _ r e n e w (count 2), so it scores 4. So does (e, w). The pseudocode says nothing about ties; the slide merges n e, which is the pair encountered first when scanning the corpus. The corpus becomes 2 × _ ne w, 2 × _ r e ne w, 1 × s e t, 1 × _ r e s e t and ne joins the vocabulary.

    PairالزوجCountالعددNoteملاحظة
    (n, e)(n, e)44winner: tied with (e, w), seen first in the corpusالفائز: متعادل مع (e, w)، وظهر أولًا في المدوّنة
    (e, w)(e, w)44tie at the maximumتعادل عند الحد الأقصى
    (_, r)(_, r)33
    (r, e)(r, e)33
    (_, n)(_, n)22
    (e, n)(e, n)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    يظهر (n, e) مرة في _ n e w (العدد 2) ومرة في _ r e n e w (العدد 2)، فيحصل على 4. وكذلك (e, w). الشيفرة الزائفة لا تقول شيئًا عن التعادل؛ الشريحة تدمج n e، وهو الزوج الذي يُصادَف أولًا عند مسح المدوّنة. تصبح المدوّنة 2 × _ ne w, 2 × _ r e ne w, 1 × s e t, 1 × _ r e s e t وتنضم ne إلى المفردات.

  2. Merge 2: recount on the new corpusالدمج 2: أعِد العدّ على المدوّنة الجديدة

    PairالزوجCountالعددNoteملاحظة
    (ne, w)(ne, w)44winner: the only pair at 4 once ne existsالفائز: الزوج الوحيد عند 4 بعد وجود ne
    (_, r)(_, r)33
    (r, e)(r, e)33
    (_, ne)(_, ne)22
    (e, ne)(e, ne)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    The old pair (e, w) no longer exists because the e in front of every w is now inside ne. (ne, w) scores 4 alone, so new is merged with no tie. The corpus becomes 2 × _ new, 2 × _ r e new, 1 × s e t, 1 × _ r e s e t.

    PairالزوجCountالعددNoteملاحظة
    (ne, w)(ne, w)44winner: the only pair at 4 once ne existsالفائز: الزوج الوحيد عند 4 بعد وجود ne
    (_, r)(_, r)33
    (r, e)(r, e)33
    (_, ne)(_, ne)22
    (e, ne)(e, ne)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    الزوج القديم (e, w) لم يعد موجودًا لأن الـ e التي تسبق كل w صارت الآن داخل ne. يحصل (ne, w) على 4 وحده، فتُدمج new دون تعادل. تصبح المدوّنة 2 × _ new, 2 × _ r e new, 1 × s e t, 1 × _ r e s e t.

  3. Merge 3: a second tieالدمج 3: تعادل ثانٍ

    PairالزوجCountالعددNoteملاحظة
    (_, r)(_, r)33winner: tied with (r, e), seen firstالفائز: متعادل مع (r, e)، وظهر أولًا
    (r, e)(r, e)33tie at the maximumتعادل عند الحد الأقصى
    (_, new)(_, new)22
    (e, new)(e, new)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    (_, r) and (r, e) both score 3: twice from _ r e new and once from _ r e s e t. The slide merges _ r, again the pair seen first. The corpus becomes 2 × _ new, 2 × _r e new, 1 × s e t, 1 × _r e s e t.

    PairالزوجCountالعددNoteملاحظة
    (_, r)(_, r)33winner: tied with (r, e), seen firstالفائز: متعادل مع (r, e)، وظهر أولًا
    (r, e)(r, e)33tie at the maximumتعادل عند الحد الأقصى
    (_, new)(_, new)22
    (e, new)(e, new)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    يحصل كل من (_, r) و(r, e) على 3: مرتين من _ r e new ومرة من _ r e s e t. الشريحة تدمج _ r، وهو مرة أخرى الزوج الذي يُرى أولًا. تصبح المدوّنة 2 × _ new, 2 × _r e new, 1 × s e t, 1 × _r e s e t.

  4. Merge 4: the tie resolves itselfالدمج 4: التعادل يحل نفسه

    PairالزوجCountالعددNoteملاحظة
    (_r, e)(_r, e)33winner: the only pair at 3 once _r existsالفائز: الزوج الوحيد عند 3 بعد وجود _r
    (_, new)(_, new)22
    (e, new)(e, new)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    With _r in place, (r, e) has disappeared and (_r, e) inherits its count of 3, the unique maximum. Merging it gives _re. Slide 47 shows merges 3 and 4 together for this reason: the second is forced by the first.

    PairالزوجCountالعددNoteملاحظة
    (_r, e)(_r, e)33winner: the only pair at 3 once _r existsالفائز: الزوج الوحيد عند 3 بعد وجود _r
    (_, new)(_, new)22
    (e, new)(e, new)22
    (s, e)(s, e)22
    (e, t)(e, t)22
    (e, s)(e, s)11

    مع وجود _r، اختفى (r, e) وورث (_r, e) عدده 3، وهو الحد الأقصى الوحيد. دمجه يعطي _re. تعرض الشريحة 47 الدمجين 3 و4 معًا لهذا السبب: الثاني يفرضه الأول.

  5. After k = 4بعد k = 4

    Vocabulary _, e, n, r, s, t, w, ne, new, _r, _re (11 entries, 7 + 4). Corpus 2 × _ new, 2 × _re new, 1 × s e t, 1 × _re s e t, which is 15 symbols instead of 29. Merge list, in order: ne, new, _r, _re.
    المفردات _, e, n, r, s, t, w, ne, new, _r, _re (11 عنصرًا، 7 + 4). المدوّنة 2 × _ new, 2 × _re new, 1 × s e t, 1 × _re s e t، أي 15 رمزًا بدلًا من 29. قائمة الدمجات بالترتيب: ne, new, _r, _re.
MergeالدمجNew token (count)الوحدة الجديدة (العدد)Corpus symbolsرموز المدوّنة|V||V|Corpusالمدوّنة
00startالبداية2929772 _ n e w, 2 _ r e n e w, 1 s e t, 1 _ r e s e t2 _ n e w, 2 _ r e n e w, 1 s e t, 1 _ r e s e t
11ne (4, tie)ne (4، تعادل)2525882 _ ne w, 2 _ r e ne w, 1 s e t, 1 _ r e s e t2 _ ne w, 2 _ r e ne w, 1 s e t, 1 _ r e s e t
22new (4)new (4)2121992 _ new, 2 _ r e new, 1 s e t, 1 _ r e s e t2 _ new, 2 _ r e new, 1 s e t, 1 _ r e s e t
33_r (3, tie)_r (3، تعادل)181810102 _ new, 2 _r e new, 1 s e t, 1 _r e s e t2 _ new, 2 _r e new, 1 s e t, 1 _r e s e t
44_re (3)_re (3)151511112 _ new, 2 _re new, 1 s e t, 1 _re s e t2 _ new, 2 _re new, 1 s e t, 1 _re s e t
The trace at a glanceالتتبّع في لمحة

Ties: the pseudocode is silent, so state your ruleالتعادل: الشيفرة الزائفة صامتة، فاذكر قاعدتك

Two of the four steps were decided by a tie, and the algorithm as written never says how to break one. Real implementations do have a rule, and it is worth knowing which. The minimal listing in the Sennrich paper (Algorithm 1) picks the best pair with Python's max(pairs, key=pairs.get), which in modern Python (3.7 and later, where dictionaries keep insertion order) returns the first pair encountered while scanning. The released subword-nmt implementation instead selects with max(stats, key=lambda x: (stats[x], x)), which prefers the lexicographically largest pair among the tied ones. On this corpus that rule agrees with the slides at merge 1, choosing (n, e) because n sorts after e, but at merge 3 it chooses (r, e) over (_, r). The Hugging Face course states the first-encountered convention explicitly: when there is a choice of the most frequent pair, the first one encountered is selected. The 🤗 Tokenizers library breaks ties by internal token ids, and the simulator's alphabetical option takes the smallest pair.

خطوتان من الخطوات الأربع حسمهما تعادل، والخوارزم كما هو مكتوب لا يقول أبدًا كيف يُكسر. التطبيقات الحقيقية لها قاعدة فعلًا، ومن المفيد معرفة أيّها. القائمة المختصرة في ورقة Sennrich (الخوارزم 1) تختار أفضل زوج بـ max(pairs, key=pairs.get) في Python، وهذا في Python الحديثة (3.7 وما بعدها، حيث تحافظ القواميس على ترتيب الإدخال) يعيد أول زوج يُصادَف أثناء المسح. أما تطبيق subword-nmt المنشور فيختار بـ max(stats, key=lambda x: (stats[x], x))، الذي يفضّل الزوج الأكبر معجميًا بين المتعادلين. على هذه المدوّنة تتفق هذه القاعدة مع الشرائح في الدمج 1، فتختار (n, e) لأن n تأتي بعد e في الترتيب، لكنها في الدمج 3 تختار (r, e) بدلًا من (_, r). دورة Hugging Face تنص على اصطلاح الظهور الأول صراحة: عندما يكون هناك خيار بين الأزواج الأكثر تكرارًا، يُختار أول زوج يُصادَف. مكتبة 🤗 Tokenizers تكسر التعادل بمعرّفات الوحدات الداخلية، والخيار الأبجدي في المحاكي يأخذ أصغر زوج.

The simulator lets you switch between first-seen and alphabetical order, and on this corpus the very first merge already differs: alphabetical order picks (e, w) over (n, e), so the vocabulary ends with ew where the slides have ne, even though the corpus rows after four merges are identical. That is exactly why an exam answer must state its rule.

يتيح لك المحاكي التبديل بين ترتيب الظهور الأول والترتيب الأبجدي، وعلى هذه المدوّنة يختلف الدمج الأول نفسه: الترتيب الأبجدي يختار (e, w) بدلًا من (n, e)، فتنتهي المفردات بـ ew حيث في الشرائح ne، رغم أن صفوف المدوّنة بعد أربع دمجات متطابقة. ولهذا بالضبط يجب أن تذكر إجابة الامتحان قاعدتها.

First pair seen (slides)أول زوج يُرى (الشرائح)Alphabetical (smallest first)أبجدي (الأصغر أولًا)
Merge 1الدمج 1ne (tied with ew, seen first)ne (متعادل مع ew، وظهر أولًا)ew (tied with ne, ew < ne)ew (متعادل مع ne، وew < ne)
Merge 2الدمج 2new from (ne, w)new من (ne, w)new from (n, ew)new من (n, ew)
Merge 3الدمج 3_r (tied with re, seen first)_r (متعادل مع re، وظهر أولًا)_r (tied with re, _ sorts first)_r (متعادل مع re، و_ تأتي أولًا في الترتيب)
Merge 4الدمج 4_re_re_re_re
Learned tokensالوحدات المتعلَّمةne, new, _r, _rene, new, _r, _reew, new, _r, _reew, new, _r, _re
Corpus after k = 4المدوّنة بعد k = 42 × _ new, 2 × _re new, s e t, _re s e t2 × _ new, 2 × _re new, s e t, _re s e t2 × _ new, 2 × _re new, s e t, _re s e t2 × _ new, 2 × _re new, s e t, _re s e t
The same corpus under two tie rules, k = 4المدوّنة نفسها تحت قاعدتين لكسر التعادل، k = 4

The order of the rows matters too, because "first encountered" depends on it. The slides list the four rows by count, most frequent first, and so does SLP3. Jurafsky and Martin continue the same trace past the slides: merges five to seven are _new, _renew and se, each decided by a tie at count 2, and merge eight, set, is then forced because (se, t) is the only pair left at 2. The simulator reproduces that order exactly when its rows are listed the same way.

ترتيب الصفوف مهم أيضًا، لأن "أول ما يُصادَف" يعتمد عليه. الشرائح ترتب الصفوف الأربعة حسب العدد، الأكثر تكرارًا أولًا، وكذلك SLP3. يواصل Jurafsky وMartin التتبّع نفسه بعد الشرائح: الدمجات من الخامس إلى السابع هي _new و_renew وse، وكل منها حسمه تعادل عند العدد 2، ثم يُفرض الدمج الثامن، set، لأن (se, t) هو الزوج الوحيد المتبقي عند 2. يعيد المحاكي إنتاج هذا الترتيب بالضبط عندما تُرتب صفوفه بالطريقة نفسها.

What the space marker does to the learned unitsماذا يفعل وسم المسافة بالوحدات المتعلَّمة

The marker is not cosmetic. Because this deck attaches it to the start of a word, the trainer learned _re, a word-initial piece, and that token is different from a re that occurs inside a word, as in _ c a re, which never merges into _re. Jurafsky and Martin put it this way: the system has essentially induced that there is a word-initial prefix re- (SLP3, section 2.4). This leading-marker convention is the one used by GPT-2, whose byte-level tokenizer shows the space as Ġ, and by SentencePiece, which shows it as ▁ (U+2581); in both, the space rides on the following word (Hugging Face tokenizers documentation). It also explains why set in the trace never carries a marker: it is the first word of the string, so no space precedes it, and s e t and _ s e t are different strings to the trainer.

الوسم ليس تجميليًا. لأن هذه الشرائح تلصقه ببداية الكلمة، تعلّم المدرِّب _re، وهي قطعة في بداية الكلمة، وهذه الوحدة تختلف عن re التي تظهر داخل كلمة، كما في _ c a re، التي لا تندمج أبدًا في _re. يعبّر Jurafsky وMartin عن ذلك هكذا: لقد استنتج النظام فعليًا أن هناك سابقة في بداية الكلمة هي re- (SLP3، القسم 2.4). اصطلاح الوسم البادئ هذا هو الذي يستخدمه GPT-2، الذي يُظهر مقطِّعه على مستوى البايت المسافة على شكل Ġ، وSentencePiece، الذي يُظهرها على شكل ▁ (U+2581)؛ وفي كليهما تركب المسافة على الكلمة التالية (توثيق Hugging Face tokenizers). وهذا يفسر أيضًا لماذا لا تحمل set في التتبّع وسمًا أبدًا: إنها الكلمة الأولى في السلسلة فلا تسبقها مسافة، وs e t و_ s e t سلسلتان مختلفتان بالنسبة للمدرِّب.

The original paper did it the other way round. Sennrich, Haddow and Birch appended a special end-of-word symbol to every word so that the original tokenization could be restored after translation, and older SLP3 drafts followed them with the corpus low lowest newer wider new (Sennrich's own listing uses low lower newest widest). Under that convention every word gets a marker, the marker sits at the end, and the prefix would be learned as plain re.

الورقة الأصلية فعلت العكس. ألحق Sennrich وHaddow وBirch رمزًا خاصًا لنهاية الكلمة بكل كلمة حتى يمكن استعادة التقطيع الأصلي بعد الترجمة، وتبعتهم مسودات SLP3 الأقدم بالمدوّنة low lowest newer wider new (القائمة الخاصة بـ Sennrich تستخدم low lower newest widest). وفق هذا الاصطلاح تحصل كل كلمة على وسم، ويقع الوسم في النهاية، وكانت السابقة ستُتعلَّم على شكل re عادية.

Leading marker (this deck)الوسم البادئ (هذه الشرائح)End-of-word suffix (Sennrich 2016)لاحقة نهاية الكلمة (Sennrich 2016)
Where the marker sitsموضع الوسمBefore the word: _new, _reقبل الكلمة: _new، _reAfter the word: new·, set·بعد الكلمة: new·، set·
First word of the stringالكلمة الأولى في السلسلةNo marker: set stays s e tبلا وسم: set تبقى s e tMarker like every word: s e t ·بوسم مثل كل كلمة: s e t ·
Prefix re- is learned asالسابقة re- تُتعلَّم على شكل_re, distinct from word-internal re_re، المختلفة عن re الواقعة داخل الكلمةre, identical to word-internal rere، المطابقة لـ re الواقعة داخل الكلمة
Used byيستخدمهThis deck, current SLP3, GPT-2 (Ġ), SentencePiece (▁)هذه الشرائح، وSLP3 الحالي، وGPT-2 (Ġ)، وSentencePiece (▁)Sennrich et al. 2016, older SLP3 draftsSennrich et al. 2016، ومسودات SLP3 الأقدم
Leading space marker versus end-of-word suffixوسم المسافة البادئ مقابل لاحقة نهاية الكلمة

Quick checkاختبار سريع

After merging ne and new on 'set new new renew reset renew', which pair wins merge 3 under first-seen tie-breaking?بعد دمج ne وnew على 'set new new renew reset renew'، أي زوج يفوز بالدمج 3 تحت قاعدة كسر التعادل بالظهور الأول؟

Recall

After merges ne, new, _r and _re on 'set new new renew reset renew', list the vocabulary and the corpus.بعد الدمجات ne وnew و_r و_re على 'set new new renew reset renew'، اسرد المفردات والمدوّنة.

Vocabulary: _, e, n, r, s, t, w, ne, new, _r, _re (11 items). Corpus: 2 × _ new, 2 × _re new, 1 × s e t, 1 × _re s e t, 15 symbols instead of 29.
المفردات: _, e, n, r, s, t, w, ne, new, _r, _re (11 عنصرًا). المدوّنة: 2 × _ new، 2 × _re new، 1 × s e t، 1 × _re s e t، أي 15 رمزًا بدلًا من 29.

Recall

Step 1 counts (n, e) = 4 and (e, w) = 4. What does the pseudocode say about the tie, and what do real implementations do?الخطوة 1 تعدّ (n, e) = 4 و(e, w) = 4. ماذا تقول الشيفرة الزائفة عن التعادل، وماذا تفعل التطبيقات الحقيقية؟

Nothing. The paper's minimal listing and the Hugging Face tutorial take the first pair encountered in the corpus. The released subword-nmt code takes the lexicographically largest tied pair, and other libraries use yet other rules, so an exam answer should state the rule it uses.
لا شيء. القائمة المختصرة في الورقة ودرس Hugging Face يأخذان أول زوج يُصادَف في المدوّنة. شيفرة subword-nmt المنشورة تأخذ الزوج المتعادل الأكبر معجميًا، ومكتبات أخرى تستخدم قواعد أخرى أيضًا، لذلك يجب أن تذكر إجابة الامتحان القاعدة التي تستخدمها.

Recall

How does the leading space marker change what is learned?كيف يغيّر وسم المسافة البادئ ما يُتعلَّم؟

Word-initial pieces such as _re become tokens distinct from word-internal re. The first word of the string carries no marker, so set and _set are different strings. With Sennrich's end-of-word suffix instead, every word ends in the marker and the prefix would be learned as plain re.
القطع التي في بداية الكلمة مثل _re تصبح وحدات مختلفة عن re الواقعة داخل الكلمة. الكلمة الأولى في السلسلة لا تحمل وسمًا، لذلك set و_set سلسلتان مختلفتان. ومع لاحقة نهاية الكلمة عند Sennrich بدلًا من ذلك، تنتهي كل كلمة بالوسم، وكانت السابقة ستُتعلَّم على شكل re عادية.

Training is over. The merge list ne, new, _r, _re is frozen, and a word arrives that the trainer never saw: renewed, with its leading space. The encoder does not count anything. It writes the word as characters and replays the four merges, first to last.

انتهى التدريب. قائمة merge وهي ne, new, _r, _re مجمّدة، وتصل كلمة لم يرها المدرِّب قط: renewed، مع مسافتها البادئة. المرمِّز لا يعدّ أي شيء. إنه يكتب الكلمة حروفًا ويعيد تطبيق الدمجات الأربع، من الأول إلى الأخير.

Worked exampleمثال محلول

Encoding three words with the four learned mergesترميز ثلاث كلمات بالدمجات الأربع المتعلَّمة

  1. _renewed, an unseen word_renewed، كلمة لم تُرَ من قبل

    Start from _ r e n e w e d, eight symbols. Merge 1 (n e) applies: _ r e ne w e d. Merge 2 (ne w) applies: _ r e new e d. Merge 3 (_ r) applies: _r e new e d. Merge 4 (_r e) applies: _re new e d. Four tokens, all in the vocabulary, no unknown.
    ابدأ من _ r e n e w e d، ثمانية رموز. الدمج 1 (n e) ينطبق: _ r e ne w e d. الدمج 2 (ne w) ينطبق: _ r e new e d. الدمج 3 (_ r) ينطبق: _r e new e d. الدمج 4 (_r e) ينطبق: _re new e d. أربع وحدات، كلها في المفردات، ولا وحدة مجهولة.
  2. _newest, where two merges do not apply_newest، حيث لا ينطبق دمجان

    _ n e w e s t becomes _ ne w e s t, then _ new e s t. Merges 3 and 4 look for _ r and _r e, find neither, and are skipped. Output _ new e s t. The marker stays separate because (_, new) was merge 5 in the book's longer run and is not in this list.
    _ n e w e s t تصبح _ ne w e s t، ثم _ new e s t. الدمجان 3 و4 يبحثان عن _ r و_r e، فلا يجدان أيًّا منهما، فيُتخطّيان. الناتج _ new e s t. يبقى الوسم منفصلًا لأن (_, new) كان الدمج 5 في التشغيل الأطول في الكتاب، وليس في هذه القائمة.
  3. set at the start of a sentenceset في بداية الجملة

    No leading marker, so the input is s e t. None of the four merges mentions s or t, so the output is s e t, three tokens. With k = 8 it would be the single token set.
    لا وسم بادئ، فالمدخل هو s e t. لا يذكر أي من الدمجات الأربع s أو t، فالناتج s e t، ثلاث وحدات. ومع k = 8 كانت ستصبح الوحدة الواحدة set.
  4. The encoder is a replayالمرمِّز إعادة تشغيل

    Same list, same order, every input. _renewed is a word the model has never seen, tokenized entirely from pieces it has.
    القائمة نفسها، والترتيب نفسه، لكل مدخل. _renewed كلمة لم يرها النموذج قط، وقد قُطّعت بالكامل من قطع يعرفها.

Try the same replay on words of your own. The panel below starts from the four slide merges; type newest, reset or an Arabic transliteration, tick sentence-initial to drop the marker, and raise k to watch _new and set collapse into single tokens once merges five to eight exist.

جرّب إعادة التشغيل نفسها على كلمات من اختيارك. تبدأ اللوحة أدناه من دمجات الشريحة الأربع؛ اكتب newest أو reset أو كلمة عربية منقحرة بحروف لاتينية، وفعّل خيار بداية الجملة لإسقاط الوسم، وارفع k لترى _new وset تنضمّان في وحدات مفردة بمجرد وجود الدمجات من الخامس إلى الثامن.

SimulatorمحاكيEncoder replay: a frozen merge list applied to any wordإعادة تشغيل المرمِّز: قائمة دمج مجمدة تُطبَّق على أي كلمة
k = 4
Merge list, in learned orderقائمة الدمج بترتيب تعلُّمها
  1. 1.ne
  2. 2.new
  3. 3._r
  4. 4._re
  1. charactersالمحارف_renewed
  2. 1. n+e_renewed
  3. 2. ne+w_renewed
  4. 3. _+r_renewed
  5. 4. _r+e_renewed
  6. outputالناتج_re new e d (4 tokens)(4 رموز)

The encoder never counts anything. It replays the merge list top to bottom; a merge whose pair does not occur in the word is skipped.المرمِّز لا يعدّ أي شيء. إنه يعيد تطبيق قائمة الدمج من أعلاها إلى أسفلها، ويتخطى كل دمج لا يظهر زوجه في الكلمة.

A playhead sweeps the frozen merge list left to right while the string below changes at each stamp. The crossed-out tally is the rule: the encoder never counts.رأس تشغيل يمسح قائمة الدمجات المجمّدة من اليسار إلى اليمين بينما تتغير السلسلة أدناه عند كل ختم. العدّاد المشطوب هو القاعدة: المرمِّز لا يعدّ أبدًا.

The rule behind the trace is short. To tokenize a new string, start from characters or bytes, apply the learned merges in the order they were learned, and output the resulting subword sequence. The slide calls this "greedy": each merge fires on every place it matches as soon as its turn comes, the encoder never goes back, and it never searches for the longest vocabulary entry. Jurafsky and Martin are exact about what the encoder does not do: it just runs on the test data the merges learned from the training data, in the order they were learned, and the frequencies in the test data play no role, only the frequencies in the training data (SLP3, section 2.4). Sennrich describes the same procedure: split words into sequences of characters, then apply the learned operations to merge the characters into larger known symbols. Because the list is fixed, the output is deterministic: the same input always yields the same tokens, which is what lets a model trained on one tokenization be served with it later.

القاعدة وراء التتبّع قصيرة. لتقطيع سلسلة جديدة، ابدأ من الحروف أو البايتات، وطبّق الدمجات المتعلَّمة بالترتيب الذي تُعلِّمت به، وأخرج تسلسل الوحدات الفرعية الناتج. تسمي الشريحة هذا "جشعًا" (greedy): كل دمج يُطلَق على كل موضع يطابقه بمجرد أن يحين دوره، والمرمِّز لا يعود إلى الوراء أبدًا، ولا يبحث أبدًا عن أطول عنصر في المفردات. Jurafsky وMartin دقيقان بشأن ما لا يفعله المرمِّز: إنه يشغّل فقط على بيانات الاختبار الدمجات التي تعلّمها من بيانات التدريب، بالترتيب الذي تُعلِّمت به، والتكرارات في بيانات الاختبار لا دور لها، فقط التكرارات في بيانات التدريب (SLP3، القسم 2.4). ويصف Sennrich الإجراء نفسه: قسّم الكلمات إلى تسلسلات من الحروف، ثم طبّق العمليات المتعلَّمة لدمج الحروف في رموز معروفة أكبر. ولأن القائمة ثابتة فالناتج حتمي: المدخل نفسه يعطي دائمًا الوحدات نفسها، وهذا ما يتيح تقديم نموذج دُرِّب على تقطيع معيّن بالتقطيع نفسه لاحقًا.

encode(w)=mk(⋯m2(m1(chars(w))))\text{encode}(w) = m_k(\cdots m_2(m_1(\text{chars}(w))))
The merges compose in learned order; nothing is recomputedتُطبَّق عمليات الدمج بالترتيب المتعلَّم؛ ولا يُعاد حساب شيء

Order is not a convention but a dependency. Merge 2 joins ne and w, and ne only exists if merge 1 has already run; merge 4 needs _r from merge 3 in the same way. Replaying the list out of order would produce segmentations that never occurred during training, so the model would receive token ids it has no experience of, even though every id is technically in the vocabulary. With tens of thousands of merges, most words in ordinary text are covered by a single token and only rare words break into pieces, which is the interpolation between word and character level that the GPT-2 paper describes (Radford et al., 2019).

الترتيب ليس اصطلاحًا بل اعتمادية. الدمج 2 يضم ne وw، وne لا توجد إلا إذا كان الدمج 1 قد نُفِّذ؛ والدمج 4 يحتاج _r من الدمج 3 بالطريقة نفسها. إعادة تطبيق القائمة بغير ترتيبها ستنتج تقسيمات لم تحدث قط أثناء التدريب، فيتلقى النموذج معرّفات وحدات لا خبرة له بها، رغم أن كل معرّف موجود تقنيًا في المفردات. ومع عشرات الآلاف من الدمجات، تغطي وحدة واحدة معظم الكلمات في النص العادي، ولا تتكسر إلى قطع إلا الكلمات النادرة، وهذا هو التدرّج بين مستوى الكلمة ومستوى الحرف الذي تصفه ورقة GPT-2 (Radford et al., 2019).

Trainerالمدرِّب (trainer)Encoderالمرمِّز (encoder)
InputالمدخلA training corpus with word countsمدوّنة تدريب مع أعداد الكلماتOne new stringسلسلة جديدة واحدة
Counts pair frequenciesيعدّ تكرارات الأزواجYes, at every stepنعم، في كل خطوةNeverأبدًا
OutputالمخرجA vocabulary plus an ordered merge listمفردات مع قائمة دمجات مرتبةA token sequenceتسلسل من الوحدات
Runsمتى يعملOnce, before any model is trainedمرة واحدة، قبل تدريب أي نموذجOn every input, forever afterعلى كل مدخل، إلى الأبد بعد ذلك
Hyperparameterالمعامل الفائق (hyperparameter)k, the number of mergesk، عدد الدمجاتNone; the merge list is fixedلا شيء، فقائمة الدمجات ثابتة
Trainer and encoder side by sideالمدرِّب والمرمِّز جنبًا إلى جنب

One last coverage detail depends on the base symbols. A character-level BPE trained on English letters still has a hole: the Hugging Face course shows mug encoding as [UNK] ug because m never appeared in its toy corpus, so it is not in the vocabulary at all. A byte-level tokenizer starts from all 256 byte values, so any UTF-8 string, including Arabic, emoji and typos, is encodable and the UNK special token is never needed (Radford et al., 2019; Hugging Face tokenizers documentation). The next part looks at what this does to non-Latin scripts.

تفصيل أخير في التغطية يعتمد على الرموز الأساسية. BPE على مستوى الحرف مدرَّب على الحروف الإنجليزية ما زال فيه ثغرة: دورة Hugging Face تُظهر mug تُرمَّز على شكل [UNK] ug لأن m لم تظهر قط في مدوّنتها الصغيرة، فهي ليست في المفردات أصلًا. أما مقطِّع byte-level فيبدأ من كل قيم البايت الـ 256، لذلك أي سلسلة UTF-8، بما في ذلك العربية والرموز التعبيرية والأخطاء الطباعية، قابلة للترميز، ولا حاجة أبدًا إلى special token UNK (Radford et al., 2019؛ توثيق Hugging Face tokenizers). الجزء التالي ينظر في أثر ذلك على الكتابات غير اللاتينية.

Quick checkاختبار سريع

When BPE encodes new text, what decides which merges are applied?عندما يرمّز BPE نصًا جديدًا، ما الذي يحدد أي الدمجات تُطبَّق؟

Recall

With merges ne, new, _r, _re learned in that order, how is the unseen word '_renewal' encoded, and why can no other segmentation occur?مع الدمجات ne وnew و_r و_re متعلَّمة بهذا الترتيب، كيف تُرمَّز الكلمة غير المرئية '_renewal'، ولماذا لا يمكن أن يحدث تقسيم آخر؟

Start from _ r e n e w a l. Merge 1 gives _ r e ne w a l, merge 2 gives _ r e new a l, merge 3 gives _r e new a l, and merge 4 gives _re new a l, four tokens. Nothing in the list ever joins a to l, and no merge produces a bare re, so segmentations such as _r e new a l or _ re new al are unreachable.
ابدأ من _ r e n e w a l. الدمج 1 يعطي _ r e ne w a l، والدمج 2 يعطي _ r e new a l، والدمج 3 يعطي _r e new a l، والدمج 4 يعطي _re new a l، أي أربع وحدات. لا شيء في القائمة يضم a إلى l أبدًا، ولا دمج ينتج re مجردة، لذلك تقسيمات مثل _r e new a l أو _ re new al غير قابلة للوصول.

Recall

Why must the encoder apply merges in the order they were learned?لماذا يجب أن يطبّق المرمِّز الدمجات بالترتيب الذي تُعلِّمت به؟

Later merges are built from earlier ones: new can only form after ne exists, and _re only after _r. The model was also trained on token sequences produced by that exact order, so a different order produces segmentations it has never seen.
الدمجات اللاحقة مبنية من السابقة: new لا تتكوّن إلا بعد وجود ne، و_re لا تتكوّن إلا بعد _r. كما أن النموذج دُرِّب على تسلسلات وحدات أنتجها ذلك الترتيب بالضبط، لذلك ينتج ترتيب مختلف تقسيمات لم يرها قط.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • Tokenization converts text into the units a model operates on; the unit choice trades coverage, compactness, meaningfulness and cross-lingual reach.يحوّل التقطيع (tokenization) النص إلى الوحدات التي يعمل عليها النموذج، واختيار الوحدة مفاضلة بين التغطية والإيجاز والدلالة والصلاحية عبر اللغات.
  • Words: meaningful but ambiguous, huge vocabularies, OOV. Characters: tiny vocabulary, no OOV, very long sequences. Subwords: the middle ground modern LMs use.الكلمات: ذات معنى لكنها ملتبسة، ومفرداتها ضخمة، وتعاني من مشكلة OOV. الحروف: مفردات صغيرة جدًا ولا OOV، لكن التسلسلات طويلة جدًا. الوحدات الفرعية (subwords): الحل الوسط الذي تستخدمه النماذج اللغوية الحديثة.
  • BPE has a trainer and an encoder. The trainer starts from characters or bytes and merges the most frequent adjacent pair k times, so |V| = initial symbols + k.لـ BPE جزءان: مدرِّب (trainer) ومرمِّز (encoder). يبدأ المدرِّب من الحروف أو البايتات ويدمج الزوج المتجاور الأكثر تكرارًا k مرة، لذلك |V| = عدد الرموز الأولية + k.
  • On 'set new new renew reset renew' the first four merges are ne (4), new (4), _r (3), _re (3), giving 11 vocabulary items and a corpus of 15 symbols instead of 29.على 'set new new renew reset renew' تكون الدمجات الأربع الأولى ne (4) ثم new (4) ثم _r (3) ثم _re (3)، فينتج 11 عنصرًا في المفردات ومدوّنة من 15 رمزًا بدلًا من 29.
  • Two of those four steps were ties. The pseudocode does not break ties; first-seen order gives ne, alphabetical order gives ew, so always state your rule.خطوتان من هذه الخطوات الأربع كانتا تعادلًا. الشيفرة الزائفة لا تحدد كيف يُكسر التعادل؛ ترتيب الظهور الأول يعطي ne والترتيب الأبجدي يعطي ew، فاذكر قاعدتك دائمًا.
  • The leading space marker (GPT-2's Ġ, SentencePiece's ▁) makes _re a word-initial token. Sennrich's original code used an end-of-word suffix instead.وسم المسافة البادئ (Ġ في GPT-2 و▁ في SentencePiece) يجعل _re وحدة تقع في بداية الكلمة. أما شيفرة Sennrich الأصلية فاستخدمت لاحقة نهاية الكلمة بدلًا منه.
  • The encoder replays merges in learned order and never counts frequencies. '_renewed' becomes _re new e d with no unknown token.يعيد المرمِّز تطبيق الدمجات بترتيب تعلّمها ولا يعدّ أي تكرارات أبدًا. تصبح '_renewed' هي _re new e d دون أي وحدة مجهولة.
  • BPE units are frequent substrings, morphemes only by accident.وحدات BPE سلاسل فرعية متكررة، ولا تكون صرفيمات (morphemes) إلا بالمصادفة.

Sourcesالمصادر