Lecture 04 · Word Embeddings

المحاضرة 04 · تضمينات الكلمات (Word Embeddings)

tf-idf Weighting

الترجيح بـ tf-idf

Slides 45–51 الشرائح 45–51 P1 MUST

How to reweight a count matrix so that words which are frequent everywhere stop drowning out the words that actually tell documents apart.

كيف نعيد وزن مصفوفة التكرارات حتى تتوقف الكلمات الشائعة في كل مكان عن طغيانها على الكلمات التي تميّز المستندات فعلياً.

High exam risk احتمال عالٍ في الامتحان

Hand computation is very likely. Expect to be handed a tiny document collection and asked for df, idf, and the final tf-idf of one word. The two things that cost marks are confusing df with total count, and using the wrong log base.

الحساب اليدوي مرجّح جداً. توقّع أن تُعطى مجموعة مستندات صغيرة ويُطلب منك df وidf وقيمة tf-idf النهائية لكلمة واحدة. الشيئان اللذان يضيّعان الدرجات هما الخلط بين df والعدد الكلي، واستخدام أساس log خاطئ.

The paradox, slide 45

المفارقة، الشريحة 45

Every cell of a co-occurrence matrix is currently a raw frequency. Slide 45 says that is a bad representation, and sets up the tension in two bullets:

كل خلية في co-occurrence matrix هي الآن تكرار خام. تقول الشريحة 45 إن هذا تمثيل سيئ، وتطرح التناقض في نقطتين:

So frequency is both the signal and the noise. The slide calls it a paradox: "How can we balance these two conflicting constraints?"

إذن التكرار هو الإشارة والضجيج في الوقت نفسه. تسمّي الشريحة ذلك تناقضاً: "How can we balance these two conflicting constraints?"

Resolve it like this. We want words that are frequent in THIS document but rare across the collection. A word that is everywhere discriminates nothing.

والحل هكذا: نريد الكلمات المتكررة في هذا المستند تحديداً والنادرة في المجموعة كلها. والكلمة الموجودة في كل مكان لا تميّز شيئاً.

Two solutions, slide 46

حلّان، الشريحة 46

The lecture names exactly two weighting schemes, and you should be able to say which is used where:

تذكر المحاضرة طريقتَي وزن فقط، ويجب أن تعرف أيّهما تُستخدم مع أي مصفوفة:

SchemeالطريقةMatrix it is forالمصفوفة التي تخصهاCore ideaالفكرة الجوهرية
tf-idftf-idfterm-document matrixمصفوفة term-documentdownweight words that appear in many documents. "the" and "it" get very low idf.خفّض وزن الكلمات التي تظهر في مستندات كثيرة. فـ "the" و"it" تحصلان على idf منخفض جداً.
PMI / PPMIPMI / PPMIterm-context (word-word) matrixمصفوفة term-context (word-word)see whether two words co-occur more than chance would predict.انظر هل تظهر كلمتان معاً أكثر مما تتوقعه الصدفة.

يقابل الجدول بين الطريقتين: tf-idf لمصفوفة term-document، وفكرتها تقليل وزن الكلمات التي تظهر في مستندات كثيرة، فتحصل "the" و"it" على idf منخفض جداً. وPMI / PPMI لمصفوفة term-context (كلمة مع كلمة)، وفكرتها هل تظهر الكلمتان معاً أكثر مما تتوقعه الصدفة.

This page is tf-idf. PMI is the next page.

هذه الصفحة عن tf-idf، وPMI في الصفحة التالية.

Term frequency, slide 47

تكرار المصطلح (term frequency)، الشريحة 47

The simple version:

النسخة البسيطة:

tft,d = count(t, d)

المعادلة تعرّف tf في صورته الخام: مجرد count(t, d)، أي عدد مرات ظهور الكلمة t داخل المستند d، بلا أي log.

But the slide says: "instead of using raw count, we squash a bit", and gives the log form.

لكن الشريحة تقول: "instead of using raw count, we squash a bit"، ثم تعطي صيغة الـ log.

tft,d = log10( count(t, d) + 1 )

هذه صيغة الشريحة: يُطبَّق log بالأساس 10 على count(t, d) + 1، في عبارة واحدة بلا تقسيم حالات، فتعمل حتى عندما يكون count = 0. أما صيغة الكتاب 1 + log10(count) فتُستخدم فقط عندما يكون count أكبر من صفر، وtf = 0 فيما عدا ذلك.

Why squash. A word appearing 100 times in a document is not 100 times more important than a word appearing once. It is maybe twice as important. Raw counts over-reward repetition. The log compresses the scale so that going from 1 to 10 matters about as much as going from 10 to 100.

لماذا نضغط المقياس. الكلمة التي تظهر 100 مرة في مستند ليست أهم بـ 100 مرة من كلمة ظهرت مرة واحدة، بل أهم بمرتين تقريباً. التكرارات الخام تكافئ الإعادة أكثر من اللازم، والـ log يضغط المقياس فيصبح الانتقال من 1 إلى 10 بأهمية الانتقال من 10 إلى 100 تقريباً.

Why the +1. It handles count = 0 gracefully: log10(0 + 1) = log10(1) = 0, so an absent word gets tf = 0 instead of log(0) = −∞.

ولماذا +1. لأنه يعالج حالة count = 0 بسلاسة: log10(0 + 1) = log10(1) = 0، فتأخذ الكلمة الغائبة tf = 0 بدلاً من log(0) الذي يساوي سالب ما لا نهاية.

Version warning تنبيه حول النسخة

The textbook writes this as a two-case definition: tft,d = 1 + log10(count) when count > 0, and 0 otherwise. Our slide 47 writes log10(count + 1), which is a single expression with no case split. Both squash, but they give different numbers.

يكتبها الكتاب بتعريف من حالتين: tft,d = 1 + log10(count) عندما يكون count > 0، و0 فيما عدا ذلك. أما الشريحة 47 فتكتب log10(count + 1)، وهي عبارة واحدة بلا تقسيم حالات. الصيغتان تضغطان المقياس لكنهما تعطيان أرقاماً مختلفة.

Use the slide's form: log10(count + 1). It is the one the lecture's own tf-idf table on slide 51 was computed with, and we verify that below.

استخدم صيغة الشريحة: log10(count + 1). فهي التي حُسب بها جدول tf-idf في الشريحة 51، ونتحقق من ذلك بالأسفل.

What the squash does, in numbers:

ما يفعله الضغط، بالأرقام:

countالعدّ (count)raw tftf الخامlog10(count+1)
000
110.301
770.903
13131.146
1001002.004
100010003.000

يضع الجدول ثلاثة أعمدة جنباً إلى جنب: count الخام، وraw tf، وlog10(count+1). اقرأ كل سطر كتحويل: 0 تبقى 0، و1 تصبح 0.301، و7 تصبح 0.903، و13 تصبح 1.146، و100 تصبح 2.004، و1000 تصبح 3.000.

Raw tf spans a factor of 1000. Squashed tf spans a factor of 10. That is the point.

مدى raw tf يمتد بعامل 1000، ومدى tf المضغوط يمتد بعامل 10 فقط. وهذا هو المقصود.

Document frequency, slide 48

تكرار المستند (document frequency)، الشريحة 48

dft = the number of documents that t occurs in

المعادلة تعرّف dft: عدد المستندات التي تظهر فيها الكلمة t مرة واحدة على الأقل. لا يوجد log هنا، ولا علاقة له بعدد مرات الظهور.

The slide puts the warning in its own bullet, which is a strong hint it is examinable: this is not collection frequency, which is the total count of t across all documents.

تضع الشريحة التحذير في نقطة مستقلة، وهذه إشارة قوية إلى أنه مادة سؤال: هذا ليس collection frequency، الذي هو العدد الكلي لظهور t في كل المستندات.

The slide's example, from Shakespeare:

مثال الشريحة، من Shakespeare:

WordالكلمةCollection Frequencyتكرار المجموعة (Collection Frequency)Document Frequencyتكرار المستند (Document Frequency)
Romeo1131
action11331

الجدول يقارن Romeo وaction: لكل منهما collection frequency يساوي 113، لكن document frequency هو 1 لـ Romeo و31 لـ action.

Both words occur 113 times in total. Identical collection frequency. But Romeo occurs inside a single play and action is spread over 31 of them. Collection frequency cannot tell them apart. Document frequency can, instantly.

كلتا الكلمتين تظهر 113 مرة إجمالاً، أي collection frequency متطابق. لكن Romeo محصورة في مسرحية واحدة، وaction موزّعة على 31 مسرحية. collection frequency لا يفرّق بينهما، وdocument frequency يفرّق فوراً.

Romeo is a perfect search term for one play. action is useless as a discriminator. That difference is the entire motivation for df.

Romeo كلمة بحث مثالية للوصول إلى مسرحية واحدة، وaction لا قيمة لها كمميّز. هذا الفرق هو كل الدافع وراء df.

Trap فخ

df counts documents, not occurrences. A word that appears 1000 times but all of them inside one document has df = 1, not 1000. If your df is bigger than N, you have computed collection frequency by mistake. df is capped at N.

df يعدّ المستندات، لا مرات الظهور. فالكلمة التي تظهر 1000 مرة وكلها داخل مستند واحد لها df = 1 لا 1000. وإذا خرج df أكبر من N فقد حسبت collection frequency بالخطأ، لأن سقف df هو N.

Inverse document frequency, slide 49

مقلوب تكرار المستند (inverse document frequency)، الشريحة 49

idft = log10 Ndft

المعادلة: idft هو log بالأساس 10 للكسر N / dft. البسط N هو عدد المستندات في المجموعة كلها، والمقام dft هو عدد المستندات التي تحتوي الكلمة t. اقسم أولاً، ثم خذ الـ log.

N is the total number of documents in the collection. The lecture's Shakespeare collection has N = 37 plays.

N هو العدد الكلي للمستندات في المجموعة، ومجموعة Shakespeare في المحاضرة فيها N = 37 مسرحية.

Read the fraction before the log. N/df is large when the word is in few documents and shrinks to 1 when the word is in every document. The log just compresses that, exactly like it did for tf.

اقرأ الكسر قبل الـ log: قيمة N/df تكون كبيرة عندما تكون الكلمة في مستندات قليلة، وتتقلص إلى 1 عندما تكون في كل مستند. والـ log يضغط ذلك فقط، تماماً كما فعل مع tf.

This is slide 49's table, with the arithmetic verified against log10(37/df):

هذا جدول الشريحة 49، وقد تم التحقق من حسابه مقابل log10(37/df):

WordالكلمةdfN / dfidf = log10(N/df)Readingالقراءة
Romeo137 / 1 = 371.57one play only, maximally distinctiveمسرحية واحدة فقط، مميِّزة إلى أقصى حد
salad237 / 2 = 18.51.27very rareنادرة جداً
Falstaff437 / 4 = 9.250.967a character in a handful of playsشخصية في عدد قليل من المسرحيات
forest1237 / 12 = 3.0830.489a topical wordكلمة موضوعية
battle2137 / 21 = 1.7620.246common but not universalشائعة لكن ليست في كل مكان
wit3437 / 34 = 1.0880.037nearly everywhereفي كل مكان تقريباً
fool3637 / 36 = 1.0280.012nearly everywhereفي كل مكان تقريباً
good3737 / 37 = 10in every play, discriminates nothingفي كل مسرحية، لا تميّز شيئاً
sweet3737 / 37 = 10in every play, discriminates nothingفي كل مسرحية، لا تميّز شيئاً

الجدول مرتب بـ df تصاعدياً، والعمود الثالث يعرض الكسر N / df قبل أخذ الـ log، والرابع هو idf بعده. اقرأه هكذا: Romeo عند df = 1 يعطي 1.57، ثم salad 1.27، وFalstaff 0.967، وforest 0.489، وbattle 0.246، وwit 0.037، وfool 0.012، وأخيراً good وsweet عند df = 37 = N فيصبح idf = 0.

Sorted by idf, the pattern is impossible to miss. Rare words get high idf. Universal words get idf exactly 0.

بالترتيب حسب idf يصبح النمط واضحاً تماماً: الكلمات النادرة تأخذ idf عالياً، والكلمات الموجودة في كل مكان تأخذ idf يساوي صفراً بالضبط.

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

Appears in every document ⇒ N/df = 1 ⇒ log(1) = 0 ⇒ idf = 0 ⇒ tf-idf = 0 no matter how often the word occurs. The word is deleted from the representation.

تظهر في كل مستند ⇒ N/df = 1 ⇒ log(1) = 0 ⇒ idf = 0 ⇒ tf-idf = 0 مهما تكرّرت الكلمة. أي أن الكلمة تُحذف من التمثيل.

That is not a bug. That is precisely the behaviour we wanted for the.

وهذا ليس خطأً، بل هو بالضبط السلوك الذي أردناه مع the.

Romeo, df=1, idf=1.57 Falstaff, df=4, idf=0.967 battle, df=21, idf=0.246 good, sweet, df=37=N, idf=0 df = N 1.57 0 df = 1 document frequency df idf
idf = log10(37/df). The curve falls steeply over the first few documents, then flattens, and hits exactly 0 when df = N. Everything in the flat tail is effectively a stopword.
idf = log10(37/df). ينحدر المنحنى بحدة على المستندات القليلة الأولى، ثم يتسطح، ويصل إلى 0 بالضبط عندما df = N. وكل ما في الذيل المسطح هو فعلياً كلمة توقف (stopword).

يرسم الشكل منحنى idf = log10(37/df): المحور الأفقي هو df من 1 إلى N = 37، والمحور الرأسي هو idf من 0 إلى 1.57. النقاط المعلّمة هي Romeo عند df=1 وidf=1.57، وFalstaff عند df=4 وidf=0.967، وbattle عند df=21 وidf=0.246، ثم good وsweet عند df=37=N وidf=0. المنحنى يهبط بحدة في المستندات الأولى ثم يستوي، وكل ما في الذيل المستوي هو عملياً stopword.

What counts as a document, slide 50

ما الذي يُعدّ مستنداً، الشريحة 50

Nothing in the formula says what a document is. You choose it, and the choice changes every number.

لا شيء في المعادلة يحدّد ما هو المستند. أنت تختاره، والاختيار يغيّر كل رقم بعده.

Smaller documents mean more documents, so N goes up and df goes down for topical words, so idf spreads out further. Choosing paragraphs instead of whole plays gives you a sharper weighting.

المستندات الأصغر تعني مستندات أكثر، فيزيد N وينقص df للكلمات الموضوعية، فيتوزع idf على مدى أوسع. واختيار الفقرات بدل المسرحيات الكاملة يعطي وزناً أدق.

The final value, slide 51

القيمة النهائية، الشريحة 51

wt,d = tft,d × idft

المعادلة النهائية: wt,d هو حاصل ضرب tft,d في idft، ضرب مباشر بلا log إضافي.

Two factors, multiplied. tf is about this document. idf is about the whole collection. A word scores high only if it is frequent here AND rare elsewhere. If either factor is near zero, the product is near zero.

عاملان مضروبان: tf يتعلق بهذا المستند، وidf يتعلق بالمجموعة كلها. فالكلمة تأخذ درجة عالية فقط إذا كانت متكررة هنا ونادرة في غيره، وإذا قارب أحد العاملين الصفر قارب الناتج الصفر.

Raw counts

العدّات الخام

As You Like ItTwelfth NightJulius CaesarHenry V
battle10713
good114806289
fool365814
wit201523

الجدول يعرض التكرارات الخام: الصفوف هي الكلمات battle وgood وfool وwit، والأعمدة هي أربع مسرحيات، As You Like It وTwelfth Night وJulius Caesar وHenry V. كل خلية هي count(t, d).

Read this table and good dominates everything. It has the biggest number in every column by a wide margin. If you used raw counts, every play would look like it is mostly about being good.

اقرأ هذا الجدول فتجد good مسيطرة على كل شيء، فلها أكبر رقم في كل عمود بفارق واسع. ولو استخدمت التكرارات الخام لظهرت كل مسرحية كأنها عن الخير.

After tf-idf

بعد tf-idf

As You Like ItTwelfth NightJulius CaesarHenry V
battle0.07400.220.28
good0000
fool0.0190.0210.00360.0083
wit0.0490.0440.0180.022

الجدول نفسه بعد تطبيق tf-idf، بنفس الصفوف والأعمدة. صف good كله أصفار، وأعلى قيمة في الجدول هي battle في Henry V عند 0.28. قارن كل خلية بنظيرتها في جدول التكرارات الخام.

good is now an entire row of zeros, because its df is 37 out of 37 plays. The 114 occurrences in As You Like It are multiplied by idf = 0 and vanish.

صف good صار أصفاراً كاملة لأن df لها 37 من 37 مسرحية. والـ 114 ظهوراً في As You Like It تُضرب في idf = 0 فتتبخر.

Meanwhile battle, which had the smallest raw numbers in the table, now has the largest tf-idf values. Its idf of 0.246 is about twenty times larger than fool's 0.012, which is enough to overcome the fact that fool occurs far more often.

في المقابل battle، التي كانت أصغر أرقامها الخام في الجدول، صارت أكبر قيم tf-idf. فـ idf لها 0.246، أي نحو عشرين ضعف 0.012 الخاصة بـ fool، وهذا كافٍ للتغلب على أن fool تظهر أكثر منها بكثير.

Raw count versus tf-idf, side by side

العدّ الخام مقابل tf-idf، جنباً إلى جنب

Raw countالعدّ الخامtf-idftf-idf
Highest cell in the tableأعلى خلية في الجدولgood, 114good، 114battle in Henry V, 0.28battle في Henry V، 0.28
What good contributesما تساهم به gooddominates every columnتهيمن على كل عمودexactly 0 everywhere0 بالضبط في كل مكان
Rewardsما يكافئهrepetitionالتكرارrepetition that is also distinctiveالتكرار الذي يكون مميِّزاً أيضاً
Stopwordsكلمات التوقف (Stopwords)largest values in the matrixأكبر القيم في المصفوفةdriven to 0 automaticallyتُدفع إلى 0 تلقائياً
Uses collection-wide infoيستخدم معلومات على مستوى المجموعة كلهاnoلاyes, through idfنعم، عبر idf

الجدول يقارن raw count مقابل tf-idf في خمسة بنود: أعلى خلية في الجدول، وما تسهم به good، وما تكافئه كل طريقة، ومصير stopwords، وهل تستخدم معلومات المجموعة كلها. عمود tf-idf هو السلوك المطلوب في كل بند.

Doing it by hand

الحساب باليد

  1. Count how many times the word occurs in the target document. That is count(t,d).

    عدّ كم مرة تظهر الكلمة في المستند المقصود. هذا هو count(t,d).

  2. tf = log10(count + 1). If the count is 0, tf = 0 and you can stop, the answer is 0.

    tf = log10(count + 1). وإذا كان count صفراً فإن tf = 0 ويمكنك التوقف، فالجواب 0.

  3. Count how many documents contain the word at least once. That is df.

    عدّ كم مستنداً يحتوي الكلمة مرة واحدة على الأقل. هذا هو df.

  4. idf = log10(N / df). If df = N, idf = 0 and the answer is 0.

    idf = log10(N / df). وإذا كان df = N فإن idf = 0 والجواب 0.

  5. Multiply. w = tf × idf.

    اضرب: w = tf × idf.

Worked مثال محلول

Every cell of the slide 51 tf-idf table, reconstructed. N = 37. idf values come from the slide 49 table.

كل خلية في جدول tf-idf من الشريحة 51، معادة البناء خطوة بخطوة. N = 37، وقيم idf مأخوذة من جدول الشريحة 49.

idf(battle) = 0.246     idf(good) = 0      idf(fool) = 0.012     idf(wit) = 0.037

battle, As You Like It
  count = 1
  tf    = log10(1 + 1)  = log10(2)  = 0.3010
  w     = 0.3010 x 0.246 = 0.0740    -> 0.074   matches slide

battle, Twelfth Night
  count = 0
  tf    = log10(0 + 1)  = log10(1)  = 0
  w     = 0 x 0.246 = 0              -> 0       matches slide

battle, Julius Caesar
  count = 7
  tf    = log10(7 + 1)  = log10(8)  = 0.9031
  w     = 0.9031 x 0.246 = 0.2222    -> 0.22    matches slide

battle, Henry V
  count = 13
  tf    = log10(13 + 1) = log10(14) = 1.1461
  w     = 1.1461 x 0.246 = 0.2819    -> 0.28    matches slide

تحسب الكتلة صف battle كله، وidf له 0.246. السطر الأول يسرد قيم idf الأربع، ثم كل مقطع يمشي من count إلى tf = log10(count + 1) ثم إلى الضرب. النتائج: 0.074 في As You Like It عند count = 1، و0 في Twelfth Night عند count = 0، و0.22 في Julius Caesar عند count = 7، و0.28 في Henry V عند count = 13، وكلها تطابق الشريحة.

good, As You Like It          the stopword case
  count = 114
  tf    = log10(114 + 1) = log10(115) = 2.0607     a large tf
  df    = 37     good appears in all 37 plays
  idf   = log10(37 / 37) = log10(1) = 0
  w     = 2.0607 x 0 = 0             -> 0       matches slide

the big tf is completely irrelevant. one zero factor kills the product.

تعرض الكتلة حالة stopword: count = 114 يعطي tf = log10(115) = 2.0607، وهو tf كبير، لكن df = 37 يعطي idf = log10(37 / 37) = 0، فيكون w = 0. كِبَر tf لا يعني شيئاً، فعامل صفري واحد يقتل حاصل الضرب.

fool, Twelfth Night
  count = 58
  tf    = log10(59) = 1.7709
  w     = 1.7709 x 0.012 = 0.02125   -> 0.021   matches slide

wit, As You Like It
  count = 20
  tf    = log10(21) = 1.3222
  w     = 1.3222 x 0.037 = 0.04892   -> 0.049   matches slide

wit, Julius Caesar
  count = 2
  tf    = log10(3) = 0.4771
  w     = 0.4771 x 0.037 = 0.01765   -> 0.018   matches slide

تحسب الكتلة ثلاث خلايا أخرى بالطريقة نفسها: fool في Twelfth Night (count = 58، tf = 1.7709، w = 0.021)، وwit في As You Like It (count = 20، tf = 1.3222، w = 0.049)، وwit في Julius Caesar (count = 2، tf = 0.4771، w = 0.018).

Every published figure reproduces with tf = log10(count + 1), which confirms the slide's version of the tf formula rather than the textbook's 1 + log10(count).

كل رقم منشور يُعاد إنتاجه بـ tf = log10(count + 1)، وهذا يثبت صيغة الشريحة لا صيغة الكتاب 1 + log10(count).

Trap فخ

Log base. tf and idf both use log base 10 in this lecture. PMI on the next page uses log base 2. Mixing them up changes every number. log10(37) = 1.568 but log2(37) = 5.21 and ln(37) = 3.61.

أساس الـ log. كل من tf وidf يستخدم الأساس 10 في هذه المحاضرة، أما PMI في الصفحة التالية فيستخدم الأساس 2. والخلط بينهما يغيّر كل رقم: log10(37) = 1.568 لكن log2(37) = 5.21 وln(37) = 3.61.

Direction of the fraction. It is log(N / df), not log(df / N). Writing it upside down makes every idf negative, which is the fastest way to notice you flipped it.

اتجاه الكسر. الصيغة log(N / df) لا log(df / N). وكتابته مقلوباً تجعل كل idf سالباً، وهذه أسرع علامة تنبّهك إلى أنك قلبته.

idf is a property of the word, not of the cell. One idf per row, reused across every document in that row. tf is the only thing that changes column to column.

idf صفة للكلمة لا للخلية. قيمة idf واحدة لكل صف، تُعاد مع كل مستند في ذلك الصف، وtf هو الشيء الوحيد الذي يتغير من عمود إلى عمود.

Thirty-second recap

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

tft,d = log10(count(t,d) + 1) dft = number of documents containing t dft = عدد المستندات التي تحتوي t df is NOT total occurrences df ليس مجموع مرات الظهور idft = log10(N / dft) wt,d = tft,d × idft df = N ⇒ idf = 0 ⇒ word deleted df = N ⇒ idf = 0، أي تُحذف الكلمة N = 37 plays in the Shakespeare example N = 37 مسرحية في مثال Shakespeare a document can be a play, an article, or a paragraph المستند قد يكون مسرحية أو مقالة أو فقرة

Check yourself

اختبر نفسك

A collection has N = 100 documents. The word neural occurs 500 times in total, spread across 20 documents. What is dfneural?

مجموعة فيها N = 100 مستند. كلمة neural تظهر 500 مرة إجمالاً، موزعة على 20 مستنداً. فما قيمة dfneural؟

Document frequency counts documents, so df = 20. A is the collection frequency, which slide 48 explicitly warns is a different quantity. The Romeo-versus-action example exists precisely to separate these two: both words have collection frequency 113 but df 1 and 31.

الجواب B. document frequency يعدّ المستندات، فـ df = 20. والخيار A هو collection frequency، وتحذّر الشريحة 48 صراحةً من أنه كمية مختلفة. ومثال Romeo مقابل action موجود تحديداً للفصل بينهما: لكلتيهما collection frequency يساوي 113، لكن df هو 1 و31.

Same collection, N = 100, dfneural = 20. What is idfneural?

المجموعة نفسها، N = 100 وdfneural = 20. فما قيمة idfneural؟

The formula is log10(N/df) = log10(5) = 0.699. A flips the fraction and gets a negative value, which is the signature of that mistake. B uses the wrong base; log base 2 belongs to PMI, not idf. D forgets the log entirely.

الجواب C. الصيغة هي log10(N/df) = log10(5) = 0.699. والخيار A يقلب الكسر فيحصل على قيمة سالبة، وهذه بصمة ذلك الخطأ. وB يستخدم الأساس الخطأ، فالأساس 2 يخص PMI لا idf. وD ينسى الـ log تماماً.

The word good occurs 114 times in As You Like It, more than any other word in the slide 51 table, yet its tf-idf there is 0. Why?

كلمة good تظهر 114 مرة في As You Like It، أكثر من أي كلمة أخرى في جدول الشريحة 51، ومع ذلك قيمة tf-idf لها هناك 0. لماذا؟

idf is the zero factor. tf is actually large here: log10(115) = 2.06. B is wrong because the log never sends a positive count to 0, only count = 0 does that. C is tempting but wrong in an important way: nobody deleted good by hand, tf-idf deleted it automatically. That automatic deletion is the feature being demonstrated.

الجواب A. idf هو العامل الصفري، أما tf فهو كبير فعلاً هنا: log10(115) = 2.06. والخيار B خاطئ لأن الـ log لا يحوّل تكراراً موجباً إلى 0 أبداً، وحالة count = 0 فقط هي التي تفعل ذلك. وC مُغر لكنه خاطئ في نقطة مهمة: لم يحذف أحد good يدوياً، بل حذفها tf-idf تلقائياً، وهذا الحذف التلقائي هو الميزة التي يُراد إظهارها.

Using the lecture's tf formula, what is tf for a word occurring 9 times in a document?

باستخدام صيغة tf في المحاضرة، ما قيمة tf لكلمة تظهر 9 مرات في مستند؟

Slide 47 gives tf = log10(count + 1), so log10(10) = 1 exactly. C is the textbook's alternative form, which is a real formula but not the one this lecture uses and not the one that reproduces the slide 51 table. B drops the +1, which would break the count = 0 case.

الجواب D. تعطي الشريحة 47 tf = log10(count + 1)، فيكون log10(10) = 1 بالضبط. والخيار C هو صيغة الكتاب البديلة، وهي صيغة حقيقية لكنها ليست المستخدمة في هذه المحاضرة ولا التي تُعيد إنتاج جدول الشريحة 51. وB يحذف +1، وهذا يُفسد حالة count = 0.

Why does tf-idf use a product of two factors rather than just idf?

لماذا يستخدم tf-idf حاصل ضرب عاملين بدلاً من idf وحده؟

idf is a per-word, collection-level constant. It cannot distinguish documents. tf supplies the local evidence, idf supplies the global discount, and the product scores a word highly only when both agree. D is wrong: idf = log(N/df) is never negative, since df is at most N.

الجواب B. idf ثابت لكل كلمة على مستوى المجموعة، فلا يستطيع التمييز بين المستندات. tf يوفّر الدليل المحلي، وidf يوفّر الخصم العام، وحاصل الضرب يرفع درجة الكلمة فقط حين يتفق العاملان. والخيار D خاطئ: idf = log(N/df) لا يكون سالباً أبداً لأن df لا يزيد على N.

Slide 50 asks what counts as a document. Which statement matches the lecture?

تسأل الشريحة 50 عمّا يُعدّ مستنداً. أي العبارات التالية يطابق المحاضرة؟

The slide states it almost word for word: documents can be anything, and we often call each paragraph a document. The practical consequence is that the choice changes N and every df, so it changes every idf. A smaller unit of document gives a sharper, more spread-out weighting.

الجواب D. تقول الشريحة ذلك شبه حرفياً: المستندات يمكن أن تكون أي شيء، وكثيراً ما نسمي كل فقرة مستنداً. والنتيجة العملية أن هذا الاختيار يغيّر N ويغيّر كل df، فيغيّر كل idf. ووحدة مستند أصغر تعطي وزناً أدق وأوسع توزعاً.