Lecture 02 · Words and Tokens

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

Words, Types, and Tokens

الكلمات والأنواع (Types) والرموز (Tokens)

Slides 2–9الشرائح 2–9 P2 SHOULD

Why "word" is not a usable unit until you define it, and the two counts (N and |V|) that every later formula in this course is built on.

لماذا لا تصلح "الكلمة" وحدةً للعمل حتى تعرّفها، والعدّتان (N و|V|) اللتان تُبنى عليهما كل معادلة لاحقة في هذا المقرر.

High exam riskخطر عالٍ في الاختبار

The single most likely slip on this material is answering with types when the question asked for tokens, or the other way round. If you fix nothing else from this page, fix that. Everything else here is vocabulary you can recite.

أكثر زلّة متوقعة في هذه المادة هي أن تجيب بعدد types والسؤال يطلب tokens، أو العكس. إن لم تُصلح شيئاً آخر من هذه الصفحة فأصلح هذا. وكل ما عداه هنا مصطلحات يمكنك تسميعها.

Where this page sits, slide 2

موقع هذه الصفحة، الشريحة 2

Slide 2 lists seven learning goals for the whole lecture. Three of them belong to this page and the next two:

تسرد الشريحة 2 سبعة أهداف تعليمية للمحاضرة كلها. ثلاثة منها تخص هذه الصفحة والصفحتين التاليتين:

The remaining four goals (Unicode and UTF-8, byte-pair encoding, regular expressions, minimum edit distance) are later pages of the deck.

أما الأهداف الأربعة الباقية (Unicode وUTF-8، وbyte-pair encoding، وregular expressions، وminimum edit distance) فهي في صفحات لاحقة من المحاضرة.

What is a word? Slide 3

ما الكلمة؟ الشريحة 3

Slide 3 does not define a word. It asks a question and then refuses to answer it, which is the point. The sentence it hands you is:

الشريحة 3 لا تعرّف الكلمة. إنها تطرح سؤالاً ثم ترفض الإجابة عنه، وهذا هو المقصود. والجملة التي تعطيك إياها هي:

They picnicked by the pool, then lay back on the grass and looked at the stars.

الجملة تعني: "ذهبوا في نزهة بجانب المسبح، ثم استلقوا على العشب ونظروا إلى النجوم." وهي المثال الذي سنعدّ كلماته.

Ask "how many words is that?" and you immediately discover you cannot answer until somebody tells you the rules. The slide's own wording: in many writing systems, spaces suggest boundaries, but it is not that simple.

اسأل "كم كلمة في هذه الجملة؟" وستكتشف فوراً أنك لا تستطيع الإجابة حتى يخبرك أحد بالقواعد. وعبارة الشريحة نفسها: في كثير من أنظمة الكتابة توحي المسافات بالحدود، لكن الأمر ليس بهذه البساطة.

The slide then lists the decisions that actually determine the number, and frames them as task-dependent, not right or wrong:

ثم تسرد الشريحة القرارات التي تحدد العدد فعلاً، وتقدّمها على أنها تعتمد على المهمة، لا على أنها صواب أو خطأ:

Its example of a disfluent utterance, straight from the slide:

ومثالها على كلام فيه تلعثم، منقول من الشريحة حرفياً:

I do uh main- mainly business data processing

المتحدث يقول "أنا أعمل في، آه، معا... معالجة بيانات الأعمال أساساً"، أي أن فيه وقفة uh ومحاولة مقطوعة main- قبل mainly.

That string contains a filled pause (uh) and a fragment (main-) which is not a word at all, it is an abandoned attempt at mainly. A speech recognition system studying disfluency wants both kept. A topic classifier wants both thrown away. Same string, two legitimate token counts.

هذه السلسلة فيها وقفة مملوءة (uh) وجزء مقطوع (main-) ليس كلمة أصلاً، بل محاولة متروكة لنطق mainly. نظام التعرف على الكلام الذي يدرس التلعثم يريد إبقاء الاثنين. ومصنّف الموضوعات يريد حذف الاثنين. السلسلة نفسها، وعددان مشروعان من tokens.

Last bullet on the slide, and it matters for the rest of the course: across languages, segmentation can be ambiguous or even absent. Chinese is the named case. Chinese text is written with no spaces between words at all, so there is nothing to split on. The spaces that English gives you for free are an accident of one writing system, not a property of language.

آخر بند في الشريحة، وهو مهم لبقية المقرر: عبر اللغات قد يكون التقطيع (segmentation) غامضاً أو غائباً تماماً. والصينية هي الحالة المذكورة بالاسم. فالنص الصيني يُكتب بلا أي مسافات بين الكلمات، فلا يوجد شيء تقطع عنده. والمسافات التي تعطيك إياها الإنجليزية مجاناً هي مصادفة في نظام كتابة واحد، لا خاصية في اللغة نفسها.

Tokens versus types, slide 4

الـ Tokens مقابل الـ Types، الشريحة 4

This is the slide you must be able to reproduce from memory. It gives two definitions under the heading "Key definitions":

هذه هي الشريحة التي يجب أن تستطيع إعادة كتابتها من الذاكرة. فهي تعطي تعريفين تحت عنوان "Key definitions":

TermالمصطلحSlide definitionتعريف الشريحةSymbolالرمز
Token (instance)Token (مثيل، instance)an occurrence in running text; total countظهور في النص المتتالي، والعدد الكليN
TypeTypea distinct vocabulary item; vocabulary sizeعنصر مفردات مميز، وحجم المفردات|V|

يقول الجدول: Token (instance) هو ظهور واحد في النص المتتالي، ومجموعها هو العدد الكلي ورمزه N. وType هو عنصر مفردات مميز (مختلف)، وعددها هو حجم المفردات ورمزه |V|.

Plain words first, names second. Imagine reading a page out loud. Every single word that leaves your mouth is a token, including the fifteen separate times you said the. Now imagine instead writing down a shopping list of every different word you would need in order to read that page. That list has one entry for the, no matter how often it occurred. The length of that list is the number of types.

الكلمات البسيطة أولاً، ثم الأسماء. تخيل أنك تقرأ صفحة بصوت عالٍ. كل كلمة تخرج من فمك هي token، بما في ذلك المرات الخمس عشرة المنفصلة التي قلت فيها the. والآن تخيل بدلاً من ذلك أنك تكتب قائمة تسوّق بكل كلمة مختلفة ستحتاجها لقراءة تلك الصفحة. هذه القائمة فيها مدخل واحد لـ the مهما تكرر. وطول هذه القائمة هو عدد types.

Tokens are events. Types are entries in a dictionary. The slide's example:

الـ tokens أحداث. والـ types مداخل في قاموس. ومثال الشريحة:

"to be or not to be" has N = 6 tokens and |V| = 4 types

أي أن "to be or not to be" فيها N = 6 من tokens و|V| = 4 من types.

Six words go by as you read it. The distinct set is {to, be, or, not}, which has four members, because to and be each occurred twice.

ست كلمات تمر بك وأنت تقرأها. والمجموعة المميزة هي {to, be, or, not} وفيها أربعة عناصر، لأن to وbe تكررت كل منهما مرتين.

running text, every occurrence counts to be or not to be 1 2 3 4 5 6 N = 6 to be or not |V| = 4 the vocabulary, one slot per distinct word
Tokens 5 and 6 do not create new vocabulary slots. They fold back onto slots that already exist, so N rises by 2 while |V| rises by 0. Every repeated word in a corpus does exactly this.
الـ tokens رقم 5 و6 لا تُنشئ خانات مفردات جديدة. إنها ترجع إلى خانات موجودة أصلاً، فيزيد N بمقدار 2 بينما يزيد |V| بمقدار 0. وكل كلمة مكررة في corpus تفعل هذا بالضبط.

في الرسم صف علوي من ست خانات هي الـ tokens مرقّمة من 1 إلى 6 (N = 6)، وتنزل الأسهم منها إلى صف سفلي من أربع خانات هو المفردات (|V| = 4). الـ tokens رقم 5 و6 (to وbe الثانيتان) لا تنشئان خانات مفردات جديدة، بل ترجعان إلى خانات موجودة أصلاً، فيرتفع N بمقدار 2 بينما يرتفع |V| بمقدار 0. وكل كلمة متكررة في أي corpus تفعل هذا بالضبط.

Workedمثال محلول

Counting N and |V| by hand on slide 3's own sentence. Rule set: split on whitespace, drop punctuation, do not lowercase.

عدّ N و|V| يدوياً على جملة الشريحة 3 نفسها. القواعد: نقطّع على المسافات، ونحذف الترقيم، ولا نحوّل إلى حروف صغيرة.

They picnicked by the pool, then lay back on the grass and looked at the stars.

walk through the tokens, numbering as you go

   1 They        2 picnicked   3 by         4 the
   5 pool        6 then        7 lay        8 back
   9 on         10 the        11 grass     12 and
  13 looked     14 at         15 the       16 stars

N = 16 tokens

now build the vocabulary list, adding a word only the first time you meet it

  They, picnicked, by, the, pool, then, lay, back,
  on, grass, and, looked, at, stars

"the" was met at position 4 and added. positions 10 and 15 added nothing.

|V| = 14 types

check:  16 tokens  -  2 repeats of "the"  =  14 types   ok

يرقّم المقطع الكلمات واحدة واحدة فيصل إلى N = 16. ثم يبني قائمة المفردات بإضافة الكلمة فقط في أول مرة تظهر: the أُضيفت عند الموضع 4، والموضعان 10 و15 لم يضيفا شيئاً، فيكون |V| = 14. والتحقق: 16 ناقص تكرارين لـ the يساوي 14.

Now change one rule. Keep punctuation as its own token. The comma after pool and the final period become tokens 17 and 18, and they are two new distinct items:

والآن غيّر قاعدة واحدة: احتفظ بالترقيم token مستقلاً. الفاصلة بعد pool والنقطة الأخيرة تصبحان الـ token رقم 17 و18، وهما عنصران مميزان جديدان:

N  = 18 tokens
|V| = 16 types

فيصبح N = 18 و|V| = 16.

The sentence did not change. Only the rule did. That is slide 3's whole argument, in numbers.

الجملة لم تتغير. القاعدة وحدها تغيرت. هذه هي حجة الشريحة 3 كلها، بالأرقام.

The one comparison to get right

المقارنة الوحيدة التي يجب أن تتقنها

TokenTokenTypeType
Symbol for the countرمز العددN|V|
What it countsماذا يعدّoccurrences in running textالظهورات في النص المتتاليdistinct vocabulary itemsعناصر المفردات المميزة
Question it answersالسؤال الذي يجيب عنهhow long is the textكم طول النصhow big is the dictionaryكم حجم القاموس
Repeating a wordتكرار كلمةincreases it every timeيزيده في كل مرةincreases it only the first timeيزيده في المرة الأولى فقط
"to be or not to be""to be or not to be"64
Which is largerأيهما أكبرN ≥ |V| always. They are equal only if no word ever repeats.N ≥ |V| دائماً. ويتساويان فقط إذا لم تتكرر أي كلمة أبداً.

الجدول يقارن بين Token وType. رمز العدد: N مقابل |V|. ما يعدّه: مرات الظهور في النص مقابل عناصر المفردات المميزة. السؤال الذي يجيب عنه: كم طول النص، مقابل كم حجم القاموس. تكرار كلمة: يزيد N في كل مرة، ويزيد |V| في المرة الأولى فقط. ومثال "to be or not to be": 6 مقابل 4. وأيهما أكبر: N ≥ |V| دائماً، ويتساويان فقط إذا لم تتكرر أي كلمة أبداً.

That last row is a free sanity check. If you ever produce |V| larger than N, you have made an arithmetic error, not a discovery.

هذا السطر الأخير اختبار منطقي مجاني. إذا حصلت يوماً على |V| أكبر من N فقد ارتكبت خطأ حسابياً، لا اكتشافاً.

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

Tokens are footsteps. Types are shoes. You take many footsteps in one pair of shoes.

الـ tokens خطوات، والـ types أحذية. تمشي خطوات كثيرة بزوج واحد من الأحذية.

And for the symbols: N is for the Number of words you said. V is for the Vocabulary you needed to say them.

وللرموز: N من Number، أي عدد الكلمات التي قلتها. وV من Vocabulary، أي المفردات التي احتجتها لقولها.

When a question says "running text", "instances", "total", or "corpus size", it wants N. When it says "distinct", "vocabulary", "unique", or "wordform types", it wants |V|.

إذا قال السؤال "running text" أو "instances" أو "total" أو "corpus size" فهو يريد N. وإذا قال "distinct" أو "vocabulary" أو "unique" أو "wordform types" فهو يريد |V|.

Corpus size varies wildly, slides 5 and 6

حجم الـ corpus يتفاوت بشدة، الشريحتان 5 و6

Slide 5 makes three claims in three bullets:

تطرح الشريحة 5 ثلاث دعاوى في ثلاثة بنود:

Slide 6 is the figure that proves it. Its caption reads: rough numbers of wordform types (|V|) and tokens (N) for some English language corpora. These are the slide's numbers, and the two right-hand columns are arithmetic I did on them:

والشريحة 6 هي الشكل الذي يثبت ذلك. وتعليقه: أرقام تقريبية لعدد wordform types (|V|) والـ tokens (N) لبعض corpora الإنجليزية. هذه أرقام الشريحة، والعمودان الأيمنان حسابات أجريتها عليها:

Corpusالـ CorpusTypes = |V|Types = |V|Instances = Nالمثيلات (Instances) = NTokens per typeعدد الـ tokens لكل type|V|N
ShakespeareShakespeare31 thousand31 ألفاً884 thousand884 ألفاً28.53.51%
Brown corpusBrown corpus38 thousand38 ألفاً1 million1 مليون26.33.80%
Switchboard telephone conversationsمحادثات Switchboard الهاتفية20 thousand20 ألفاً2.4 million2.4 مليون1200.83%
COCACOCA2 million2 مليون440 million440 مليوناً2200.45%
Google n-gramsGoogle n-grams13 million13 مليوناً1 trillion1 تريليون76,9000.0013%

الجدول لكل corpus: Shakespeare فيه 31 ألف type و884 ألف token، أي 28.5 token لكل type ونسبة |V|/N تساوي 3.51%. وBrown corpus: 38 ألفاً و1 مليون، أي 26.3 و3.80%. وSwitchboard (محادثات هاتفية): 20 ألفاً و2.4 مليون، أي 120 و0.83%. وCOCA: 2 مليون و440 مليوناً، أي 220 و0.45%. وGoogle n-grams: 13 مليوناً و1 تريليون، أي 76,900 و0.0013%.

Read the first two columns and notice that they do not move together. Switchboard is almost three times the size of Shakespeare in tokens and yet has a smaller vocabulary: 20 thousand types against 31 thousand. That is the genre effect slide 5 mentions. Switchboard is recorded telephone chat, which reuses a small conversational vocabulary very heavily. Shakespeare is poetry and drama, deliberately inventive.

اقرأ العمودين الأولين ولاحظ أنهما لا يتحركان معاً. Switchboard أكبر من Shakespeare بنحو ثلاث مرات في عدد الـ tokens، ومع ذلك مفرداته أصغر: 20 ألف type مقابل 31 ألفاً. هذا هو أثر النوع (genre) الذي تذكره الشريحة 5. فـ Switchboard دردشة هاتفية مسجلة تعيد استخدام مفردات حوارية صغيرة بكثافة شديدة. أما Shakespeare فشعر ومسرح، ومبتكر عن قصد.

Read the last column and notice how fast it collapses. Going from Brown to Google n-grams multiplies N by a million but multiplies |V| by only about 342. Vocabulary grows, but nowhere near as fast as text. The next page gives that observation a name: Heaps' law.

اقرأ العمود الأخير ولاحظ سرعة انهياره. الانتقال من Brown إلى Google n-grams يضاعف N مليون مرة، لكنه يضاعف |V| نحو 342 مرة فقط. المفردات تنمو، لكن ليس بقريب من سرعة نمو النص. والصفحة التالية تعطي هذه الملاحظة اسماً: Heaps' law.

Why vocabulary is hard, slide 7

لماذا المفردات صعبة، الشريحة 7

Why can you not just write down the English dictionary once and be done? Slide 7 gives three bullets, and each one is a different leak:

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

New items keep arriving

عناصر جديدة تصل باستمرار

Proper names, new products, creative spellings, typos, and code-switching. There is no closed list of these and there never will be. Every new person, brand, or meme is a new type.

أسماء العلم، والمنتجات الجديدة، والتهجئات الإبداعية، والأخطاء المطبعية، والتبديل بين اللغات (code-switching). لا توجد قائمة مغلقة لهذه ولن توجد أبداً. كل شخص أو علامة تجارية أو meme جديد هو type جديد.

Morphology multiplies forms

الصرف يضاعف الأشكال

The slide's example: walk, walks, walked, walking. One lexical idea, four surface forms, four types. In a morphologically rich language this factor is far larger, which is the subject of page three.

مثال الشريحة: walk, walks, walked, walking. فكرة معجمية واحدة، وأربعة أشكال سطحية، وأربعة types. وفي لغة غنية صرفياً يكون هذا المضاعِف أكبر بكثير، وهذا موضوع الصفحة الثالثة.

Units span spaces

وحدات تمتد عبر المسافات

Compounding and multiword expressions. The slide names New York and ice cream. Each is two space-separated tokens but one meaning, so whitespace is giving you the wrong unit in both directions.

التركيب والتعابير متعددة الكلمات (multiword expressions). تذكر الشريحة New York وice cream. كل منهما token اثنان تفصل بينهما مسافة لكن بمعنى واحد، فالمسافات تعطيك الوحدة الخاطئة في الاتجاهين.

Preprocessing decisions, slide 8

قرارات المعالجة المسبقة، الشريحة 8

Slide 8 lists four knobs you have to set before you can count anything. None of them has a universally correct setting.

تسرد الشريحة 8 أربعة مفاتيح يجب أن تضبطها قبل أن تعدّ أي شيء. ولا يوجد لأي منها ضبط صحيح في كل الحالات.

DecisionالقرارSlide's exampleمثال الشريحةWhat it costs youما يكلّفك
Case foldingتوحيد حالة الأحرف (Case folding)Apple vs appleApple مقابل appleshrinks |V|, but merges the company with the fruit and loses sentence-initial informationيقلّص |V|، لكنه يدمج الشركة مع الفاكهة ويُضيع معلومة بداية الجملة
Punctuationعلامات الترقيمdon't vs do + n'tdon't مقابل do + n'tsplitting raises N and exposes the negation as its own unit; not splitting keeps don't and do not as unrelated typesالتقسيم يرفع N ويُظهر النفي وحدةً مستقلة؛ وعدم التقسيم يُبقي don't وdo not types غير مترابطة
Normalizationالتطبيع (Normalization)accents, Unicode variants, quotes and dashesعلامات التشكيل، ومتغيرات Unicode، وعلامات الاقتباس والشرطاتmerges forms that should be the same, but two visually identical strings can be different byte sequences, which is the Unicode page's topicيدمج أشكالاً ينبغي أن تكون واحدة، لكن سلسلتين متطابقتين بصرياً قد تكونان تسلسلَي bytes مختلفين، وهذا موضوع صفحة Unicode
Numbersالأعدادkeep raw, map to a <NUM> token, or segmentإبقاؤها كما هي، أو تحويلها إلى token هو <NUM>، أو تقطيعهاkeeping raw explodes |V| with values seen once; mapping to <NUM> collapses it but destroys the actual quantityإبقاؤها كما هي يُضخّم |V| بقيم تظهر مرة واحدة؛ وتحويلها إلى <NUM> يقلّصها لكنه يُتلف الكمية الفعلية

الجدول: Case folding (مثل Apple وapple) يقلّص |V|، لكنه يدمج الشركة بالفاكهة ويفقد معلومة بداية الجملة. والترقيم (don't مقابل do + n't): التقسيم يرفع N ويُظهر النفي وحدةً مستقلة، وعدم التقسيم يُبقي don't وdo not نوعين لا علاقة بينهما. وNormalization (علامات التشكيل، وصيغ Unicode المختلفة، وعلامات التنصيص والشرطات): يدمج أشكالاً يجب أن تكون واحدة، لكن سلسلتين متطابقتين بصرياً قد تكونان تسلسلَي بايتات مختلفين، وهذا موضوع صفحة Unicode. والأرقام (تُترك خاماً، أو تُحوَّل إلى <NUM>، أو تُقطَّع): تركها خاماً يفجّر |V| بقيم ظهرت مرة واحدة، وتحويلها إلى <NUM> يقلّصه لكنه يمحو القيمة الفعلية.

Workedمثال محلول

What case folding actually does to the two counts. Take the string:

ما الذي يفعله case folding فعلاً بالعدّتين. خذ السلسلة:

Apple released a new apple.

tokenize on whitespace, drop the period, do NOT lowercase

  tokens : Apple | released | a | new | apple
  N      = 5
  types  : {Apple, released, a, new, apple}
  |V|    = 5                "Apple" and "apple" are two different strings

now apply case folding and recount

  tokens : apple | released | a | new | apple
  N      = 5                UNCHANGED
  types  : {apple, released, a, new}
  |V|    = 4                one slot saved

الجملة Apple released a new apple. بعد التقطيع على المسافات وحذف النقطة وبدون تحويل إلى صغيرة: N = 5 و|V| = 5، لأن Apple وapple سلسلتان مختلفتان. وبعد case folding: يبقى N = 5 دون تغيير، ويصبح |V| = 4، أي وفّرنا خانة واحدة.

Two lessons in one example. First, preprocessing moves |V| but leaves N alone, because folding merges vocabulary entries without deleting any occurrence. Second, the merge was semantically wrong here: the company and the fruit are now the same type. That is the trade slide 8 is pointing at.

درسان في مثال واحد. أولاً، المعالجة المسبقة تحرّك |V| وتترك N كما هو، لأن التحويل يدمج مداخل المفردات دون حذف أي ظهور. ثانياً، كان الدمج هنا خاطئاً دلالياً: الشركة والفاكهة صارتا type واحداً. وهذه هي المقايضة التي تشير إليها الشريحة 8.

Now the contraction, same idea in the other direction:

والآن الاختصار (contraction)، الفكرة نفسها في الاتجاه الآخر:

I don't know

no split       : I | don't | know          N = 3,  |V| = 3
split the clitic: I | do | n't | know      N = 4,  |V| = 4

الجملة I don't know: بدون تقسيم تكون I | don't | know فيكون N = 3 و|V| = 3. وبتقسيم الـ clitic تكون I | do | n't | know فيكون N = 4 و|V| = 4.

Here splitting raised N. Punctuation and clitic policy pushes N up, case folding pulls |V| down. Different knobs, different counts.

هنا رفع التقسيمُ N. سياسة الترقيم والـ clitics تدفع N إلى الأعلى، وcase folding يسحب |V| إلى الأسفل. مفاتيح مختلفة، وعدّات مختلفة.

Ambiguous boundaries, slide 9

حدود غامضة، الشريحة 9

Slide 8 was about choices you make deliberately. Slide 9 is about places where the text itself is genuinely unclear, so no setting of the knobs rescues you. Four categories, with the slide's own examples:

الشريحة 8 كانت عن اختيارات تتخذها عن قصد. أما الشريحة 9 فعن مواضع يكون فيها النص نفسه غامضاً فعلاً، فلا ينقذك أي ضبط للمفاتيح. أربع فئات، بأمثلة الشريحة نفسها:

Hyphens: state-of-the-artالشرطات: state-of-the-art Abbreviations: U.S., Dr., e.g.الاختصارات: U.S., Dr., e.g. Clitics: we'll, I'm, possessive 'sالـ Clitics: we'll, I'm، و's الملكية Social media: #NLP, @user, URLsوسائل التواصل: #NLP, @user, URLs

Take them one at a time, because the difficulty is different in each.

خذها واحدة واحدة، لأن الصعوبة مختلفة في كل منها.

Trapفخ

Answering the wrong count. Read the question twice. "How many words are in this sentence" is ambiguous and will usually be disambiguated by the words tokens, types, distinct, or running. If it says tokens, repeats count. If it says types, they do not.

الإجابة بالعدد الخطأ. اقرأ السؤال مرتين. "كم كلمة في هذه الجملة" سؤال غامض، وعادة يُزال غموضه بكلمات مثل tokens أو types أو distinct أو running. إذا قال tokens فالتكرارات تُحسب. وإذا قال types فلا تُحسب.

Forgetting to state your tokenization rules. If an exam sentence has punctuation and the question does not say what to do with it, say what you assumed in one line before the number. "Punctuation dropped, no case folding, N = 16" is a complete answer. A bare "16" is a guess.

نسيان ذكر قواعد التقطيع. إذا كان في جملة الامتحان ترقيم ولم يقل السؤال ماذا تفعل به، فاذكر افتراضك في سطر واحد قبل الرقم. عبارة "Punctuation dropped, no case folding, N = 16" إجابة كاملة. أما "16" وحدها فتخمين.

Thinking a bigger corpus necessarily has a bigger vocabulary. The slide 6 figure disproves it directly: Switchboard has 2.4 million tokens against Shakespeare's 884 thousand, yet Switchboard has 20 thousand types against Shakespeare's 31 thousand. Genre beats raw size at this scale.

الظن بأن corpus أكبر يعني بالضرورة مفردات أكبر. شكل الشريحة 6 ينقض هذا مباشرة: Switchboard فيه 2.4 مليون token مقابل 884 ألفاً لـ Shakespeare، ومع ذلك فيه 20 ألف type مقابل 31 ألفاً لـ Shakespeare. النوع يتغلب على الحجم الخام عند هذا المستوى.

Thinking case folding changes N. It does not. It can only merge types. Nothing is added to or removed from the running text.

الظن بأن case folding يغيّر N. لا يغيّره. كل ما يستطيعه هو دمج types. لا يُضاف شيء إلى النص المتتالي ولا يُحذف منه شيء.

Thirty-second recap

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

token = occurrence, total count Ntoken = ظهور، والعدد الكلي N type = distinct item, vocabulary size |V|type = عنصر مميز، وحجم المفردات |V| N ≥ |V|, alwaysN ≥ |V| دائماً "to be or not to be": N = 6, |V| = 4 Shakespeare: |V| = 31k, N = 884kShakespeare: |V| = 31k، N = 884k Switchboard: |V| = 20k, N = 2.4M, bigger text, smaller vocabularySwitchboard: |V| = 20k، N = 2.4M، نص أكبر ومفردات أصغر Google n-grams: |V| = 13M, N = 1 trillionGoogle n-grams: |V| = 13M، N = 1 تريليون case folding lowers |V|, leaves N alonecase folding يخفض |V| ولا يمسّ N splitting don't into do + n't raises Nتقسيم don't إلى do + n't يرفع N Chinese has no spaces to split onالصينية لا مسافات فيها للتقسيم عليها

ملخص الشرائح: token هو ظهور وعددها الكلي N، وtype عنصر مميز وعددها حجم المفردات |V|، وN ≥ |V| دائماً. "to be or not to be": N = 6 و|V| = 4. Shakespeare: |V| = 31k وN = 884k. Switchboard: |V| = 20k وN = 2.4M، نص أكبر ومفردات أصغر. Google n-grams: |V| = 13M وN = 1 trillion. case folding يخفض |V| ويترك N. تقسيم don't إلى do + n't يرفع N. والصينية لا مسافات فيها تقطع عندها.

Check yourself

اختبر نفسك

Tokenize "the cat sat on the mat and the mat was flat" on whitespace, no punctuation involved. What are N and |V|?

قطّع الجملة "the cat sat on the mat and the mat was flat" على المسافات، ولا ترقيم فيها. كم N و|V|؟

Eleven words go by, so N = 11. The distinct set is {the, cat, sat, on, mat, and, was, flat}, which is 8, because the occurs three times and mat twice: 11 minus 2 extra the minus 1 extra mat = 8. A is the same two numbers with the labels swapped, which is the mistake this question exists to catch. Remember N ≥ |V| always, so any answer with |V| bigger than N is impossible on sight.

الجواب C. تمر بك إحدى عشرة كلمة، فـ N = 11. والمجموعة المميزة هي {the, cat, sat, on, mat, and, was, flat} وعددها 8، لأن the تظهر ثلاث مرات وmat مرتين: 11 ناقص 2 زائدتين لـ the ناقص 1 زائدة لـ mat يساوي 8. والجواب A هو الرقمان نفسهما مع تبديل التسميتين، وهذا هو الخطأ الذي وُضع السؤال لاصطياده. تذكر أن N ≥ |V| دائماً، فأي إجابة فيها |V| أكبر من N مستحيلة من النظرة الأولى.

Slide 6 reports Switchboard with |V| = 20 thousand and N = 2.4 million, and Shakespeare with |V| = 31 thousand and N = 884 thousand. What does this pair show?

تذكر الشريحة 6 أن Switchboard فيه |V| = 20 ألفاً وN = 2.4 مليون، وShakespeare فيه |V| = 31 ألفاً وN = 884 ألفاً. ماذا يُظهر هذا الزوج؟

This is slide 5's middle bullet made concrete: even within one language, genre and domain shift the vocabulary. Conversational telephone speech reuses a small set of words very heavily. A is the tempting answer because Heaps' law does say vocabulary grows with N, but that holds within one growing corpus, not across two different corpora from different genres. D is backwards: Switchboard's |V|/N is 0.83%, far below Shakespeare's 3.51%.

الجواب B. هذا هو البند الأوسط في الشريحة 5 بصورة ملموسة: حتى داخل لغة واحدة، النوع والمجال يغيّران المفردات. فالكلام الهاتفي الحواري يعيد استخدام مجموعة صغيرة من الكلمات بكثافة. والجواب A مُغرٍ لأن Heaps' law يقول فعلاً إن المفردات تنمو مع N، لكن هذا يصح داخل corpus واحد ينمو، لا بين corpora مختلفة من أنواع مختلفة. والجواب D معكوس: نسبة |V|/N في Switchboard هي 0.83%، أقل بكثير من 3.51% في Shakespeare.

You apply case folding to a corpus. What happens to N and |V|?

طبّقت case folding على corpus. ماذا يحدث لـ N و|V|؟

Case folding rewrites the spelling of occurrences, it never deletes one, so the running text is still the same length and N is fixed. What it can do is merge two vocabulary entries into one, as with Apple and apple, which lowers |V|. If no word in the corpus ever appeared in two cases, |V| would not move either, which is why the answer says "or stays the same". A is the common wrong answer: people assume merging shrinks everything, but merging is a vocabulary operation.

الجواب D. الـ case folding يعيد كتابة تهجئة مرات الظهور ولا يحذف أياً منها، فيبقى طول النص المتتالي كما هو ويبقى N ثابتاً. وما يستطيعه هو دمج مدخلين من المفردات في مدخل واحد، كما في Apple وapple، فينخفض |V|. وإذا لم تظهر أي كلمة في الـ corpus بحالتين مختلفتين فلن يتحرك |V| أيضاً، ولهذا تقول الإجابة "أو يبقى كما هو". والجواب A هو الخطأ الشائع: يفترض الناس أن الدمج يقلّص كل شيء، لكن الدمج عملية على المفردات فقط.

Slide 8 contrasts don't with do + n't. Suppose you switch a tokenizer from the first policy to the second across a whole corpus. Which is true?

تقارن الشريحة 8 بين don't وdo + n't. افترض أنك حوّلت tokenizer من السياسة الأولى إلى الثانية على corpus كامل. أي العبارات صحيحة؟

Splitting creates occurrences, so N rises by one per contraction. |V| also changes, but not in an obvious direction: you lose the type don't and gain do and n't, and do very likely existed already. B confuses string length with token count. Token counts do not care how many characters a token has.

الجواب A. التقسيم يُنشئ مرات ظهور جديدة، فيرتفع N بواحد لكل اختصار. و|V| يتغير أيضاً لكن ليس في اتجاه واضح: تخسر الـ type don't وتكسب do وn't، وdo غالباً موجودة أصلاً. والجواب B يخلط بين طول السلسلة وعدد الـ tokens. فعدّ الـ tokens لا يهتم بعدد حروف كل token.

Slide 9 groups U.S., Dr. and e.g. under ambiguous boundaries. What specifically makes them hard?

تضع الشريحة 9 U.S. وDr. وe.g. تحت الحدود الغامضة. ما الذي يجعلها صعبة تحديداً؟

The period is doing double duty in English: it abbreviates and it terminates. A naive splitter that treats every period as a boundary will chop U.S. into U and S and start a spurious new sentence. D describes a different slide 7 problem, New York and ice cream, where the unit spans a space rather than containing a period.

الجواب C. النقطة تؤدي وظيفتين في الإنجليزية: تختصر وتُنهي. والمقطّع الساذج الذي يعامل كل نقطة حدّاً سيقطع U.S. إلى U وS ويبدأ جملة جديدة زائفة. والجواب D يصف مشكلة أخرى من الشريحة 7، أي New York وice cream، حيث تمتد الوحدة عبر مسافة بدلاً من أن تحتوي نقطة.

Slide 3 mentions Chinese when discussing segmentation across languages. Why is it raised?

تذكر الشريحة 3 الصينية عند الحديث عن التقطيع عبر اللغات. لماذا ذُكرت؟

The slide's bullet is that segmentation can be ambiguous or absent. English gives you spaces for free and you only argue about edge cases. Chinese gives you nothing, so segmentation is a modelling problem from the very first step. D is the opposite of the truth and also a popular misconception: many Chinese words are two or more characters, which is exactly why the boundary is genuinely ambiguous rather than trivially solved.

الجواب B. بند الشريحة يقول إن التقطيع قد يكون غامضاً أو غائباً. الإنجليزية تعطيك المسافات مجاناً ولا تتجادل إلا في الحالات الحدية. أما الصينية فلا تعطيك شيئاً، فيصبح التقطيع مسألة نمذجة من الخطوة الأولى. والجواب D عكس الحقيقة، وهو أيضاً تصور خاطئ شائع: كثير من الكلمات الصينية من حرفين أو أكثر، وهذا بالضبط سبب أن الحدود غامضة فعلاً لا محلولة ببساطة.

The sentence on slide 3 is "They picnicked by the pool, then lay back on the grass and looked at the stars." A question asks for the number of types, with punctuation dropped and no case folding. What do you answer?

جملة الشريحة 3 هي "They picnicked by the pool, then lay back on the grass and looked at the stars." يطلب السؤال عدد types، مع حذف الترقيم وبدون case folding. ماذا تجيب؟

There are 16 word tokens, and the occurs three times, so two of those occurrences add nothing to the vocabulary: 16 minus 2 = 14 types. A is the token count, which is the answer to the other question, and is the trap. B is the token count with the comma and period kept, which the question explicitly excluded.

الجواب D. فيها 16 token من الكلمات، وthe تظهر ثلاث مرات، فاثنتان من مرات ظهورها لا تضيفان شيئاً إلى المفردات: 16 ناقص 2 يساوي 14 type. والجواب A هو عدد الـ tokens، أي جواب السؤال الآخر، وهو الفخ. والجواب B هو عدد الـ tokens مع الإبقاء على الفاصلة والنقطة، وهذا ما استبعده السؤال صراحة.