Lab · Bag of words词袋实验 · 词袋
When do two headlines count as the same claim?两则标题何时算同一主张?
A press officer has two headlines about a training program and has to say, in one line, whether the coverage agrees. The headlines are “The new training program raised wages for the workers in the plant” and “The new training program lowered wages for the workers in the plant.” A bag of words counts the words and drops the order. The counts barely move when “raised” becomes “lowered,” so a high score can be sent upstairs as agreement.一位新闻官有两则关于培训项目的标题,必须用一句话说明报道是否一致。标题是 “The new training program raised wages for the workers in the plant” 和 “The new training program lowered wages for the workers in the plant”。词袋数词,并丢掉顺序。raised 换成 lowered 时,计数几乎不动,于是一个高分可以被送上去,写成“口径一致”。
Why this matters.为何重要。 The agreement score only sees the words you kept. Shared little words, a missed synonym, or one verb that flips the claim can move the score without telling the press officer whether the two headlines agree.一致分数只看见你留下的词。共享的小词、没认出的同义词,或一个把主张翻过来的动词,都可以移动分数,却不能告诉新闻官两则标题是不是在说同一件事。
Try this试一试 Start with “Opposite claims” and keep little words such as the and for. Then drop them. Switch to “Different words” and compare the agreement score.从“相反的主张”开始,留下 the、for 这类小词。再去掉它们。换到“用词不同”,比较一致分数。
A.A. The new training program raised wages for the workers in the plant.
B.B. The new training program lowered wages for the workers in the plant.
Read the chart读这张图
If you misread this读错了会怎样
If the press officer sends upstairs “the coverage agrees” because the score is high, the labour desk can tell workers the program is uncontroversial. In the first pair, raised and lowered flip whether pay went up, and the shared words keep the score high.如果新闻官因为分数高,就向上送出“报道口径一致”,劳工处可能会告诉工人这个项目没有争议。第一对里,raised 和 lowered 把工资到底涨没涨说反了,共享的词仍把分数维持得很高。
Enough, and not enough够用,以及不够
Enough to see that the agreement score is the word counts that were kept, including the and for.够用来看见:这个“一致”分数就是被留下的词数,包括 the 和 for。
Not enough for a press note that says the coverage agrees. It still needs the headlines that actually ran, a word list you can defend, and a check that the score tracks whether pay rose, not shared scaffolding.不够写一份说报道口径一致的新闻稿。稿子仍需要实际刊出的标题、一份说得清的词表,并检查分数跟的是工资涨没涨,而不是共享的骨架。
Equations, assumptions, and limits方程、假设与限度
Tokenize by lowercasing and keeping letters. Each document becomes a vector of term counts. Cosine similarity is the usual angle between those vectors: the dot product divided by the product of the lengths. For nonnegative counts it falls between 0 and 1. Empty vectors have no cosine.分词时改为小写并只保留字母。每份文档变成词数向量。余弦相似度是这些向量夹角的常见定义:点积除以长度之积。非负计数时它落在 0 和 1 之间。空向量没有余弦。
A document-term matrix is the same idea with one row per document and one column per term. This lab shows two rows. It does not weight terms by inverse document frequency, stem words, or expand synonyms.文档—词矩阵是同一想法:一行一份文档,一列一个词。本实验只显示两行。它不做逆文档频率加权,不提取词干,也不扩展同义词。
Common pitfall.常见陷阱。 A high cosine is easy to read as “these texts say the same thing.” The opposite-claims pair is there to block that reading: one verb flips the claim, and the score can stay high. A low cosine is easy to read as “unrelated.” The different-words pair is there to block that reading too. Another pitfall is to treat the function-word list as neutral. It is a dictionary choice, and it changes the score.余弦高,很容易被读成“这些文本在说同一件事”。相反主张那一对就是为了挡住这种读法:一个动词翻转主张,分数仍可以很高。余弦低,也很容易被读成“无关”。用词不同那一对就是为了挡住这种读法。另一个陷阱是把功能词表当成中性的。它是词典选择,而且会改变分数。