Majid Al-RaimiReference sheetالورقة المرجعية

ICS 582Lecture 02المحاضرة 02Referenceالمرجع

Reference sheetالورقة المرجعية

Words and tokens compressed onto one page: the definitions, formulas and numbers to have in your head before a quiz or exam.محاضرة «الكلمات والرموز (Tokens)» مضغوطة في صفحة واحدة: التعريفات والمعادلات والأرقام التي يجب أن تكون حاضرة في ذهنك قبل الاختبار القصير أو الامتحان.

Tokens, types and vocabularyالوحدات والأنواع والمفردات

A token is one occurrence, counted by N. A type is one distinct vocabulary item, counted by |V|. The count is never a property of the language: it follows from the policy. Part 01: What is a word

الوحدة (token) هي ظهور واحد، ويعدّها N. والنوع (type) هو عنصر مفردات مميز واحد، ويعدّه |V|. والعدد ليس أبدًا خاصية للغة، بل ينتج من السياسة المتبعة. الجزء 01: ما الكلمة

N=∑w∈Vc(w)N = \sum_{w \in V} c(w)
Every token belongs to exactly one type, so the type counts add up to Nكل رمز ينتمي إلى نوع واحد بالضبط، لذلك مجموع تكرارات الأنواع يساوي N
PolicyالسياسةTokens Nالوحدات NTypes |V|الأنواع |V|
Whitespace onlyالمسافات فقط1614
Punctuation splitفصل علامات الترقيم1816
The picnic sentence under two policiesجملة النزهة وفق سياستين

Definitions worth memorizingتعريفات تستحق الحفظ

Tokenالوحدة
One occurrence in running text; the total is N.ظهور واحد في النص المتصل، ومجموعها N.
Typeالنوع
A distinct vocabulary item; the total is |V|, the vocabulary size.عنصر مفردات مميز، ومجموعها |V|، أي حجم المفردات.
Lemmaالصيغة المعجمية
The dictionary form shared by a word family: walk, walks, walked, walking.صيغة القاموس المشتركة بين أفراد عائلة كلمات واحدة: walk, walks, walked, walking.
Hapax legomenonالكلمة الفريدة
A type seen exactly once; about half the types of a natural corpus.نوع يظهر مرة واحدة بالضبط (hapax legomenon)، ويشكل نحو نصف أنواع أي مدوّنة طبيعية.
Out of vocabularyخارج المفردات
A test-time token absent from V; unavoidable at the word level.وحدة تظهر وقت الاختبار وليست في V، وهذا لا مفر منه على مستوى الكلمة.
Type to token ratioنسبة الأنواع إلى الوحدات
|V| / N, which falls as N grows.|V| / N، وتنخفض كلما زاد N.
CorpusالمدوّنةTypes |V|الأنواع |V|Tokens Nالوحدات NTypes per 1,000الأنواع لكل 1,000
Shakespeare31 k884 k35.1
Brown38 k1 M38.0
Switchboard20 k2.4 M8.3
COCA2 M440 M4.5
Google n-grams13 M1 T0.013
One table of English corpora, with types per 1,000 tokens computedجدول واحد لمدوّنات إنجليزية، مع حساب عدد الأنواع لكل 1,000 وحدة

Zipf and Heapsقانونا Zipf وHeaps

Frequency follows a steep power law and vocabulary follows a sublinear power law. Both are straight lines on log axes. Part 02: Zipf and Heaps

يتبع التكرار قانون قوة حادًا (power law)، ويتبع حجم المفردات قانون قوة دون خطي (sublinear). وكلاهما خط مستقيم على محاور لوغاريتمية. الجزء 02: قانونا Zipf وHeaps

f(R)∝1Rαf(R)≈f(1)Rαf(R) \propto \frac{1}{R^{\alpha}} \qquad f(R) \approx \frac{f(1)}{R^{\alpha}}
Zipf's law: the frequency of the rank R typeقانون Zipf: تكرار النوع ذي الرتبة R
log⁡f=log⁡C−αlog⁡R\log f = \log C - \alpha \log R
Log frequency falls linearly in log rank with slope minus alphaلوغاريتم التكرار يهبط خطيًا مع لوغاريتم الرتبة بميل سالب alpha
f(R)=P(R+ρ)−Bf(R) = P (R + \rho)^{-B}
Mandelbrot's refined form, which flattens the lowest ranksصيغة Mandelbrot المحسَّنة، التي تسطّح الرتب الأولى
∣V∣=kNβ|V| = k N^{\beta}
Heaps' law, also Herdan's lawقانون Heaps، ويُسمى أيضًا قانون Herdan
Fitالمطابقةkkbetabetaat 10^4عند 10^4at 10^6عند 10^6at 10^8عند 10^8
English (dotted)الإنجليزية (dotted)14.9470.5833,21047,049689,531
Arabic (dotted)العربية المنقوطة73.3210.5332,576115,6725,193,404
Arabic (undotted)العربية غير المنقوطة90.4910.5062,84698,3123,396,228
Heaps fits and predicted vocabulary sizeمطابقات Heaps وحجم المفردات المتوقع

Sample numbers worth quotingأرقام من العينة تستحق الاستشهاد بها

Tom Sawyer
71,370 tokens and 8,018 types.71,370 وحدة و8,018 نوعًا.
Top typeالنوع الأعلى
the at 3,332, then and at 2,972, then a at 1,775.the بتكرار 3,332، ثم and بتكرار 2,972، ثم a بتكرار 1,775.
Zipf checkالتحقق من Zipf
The product of frequency and rank holds near 8,000 to 10,000 over the top ranks.يبقى حاصل ضرب التكرار في الرتبة قريبًا من 8,000 إلى 10,000 عبر الرتب العليا.
Printed slipخطأ مطبعي
Manning and Schütze print 5,235 for a at rank 3; the arithmetic gives 1,775 x 3 = 5,325.يطبع Manning وSchütze القيمة 5,235 لـ a في الرتبة 3، بينما يعطي الحساب 1,775 x 3 = 5,325.
Coverageالتغطية
The top 100 types are 50.9% of all tokens.أعلى 100 نوع تمثل 50.9% من كل الوحدات.
Tailالذيل
The frequency staircase collapses at f = 3, 2, 1, where thousands of types tie.ينهار درج التكرارات عند f = 3, 2, 1، حيث تتعادل آلاف الأنواع.
Hapax shareنسبة الكلمات الفريدة
49.8% of Tom Sawyer types occur once.49.8% من أنواع Tom Sawyer تظهر مرة واحدة.

Morphemes and word structureالوحدات الصرفية وبنية الكلمة

The meaningful parts inside a word explain why walk, walks and walked are three types but one lemma. Part 03: Morphemes

الأجزاء ذات المعنى داخل الكلمة تفسر لماذا تكون walk وwalks وwalked ثلاثة أنواع لكنها جذر معجمي واحد (lemma). الجزء 03: الوحدات الصرفية

Morphemeالوحدة الصرفيةPositionالموضعFree or boundحرة أو مقيدةFunctionالوظيفةExampleمثال
un-PrefixبادئةBoundمقيدةNegationالنفيunhappy
happyRootجذرFreeحرةLexical coreالنواة المعجميةunhappiness
-nessSuffixلاحقةBoundمقيدةNominalizerتحويل إلى اسم (nominalizer)happiness
-sSuffixلاحقةBoundمقيدةInflectional pluralجمع تصريفيcats
abso-bloody-lutelyInfixداخلة (infix)BoundمقيدةIntensifierتكثيف وتوكيدabso-bloody-lutely
ge- ... -tCircumfixزائدة محيطة (circumfix)BoundمقيدةParticipleاسم المفعول (participle)gespielt
Morpheme types in unhappiness and beyondأنواع الوحدات الصرفية في unhappiness وما بعدها
ProcessالعمليةWhat changesما الذي يتغيرLexicon effectالأثر في المعجمExampleمثال
Inflectionالتصريف (inflection)Same lexeme, grammatical featuresالوحدة المعجمية نفسها، مع سمات نحويةPhrase stays the sameتبقى العبارة كما هيwalk to walks, walkedwalk إلى walks, walked
Derivationالاشتقاق (derivation)New lexeme, new meaning or categoryوحدة معجمية جديدة، بمعنى جديد أو فئة جديدةNew lexical entryمدخل معجمي جديدhappy to un+happy+nesshappy إلى un+happy+ness
Conversionالتحويل (conversion)No affix at all, category changesلا زائدة إطلاقًا، وتتغير الفئةZero derivationاشتقاق صفري (zero derivation)an email to to emailan email إلى to email
Inflection, derivation and conversionالتصريف والاشتقاق والتحويل

Arabic root and patternالجذر والوزن في العربية

Rootالجذر
K-T-B
kataba
Pattern CaCaCa, he wrote.الوزن CaCaCa، كَتَبَ.
kitāb
Pattern CiCāC, book.الوزن CiCāC، كِتاب.
kātib
Pattern CāCiC, writer.الوزن CāCiC، كاتِب.
yaktubu
Prefix ya- around CCuC plus suffix -u, he writes.البادئة ya- حول CCuC مع اللاحقة -u، يَكتُبُ.
Non-concatenativeالصرف غير التسلسلي
Ablaut and suppletion: sing, sang, sung; go, went; good, better.التبدل الصوتي الداخلي (ablaut) والإبدال الكامل (suppletion): sing, sang, sung، وgo, went، وgood, better.
  • Four decision tests for an affix: the lexeme test, the category test, the productivity test and the position test. Give at least two in an answer.أربعة اختبارات لتحديد الزائدة: اختبار الوحدة المعجمية (lexeme)، واختبار الفئة (category)، واختبار الإنتاجية (productivity)، واختبار الموقع (position). اذكر اثنين منها على الأقل في الإجابة.
  • Agglutinative stacking keeps seams visible: Turkish ev-ler-im-den is house, plural, first person possessive, ablative.التراكب الإلصاقي (agglutinative) يُبقي الحدود بين الأجزاء ظاهرة: الكلمة التركية ev-ler-im-den تعني بيت، جمع، ملكية المتكلم المفرد، حالة المصدر بمعنى "من" (ablative).

Clitics and typologyاللواصق والتصنيف اللغوي

A clitic sits between a word and an affix. Zwicky and Pullum's tests, selectivity, paradigm membership, arbitrary gaps, idiosyncrasy, syntactic rules and stacking, decide which side. Part 04: Clitics and typology

اللاصقة (clitic) تقع بين الكلمة والزائدة (affix). واختبارات Zwicky وPullum تحدد إلى أي جانب تنتمي: الانتقائية (selectivity)، والانتماء إلى الجدول الصرفي (paradigm)، والفجوات الاعتباطية (arbitrary gaps)، والخصوصية (idiosyncrasy)، والقواعد النحوية، والتراكب (stacking). الجزء 04: اللواصق والتصنيف اللغوي

FormالصيغةStatusالحالةSelectivityالانتقائيةEvidenceالدليل
wa-Procliticلاصقة سابقة (proclitic)Low: conjunctionsمنخفضة: أدوات العطفSlide 28, ATB keeps it separateالشريحة 28، ويُبقيها ATB منفصلة
bi-Procliticلاصقة سابقة (proclitic)Low: prepositionsمنخفضة: حروف الجرPOS varies with hostيتغير قسم الكلام (POS) بحسب المضيف
al-Borderlineحالة حدّيةModerate: definitenessمتوسطة: التعريفATB keeps it, D3 splits itيُبقيها ATB ويفصلها D3
-huEncliticلاصقة لاحقة (enclitic)Low: nouns, verbs, prepositionsمنخفضة: الأسماء والأفعال وحروف الجرAttaches across categoriesتلتصق عبر الفئات
-tuInflectional affixزائدة تصريفيةHigh: perfective verbs onlyمرتفعة: الأفعال التامة (الماضية) فقطOne paradigm cellخانة واحدة في الجدول الصرفي
Arabic host plus clitic decisionsقرارات المضيف واللاصقة في العربية
PolicyالسياسةTokensالوحداتOutputالناتج
Whitespaceالمسافات1وَبِالْبَيْت
ATB3wa+ bi+ albayt
D34wa+ bi+ al+ bayt
One string, three tokenizations of و بالبيتسلسلة واحدة وثلاثة تقطيعات لـ و بالبيت
TypeالنوعDefinitionالتعريفExampleمثالM/WM/WLanguageاللغة
Isolatingعازلة (isolating)One morpheme per wordوحدة صرفية واحدة في الكلمةwǒmen míngtiān qù Běijīng1.06Mandarinالماندرينية
Agglutinativeإلصاقية (agglutinative)Many morphemes, clear seamsوحدات صرفية كثيرة بحدود واضحةev-ler-im-den2.55Turkishالتركية
Fusionalاندماجية (fusional)Portmanteau morphemesوحدات صرفية مدمجة (portmanteau)habl-o2.59Spanish, Sanskritالإسبانية، السنسكريتية
Polysyntheticمتعددة التركيب (polysynthetic)Many morphemes, often a sentenceوحدات صرفية كثيرة، وكثيرًا ما تكون الكلمة جملة كاملةt-ə-nk'e-mejŋ-ə-jetemə-nni-k3.72Inuktitut, Koryakالإنوكتيتوت، الكورياكية
Typology, with Greenberg's index of synthesis M/Wالتصنيف اللغوي، مع مؤشر التركيب M/W عند Greenberg
LanguageاللغةM/WM/WRounded on the slideالقيمة المقرّبة في الشريحة
Vietnameseالفيتنامية1.06Slide 1.1الشريحة 1.1
Persianالفارسية1.52Slide 1.5الشريحة 1.5
Englishالإنجليزية1.68Slide 1.7الشريحة 1.7
Old Englishالإنجليزية القديمة2.12Slide 2.1الشريحة 2.1
Yakutالياقوتية2.17Slide 2.2الشريحة 2.2
Swahiliالسواحيلية2.55Slide 2.5الشريحة 2.5
Sanskritالسنسكريتية2.59Slide 2.6الشريحة 2.6
Eskimo / Greenlandicالإسكيمو / الغرينلاندية3.72Slide 3.7الشريحة 3.7
Greenberg's index by languageمؤشر Greenberg حسب اللغة
index of synthesis=MW\text{index of synthesis} = \frac{M}{W}
Morphemes per word; bands are analytic under 2, synthetic 2 to 3, polysynthetic over 3المورفيمات لكل كلمة؛ والفئات: تحليلية دون 2، وتركيبية من 2 إلى 3، ومتعددة التركيب فوق 3
TTR=∣V∣N\mathrm{TTR} = \frac{|V|}{N}
Type to token ratio, the diagnostic that falls with corpus sizeنسبة الأنواع إلى الرموز، وهو مؤشر ينخفض مع حجم المدونة

Why morphology decides tokenizer policyلماذا يحدد الصرف سياسة المقطِّع

Nunavut Hansard
10,869,995 Inuktitut tokens give 1,563,883 types, TTR 0.144.10,869,995 وحدة بلغة الإنوكتيتوت تعطي 1,563,883 نوعًا، وTTR تساوي 0.144.
English at the same scaleالإنجليزية بالحجم نفسه
20,367,595 tokens give 59,234 types, TTR 0.003, about 26x fewer types.20,367,595 وحدة تعطي 59,234 نوعًا، وTTR تساوي 0.003، أي أنواع أقل بنحو 26x.
OOVخارج المفردات
A 1.3 million word vocabulary still leaves more than 60% of tokens unknown on a hard language pair (Gupta and Boulianne 2020).حتى مفردات من 1.3 مليون كلمة تترك أكثر من 60% من الوحدات مجهولة في زوج لغوي صعب (Gupta and Boulianne 2020).
Arabic verbsالأفعال العربية
Upwards of 5,400 forms per Modern Standard Arabic verb (Obeid et al.).أكثر من 5,400 صيغة لكل فعل في العربية الفصحى المعاصرة (Obeid et al.).
Three responsesثلاث استجابات
Subword tokenization (BPE, WordPiece), morphological segmentation (MADAMIRA, CAMeL Tools), careful preprocessing.التقطيع إلى وحدات جزئية (BPE، WordPiece)، والتقطيع الصرفي (MADAMIRA، CAMeL Tools)، والمعالجة المسبقة المتأنية.

Corpora, code points and UTF-8المدوّنات والنقاط الرمزية وUTF-8

Unicode assigns each character a code point in U+0000 to U+10FFFF, 1,114,112 positions. UTF-8 encodes each code point as one to four bytes. Part 05: Corpora and Unicode

يخصص Unicode لكل حرف نقطة رمزية (code point) في المدى U+0000 إلى U+10FFFF، أي 1,114,112 موقعًا. ويرمّز UTF-8 كل نقطة رمزية في بايت واحد إلى أربعة بايتات. الجزء 05: المدوّنات وUnicode

a=0x61=0x41+0x20=A  ∨  0x20\text{a} = 0x61 = 0x41 + 0x20 = \text{A} \;\lor\; 0x20
Case folding as a single bit: ASCII letters differ by 0x20توحيد حالة الأحرف (case folding) ببت واحد: أحرف ASCII تختلف بمقدار 0x20
RangeالمدىTemplateالقالبBitsالبتاتBytesالبايتاتExampleمثال
U+0000 to U+007Fمن U+0000 إلى U+007F0xxxxxxx71a = 0x61
U+0080 to U+07FFمن U+0080 إلى U+07FF110yyyyy 10xxxxxx112é = C3 A9
U+0800 to U+FFFFمن U+0800 إلى U+FFFF1110zzzz 10yyyyyy 10xxxxxx163ب = D8 A8
U+010000 to U+10FFFFمن U+010000 إلى U+10FFFF11110uuu 10uuzzzz 10yyyyyy 10xxxxxx214😀 = F0 9F 98 80
UTF-8 byte templates by code point rangeقوالب بايتات UTF-8 حسب مدى النقطة الرمزية
CharacterالحرفCode pointالنقطة الرمزيةUTF-8 bytesبايتات UTF-8
aU+006161
éU+00E9C3 A9
بU+0628D8 A8
€U+20ACE2 82 AC
中U+4E2DE4 B8 AD
ﻻU+FEFBEF BB BB
😀U+1F600F0 9F 98 80
Worked encodingsترميزات محلولة
FormالشكلOperationالعمليةééEquivalenceالتكافؤ
NFDDecomposeتفكيكe + U+0301Canonicalقانوني (canonical)
NFCComposeتركيبU+00E9Canonicalقانوني (canonical)
NFKDCompatibility decomposeتفكيك توافقيE + U+0301Compatibilityتوافقي (compatibility)
NFKCCompatibility composeتركيب توافقيU+00C9Compatibilityتوافقي (compatibility)
The four Unicode normalization formsأشكال التطبيع الأربعة في Unicode
  • Byte sequences starting C0, C1 or anything F5 to FF are never valid UTF-8.تسلسلات البايتات التي تبدأ بـ C0 أو C1 أو بأي قيمة من F5 إلى FF ليست أبدًا UTF-8 صالحًا.
  • UTF-8 is backward compatible with ASCII and self-synchronizing: a lead byte tells you how many bytes follow.UTF-8 متوافق مع ASCII ويعيد المزامنة ذاتيًا (self-synchronizing): البايت القائد يخبرك بعدد البايتات التي تليه.
  • كتاب is four code points and eight bytes, a reminder that byte-level tokenizers see twice the length.كتاب أربع نقاط رمزية وثمانية بايتات، وهذا تذكير بأن المقطِّعات على مستوى البايت ترى ضعف الطول.

Byte-pair encodingترميز أزواج البايتات (BPE)

BPE starts from characters and greedily merges the most frequent adjacent pair, learning a vocabulary from data. Part 06: Tokenization and BPE

يبدأ BPE من الحروف ويدمج بطريقة جشعة (greedy) الزوج المتجاور الأكثر تكرارًا، فيتعلم المفردات من البيانات. الجزء 06: التقطيع وBPE

∣Vfinal∣=∣Vinitial∣+k|V_{\text{final}}| = |V_{\text{initial}}| + k
k merges add k vocabulary entriesk عملية دمج تضيف k مدخلًا إلى المفردات
CriterionالمعيارAchievable at onceقابل للتحقيق معًاWhat it meansما يعنيهEffectالأثر
CoverageالتغطيةNAny character, any scriptأي حرف، وأي نظام كتابةByte fallback has no unknown symbolالاحتياط بالبايتات (byte fallback) لا يترك رمزًا مجهولًا
CompactnessالإيجازNRare words cost few piecesالكلمات النادرة تكلّف قطعًا قليلةFewer tokens per sentenceوحدات أقل في كل جملة
MeaningfulnessالدلالةPieces line up with morphemesالقطع تتطابق مع الوحدات الصرفيةBetter generalization to unseen wordsتعميم أفضل على الكلمات غير المرئية
Cross-lingualتعدد اللغاتNOne vocabulary for many scriptsمفردات واحدة لأنظمة كتابة كثيرةNo language left with a long tailلا تُترك لغة بذيل طويل
The four design criteria a tokenizer must trade offمعايير التصميم الأربعة التي يوازن بينها المقطِّع
MergeالدمجCountالعددSymbols beforeالرموز قبلSymbols afterالرموز بعد
ne42925
new42521
_r32118
_re31815
Merge trace on the slide corpus set new new renew reset renewتتبّع الدمج على مدوّنة الشريحة set new new renew reset renew

Trainer and encoder procedureإجراء المدرِّب والمرمِّز

1. Initialize1. التهيئة
Split every word into characters plus the space marker, then count.قسّم كل كلمة إلى حروف مع علامة المسافة، ثم احسب التكرارات.
2. Count pairs2. عدّ الأزواج
Count every adjacent symbol pair across the corpus.عُدّ كل زوج رموز متجاورين في المدوّنة كلها.
3. Merge3. الدمج
Take the most frequent pair, replace it with a new symbol, record the rule.خذ الزوج الأكثر تكرارًا، واستبدله برمز جديد، وسجّل القاعدة.
4. Repeat4. التكرار
Run k merges; the recorded rules are the tokenizer.نفّذ k عمليات دمج، والقواعد المسجلة هي المقطِّع.
5. Encode5. الترميز
encode(w) = m_k( ... m_1(chars(w))), replaying the merges in order.encode(w) = m_k( ... m_1(chars(w)))، بإعادة تطبيق عمليات الدمج بالترتيب.
Space markerعلامة المسافة
Leading _ (GPT-2 Ġ, SentencePiece ▁ U+2581) or a trailing suffix.علامة _ في البداية (Ġ في GPT-2، و▁ U+2581 في SentencePiece) أو لاحقة في النهاية.
Worked replayإعادة تطبيق محلولة
_renewed encodes as _re new e d.تُرمَّز _renewed إلى _re new e d.
Tie ruleقاعدة كسر التعادل
First seen, alphabetical, lexicographically largest (subword-nmt) or highest token id; the rule is an implementation choice.الأسبق ظهورًا، أو الترتيب الأبجدي، أو الأكبر معجميًا (subword-nmt)، أو أعلى معرّف وحدة (token id)، فالقاعدة اختيار يعود إلى التطبيق.

Tokenizers in practiceالمقطِّعات في التطبيق العملي

A modern tokenizer is a pre-tokenizer plus a subword model plus a normalization and special-token policy. Part 07: Tokenizers in practice

المقطِّع الحديث هو مقطِّع أولي (pre-tokenizer) مع نموذج وحدات جزئية (subword model) مع سياسة للتطبيع والوحدات الخاصة (special tokens). الجزء 07: المقطِّعات في التطبيق العملي

TokenizerالمقطِّعVocabularyالمفرداتTokensالوحدات
GPT-250,25714
cl100k100 k14
o200k200 k13
The same sentence under three tokenizersالجملة نفسها في ثلاثة مقطِّعات
##PatternالنمطMatchesما يطابقه
1's|'t|'re|'ve|'m|'ll|'dEnglish contractionsاختصارات الإنجليزية (contractions)
2 ?\p{L}+Optional space then lettersمسافة اختيارية ثم حروف
3 ?\p{N}+Optional space then digitsمسافة اختيارية ثم أرقام
4 ?[^\s\p{L}\p{N}]+Everything else, one runكل ما عدا ذلك، في تتابع واحد
5\s+(?!\S)Trailing whitespaceالمسافات البيضاء في النهاية
6\s+Last resort, any whitespaceالملاذ الأخير، أي مسافة بيضاء
GPT-2 style pre-tokenizer, six alternatives in priority orderمقطِّع أولي على نمط GPT-2، ستة بدائل مرتبة حسب الأولوية

Vocabulary sizes to knowأحجام مفردات يجب معرفتها

GPT-2
50,257
BERT base (WordPiece)
30,522
Llama 3
128 K
GPT-4o (o200k)
200 K
Special tokenالوحدة الخاصة
<|endoftext|> sits at id 50256 in GPT-2.<|endoftext|> تقع عند المعرّف 50256 في GPT-2.
SentenceالجملةLanguageاللغةWordsالكلماتTokensالوحداتFertilityالخصوبة
The book is on the table.Englishالإنجليزية671.17
الكتاب على الطاولة.Arabicالعربية3124.0
Fertility: tokens per wordالخصوبة: عدد الوحدات لكل كلمة
premiumA∣B=∣t(sA)∣∣t(sB)∣\text{premium}_{A \mid B} = \frac{|t(s_A)|}{|t(s_B)|}
Tokenization premium: tokens for a sentence in A over tokens for its translation in B (Petrov et al. 2023)علاوة التقسيم (tokenization premium): رموز جملة في اللغة A مقسومة على رموز ترجمتها في اللغة B (Petrov et al. 2023)
LanguageاللغةGPT-2GPT-2cl100kcl100kByT5ByT5
Portugueseالبرتغالية1.941.48n/aغير متاح
Germanالألمانية2.141.58n/aغير متاح
Chinese (Simplified)الصينية (المبسطة)3.211.910.93
Standard Arabicالعربية الفصحى4.403.041.60
Burmeseالبورمية16.8911.703.51
Shanالشانية18.7615.053.94
Premium by language, GPT-2 / cl100k / ByT5علاوة التقطيع حسب اللغة، GPT-2 / cl100k / ByT5
TokenizerالمقطِّعOutputالناتجReversibilityقابلية العكس
BERT (WordPiece)Hello | worldDiscarded, not reversibleتُحذف، وغير قابلة للعكس
GPT-2Hello | ·worldGlued, reversibleتُلصق، وقابلة للعكس
SentencePiece▁Hello | ▁worldExplicit, losslessصريحة، وبلا فقد
Whitespace policies on Hello worldسياسات المسافات على Hello world

Sentence segmentationتقطيع الجمل

A sentence boundary is a period that is not part of an abbreviation, a number or a quotation. Part 07: Tokenizers in practice

حد الجملة هو نقطة ليست جزءًا من اختصار أو رقم أو اقتباس. الجزء 07: المقطِّعات في التطبيق العملي

One passage, four sentencesمقطع واحد وأربع جمل

Passageالمقطع
Dr. Ahmad arrived at 5 p.m. on Monday. He paid 3.50 riyals. Was it enough? Yes!
Sentencesالجمل
4
Trapsالفخاخ
Dr. and p.m. hold periods; 5 and 3.50 hold periods with digits on both sides.Dr. وp.m. تحملان نقاطًا، و5 و3.50 تحملان نقاطًا تحيط بها أرقام على الجانبين.
ApproachالمنهجHow it worksطريقة العملEvidenceالدليل
Rule-basedقائم على القواعدPunctuation plus capitalization, abbreviation list, quote balancing, digits on both sidesعلامات الترقيم مع الأحرف الكبيرة، وقائمة اختصارات، وموازنة علامات الاقتباس، وأرقام على الجانبينFast, needs a hand-written abbreviation listسريع، ويحتاج قائمة اختصارات مكتوبة يدويًا
StatisticalإحصائيSupervised, learn the boundary probability from annotated textموجَّه (supervised): يتعلم احتمال الحد من نص موسومNeeds labeled dataيحتاج بيانات موسومة
PunktUnsupervised, English boundary error 1.65% and German 0.35%غير موجَّه (unsupervised)، وخطأ الحدود 1.65% في الإنجليزية و0.35% في الألمانية98.74% mean accuracy over eleven languages (Kiss and Strunk 2006)متوسط دقة 98.74% على إحدى عشرة لغة (Kiss and Strunk 2006)
Approaches to segmentationمناهج تقطيع الجمل

Regular expressionsالتعابير النمطية

Regex is the pattern language under every pre-tokenizer, cleaner and feature extractor. ELIZA 1966 used about 50 keyword patterns of the form .* YOU ARE (DEPRESSED|SAD) .* replacing with I AM SORRY TO HEAR YOU ARE \1. Part 08: Regex basics, Part 09: Regex in practice

التعابير النمطية (regex) هي لغة الأنماط التي تقوم عليها كل المقطِّعات الأولية وأدوات التنظيف واستخراج السمات. استخدم ELIZA عام 1966 نحو 50 نمطًا من الكلمات المفتاحية على صورة .* YOU ARE (DEPRESSED|SAD) .* مع الاستبدال بـ I AM SORRY TO HEAR YOU ARE \1. الجزء 08: أساسيات regex، الجزء 09: regex في التطبيق العملي

OperatorالمعاملMeaningالمعنىExampleمثالMatchesما يطابقه
*Zero or moreصفر أو أكثرab*cac, abc, abbc
+One or moreواحد أو أكثرab+cabc, abbc, not acabc, abbc، وليس ac
?Zero or oneصفر أو واحدab?cac, abc
{n}Exactly nn بالضبطa{3}aaa
{m,n}Between m and nبين m وna{2,4}aa, aaa, aaaa
.Any char but newlineأي حرف عدا السطر الجديدa.cabc, a c
Quantifiersالمكمِّمات
PatternالنمطTextالنصResultالنتيجة
<.*><a><b>1 match, length 6مطابقة واحدة، طولها 6
<.*?><a><b>2 matches, length 3مطابقتان، طول كل منهما 3
a.*bxaxbxbxaxbxb, span 1 to 5axbxb، المدى من 1 إلى 5
a.*?bxaxbxbxaxb, span 1 to 3axb، المدى من 1 إلى 3
Greedy versus lazyالجشع مقابل الكسول
AnchorالمرساةMeaningالمعنىExampleمثال
^Start of string, or line under mبداية السلسلة، أو بداية السطر مع m^The
$End of string, or line under mنهاية السلسلة، أو نهاية السطر مع mend$
\bWord boundaryحد كلمة\b99\b
\BNot a word boundaryليس حد كلمة\B99
Anchorsالمراسي
AliasالاختصارMeaningالمعنىEquivalentالمكافئ
\dA digitرقم[0-9]
\DNot a digitليس رقمًا[^0-9]
\wWord characterحرف كلمة[a-zA-Z0-9_]
\WNot a word characterليس حرف كلمة[^a-zA-Z0-9_]
\sWhitespaceمسافة بيضاء[ \r\t\n\f]
\SNot whitespaceليس مسافة بيضاء[^ \r\t\n\f]
Character class aliasesاختصارات فئات الحروف
LevelالمستوىBindsما يربطهOperatorsالمعاملات
1Parenthesisالأقواس( )
2Countersالعدّادات* + ? { }
3Sequences and anchorsالتسلسلات والمراسيabc, ^, $
4Disjunctionالاختيار (disjunction)|
Precedence, tightest firstالأولوية، الأشد ارتباطًا أولًا

Operator details worth memorizingتفاصيل المعاملات التي تستحق الحفظ

The caretعلامة ^
Anchor outside brackets, negation only as the first character inside brackets, literal elsewhere inside.مرساة خارج الأقواس المربعة، ونفي فقط عندما تكون الحرف الأول داخلها، وحرف عادي في أي موضع آخر داخلها.
{m,}
At least m; JavaScript needs {0,n} for the at-most form.على الأقل m، وتحتاج JavaScript إلى {0,n} لصيغة "على الأكثر".
Escapeالهروب
Fourteen metacharacters take a backslash: dot, caret, dollar, star, plus, question mark, the two parentheses, the two brackets, the two braces, the pipe and the backslash itself.أربعة عشر حرفًا خاصًا (metacharacters) تحتاج شرطة مائلة عكسية: النقطة، وعلامة ^، وعلامة الدولار، والنجمة، وعلامة الجمع، وعلامة الاستفهام، والقوسان الهلاليان، والقوسان المربعان، والقوسان المعقوفان، والخط العمودي، والشرطة المائلة العكسية نفسها.
Lookaroundالنظر حول الموضع
(?=...) and (?<=...) assert forward and behind without consuming.(?=...) و(?<=...) تتحققان للأمام وللخلف دون استهلاك أي حرف.
Disjunctionالاختيار
cat|dogs matches cat, dogs and the cat inside cats; parenthesize to group.cat|dogs تطابق cat وdogs وcat داخل cats، واستخدم الأقواس للتجميع.
Flagsالأعلام
g all matches, m multiline anchors, i case-insensitive.g كل المطابقات، وm مراسٍ متعددة الأسطر، وi عدم التمييز بين حالة الأحرف.

Minimum edit distanceأدنى مسافة تحرير

The distance between two strings is the cost of the cheapest edit script, found by dynamic programming over prefix pairs. Part 10: Edit distance, Part 11: Edit distance DP

المسافة بين سلسلتين هي تكلفة أرخص سلسلة تعديلات (edit script)، ونجدها بالبرمجة الديناميكية على أزواج البادئات (prefixes). الجزء 10: مسافة التحرير، الجزء 11: البرمجة الديناميكية لمسافة التحرير

D[0,0]=0,D[i,0]=i,D[0,j]=jD[0,0] = 0, \qquad D[i,0] = i, \qquad D[0,j] = j
Initialization: an empty target forces i deletions, an empty source forces j insertionsالتهيئة: الهدف الفارغ يفرض i عملية حذف، والمصدر الفارغ يفرض j عملية إدراج
D[i,j]=min⁡{D[i−1,j]+del(xi)D[i−1,j−1]+sub(xi,yj)D[i,j−1]+ins(yj)D[i,j] = \min \begin{cases} D[i-1,j] + \text{del}(x_i) \\ D[i-1,j-1] + \text{sub}(x_i, y_j) \\ D[i,j-1] + \text{ins}(y_j) \end{cases}
The recurrence, SLP3 Eq. 2.19: up, diagonal, leftالعلاقة التكرارية، المعادلة 2.19 في SLP3: أعلى، قطري، يسار
D[i,j]=min⁡{D[i−1,j]+1D[i−1,j−1]+{2xi≠yj0xi=yjD[i,j−1]+1D[i,j] = \min \begin{cases} D[i-1,j] + 1 \\ D[i-1,j-1] + \begin{cases} 2 & x_i \ne y_j \\ 0 & x_i = y_j \end{cases} \\ D[i,j-1] + 1 \end{cases}
The cost-2 convention of slide 89, SLP3 Eq. 2.20: a substitution counts as a deletion plus an insertionاصطلاح الكلفة 2 في الشريحة 89، المعادلة 2.20 في SLP3: الاستبدال يُحسب حذفًا مع إدراج
OperationالعمليةUnit costالتكلفة الموحدةCost 2التكلفة 2Slide 82 exampleمثال الشريحة 82
Matchتطابق00E over EE فوق E
Insertionإدراج11* over C* فوق C
Deletionحذف11I over *I فوق *
Substitutionاستبدال12N over EN فوق E
Cost conventionsاصطلاحات التكلفة
MoveالحركةOperationالعمليةCellالخلية
UpللأعلىDeletion of source characterحذف حرف من المصدرD[i-1,j] + del
DiagonalقطريSubstitution or matchاستبدال أو تطابقD[i-1,j-1] + sub(x_i, y_j)
LeftلليسارInsertion of target characterإدراج حرف من الهدفD[i,j-1] + ins
Which move is whichأي حركة تقابل أي عملية
Dεcat
ε0123
c1012
a2112
t3221
Worked table, cat to cut, unit costsجدول محلول من cat إلى cut بالتكاليف الموحدة

Worked numbersأرقام محلولة

Slide 82 alignmentمحاذاة الشريحة 82
d s s _ i s: delete, two substitutions, match, insertion, substitution.d s s _ i s: حذف، واستبدالان، وتطابق، وإدراج، واستبدال.
Slide 82 totalsمجموعا الشريحة 82
5 under unit cost, 8 under cost 2.5 بالتكلفة الموحدة، و8 بالتكلفة 2.
Position by positionموضعًا بموضع
Five substitutions, 5 under unit cost and 10 under cost 2.خمسة استبدالات، أي 5 بالتكلفة الموحدة و10 بالتكلفة 2.
Step 1الخطوة 1
Cost 2 gives D[1,1] = 2 on the slide; under slide 86 unit cost it would be 1.التكلفة 2 تعطي D[1,1] = 2 في الشريحة، وبالتكلفة الموحدة للشريحة 86 تكون 1.
Alignment countعدد المحاذاات
Cost 2 admits 134 optimal alignments, unit cost only 7.التكلفة 2 تسمح بـ 134 محاذاة مثلى، والتكلفة الموحدة بـ 7 فقط.
Erickson to ALTRUISTICمن Erickson إلى ALTRUISTIC
Exactly 3 optimal paths.3 مسارات مثلى بالضبط.
Hamming versus editHamming مقابل مسافة التحرير
flaw to lawn is Hamming 4 but edit 2.من flaw إلى lawn مسافة Hamming تساوي 4 لكن مسافة التحرير 2.
CallHome WERWER في CallHome
6 substitutions, 3 insertions and 1 deletion over 13 reference words give WER 76.9%.6 استبدالات و3 إدراجات وحذف واحد (1) على 13 كلمة مرجعية تعطي WER يساوي 76.9%.

Backtrace on intention to execution, cost 2التتبع العكسي من intention إلى execution بالتكلفة 2

Bottom rightالخلية السفلية اليمنى
D[m,n] = 8.
Matchesالتطابقات
Five on the diagonal, each cost 0: e, t, i, o, n.خمسة على القطر، كل منها بتكلفة 0: e، t، i، o، n.
Substitutionsالاستبدالات
n to u, t to x, n to e, each cost 2.n إلى u، وt إلى x، وn إلى e، كل منها بتكلفة 2.
Deletionالحذف
i at the left edge of the source, cost 1.i عند الطرف الأيسر من المصدر، بتكلفة 1.
Insertionالإدراج
c inserted into the target, cost 1.c مُدرجة في الهدف، بتكلفة 1.

Evidence for edit distance in spelling correctionأدلة على مسافة التحرير في تصحيح الإملاء

Damerau 1964
A single wrong, missing, extra or transposed letter accounts for about 80% of spelling errors.حرف واحد خاطئ أو ناقص أو زائد أو مبدَّل الموضع يفسر نحو 80% من الأخطاء الإملائية.
Kernighan, Church and Gale
On 44 million words of 1988 AP newswire, automatic correction agreed with human judges on 87% of 329 sampled cases.على 44 مليون كلمة من أخبار AP لعام 1988، اتفق التصحيح الآلي مع المحكّمين البشريين في 87% من 329 حالة في العينة.
TaskالمهمةTimeالزمنSpaceالذاكرةNoteملاحظة
Distance onlyالمسافة فقطO(mn)O(min(m,n))Two rowsصفّان
Distance and alignmentالمسافة والمحاذاةO(mn)O(mn)Store every cellتخزين كل الخلايا
Alignment in linear spaceالمحاذاة بذاكرة خطيةO(mn)O(m+n)Hirschberg, about twice the constantHirschberg، بنحو ضعف الثابت
Space and timeالذاكرة والزمن
tree nodes≈(2∣Σ∣L)dgrid cells=(m+1)(n+1)\text{tree nodes} \approx (2|\Sigma| L)^{d} \qquad \text{grid cells} = (m+1)(n+1)
Why DP wins: from intention to execution (9-letter words) the search tree has 494 children per step and about 3 x 10^13 nodes at depth 5, the grid only 100 cellsلماذا تتفوق البرمجة الديناميكية: من intention إلى execution (كلمتان من 9 أحرف) لشجرة البحث 494 ابنًا في كل خطوة ونحو 3 x 10^13 عقدة عند العمق 5، أما الشبكة فلا تتجاوز 100 خلية
WER=I+S+Dwords in the reference\mathrm{WER} = \frac{I + S + D}{\text{words in the reference}}
Word error rate from a word-level minimum edit distance alignment (SLP3 section 16.6)معدل خطأ الكلمات (WER) من محاذاة مسافة التحرير الدنيا على مستوى الكلمات (SLP3، القسم 16.6)

Slide errataأخطاء الشرائح

Answer with the corrected fact, and name the slide version when a question depends on it. Part 01: What is a word

أجب بالمعلومة المصححة، واذكر نسخة الشريحة عندما يعتمد السؤال عليها. الجزء 01: ما الكلمة

What the slides get wrongما تخطئ فيه الشرائح

Slide 12الشريحة 12
The second dashed-line legend reads "standard zipfian distribution dotted english un", truncated; it should read English Wikipedia, and that fit belongs to the blue English curve.عنوان المفتاح الثاني للخط المتقطع يقرأ "standard zipfian distribution dotted english un" وهو مقطوع، وصحته English Wikipedia، وتلك المطابقة تخص المنحنى الإنجليزي الأزرق.
Slide 14الشريحة 14
The Heaps fit is extrapolated to 1.2 x 10^19, far past the data, and the curves do not reproduce from the legend constants.مطابقة Heaps ممدودة إلى 1.2 x 10^19، أبعد بكثير من البيانات، والمنحنيات لا يمكن إعادة إنتاجها من الثوابت المذكورة في المفتاح.
Slide 33الشريحة 33
The caption promises a binary column that is absent, "for letters" is wrong (the template holds any code point), and hex 5D is displayed as [ where it should be ].يعِد التعليق بعمود ثنائي غير موجود، وعبارة "for letters" خاطئة (القالب يصلح لأي نقطة رمزية)، والقيمة الست عشرية 5D معروضة على أنها [ وصحتها ].
Slide 43الشريحة 43
The caption says toy-corpus step-by-step, but the figure is the SLP3 Fig. 2.6 pseudocode; the toy trace is slides 44 to 47.يقول التعليق إنه شرح خطوة بخطوة على المدوّنة المصغرة، لكن الشكل هو الشيفرة الزائفة (pseudocode) في SLP3 Fig. 2.6، أما تتبع المدوّنة المصغرة ففي الشرائح 44 إلى 47.
Slide 44الشريحة 44
The bullet says "with end-of-word marker or space markers", but the tables on slides 44 to 47 use the leading space marker only. Follow the tables.تقول النقطة "with end-of-word marker or space markers"، لكن الجداول في الشرائح 44 إلى 47 تستخدم علامة المسافة البادئة فقط. اتبع الجداول.
Slide 56الشريحة 56
The ELIZA script line reads "WHO ELSE IN YOU FAMILY"; the source line is "WHO ELSE IN YOUR FAMILY".سطر سكربت ELIZA يقرأ "WHO ELSE IN YOU FAMILY"، والسطر في المصدر هو "WHO ELSE IN YOUR FAMILY".
Slide 61الشريحة 61
The a^b example inherited from SLP3 Fig. 2.10 does not hold in modern engines; write a\^b, which matches the span (8, 11).مثال a^b الموروث من SLP3 Fig. 2.10 لا يصح في المحركات الحديثة، فاكتب a\^b الذي يطابق المدى (8, 11).
Slide 72الشريحة 72
2026-25-01 is not valid ISO 8601 (month 25), and <\End> uses a backslash where HTML closes a tag with a slash.2026-25-01 ليس تاريخًا صالحًا وفق ISO 8601 (الشهر 25)، و<\End> يستخدم شرطة مائلة عكسية حيث يغلق HTML الوسم بشرطة مائلة عادية.
Slide 85 and 88الشريحتان 85 و88
Slide 85 writes source x length m and target y length n; the slide 88 pseudocode and slide 90 backtrace index rows n and columns m. Fix one convention and keep the answer cell consistent.تكتب الشريحة 85 المصدر x بطول m والهدف y بطول n، بينما تفهرس الشيفرة الزائفة في الشريحة 88 والتتبع العكسي في الشريحة 90 الصفوف بـ n والأعمدة بـ m. ثبّت اصطلاحًا واحدًا وأبقِ خلية الإجابة متسقة معه.
Slide 89الشريحة 89
The table charges substitution 2, following SLP3 Fig. 2.20, while slide 86 defines substitution cost 1; under slide 86 D[1,1] = 1 and the bottom right is 5, not 8.يحتسب الجدول الاستبدال بتكلفة 2 متبعًا SLP3 Fig. 2.20، بينما تعرّف الشريحة 86 تكلفة الاستبدال بـ 1. ووفق الشريحة 86 تكون D[1,1] = 1 والخلية السفلية اليمنى 5 وليست 8.