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: ما الكلمة
| Policyالسياسة | Tokens Nالوحدات N | Types |V|الأنواع |V| |
|---|---|---|
| Whitespace onlyالمسافات فقط | 16 | 14 |
| Punctuation splitفصل علامات الترقيم | 18 | 16 |
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الوحدات N | Types per 1,000الأنواع لكل 1,000 |
|---|---|---|---|
| Shakespeare | 31 k | 884 k | 35.1 |
| Brown | 38 k | 1 M | 38.0 |
| Switchboard | 20 k | 2.4 M | 8.3 |
| COCA | 2 M | 440 M | 4.5 |
| Google n-grams | 13 M | 1 T | 0.013 |
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
| Fitالمطابقة | kk | betabeta | at 10^4عند 10^4 | at 10^6عند 10^6 | at 10^8عند 10^8 |
|---|---|---|---|---|---|
| English (dotted)الإنجليزية (dotted) | 14.947 | 0.583 | 3,210 | 47,049 | 689,531 |
| Arabic (dotted)العربية المنقوطة | 73.321 | 0.533 | 2,576 | 115,672 | 5,193,404 |
| Arabic (undotted)العربية غير المنقوطة | 90.491 | 0.506 | 2,846 | 98,312 | 3,396,228 |
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 |
| happy | Rootجذر | Freeحرة | Lexical coreالنواة المعجمية | unhappiness |
| -ness | Suffixلاحقة | Boundمقيدة | Nominalizerتحويل إلى اسم (nominalizer) | happiness |
| -s | Suffixلاحقة | Boundمقيدة | Inflectional pluralجمع تصريفي | cats |
| abso-bloody-lutely | Infixداخلة (infix) | Boundمقيدة | Intensifierتكثيف وتوكيد | abso-bloody-lutely |
| ge- ... -t | Circumfixزائدة محيطة (circumfix) | Boundمقيدة | Participleاسم المفعول (participle) | gespielt |
| 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 |
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 |
| -hu | Encliticلاصقة لاحقة (enclitic) | Low: nouns, verbs, prepositionsمنخفضة: الأسماء والأفعال وحروف الجر | Attaches across categoriesتلتصق عبر الفئات |
| -tu | Inflectional affixزائدة تصريفية | High: perfective verbs onlyمرتفعة: الأفعال التامة (الماضية) فقط | One paradigm cellخانة واحدة في الجدول الصرفي |
| Policyالسياسة | Tokensالوحدات | Outputالناتج |
|---|---|---|
| Whitespaceالمسافات | 1 | وَبِالْبَيْت |
| ATB | 3 | wa+ bi+ albayt |
| D3 | 4 | wa+ bi+ al+ bayt |
| Typeالنوع | Definitionالتعريف | Exampleمثال | M/WM/W | Languageاللغة |
|---|---|---|---|---|
| Isolatingعازلة (isolating) | One morpheme per wordوحدة صرفية واحدة في الكلمة | wǒmen míngtiān qù Běijīng | 1.06 | Mandarinالماندرينية |
| Agglutinativeإلصاقية (agglutinative) | Many morphemes, clear seamsوحدات صرفية كثيرة بحدود واضحة | ev-ler-im-den | 2.55 | Turkishالتركية |
| Fusionalاندماجية (fusional) | Portmanteau morphemesوحدات صرفية مدمجة (portmanteau) | habl-o | 2.59 | Spanish, Sanskritالإسبانية، السنسكريتية |
| Polysyntheticمتعددة التركيب (polysynthetic) | Many morphemes, often a sentenceوحدات صرفية كثيرة، وكثيرًا ما تكون الكلمة جملة كاملة | t-ə-nk'e-mejŋ-ə-jetemə-nni-k | 3.72 | Inuktitut, Koryakالإنوكتيتوت، الكورياكية |
| Languageاللغة | M/WM/W | Rounded on the slideالقيمة المقرّبة في الشريحة |
|---|---|---|
| Vietnameseالفيتنامية | 1.06 | Slide 1.1الشريحة 1.1 |
| Persianالفارسية | 1.52 | Slide 1.5الشريحة 1.5 |
| Englishالإنجليزية | 1.68 | Slide 1.7الشريحة 1.7 |
| Old Englishالإنجليزية القديمة | 2.12 | Slide 2.1الشريحة 2.1 |
| Yakutالياقوتية | 2.17 | Slide 2.2الشريحة 2.2 |
| Swahiliالسواحيلية | 2.55 | Slide 2.5الشريحة 2.5 |
| Sanskritالسنسكريتية | 2.59 | Slide 2.6الشريحة 2.6 |
| Eskimo / Greenlandicالإسكيمو / الغرينلاندية | 3.72 | Slide 3.7الشريحة 3.7 |
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
| Rangeالمدى | Templateالقالب | Bitsالبتات | Bytesالبايتات | Exampleمثال |
|---|---|---|---|---|
| U+0000 to U+007Fمن U+0000 إلى U+007F | 0xxxxxxx | 7 | 1 | a = 0x61 |
| U+0080 to U+07FFمن U+0080 إلى U+07FF | 110yyyyy 10xxxxxx | 11 | 2 | é = C3 A9 |
| U+0800 to U+FFFFمن U+0800 إلى U+FFFF | 1110zzzz 10yyyyyy 10xxxxxx | 16 | 3 | ب = D8 A8 |
| U+010000 to U+10FFFFمن U+010000 إلى U+10FFFF | 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx | 21 | 4 | 😀 = F0 9F 98 80 |
| Characterالحرف | Code pointالنقطة الرمزية | UTF-8 bytesبايتات UTF-8 |
|---|---|---|
| a | U+0061 | 61 |
| é | U+00E9 | C3 A9 |
| ب | U+0628 | D8 A8 |
| € | U+20AC | E2 82 AC |
| 中 | U+4E2D | E4 B8 AD |
| ﻻ | U+FEFB | EF BB BB |
| 😀 | U+1F600 | F0 9F 98 80 |
| Formالشكل | Operationالعملية | éé | Equivalenceالتكافؤ |
|---|---|---|---|
| NFD | Decomposeتفكيك | e + U+0301 | Canonicalقانوني (canonical) |
| NFC | Composeتركيب | U+00E9 | Canonicalقانوني (canonical) |
| NFKD | Compatibility decomposeتفكيك توافقي | E + U+0301 | Compatibilityتوافقي (compatibility) |
| NFKC | Compatibility composeتركيب توافقي | U+00C9 | Compatibilityتوافقي (compatibility) |
- 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
| Criterionالمعيار | Achievable at onceقابل للتحقيق معًا | What it meansما يعنيه | Effectالأثر |
|---|---|---|---|
| Coverageالتغطية | N | Any character, any scriptأي حرف، وأي نظام كتابة | Byte fallback has no unknown symbolالاحتياط بالبايتات (byte fallback) لا يترك رمزًا مجهولًا |
| Compactnessالإيجاز | N | Rare words cost few piecesالكلمات النادرة تكلّف قطعًا قليلة | Fewer tokens per sentenceوحدات أقل في كل جملة |
| Meaningfulnessالدلالة | Pieces line up with morphemesالقطع تتطابق مع الوحدات الصرفية | Better generalization to unseen wordsتعميم أفضل على الكلمات غير المرئية | |
| Cross-lingualتعدد اللغات | N | One vocabulary for many scriptsمفردات واحدة لأنظمة كتابة كثيرة | No language left with a long tailلا تُترك لغة بذيل طويل |
| Mergeالدمج | Countالعدد | Symbols beforeالرموز قبل | Symbols afterالرموز بعد |
|---|---|---|---|
| ne | 4 | 29 | 25 |
| new | 4 | 25 | 21 |
| _r | 3 | 21 | 18 |
| _re | 3 | 18 | 15 |
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-2 | 50,257 | 14 |
| cl100k | 100 k | 14 |
| o200k | 200 k | 13 |
| ## | Patternالنمط | Matchesما يطابقه |
|---|---|---|
| 1 | 's|'t|'re|'ve|'m|'ll|'d | English 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الملاذ الأخير، أي مسافة بيضاء |
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الإنجليزية | 6 | 7 | 1.17 |
| الكتاب على الطاولة. | Arabicالعربية | 3 | 12 | 4.0 |
| Languageاللغة | GPT-2GPT-2 | cl100kcl100k | ByT5ByT5 |
|---|---|---|---|
| Portugueseالبرتغالية | 1.94 | 1.48 | n/aغير متاح |
| Germanالألمانية | 2.14 | 1.58 | n/aغير متاح |
| Chinese (Simplified)الصينية (المبسطة) | 3.21 | 1.91 | 0.93 |
| Standard Arabicالعربية الفصحى | 4.40 | 3.04 | 1.60 |
| Burmeseالبورمية | 16.89 | 11.70 | 3.51 |
| Shanالشانية | 18.76 | 15.05 | 3.94 |
| Tokenizerالمقطِّع | Outputالناتج | Reversibilityقابلية العكس |
|---|---|---|
| BERT (WordPiece) | Hello | world | Discarded, not reversibleتُحذف، وغير قابلة للعكس |
| GPT-2 | Hello | ·world | Glued, reversibleتُلصق، وقابلة للعكس |
| SentencePiece | ▁Hello | ▁world | Explicit, losslessصريحة، وبلا فقد |
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يحتاج بيانات موسومة |
| Punkt | Unsupervised, 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) |
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*c | ac, abc, abbc |
| + | One or moreواحد أو أكثر | ab+c | abc, abbc, not acabc, abbc، وليس ac |
| ? | Zero or oneصفر أو واحد | ab?c | ac, abc |
| {n} | Exactly nn بالضبط | a{3} | aaa |
| {m,n} | Between m and nبين m وn | a{2,4} | aa, aaa, aaaa |
| . | Any char but newlineأي حرف عدا السطر الجديد | a.c | abc, a c |
| Patternالنمط | Textالنص | Resultالنتيجة |
|---|---|---|
| <.*> | <a><b> | 1 match, length 6مطابقة واحدة، طولها 6 |
| <.*?> | <a><b> | 2 matches, length 3مطابقتان، طول كل منهما 3 |
| a.*b | xaxbxbx | axbxb, span 1 to 5axbxb، المدى من 1 إلى 5 |
| a.*?b | xaxbxbx | axb, span 1 to 3axb، المدى من 1 إلى 3 |
| Anchorالمرساة | Meaningالمعنى | Exampleمثال |
|---|---|---|
| ^ | Start of string, or line under mبداية السلسلة، أو بداية السطر مع m | ^The |
| $ | End of string, or line under mنهاية السلسلة، أو نهاية السطر مع m | end$ |
| \b | Word boundaryحد كلمة | \b99\b |
| \B | Not a word boundaryليس حد كلمة | \B99 |
| Aliasالاختصار | Meaningالمعنى | Equivalentالمكافئ |
|---|---|---|
| \d | A digitرقم | [0-9] |
| \D | Not a digitليس رقمًا | [^0-9] |
| \w | Word characterحرف كلمة | [a-zA-Z0-9_] |
| \W | Not a word characterليس حرف كلمة | [^a-zA-Z0-9_] |
| \s | Whitespaceمسافة بيضاء | [ \r\t\n\f] |
| \S | Not whitespaceليس مسافة بيضاء | [^ \r\t\n\f] |
| Levelالمستوى | Bindsما يربطه | Operatorsالمعاملات |
|---|---|---|
| 1 | Parenthesisالأقواس | ( ) |
| 2 | Countersالعدّادات | * + ? { } |
| 3 | Sequences and anchorsالتسلسلات والمراسي | abc, ^, $ |
| 4 | Disjunctionالاختيار (disjunction) | | |
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: البرمجة الديناميكية لمسافة التحرير
| Operationالعملية | Unit costالتكلفة الموحدة | Cost 2التكلفة 2 | Slide 82 exampleمثال الشريحة 82 |
|---|---|---|---|
| Matchتطابق | 0 | 0 | E over EE فوق E |
| Insertionإدراج | 1 | 1 | * over C* فوق C |
| Deletionحذف | 1 | 1 | I over *I فوق * |
| Substitutionاستبدال | 1 | 2 | N over EN فوق E |
| 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 |
| D | ε | c | a | t |
|---|---|---|---|---|
| ε | 0 | 1 | 2 | 3 |
| c | 1 | 0 | 1 | 2 |
| a | 2 | 1 | 1 | 2 |
| t | 3 | 2 | 2 | 1 |
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، بنحو ضعف الثابت |
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.