Lecture 02 · Words and Tokens
المحاضرة 02 · الكلمات والرموز (Tokens)
Zipf and Heaps
قانونا Zipf وHeaps
P2 SHOULDTwo laws about the same pile of text: one says how unevenly frequency is spread over the words you have, the other says how fast new words keep arriving.
قانونان عن كومة النص نفسها: الأول يقول كم يتوزع التكرار بشكل غير متساوٍ على الكلمات التي لديك، والثاني يقول بأي سرعة تستمر الكلمات الجديدة في الوصول.
Both formulas are short enough to be asked for verbatim. Expect to write f(R) ∝ 1/Rα and |V| = kNβ, to say what each symbol is, and to state the range of β and why it matters. The conceptual question that separates marks is which law is about which quantity.
المعادلتان قصيرتان بما يكفي ليُطلب منك كتابتهما حرفياً. توقّع أن تكتب f(R) ∝ 1/Rα و|V| = kNβ، وأن تقول ما يعنيه كل رمز، وأن تذكر مدى β ولماذا يهم. والسؤال المفاهيمي الذي يفرّق الدرجات هو: أي قانون يتحدث عن أي كمية.
Zipf's law, slide 10
قانون Zipf، الشريحة 10
Start with a procedure, not a formula. Take a corpus. Count how often every word occurs. Sort the list from most frequent down to least frequent. Now number the rows: the most frequent word is rank R = 1, the next is R = 2, and so on. Slide 10 states that first bullet exactly this way: sort words by frequency, rank R = 1 is most frequent.
ابدأ بإجراء لا بمعادلة. خذ corpus. عدّ كم مرة تظهر كل كلمة. رتّب القائمة من الأكثر تكراراً إلى الأقل. ثم رقّم الصفوف: الكلمة الأكثر تكراراً رتبتها R = 1، والتالية R = 2، وهكذا. والشريحة 10 تذكر البند الأول بهذه الطريقة تماماً: رتّب الكلمات حسب التكرار، والرتبة R = 1 هي الأكثر تكراراً.
Zipf's observation is about the shape of that sorted list. The frequency does not trail off gently. It collapses, and it collapses in a very regular way:
ملاحظة Zipf تتعلق بشكل هذه القائمة المرتبة. التكرار لا يتناقص بلطف، بل ينهار، وينهار بطريقة منتظمة جداً:
تُقرأ المعادلة: تكرار الكلمة في الرتبة R يتناسب مع واحد مقسوماً على R مرفوعة للأس α.
The slide's wording: frequency decreases roughly as a power law. Read the formula as a sentence. The frequency of the word in position R is proportional to one over R raised to some exponent α. Halve nothing, just move down the ranked list, and the frequency falls off a cliff.
عبارة الشريحة: التكرار يتناقص تقريباً وفق قانون قوة (power law). اقرأ المعادلة كجملة: تكرار الكلمة في الموضع R يتناسب مع واحد على R مرفوعة لأس ما هو α. لا تفعل شيئاً سوى أن تنزل في القائمة المرتبة، فيسقط التكرار من حافة جرف.
Slide 10's third bullet is the intuition in eight words: few words are extremely common, most are rare. The symbol ∝ means "proportional to", so the formula fixes the shape of the curve but not its height. The height is set by the corpus size.
البند الثالث في الشريحة 10 هو الحدس في ثماني كلمات: كلمات قليلة شائعة جداً، ومعظم الكلمات نادرة. والرمز ∝ يعني "يتناسب مع"، فالمعادلة تحدد شكل المنحنى لا ارتفاعه. والارتفاع يحدده حجم الـ corpus.
What α does
ماذا يفعل α
If α = 1, the law reads: the second most common word occurs about half as often as the first, the tenth about a tenth as often, the hundredth about a hundredth as often. That is the version worth carrying in your head because the arithmetic is trivial.
إذا كان α = 1 فالقانون يقول: الكلمة الثانية في الشيوع تظهر بنحو نصف مرات الأولى، والعاشرة بنحو عُشرها، والمئة بنحو جزء من مئة. هذه هي النسخة التي تستحق أن تحملها في رأسك لأن حسابها بديهي.
Real corpora sit near α = 1 but not exactly on it. The figure on slide 11 fits two reference power laws and prints their exponents: α = 0.9290 for English Wikipedia and α = 0.9252 for Arabic Wikipedia. Nearly identical, both just under 1, in two unrelated languages with completely different morphology. That robustness is the reason the law is taken seriously.
الـ corpora الحقيقية قريبة من α = 1 لكنها ليست عليها تماماً. شكل الشريحة 11 يطابق قانونَي قوة مرجعيين ويطبع أسّيهما: α = 0.9290 لويكيبيديا الإنجليزية وα = 0.9252 لويكيبيديا العربية. متطابقان تقريباً، وكلاهما أقل من 1 بقليل، في لغتين لا علاقة بينهما وصرفهما مختلف تماماً. وهذه المتانة هي سبب أخذ القانون بجدية.
The Zipf curve, slide 11
منحنى Zipf، الشريحة 11
Slide 11 is a figure captioned "Rank vs. frequency (Zipf's law)". Both axes are logarithmic, which is the key to reading it. Taking logs of f(R) ∝ 1/Rα gives:
الشريحة 11 شكل عنوانه "Rank vs. frequency (Zipf's law)". المحوران لوغاريتميان، وهذا مفتاح قراءته. أخذ اللوغاريتم لـ f(R) ∝ 1/Rα يعطي:
أي أن log f(R) يساوي −α مضروباً في log R زائد ثابت، وهذه معادلة خط مستقيم.
A power law becomes a straight line with slope −α on log-log axes. So the way you test Zipf's law is: plot it log-log, and check whether you get a straight line. The slide's figure plots three real datasets (English Wikipedia, Arabic Wikipedia, and an undotted Arabic Wikipedia variant) against two dotted reference lines, and they all run close to straight across roughly six decades of rank.
قانون القوة يصبح خطاً مستقيماً ميله −α على محاور log-log. فطريقة اختبار Zipf's law هي: ارسمه log-log وتحقق هل تحصل على خط مستقيم. يرسم شكل الشريحة ثلاث مجموعات بيانات حقيقية (ويكيبيديا الإنجليزية، وويكيبيديا العربية، ونسخة من ويكيبيديا العربية بلا نقاط) مقابل خطين مرجعيين منقطين، وكلها تسير قريبة من الاستقامة عبر نحو ست مراتب عشرية من الرتب.
في الرسم محور أفقي للرتبة R ومحور رأسي للتكرار، وكلاهما بمقياس لوغاريتمي. تبدأ النقطة R = 1 (أكثر الكلمات تكراراً) في الأعلى يساراً، والخط المنقط هو قانون القوة الخالص بميل −α = −0.929. على محاور log-log يكون قانون القوة خطاً مستقيماً ميله −α. والمنحنى الحقيقي يتبع الخط المرجعي عبر عدة مراتب عشرية ثم يهبط في الذيل البعيد، حيث يصل التكرار إلى 1 ولا يمكنه النزول أكثر. وكل ما هو مسطّح على طول القاع هو كلمة ظهرت مرة واحدة بالضبط، وهذا هو الذيل الطويل (long tail) الذي تسكنه معظم الـ types.
Zipf with numbers. The slide 11 figure tops out near 107 for the most frequent word, so set f(1) = 10,000,000 and use the English Wikipedia exponent α = 0.9290. The formula with the proportionality turned into an equation is f(R) = f(1) / Rα.
Zipf بالأرقام. شكل الشريحة 11 يصل قمته قرب 107 للكلمة الأكثر تكراراً، فنضع f(1) = 10,000,000 ونستخدم أس ويكيبيديا الإنجليزية α = 0.9290. والمعادلة بعد تحويل التناسب إلى مساواة هي f(R) = f(1) / Rα.
f(R) = 10,000,000 / R^0.9290
R = 1 10^0.9290 = 1
f = 10,000,000 / 1 = 10,000,000
R = 10 10^0.9290 = 8.4918
f = 10,000,000 / 8.4918 = 1,177,606
R = 100 100^0.9290 = 10^1.858 = 72.11
f = 10,000,000 / 72.11 = 138,676
R = 1000 1000^0.9290 = 10^2.787 = 612.3
f = 10,000,000 / 612.3 = 16,331
R = 10000 10^3.716 = 5,200
f = 10,000,000 / 5,200 = 1,923
R = 100000 10^4.645 = 44,157
f = 10,000,000 / 44,157 = 226
يحسب المقطع f(R) = 10,000,000 / R^0.9290 لست رتب: عند R = 1 يكون f = 10,000,000. وعند R = 10 يكون المقام 8.4918 فـ f = 1,177,606. وعند R = 100 المقام 72.11 فـ f = 138,676. وعند R = 1000 المقام 612.3 فـ f = 16,331. وعند R = 10000 المقام 5,200 فـ f = 1,923. وعند R = 100000 المقام 44,157 فـ f = 226.
Read down the right-hand column. The word ranked 100,000th occurs 226 times. The word ranked 1st occurs ten million times. That is a factor of about 44,000 between two entries of the same list.
اقرأ العمود الأيمن من أعلى إلى أسفل. الكلمة في الرتبة 100,000 تظهر 226 مرة. والكلمة في الرتبة الأولى تظهر عشرة ملايين مرة. هذا فرق بمعامل يقارب 44,000 بين مدخلين في القائمة نفسها.
Sanity check with the easy case α = 1, which you can do in your head: f(10) = 1,000,000, f(100) = 100,000, f(1000) = 10,000. One decade of rank costs exactly one decade of frequency. With α = 0.929 the drop is slightly gentler, 8.49× per decade instead of 10×, which is why the real line is a hair shallower than a 45-degree descent.
تحقق منطقي بالحالة السهلة α = 1 التي تستطيع حسابها في رأسك: f(10) = 1,000,000، وf(100) = 100,000، وf(1000) = 10,000. كل مرتبة عشرية في الرتبة تكلّف مرتبة عشرية واحدة بالضبط في التكرار. ومع α = 0.929 يكون الهبوط ألطف قليلاً، 8.49× لكل مرتبة عشرية بدلاً من 10×، ولهذا يكون الخط الحقيقي أقل انحداراً بشعرة من نزول بزاوية 45 درجة.
Heaps' law, slide 12
قانون Heaps، الشريحة 12
Zipf described a corpus you already finished reading. Heaps describes what happens while you are still reading it.
Zipf وصف corpus انتهيت من قراءته. أما Heaps فيصف ما يحدث وأنت ما زلت تقرأ.
Slide 12's first bullet: as we see more tokens (N), we keep encountering new types (|V|). The question is at what rate, and the answer is called Heaps' law, or Herdan's law, and the slide gives both names:
البند الأول في الشريحة 12: كلما رأينا tokens أكثر (N) استمررنا في مصادفة types جديدة (|V|). والسؤال بأي معدل، والجواب يسمى Heaps' law أو Herdan's law، والشريحة تذكر الاسمين معاً:
تُقرأ المعادلة: |V| يساوي k مضروباً في N مرفوعة للأس β، بشرط 0 < β < 1.
Here N is the number of tokens read so far, |V| is the number of distinct types you have met, k is a constant that sets the scale, and β is the growth exponent. The parenthesis is part of the slide and it is the whole content of the law.
هنا N عدد الـ tokens المقروءة حتى الآن، و|V| عدد الـ types المميزة التي صادفتها، وk ثابت يحدد المقياس، وβ أس النمو. والشرط بين القوسين جزء من الشريحة، وهو مضمون القانون كله.
The slide's final bullet is the sentence to memorise: vocabulary growth is sublinear but unbounded. Both halves matter and they are easy to confuse.
البند الأخير في الشريحة هو الجملة التي يجب حفظها: نمو المفردات دون خطي (sublinear) لكنه غير محدود (unbounded). والنصفان كلاهما مهم، ومن السهل الخلط بينهما.
| Phraseالعبارة | Which part of the formula says itأي جزء من الصيغة يقولها | What it rules outما الذي تستبعده |
|---|---|---|
| sublinearدون خطي (sublinear) | β < 1 | rules out |V| growing in proportion to N. Doubling the text does not double the vocabulary.تستبعد أن ينمو |V| بالتناسب مع N. مضاعفة النص لا تضاعف المفردات. |
| unboundedغير محدود (unbounded) | β > 0 | rules out |V| ever levelling off at a ceiling. There is no corpus size at which you stop meeting new words.تستبعد أن يستقر |V| يوماً عند سقف. لا يوجد حجم corpus تتوقف عنده عن مصادفة كلمات جديدة. |
الجدول: sublinear يعبّر عنه الشرط β < 1، وهو يستبعد أن ينمو |V| بالتناسب مع N، فمضاعفة النص لا تضاعف المفردات. وunbounded يعبّر عنه الشرط β > 0، وهو يستبعد أن يستقر |V| يوماً عند سقف، فلا يوجد حجم corpus تتوقف عنده عن مصادفة كلمات جديدة.
If β were 1 the growth would be linear. If β were 0 then |V| = k, a constant, and vocabulary would be fixed from the first sentence. The condition 0 < β < 1 is exactly the statement that reality sits strictly between those two.
لو كان β يساوي 1 لكان النمو خطياً. ولو كان 0 لكان |V| = k ثابتاً، ولكانت المفردات محددة منذ الجملة الأولى. والشرط 0 < β < 1 هو بالضبط القول بأن الواقع يقع بين هاتين الحالتين تماماً.
The Heaps curve, slide 13
منحنى Heaps، الشريحة 13
Slide 13 is a figure captioned "Vocabulary size |V| as a function of N (Heaps' law)". It plots three fitted curves and prints the fitted parameters in the legend:
الشريحة 13 شكل عنوانه "Vocabulary size |V| as a function of N (Heaps' law)". يرسم ثلاثة منحنيات مُطابَقة ويطبع المعاملات المطابقة في مفتاح الرسم:
| Dataset on slide 13مجموعة البيانات في الشريحة 13 | k | β |
|---|---|---|
| english_wiki | 14.947 | 0.583 |
| arabic_wiki | 73.321 | 0.533 |
| undotted_arabic_wiki | 90.491 | 0.506 |
قيم الجدول: english_wiki فيها k = 14.947 وβ = 0.583. وarabic_wiki فيها k = 73.321 وβ = 0.533. وundotted_arabic_wiki فيها k = 90.491 وβ = 0.506.
All three β values are strictly between 0 and 1, exactly as slide 12 requires. Notice also that Arabic has the much larger k. We will see what that buys in the worked example below.
قيم β الثلاث كلها بين 0 و1 تماماً كما تشترط الشريحة 12. ولاحظ أيضاً أن العربية لها k أكبر بكثير. وسنرى ما الذي يعنيه ذلك في المثال المحلول أدناه.
في الرسم محور أفقي هو النص المقروء N ومحور رأسي هو المفردات |V|. المنحنى الملوّن هو |V| = k · Nβ مع β = 0.583: ينحني، وهذا معنى sublinear. ولا يصبح أفقياً أبداً، وهذا معنى unbounded، وتشير العلامة عند طرفه إلى أنه ما زال يرتفع، والخط الأفقي المنقط في الأعلى يذكّر بأنه لا يوجد سقف. أما الخط المستقيم المتقطع فهو ما سيبدو عليه النمو الخطي، ويخرج من أعلى الرسم فوراً تقريباً.
Heaps with the slide 13 English Wikipedia fit, k = 14.947 and β = 0.583. Feed it four corpus sizes:
Heaps مع مطابقة ويكيبيديا الإنجليزية من الشريحة 13، أي k = 14.947 وβ = 0.583. نعطيه أربعة أحجام للـ corpus:
|V| = 14.947 x N^0.583
N = 100,000 N^0.583 = 10^(5 x 0.583) = 10^2.915 = 822.2
|V| = 14.947 x 822.2 = 12,290
N = 1,000,000 N^0.583 = 10^(6 x 0.583) = 10^3.498 = 3,147.7
|V| = 14.947 x 3,147.7 = 47,049
N = 10,000,000 N^0.583 = 10^(7 x 0.583) = 10^4.081 = 12,050.0
|V| = 14.947 x 12,050 = 180,117
N = 100,000,000 N^0.583 = 10^(8 x 0.583) = 10^4.664 = 46,131
|V| = 14.947 x 46,131 = 689,531
يحسب المقطع |V| = 14.947 x N^0.583: عند N = 100,000 يكون N^0.583 = 822.2 فـ |V| = 12,290. وعند N = 1,000,000 يكون 3,147.7 فـ |V| = 47,049. وعند N = 10,000,000 يكون 12,050 فـ |V| = 180,117. وعند N = 100,000,000 يكون 46,131 فـ |V| = 689,531.
Now the part worth memorising. Look at what each tenfold increase in N buys:
والآن الجزء الذي يستحق الحفظ. انظر ماذا تشتري كل زيادة بعشرة أضعاف في N:
47,049 / 12,290 = 3.828 180,117 / 47,049 = 3.828 689,531 / 180,117 = 3.828 and 10^0.583 = 3.828 the same number, every time
كل نسبة بين صفين متتاليين (47,049 / 12,290، و180,117 / 47,049، و689,531 / 180,117) تساوي 3.828، وهو نفسه 10^0.583، الرقم نفسه في كل مرة.
Multiplying N by 10 multiplies |V| by 10β, always. That is the whole behaviour of a power law in one line. Ten times the text, but under four times the vocabulary. The vocabulary is falling behind by a factor of 2.6 per decade, forever, and yet it never stops rising.
ضرب N في 10 يضرب |V| في 10β، دائماً. هذا سلوك قانون القوة كله في سطر واحد. عشرة أضعاف النص، لكن أقل من أربعة أضعاف المفردات. المفردات تتأخر بمعامل 2.6 في كل مرتبة عشرية، إلى الأبد، ومع ذلك لا تتوقف عن الارتفاع أبداً.
A rough cross-check against page one. Shakespeare has N = 884,000 tokens. This English Wikipedia fit predicts 14.947 × 884,0000.583 = 43,786 types, and the slide 6 figure reports Shakespeare's actual |V| as about 31,000. Same ballpark, and an over-estimate, which is what you would expect from a fit made on a different and far more varied corpus. Heaps' constants are corpus-specific, not universal.
تحقق تقريبي مقابل الصفحة الأولى. Shakespeare فيه N = 884,000 token. ومطابقة ويكيبيديا الإنجليزية هذه تتنبأ بـ 14.947 × 884,0000.583 = 43,786 type، بينما يذكر شكل الشريحة 6 أن |V| الفعلي لـ Shakespeare نحو 31,000. نفس النطاق تقريباً، مع تقدير زائد، وهذا متوقع من مطابقة أُجريت على corpus مختلف وأكثر تنوعاً بكثير. ثوابت Heaps خاصة بكل corpus، وليست عالمية.
Now the same arithmetic for Arabic, using slide 13's arabic_wiki fit, k = 73.321 and β = 0.533. Compare the two languages at identical corpus sizes.
والآن الحساب نفسه للعربية، باستخدام مطابقة arabic_wiki من الشريحة 13، أي k = 73.321 وβ = 0.533. قارن اللغتين عند أحجام corpus متطابقة.
English fit Arabic fit
k=14.947, B=0.583 k=73.321, B=0.533
N = 100,000 12,290 33,902
N = 1,000,000 47,049 115,672
N = 10,000,000 180,117 394,665
N = 100,000,000 689,531 1,346,568
growth per 10x N 10^0.583 = 3.828 10^0.533 = 3.412
المقطع يضع اللغتين جنباً إلى جنب. عند N = 100,000: الإنجليزية 12,290 والعربية 33,902. وعند 1,000,000: 47,049 مقابل 115,672. وعند 10,000,000: 180,117 مقابل 394,665. وعند 100,000,000: 689,531 مقابل 1,346,568. والنمو لكل عشرة أضعاف في N: 10^0.583 = 3.828 للإنجليزية و10^0.533 = 3.412 للعربية.
At one million tokens, the Arabic corpus carries roughly 2.5 times as many distinct surface forms as the English one (115,672 against 47,049). That gap comes from Arabic morphology, which generates far more written forms per lexical item. You will see exactly why on the next page.
عند مليون token، يحمل الـ corpus العربي نحو 2.5 ضعف الأشكال السطحية المميزة التي يحملها الإنجليزي (115,672 مقابل 47,049). وهذه الفجوة سببها الصرف العربي، الذي يولّد أشكالاً مكتوبة أكثر بكثير لكل وحدة معجمية. وسترى السبب بالضبط في الصفحة التالية.
The two exponents go the other way: Arabic's β is smaller, so its curve is flatter. Does English ever catch up? Set the two equal and solve for N. You need N0.05 = 73.321 / 14.947 = 4.905, so N = 4.90520 ≈ 6.5 × 1013 tokens. That is sixty-five trillion tokens, far beyond any corpus anyone has. In every realistic range, Arabic's vocabulary is the larger one.
أما الأسّان فيسيران في الاتجاه المعاكس: β العربية أصغر، فمنحناها أكثر تسطحاً. فهل تلحق الإنجليزية بها يوماً؟ ساوِ بين الاثنين وحلّ لـ N. تحتاج N0.05 = 73.321 / 14.947 = 4.905، فيكون N = 4.90520 ≈ 6.5 × 1013 token. أي خمسة وستون تريليون token، أبعد بكثير من أي corpus يملكه أحد. وفي كل نطاق واقعي تكون مفردات العربية هي الأكبر.
Zipf versus Heaps, the comparison that gets examined
Zipf مقابل Heaps، المقارنة التي يُختبر عليها
They are easy to blur because both are power laws about the same corpus. Here is the difference in one line: Zipf describes how frequency is distributed over the words you already have. Heaps describes how fast new words keep arriving.
من السهل الخلط بينهما لأن كليهما قانون قوة عن الـ corpus نفسه. وهذا هو الفرق في سطر واحد: Zipf يصف كيف يتوزع التكرار على الكلمات التي لديك أصلاً. وHeaps يصف بأي سرعة تستمر الكلمات الجديدة في الوصول.
| Zipf's law (slide 10)قانون Zipf (الشريحة 10) | Heaps' law (slide 12)قانون Heaps (الشريحة 12) | |
|---|---|---|
| Formulaالصيغة | f(R) ∝ 1Rα | |V| = k · Nβ |
| Input variableمتغير الإدخال | R, a word's rank in the frequency-sorted listR، رتبة الكلمة في القائمة المرتبة حسب التكرار | N, how much running text you have readN، كمية النص المتتالي الذي قرأته |
| Outputالمخرَج | f, that word's frequencyf، تكرار تلك الكلمة | |V|, the vocabulary size so far|V|، حجم المفردات حتى الآن |
| Question it answersالسؤال الذي يجيب عنه | how uneven is frequency across wordsما مدى تفاوت التكرار بين الكلمات | how fast does the dictionary growما سرعة نمو القاموس |
| Exponent sits whereأين يقع الأس | in the denominator, so bigger α means a steeper collapseفي المقام، فـ α الأكبر تعني انهياراً أشد | in the numerator, so bigger β means faster vocabulary growthفي البسط، فـ β الأكبر تعني نمواً أسرع للمفردات |
| Directionالاتجاه | decreasing in Rمتناقص مع R | increasing in Nمتزايد مع N |
| Slide's fitted valuesالقيم المُوفَّقة في الشريحة | α = 0.9290 English, 0.9252 Arabicα = 0.9290 للإنجليزية، و0.9252 للعربية | β = 0.583 English, 0.533 Arabicβ = 0.583 للإنجليزية، و0.533 للعربية |
| Says anything about |V|?هل يقول شيئاً عن |V|؟ | noلا | yes, that is its entire subjectنعم، فهذا موضوعه كله |
الجدول يقارن القانونين. المعادلة: f(R) ∝ 1/Rα مقابل |V| = k · Nβ. المتغير الداخل: R رتبة الكلمة في القائمة المرتبة بالتكرار، مقابل N كمية النص المقروء. الخارج: f تكرار تلك الكلمة، مقابل |V| حجم المفردات حتى الآن. السؤال: كم يتفاوت التكرار بين الكلمات، مقابل بأي سرعة ينمو القاموس. موضع الأس: في المقام، فـ α أكبر تعني انهياراً أشد، مقابل في البسط، فـ β أكبر تعني نمواً أسرع للمفردات. الاتجاه: متناقص في R، مقابل متزايد في N. القيم المطابقة في الشرائح: α = 0.9290 للإنجليزية و0.9252 للعربية، مقابل β = 0.583 للإنجليزية و0.533 للعربية. وهل يقول شيئاً عن |V|؟ Zipf لا، وHeaps نعم، فهذا موضوعه كله.
Zipf looks down the list. Heaps looks ahead at the page. Zipf needs a finished, sorted corpus. Heaps needs a corpus you are still reading.
Zipf ينظر إلى أسفل القائمة. وHeaps ينظر إلى الأمام في الصفحة. Zipf يحتاج corpus منتهياً ومرتباً. وHeaps يحتاج corpus ما زلت تقرؤه.
For the formulas: Zipf puts the exponent under the bar, so the curve goes down. Heaps puts it up top, so the curve goes up.
وللمعادلتين: Zipf يضع الأس تحت خط الكسر، فينزل المنحنى. وHeaps يضعه في الأعلى، فيصعد المنحنى.
For the β condition: below one means it bends. Above zero means it never stops. Say both halves, because an exam answer with only one half is only half right.
ولشرط β: أقل من واحد يعني أنه ينحني. وأكبر من صفر يعني أنه لا يتوقف أبداً. قل النصفين معاً، لأن إجابة الامتحان التي فيها نصف واحد صحيحة بالنصف فقط.
For the growth rule: ten times the text, ten-to-the-beta times the vocabulary. With β = 0.583 that is 3.83×, and it is the same multiplier at every scale.
ولقاعدة النمو: عشرة أضعاف النص، تعطي عشرة مرفوعة لـ β أضعاف المفردات. ومع β = 0.583 يكون ذلك 3.83×، وهو المضاعِف نفسه عند كل مقياس.
Why it matters, slide 14
لماذا يهم هذا، الشريحة 14
Slide 14 draws the engineering consequence in three bullets, and they form a chain:
ترسم الشريحة 14 النتيجة الهندسية في ثلاثة بنود، وهي تشكّل سلسلة:
- Word-level vocabularies become huge, giving memory and sparsity problems. A neural model needs an embedding row and an output logit per type. At 689,531 types that is 689,531 rows. Sparsity is the deeper problem: most of those types occur a handful of times, so there is not enough evidence to estimate anything about them.
المفردات على مستوى الكلمة تصبح ضخمة، فتنشأ مشكلات في الذاكرة والتناثر (sparsity). النموذج العصبي يحتاج صف embedding وlogit خرج لكل type. وعند 689,531 type يعني ذلك 689,531 صفاً. والتناثر هو المشكلة الأعمق: معظم هذه الـ types تظهر بضع مرات فقط، فلا توجد أدلة كافية لتقدير أي شيء عنها.
- Many words are out-of-vocabulary (OOV) in training. This is Heaps' law restated as a threat. Because |V| never saturates, your test set is guaranteed to contain words your training set never showed you. You cannot fix that by collecting more training data, because the test data grows new words too.
كلمات كثيرة تكون خارج المفردات (OOV) في التدريب. هذا هو Heaps' law معاداً صياغته كتهديد. لأن |V| لا يتشبع أبداً، فمجموعة الاختبار مضمون أن تحتوي كلمات لم تُرِك إياها مجموعة التدريب. ولا يمكنك إصلاح ذلك بجمع مزيد من بيانات التدريب، لأن بيانات الاختبار تنمو فيها كلمات جديدة أيضاً.
- Motivates subword and byte tokenization. The escape. Stop making the token a word. If your units are pieces of words, or raw bytes, then the inventory is small and closed, and an unseen word is spelled out of pieces you already know rather than being an unknown. This is why byte-pair encoding exists, and it is the topic later in this same deck.
هذا يدفع نحو subword وbyte tokenization. هذا هو المخرج. توقف عن جعل الـ token كلمة. إذا كانت وحداتك أجزاء كلمات أو بايتات خاماً، فالمخزون صغير ومغلق، والكلمة غير المرئية تُهجّأ من أجزاء تعرفها أصلاً بدلاً من أن تكون مجهولة. ولهذا وُجد byte-pair encoding، وهو موضوع لاحق في المحاضرة نفسها.
Notice the logic. Heaps' law is not a curiosity. It is the formal reason that the field abandoned word-level vocabularies.
لاحظ المنطق. Heaps' law ليس طرفة. إنه السبب الرسمي الذي جعل المجال يتخلى عن المفردات على مستوى الكلمة.
Rare words dominate, slide 15
الكلمات النادرة هي الغالبة، الشريحة 15
Slide 15's first bullet introduces the term you need: a hapax legomenon is a word that appears exactly once in a corpus. The plural is hapax legomena. The slide's claim is that a large fraction of types appear only once.
البند الأول في الشريحة 15 يقدّم المصطلح الذي تحتاجه: hapax legomenon هي كلمة تظهر مرة واحدة بالضبط في الـ corpus. وجمعها hapax legomena. ودعوى الشريحة أن نسبة كبيرة من الـ types تظهر مرة واحدة فقط.
That phrasing is deliberate and it is where students lose marks. Hapax legomena are a large share of the types. They are a small share of the tokens. Both statements are true at the same time, and they are not in tension once you see the arithmetic.
هذه الصياغة مقصودة، وهي الموضع الذي يخسر فيه الطلاب الدرجات. الـ hapax legomena حصة كبيرة من الـ types. وهي حصة صغيرة من الـ tokens. العبارتان صحيحتان في الوقت نفسه، ولا تعارض بينهما بمجرد أن ترى الحساب.
A toy corpus with a Zipf-like shape, small enough to count by hand. Ten common words plus a tail of words seen once:
corpus تجريبي بشكل يشبه Zipf، صغير بما يكفي لعدّه يدوياً. عشر كلمات شائعة ومعها ذيل من كلمات ظهرت مرة واحدة:
rank word count
1 the 20
2 of 12
3 and 9
4 a 7
5 to 6
6 in 5
7 is 4
8 it 3
9 that 3
10 was 3
---
subtotal 72 tokens from 10 types
plus 28 further words, each occurring exactly once
subtotal 28 tokens from 28 types
totals
N = 72 + 28 = 100 tokens
|V| = 10 + 28 = 38 types
في المقطع عشر كلمات شائعة: the (20)، وof (12)، وand (9)، وa (7)، وto (6)، وin (5)، وis (4)، وit وthat وwas (3 لكل منها)، فيكون المجموع 72 token من 10 types. ثم 28 كلمة أخرى كل منها ظهرت مرة واحدة، أي 28 token من 28 type. والمجموع الكلي N = 72 + 28 = 100 و|V| = 10 + 28 = 38.
Now the two percentages, which are the whole lesson:
والآن النسبتان، وهما الدرس كله:
hapax as a share of TYPES = 28 / 38 = 73.7 % dominant hapax as a share of TOKENS = 28 / 100 = 28.0 % a minority meanwhile the single word "the" is 1 / 38 = 2.6 % of the types but 20 / 100 = 20 % of the tokens
الـ hapax كحصة من الـ TYPES تساوي 28 / 38 = 73.7%، أي أنها مهيمنة. وكحصة من الـ TOKENS تساوي 28 / 100 = 28.0%، أي أنها أقلية. وفي المقابل الكلمة الواحدة the هي 1 / 38 = 2.6% من الـ types، لكنها 20 / 100 = 20% من الـ tokens.
One word is a fifth of everything you read. Twenty-eight words are three quarters of your dictionary and you saw each of them once. Slide 15 is the statement that the second group is the normal case, not the exception.
كلمة واحدة هي خُمس كل ما تقرؤه. وثمانٍ وعشرون كلمة هي ثلاثة أرباع قاموسك، ورأيت كل واحدة منها مرة واحدة. والشريحة 15 تقرر أن المجموعة الثانية هي الحالة الطبيعية، لا الاستثناء.
Slide 15's remaining two bullets say what you do about it, and both are forward references to material you already have on other pages:
البندان الباقيان في الشريحة 15 يقولان ماذا تفعل حيال ذلك، وكلاهما إحالة إلى مادة موجودة في صفحات أخرى:
- Smoothing and backoff in n-gram models. Maximum likelihood gives probability zero to anything unseen, and with this many hapax that is a disaster. Smoothing moves probability mass towards the rare and unseen.
Smoothing وbackoff في نماذج n-gram. الـ Maximum likelihood يعطي احتمال صفر لأي شيء لم يُرَ، ومع هذا العدد من الـ hapax تكون كارثة. والـ Smoothing ينقل كتلة احتمالية نحو النادر وغير المرئي.
- Subwords in neural models. The same escape slide 14 named, applied to the same problem from the other direction.
الـ Subwords في النماذج العصبية. المخرج نفسه الذي سمّته الشريحة 14، مطبقاً على المشكلة نفسها من الاتجاه الآخر.
- Evaluation depends on how you treat unseen items. Two systems can be compared only if they handle unknown words the same way. Change the OOV policy and you change the score without changing the model.
التقييم يعتمد على طريقة معاملة العناصر غير المرئية. لا يمكن مقارنة نظامين إلا إذا تعاملا مع الكلمات المجهولة بالطريقة نفسها. غيّر سياسة الـ OOV فتتغير النتيجة دون أن يتغير النموذج.
Thinking Zipf's law is about vocabulary size. It is not. It never mentions |V|. It is purely about how frequency is distributed across ranks. The law about vocabulary size is Heaps.
الظن بأن Zipf's law يتعلق بحجم المفردات. ليس كذلك. فهو لا يذكر |V| أبداً. إنه يتعلق فقط بكيفية توزع التكرار على الرتب. والقانون الذي يتعلق بحجم المفردات هو Heaps.
Thinking |V| grows linearly with N. That would be β = 1, which the slide explicitly excludes. In the English fit, ten times the text gives only 3.83 times the vocabulary.
الظن بأن |V| ينمو خطياً مع N. هذا يعني β = 1، وهو ما تستبعده الشريحة صراحة. في المطابقة الإنجليزية، عشرة أضعاف النص تعطي 3.83 ضعف المفردات فقط.
Thinking |V| eventually stops growing because a language has a finite dictionary. Slide 12 says unbounded, and slide 7 says why: names, products, typos, and creative spellings arrive without limit. There is no N at which you are finished.
الظن بأن |V| يتوقف عن النمو في النهاية لأن للغة قاموساً محدوداً. الشريحة 12 تقول unbounded، والشريحة 7 تقول لماذا: الأسماء والمنتجات والأخطاء المطبعية والتهجئات الإبداعية تصل بلا حد. لا يوجد N تكون عنده قد انتهيت.
Thinking hapax legomena are unimportant because they are only a small fraction of the text. Backwards. Slide 15 says a large fraction of types occur once. In the toy corpus above, hapax are 28% of tokens but 73.7% of types. Any question that says "fraction of types" and gets answered with a token fraction loses the mark.
الظن بأن الـ hapax legomena غير مهمة لأنها جزء صغير من النص. هذا معكوس. الشريحة 15 تقول إن نسبة كبيرة من الـ types تظهر مرة واحدة. وفي الـ corpus التجريبي أعلاه الـ hapax هي 28% من الـ tokens لكنها 73.7% من الـ types. وأي سؤال يقول "نسبة من الـ types" ويُجاب بنسبة من الـ tokens يخسر الدرجة.
Mixing up where the exponent lives. Zipf's α is in a denominator and controls a falling curve. Heaps' β is an exponent on N in a numerator and controls a rising curve. Writing |V| = k / Nβ says vocabulary shrinks as you read more, which is visibly absurd and is a fast self-check.
الخلط في موضع الأس. α في Zipf في مقام ويتحكم في منحنى هابط. وβ في Heaps أس على N في البسط ويتحكم في منحنى صاعد. وكتابة |V| = k / Nβ تعني أن المفردات تتقلص كلما قرأت أكثر، وهذا عبث واضح، وهو اختبار ذاتي سريع.
Thirty-second recap
خلاصة في ثلاثين ثانية
ملخص: Zipf هو f(R) ∝ 1 / Rα، وR = 1 هي الكلمة الأكثر تكراراً، ويظهر خطاً مستقيماً ميله −α على محاور log-log، ومطابقات الشريحة 11 هي α = 0.9290 للإنجليزية و0.9252 للعربية. وHeaps هو |V| = k · Nβ مع 0 < β < 1، أي sublinear (β < 1) لكنه unbounded (β > 0)، ومطابقات الشريحة 13 هي k = 14.947 وβ = 0.583 للإنجليزية وk = 73.321 وβ = 0.533 للعربية. عشرة أضعاف الـ tokens تعطي 10β = 3.83× من الـ types. و|V| الضخم يسبب مشكلات الذاكرة والتناثر والـ OOV. وhapax legomenon كلمة ظهرت مرة واحدة بالضبط، والـ hapax هي معظم الـ types وأقلية من الـ tokens.
Check yourself
اختبر نفسك
Which quantity does Zipf's law, as stated on slide 10, predict?
أي كمية يتنبأ بها Zipf's law كما تذكره الشريحة 10؟
Slide 10 is f(R) ∝ 1/Rα: given a rank, it predicts a frequency. A is the tempting wrong answer because it is Heaps' law, which is the next slide and is also a power law. The quickest way to keep them apart is to look at what goes in: Zipf takes a rank, Heaps takes a token count.
الجواب C. الشريحة 10 هي f(R) ∝ 1/Rα: تعطيها رتبة فتتنبأ بتكرار. والجواب A هو الخطأ المُغري لأنه Heaps' law، وهو في الشريحة التالية وهو أيضاً قانون قوة. وأسرع طريقة للتفريق بينهما أن تنظر إلى ما يدخل: Zipf يأخذ رتبة، وHeaps يأخذ عدد tokens.
A corpus fits Heaps' law with k = 14.947 and β = 0.583. You currently have 1,000,000 tokens and 47,049 types. You collect ten million more tokens, reaching N = 10,000,000. Roughly how many types will you have?
corpus يطابق Heaps' law بـ k = 14.947 وβ = 0.583. لديك حالياً 1,000,000 token و47,049 type. تجمع عشرة ملايين token أخرى فتصل إلى N = 10,000,000. كم type سيكون لديك تقريباً؟
Multiplying N by 10 multiplies |V| by 10β = 100.583 = 3.828, giving 47,049 × 3.828 = 180,117. A assumes linear growth, which is β = 1 and is exactly what sublinear denies. C assumes saturation, which is exactly what unbounded denies. D misreads β as a percentage rather than an exponent.
الجواب B. ضرب N في 10 يضرب |V| في 10β = 100.583 = 3.828، فيكون 47,049 × 3.828 = 180,117. والجواب A يفترض نمواً خطياً، أي β = 1، وهو بالضبط ما ينفيه sublinear. والجواب C يفترض التشبع، وهو بالضبط ما ينفيه unbounded. والجواب D يقرأ β نسبة مئوية بدلاً من أس.
Slide 12 says vocabulary growth is "sublinear but unbounded". Which pair of conditions on β encodes that?
تقول الشريحة 12 إن نمو المفردات "sublinear but unbounded". أي زوج من الشروط على β يعبّر عن ذلك؟
The slide writes the condition 0 < β < 1 next to the formula, and the two inequalities carry one word each. β < 1 means |V| falls behind N, which is sublinear. β > 0 means |V| keeps rising with no ceiling, which is unbounded. C is the tempting distractor because k also appears in the formula, but k only sets the vertical scale, it cannot change the shape of the curve.
الجواب A. تكتب الشريحة الشرط 0 < β < 1 بجانب المعادلة، وكل متباينة تحمل كلمة واحدة. β < 1 يعني أن |V| يتأخر عن N، وهذا sublinear. وβ > 0 يعني أن |V| يستمر في الارتفاع بلا سقف، وهذا unbounded. والجواب C هو المشتت المُغري لأن k تظهر أيضاً في المعادلة، لكن k تحدد المقياس الرأسي فقط ولا تستطيع تغيير شكل المنحنى.
In a corpus of 100 tokens and 38 types, 28 types occur exactly once. Which statement is correct?
في corpus فيه 100 token و38 type، هناك 28 type يظهر كل منها مرة واحدة بالضبط. أي العبارات صحيحة؟
28/38 = 73.7% of types and 28/100 = 28% of tokens. Both numbers describe the same 28 words; they differ because the denominators differ. A has the two percentages swapped. B is the misconception slide 15 is aimed at: judging importance by the token share misses that these words are most of your dictionary and most of your OOV risk. C invents a definition; a type that occurs once is still a type.
الجواب D. 28/38 = 73.7% من الـ types و28/100 = 28% من الـ tokens. الرقمان يصفان الكلمات الثماني والعشرين نفسها، ويختلفان لأن المقامين مختلفان. والجواب A بدّل النسبتين. والجواب B هو التصور الخاطئ الذي تستهدفه الشريحة 15: الحكم على الأهمية بحصة الـ tokens يُغفل أن هذه الكلمات هي معظم قاموسك ومعظم خطر الـ OOV. والجواب C يخترع تعريفاً، فالـ type الذي يظهر مرة واحدة ما زال type.
Why does the Zipf relationship appear as a straight line on the log-log plot of slide 11?
لماذا تظهر علاقة Zipf خطاً مستقيماً على رسم log-log في الشريحة 11؟
Any power law becomes a straight line under logs, with the exponent as the slope. A describes arithmetic decrease, which would be a straight line on linear axes, not log-log, and is not what Zipf says. D is wrong in an instructive way: the line is straight for any α, and α only sets how steep it is. The slide's two fits, 0.9290 and 0.9252, are both straight and neither equals 1.
الجواب B. أي قانون قوة يصبح خطاً مستقيماً بعد أخذ اللوغاريتم، ويكون الأس هو الميل. والجواب A يصف تناقصاً حسابياً، وهذا يكون خطاً مستقيماً على محاور خطية لا log-log، وليس ما يقوله Zipf. والجواب D خاطئ بطريقة مفيدة: الخط مستقيم لأي α، وα تحدد فقط مدى انحداره. ومطابقتا الشريحة 0.9290 و0.9252 كلتاهما مستقيمتان ولا تساوي أي منهما 1.
Slide 14 lists the consequences of huge word-level vocabularies. Which of these does it name as the fix?
تسرد الشريحة 14 عواقب المفردات الضخمة على مستوى الكلمة. أي مما يلي تسمّيه حلاً؟
The slide's third bullet is exactly "motivates subword/byte tokenization". A contradicts Heaps' law directly, since unbounded means saturation never arrives no matter how much data you collect. B is tempting because hapax are most of the types, but deleting them turns every one of them into an unknown token at test time, which is the OOV problem rather than a solution to it.
الجواب C. البند الثالث في الشريحة هو بالضبط "motivates subword/byte tokenization". والجواب A يناقض Heaps' law مباشرة، لأن unbounded يعني أن التشبع لا يأتي أبداً مهما جمعت من بيانات. والجواب B مُغرٍ لأن الـ hapax هي معظم الـ types، لكن حذفها يحوّل كل واحدة منها إلى token مجهول وقت الاختبار، وهذه مشكلة الـ OOV نفسها لا حل لها.
Slide 13 fits arabic_wiki with k = 73.321, β = 0.533 and english_wiki with k = 14.947, β = 0.583. At N = 1,000,000 tokens, which corpus has the larger predicted vocabulary, and why?
تطابق الشريحة 13 arabic_wiki بـ k = 73.321 وβ = 0.533، وenglish_wiki بـ k = 14.947 وβ = 0.583. عند N = 1,000,000 token، أي corpus له مفردات متوقعة أكبر، ولماذا؟
Plug in: 73.321 × 1,000,0000.533 = 115,672 and 14.947 × 1,000,0000.583 = 47,049. B is the trap: β controls the growth rate, not the level, and k scales the level. English's faster growth does eventually overtake Arabic, but only at around 6.5 × 1013 tokens, which no corpus reaches. D overgeneralises in the opposite direction; a smaller β on its own says nothing about the level.
الجواب A. عوّض: 73.321 × 1,000,0000.533 = 115,672 و14.947 × 1,000,0000.583 = 47,049. والجواب B هو الفخ: β يتحكم في معدل النمو لا في المستوى، وk هو الذي يحدد المستوى. نمو الإنجليزية الأسرع يتجاوز العربية فعلاً في النهاية، لكن فقط عند نحو 6.5 × 1013 token، وهو ما لا يصل إليه أي corpus. والجواب D يعمّم في الاتجاه المعاكس، فـ β أصغر وحدها لا تقول شيئاً عن المستوى.