先算一遍,再问是谁教的
0:00先做一道算术题。它简单到可以在纸上写完,却花了很多年才让机器算对。
每个词被放进一个坐标里——不是表格里的一格,而是一个位置,比如三百个数字组成的一串。两个词的坐标可以相减,减出来的不是数,是一个方向;把方向加到第三个词上,再去找离落点最近的那个词。
King,减 Man,加 Woman。落点最近的那个词,是 Queen。
[001]
引用 [001]
原句把这条算式的展示记为引用 [20],即更早的文献;本文的贡献是设计新架构以提高这类运算的准确性。因此口播不说'他们发现词向量能做算术',只说'这条算式成立'。三百维的说法来自 §4 的实验配置(300 维),也来自 05 段那个预训练包,不是唯一可能取值。
§1.1, PDF p.2: 'Using a word offset technique ... vector("King") - vector("Man") + vector("Woman") results in a vector that is closest to the vector representation of the word Queen [20]'
现在把这道题翻过来问一次:没有人写下"国王与男人的差别是王权",也没有人告诉模型"男人与女人的差别"该指向哪里。这个方向,是从文本里自己长出来的。
这一段先只留一个结论给你:它能算。怎么算出来的,为什么是三百个数字而不是别的数目,我们放到后面——先记住这一刻的意外感,因为它马上就会被解释掉。
2013 年,四个人的任务小得离谱
0:54时间给到二零一三年。地点是 Google,四个人:Tomas Mikolov、Kai Chen、Greg Corrado、Jeffrey Dean。他们要解决的问题,说出来有点反直觉——不是让机器理解语言,而是让它在语料大到离谱的时候,还能在一天之内训出能用的向量。
那个年代处理文本的主流办法,是把词当成一个个编号:bank 是一个编号,river 是另一个编号,编号之间没有远近,也就没有"相似"这回事。要在这个基础上谈相似,只能靠人先定义好词典、定义好同义词表。
他们换了一个办法:不定义,让它自己长。语料是十六亿个词,训练目标小得离谱——猜邻居。这两件事同时成立,后面所有的取舍才有道理。
在讲他们怎么猜之前,先把这条动作的旧账交代清楚,因为它已经出现过三次。
第一次是 Claude Shannon。他拿字符的统计去猜下一个字符,用猜中的难易,给语言定了一个下限。
第二次是统计语音识别的年代。IBM 的人把这个动作做成可以查的表:看前面几个词,数下一个词出现的概率。
第三次是循环网络。它把"前面几个词"换成一个可以被训练的状态——记住什么、放下什么,由训练决定。
三次都是拿前面的东西,猜后面的东西。二零一三年这一次,猜的是旁边的东西。
换的不是模型更大,是猜的位置移动了:从前面的符号,移到旁边的词。移动之后,第一次留下了"每个词一个坐标"这样的产物。关于这一步,讲者本人在九年后的一场讲座里讲过一遍,我们直接听他说。
(原声片段:Tomáš Mikolov 在 F. Jelinek Series #44 的讲座,源 00:03:55–00:04:40,成片 02:39.435–03:24.435。讲者在这里回顾前面提到的几次旧账。这一段原声的逐字与译义尚未核定,本站只标位置与作用,不转录原话。)
[014]
引用 [014]
讲者身份依讲座页面描述(Tomáš Mikolov,CIIRC ČVUT)。本段只交代位置与叙事作用:该片段的逐字、译义与用途权利尚未核定,公开逐字稿不转录原话。
FJelinekSeries #44,源 00:03:55–00:04:40(45.0 秒),成片 02:39.435–03:24.435
他说完这一点,问题就变成技术问题了:猜到旁边的词,为什么会在训练里留下坐标?
猜邻居,怎么就留下坐标了
3:34现在把镜头推到机制上。这一次的任务长这样:给一个词,猜它窗口里的邻居。
窗口是五个词,就猜左右各两个。反过来也行:给一圈邻居,猜中间那个。第一种叫 Skip gram,第二种叫 C B O W——名字不用记,记住方向就行:一个从词猜邻居,一个从邻居猜词。
[002]
引用 [002]
支撑的是两种架构的方向、'输出层在词表上归一化很贵'、以及层次 softmax 沿树路径选择这一机制;原文给的是复杂度表达式,不承诺任意词表规模都可行。口播里的'二十层上下'是按 692K 词表取 log2 的量级推算(≈19.4),Huffman 树对高频词更浅、罕见词更深,故只说'上下',不当作论文数值。
§3.1 CBOW 与 §3.2 Skip-gram(p.3–4);同节关于每步训练复杂度随词表规模增长的讨论;§4.4 大规模并行训练
任务小到几乎没有信息量。它不问词义,不问语法,只问一件事:这段文本里,谁常和谁挨着。
麻烦在代价。每猜一次,输出都要在几十万个词上分一次概率——词表有多大,这一步就有多贵。
[002]
引用 [002]
支撑的是两种架构的方向、'输出层在词表上归一化很贵'、以及层次 softmax 沿树路径选择这一机制;原文给的是复杂度表达式,不承诺任意词表规模都可行。口播里的'二十层上下'是按 692K 词表取 log2 的量级推算(≈19.4),Huffman 树对高频词更浅、罕见词更深,故只说'上下',不当作论文数值。
§3.1 CBOW 与 §3.2 Skip-gram(p.3–4);同节关于每步训练复杂度随词表规模增长的讨论;§4.4 大规模并行训练
"几十万"是个虚数,论文里给了一个实数。那一轮实验用的是十亿词的新闻语料,把出现不到五次的词全部丢掉,剩下六十九万两千个词。每猜一次,都要在这六十九万个词上分一次概率。而语料里有十亿个词,每个词都是一个样本。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
所以真正的困难不是任务难,是任务太多了。同样的模型,如果每一步都要扫一遍全词表,语料再大一点就跑不动。
于是他们砍了两刀。第一刀是层次 softmax:把词表按词频排成一棵二叉树,高频词在浅处、罕见词在深处,每猜一次只沿着一条路径一层层往下选——六十九万个词,路径长度是二十层上下,而不是跟六十九万个词逐个比。第二刀是负采样:不再和整个词表比,只和几个随机抽到的"假邻居"比。真邻居算正例,抽来的算负例,做几次二分类就完事。
[002]
引用 [002]
支撑的是两种架构的方向、'输出层在词表上归一化很贵'、以及层次 softmax 沿树路径选择这一机制;原文给的是复杂度表达式,不承诺任意词表规模都可行。口播里的'二十层上下'是按 692K 词表取 log2 的量级推算(≈19.4),Huffman 树对高频词更浅、罕见词更深,故只说'上下',不当作论文数值。
§3.1 CBOW 与 §3.2 Skip-gram(p.3–4);同节关于每步训练复杂度随词表规模增长的讨论;§4.4 大规模并行训练
[003]
引用 [003]
负采样是对层次 softmax 的简化替代,只对噪声分布采几个负例,不是'排除错误答案以求真';短语是按分数合并的高频组合,不是语法短语分析。
摘要(subsampling、negative sampling、phrase vectors);§2.2 Negative Sampling pp.3–4;§4 phrase score
这两刀哪个好,论文自己拿表回答。同一份十亿词语料、同样三百维、同一个任务,试了四种训练方式:负采样每次抽五个、抽十五个、层次 softmax、以及另一种叫噪声对比估计的。只算时间:负采样五个三十八分钟,层次 softmax 四十一分钟,差距不大。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
分数差得很远。负采样五个,总分五十九;负采样十五个,六十一;层次 softmax,四十七。也就是说,那个更省事的近似,在这次比较里不但没有输,还赢了十二个点。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
但这一段真正反常的还不是这个。他们把同一套设置又跑了一遍,只加了一件事:把太常见的词按概率丢掉。负采样五个从三十八分钟变成十四分钟——快了两倍多——总分从五十九升到六十;层次 softmax 的总分从四十七升到五十五,其中语义题从四十跳到五十九。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
扔掉数据,反而更准、更快。这不是调参调出来的巧合,作者给了理由:France 和 the 的共现几乎不携带信息,因为几乎每个词都会在句子里遇到 the;France 和 Paris 的共现才携带信息。他们还反过来看到一件事——一个高频词的向量,在看过几百万个例子之后几乎不再变化,继续喂它,只是重复付费。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
这里必须留一句边界:三十八、十四、五十九、六十这四个数,只在那一张表里成立——十亿词、三百维、Skip gram、类比题。换架构、换语言、换任务,排序都可能变。它不是"下采样永远更好",它是"在这份语料上,丢掉高频词没有损失,还省了时间"。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
短语层面也是同一现象。他们另外做了一个短语版类比集,三千二百一十八道题。把高频词丢掉之后,三种训练方式的分数一起往上走:负采样五个从二十四到二十七,负采样十五个从二十七到四十二,层次 softmax 从十九到四十七。同一个动作,在短语上也成立。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
短语也不是靠句法分析出来的。他们用一个很朴素的分数:分母是两个词各自出现次数的乘积,分子是它们一起出现的次数减一个折扣;分数过线的二元组就并成一个记号。这样 New York Times、Toronto Maple Leafs 会被并起来,this is 不会。跑两到四轮、阈值逐轮放宽,还能并出更长的组合。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
训练完,输出那层其实不是重点。重点在输入侧:每个词对应一串数字,每次更新只动到其中几行,动过几百万次之后,它变成了坐标。
这里要把一句话说清:坐标不是被设计出来的,是被"猜准"这个目标逼出来的副产品。
这里还有个容易被讲成玄学的地方:为什么这些向量会服从线性?作者自己在论文里给了一个诚实的说法——Skip gram 的结构确实天生更贴近线性关系;但另一个事实是,标准循环网络那种高度非线性的模型,在数据变多之后,在这个任务上的分数也一起涨。所以更像是"数据够多时,线性结构自己浮现",而不是"只有这套架构才行"。
[008]
引用 [008]
所有比较限定为:Skip-gram、300 维、1B 词、类比题任务。原文未声称下采样普遍提升精度,只报告这一组结果;口播已按此设边界(pred-12)。短语层面的数字来自 Table 3,同一语料与维度,不外推到句法任务。
§3 训练设置(内部 Google 新闻语料 1B 词;丢弃出现少于 5 次的词后词表 692K);Table 1 p.5(Time[min] / Syntactic / Semantic / Total:NEG-5 38/63/54/59;NEG-15 97/63/58/61;HS-Huffman 41/53/40/47;NCE-5 38/60/45/53;加 10⁻⁵ 下采样后 NEG-5 14/61/58/60、NEG-15 36/61/61/61、HS-Huffman 21/52/59/55);§2.3 Subsampling of Frequent Words(阈值 t≈10⁻⁵;`France`/`the` 与 `France`/`Paris` 的对比理由;原文自称'chosen heuristically');§4 短语构成(score(wi, wj) = (count(wi wj) − δ) / (count(wi) × count(wj)),跑 2–4 轮、阈值逐轮放宽;'New York Times' / 'Toronto Maple Leafs' 并为单一记号而 'this is' 不并;短语类比最好 72%)与 Table 3(3218 例;无下采样 / 10⁻⁵ 下采样:NEG-5 24→27、NEG-15 27→42、HS-Huffman 19→47);§3 末段(线性关系更贴合 Skip-gram,但高度非线性的循环网络在数据增加后也显著提升,'suggesting that non-linear models also have a preference for a linear structure')
在它之前,还有一条更老的路:给词分类。Brown clusters 的做法是把每个词指派进一个类——一个词,只能待在一个类里。
[003]
引用 [003]
负采样是对层次 softmax 的简化替代,只对噪声分布采几个负例,不是'排除错误答案以求真';短语是按分数合并的高频组合,不是语法短语分析。
摘要(subsampling、negative sampling、phrase vectors);§2.2 Negative Sampling pp.3–4;§4 phrase score
(原声片段:同一场讲座,源 00:19:30–00:20:15,成片 08:40.462–09:25.462。讲者在这里从给词分类讲到给词坐标。这一段原声的逐字与译义尚未核定,本站只标位置与作用,不转录原话。)
[015]
引用 [015]
同一场讲座的第二个窗口,与 W1 同源,不构成两条独立证词。逐字与译义同样未核定,逐字稿只标位置与作用。
FJelinekSeries #44,源 00:19:30–00:20:15(45.0 秒),成片 08:40.462–09:25.462
他从这里直接走到坐标:如果一个词可以同时属于很多类,那就不必只给它一个类,可以给它一串数,让每个类各占一点。
还有个容易忽略的细节:源码里的默认值很朴素——窗口五、一百维、五轮、负采样五个。而论文表格里那些分数,用的是另一套:三百维、三个 epoch、起始学习率零点零二五并线性衰减到零。起点一致,轮数不同。也就是说,"能跑"和"刷到表里的分",是两套配置。
[004]
引用 [004]
默认值不等于论文实验配置;论文里跑出表格数字用的是 300–600 维、783M–1.6B 词等另一套设置。项目页清单是经验陈述,不是最优配置的保证。
- word2vec.c(tmikolov/word2vec master 分支原始文件,节选为默认参数段)
- Efficient Estimation of Word Representations in Vector Space(arXiv:1301.3781v3)
- word2vec 项目页(Google Code,Wayback 2016-01-08 快照)
word2vec.c 第 40–49 行默认参数:cbow=1、window=5、layer1_size=100、iter=5、negative=5、sample=1e-3、alpha=0.025;1301 §4.2 末段(Table 2 与 Table 4 的实验用 3 epoch、起始学习率 0.025 线性衰减);项目页 Performance 一节(skip-gram 更慢但罕词更好;HS 对罕词好、NEG 对高频词好且低维更好;下采样 1e-3~1e-5;维度'usually more is better, but not always';窗口 skip-gram ≈10、CBOW ≈5)
项目页把这些经验直接写成了清单,语气很像说明书:Skip gram 更慢,但对罕见词更好;层次 softmax 对罕见词好,负采样对高频词好、维度低时也更好;窗口 Skip gram 取十左右,C B O W 取五左右;维度"通常越多越好,但不总是"。
[004]
引用 [004]
默认值不等于论文实验配置;论文里跑出表格数字用的是 300–600 维、783M–1.6B 词等另一套设置。项目页清单是经验陈述,不是最优配置的保证。
- word2vec.c(tmikolov/word2vec master 分支原始文件,节选为默认参数段)
- Efficient Estimation of Word Representations in Vector Space(arXiv:1301.3781v3)
- word2vec 项目页(Google Code,Wayback 2016-01-08 快照)
word2vec.c 第 40–49 行默认参数:cbow=1、window=5、layer1_size=100、iter=5、negative=5、sample=1e-3、alpha=0.025;1301 §4.2 末段(Table 2 与 Table 4 的实验用 3 epoch、起始学习率 0.025 线性衰减);项目页 Performance 一节(skip-gram 更慢但罕词更好;HS 对罕词好、NEG 对高频词好且低维更好;下采样 1e-3~1e-5;维度'usually more is better, but not always';窗口 skip-gram ≈10、CBOW ≈5)
同一份数据,两种架构,两个世界
10:23论文里有一张表,只比同一件事:同一份七亿多词的语料、同样的三百维,Skip gram 和 C B O W,谁更强。
结果是分岔的。句法题上两边几乎打平:五十五点九对五十三点一。语义题上差得很远:五十对十五点五。
[005]
引用 [005]
所有数字只在同表、同语料、同维度内比较;`-30 / -50` 是训练样本最大长度,不是隐藏层维度;不使用集成或重排类数字;摘要的'不到一天'只对应特定配置。
§4 Table 1(8869 semantic + 10675 syntactic 题);Table 4 p.7(CBOW 300d/783M:15.5 / 53.1 / 36.1;Skip-gram 300d/783M:50.0 / 55.9 / 53.3;Our NNLM 100d/6B:34.2 / 64.5 / 50.8;Mikolov RNNLM 640d/320M:8.6 / 36.5 / 24.6);Table 5 p.8(训练时间:CBOW 3 epoch 1 天、Skip-gram 3 epoch 3 天、1 epoch CBOW 1.6B 0.6 天、1 epoch Skip-gram 1.6B 2 天);§4.1(判对口径:同义词算错;'reaching 100% accuracy is likely to be impossible, as the current models do not have any input information about word morphology')
代价也一起涨。C B O W 跑三轮约一天,Skip gram 约三天。摘要里那句"不到一天",说的是 C B O W 在十六亿词上跑一轮的配置,零点六天;同一个条件换成 Skip gram 要两天。
[005]
引用 [005]
所有数字只在同表、同语料、同维度内比较;`-30 / -50` 是训练样本最大长度,不是隐藏层维度;不使用集成或重排类数字;摘要的'不到一天'只对应特定配置。
§4 Table 1(8869 semantic + 10675 syntactic 题);Table 4 p.7(CBOW 300d/783M:15.5 / 53.1 / 36.1;Skip-gram 300d/783M:50.0 / 55.9 / 53.3;Our NNLM 100d/6B:34.2 / 64.5 / 50.8;Mikolov RNNLM 640d/320M:8.6 / 36.5 / 24.6);Table 5 p.8(训练时间:CBOW 3 epoch 1 天、Skip-gram 3 epoch 3 天、1 epoch CBOW 1.6B 0.6 天、1 epoch Skip-gram 1.6B 2 天);§4.1(判对口径:同义词算错;'reaching 100% accuracy is likely to be impossible, as the current models do not have any input information about word morphology')
更有意思的是同一张表里另外两行——作者自己更早的模型:N N L M 用一百维、六十亿词,做到五十点八;R N N L M 用六百四十维、三亿多词,只有二十四点六。
[005]
引用 [005]
所有数字只在同表、同语料、同维度内比较;`-30 / -50` 是训练样本最大长度,不是隐藏层维度;不使用集成或重排类数字;摘要的'不到一天'只对应特定配置。
§4 Table 1(8869 semantic + 10675 syntactic 题);Table 4 p.7(CBOW 300d/783M:15.5 / 53.1 / 36.1;Skip-gram 300d/783M:50.0 / 55.9 / 53.3;Our NNLM 100d/6B:34.2 / 64.5 / 50.8;Mikolov RNNLM 640d/320M:8.6 / 36.5 / 24.6);Table 5 p.8(训练时间:CBOW 3 epoch 1 天、Skip-gram 3 epoch 3 天、1 epoch CBOW 1.6B 0.6 天、1 epoch Skip-gram 1.6B 2 天);§4.1(判对口径:同义词算错;'reaching 100% accuracy is likely to be impossible, as the current models do not have any input information about word morphology')
所以这不是一场"新方法打败别人"的战争,更像一次自家产品的换轴:同样的任务,换一个更便宜的结构。
论文还有第二张表,换一组条件:统一六百四十维,同一份三亿两千万词的语料,把四种架构排在一条线上。语义题上,R N N L M 是九,N N L M 是二十三,C B O W 是二十四,Skip gram 是五十五。句法题上顺序反过来:C B O W 最高,六十四。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
两张表的数字不能混着比。第一张是七亿八千三百万词、三百维;第二张是三亿两千万词、六百四十维。同一个模型在两处分数不同,不是谁错了,是条件换了——维度翻倍、数据减半。这也是这一集里唯一想让人记住的表格纪律:数字只在同一张表内比较。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
第二张表还藏着一个时间尺度。那个 R N N L M 是此前训练好的,训一次大约八周,用的是一颗 CPU。要注意这不是第一张表里"一天对三天"的那条时间线——语料和配置都不同,不能相减。但两个量级放在一起,当时的处境就清楚了。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
这些数字背后还有一层代价,藏在一张更不起眼的表里。这些模型不是在笔记本上跑的:作者用的是一个叫 DistBelief 的分布式框架,同一个模型复制五十到一百份同时训练。于是训练时间被记成"天乘核数"。六十亿词、一千维:C B O W 用了两天、一百四十个核;Skip gram 两天半、一百二十五个核。而同一份数据上,N N L M 一百维,用了十四天乘一百八十个核。
[012]
引用 [012]
表 6 的训练词量为 6B(Google News 6B 数据集),不是 1.6B;口播在 table-17 已说明它与摘要'不到一天'不是同一实验。表 7 说明 Skip-gram 单独在此任务上不如 LSA / log-bilinear / RNNLM,口播按此如实交代,不用它做胜利叙事。
§4.4(DistBelief 分布式框架、mini-batch 异步梯度下降 + AdaGrad、训练时用 50–100 个模型副本;Table 6:NNLM 100d/6B 50.8 / 14 天 × 180 核;CBOW 1000d/6B 63.7 / 2 天 × 140 核;Skip-gram 1000d/6B 65.6 / 2.5 天 × 125 核;'due to the overhead of the distributed framework, the CPU usage of the CBOW model and the Skip-gram model are much closer to each other than their single-machine implementations');§4.5(MSR Sentence Completion Challenge 1040 句、每句五个选项;Table 7:4-gram 39、Average LSA 49、log-bilinear 54.8、RNNLMs 55.4、Skip-gram 48.0、Skip-gram + RNNLMs 58.9)
两个口径要补一句。分布式框架自己有开销,所以论文自己承认:多核下 C B O W 和 Skip gram 的耗时比单机时更接近。这也意味着,摘要里那句"不到一天",和这张表里的"两天"不是一回事——一处是十六亿词上跑一轮,一处是六十亿词、一千维,还得摊上并行的损耗。
[012]
引用 [012]
表 6 的训练词量为 6B(Google News 6B 数据集),不是 1.6B;口播在 table-17 已说明它与摘要'不到一天'不是同一实验。表 7 说明 Skip-gram 单独在此任务上不如 LSA / log-bilinear / RNNLM,口播按此如实交代,不用它做胜利叙事。
§4.4(DistBelief 分布式框架、mini-batch 异步梯度下降 + AdaGrad、训练时用 50–100 个模型副本;Table 6:NNLM 100d/6B 50.8 / 14 天 × 180 核;CBOW 1000d/6B 63.7 / 2 天 × 140 核;Skip-gram 1000d/6B 65.6 / 2.5 天 × 125 核;'due to the overhead of the distributed framework, the CPU usage of the CBOW model and the Skip-gram model are much closer to each other than their single-machine implementations');§4.5(MSR Sentence Completion Challenge 1040 句、每句五个选项;Table 7:4-gram 39、Average LSA 49、log-bilinear 54.8、RNNLMs 55.4、Skip-gram 48.0、Skip-gram + RNNLMs 58.9)
回到那个问题:为什么是三百维,不是三十,也不是三千。论文给了一张很朴素的表——同一个 C B O W,词表只取最高频的三万个词,横着是语料从两千四百万词加到七亿八千三百万词,竖着是维度:
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
五十维:十三点四一路涨到二十三点二。一百维:十九点四到三十二点二。三百维:二十三点二到四十五点九。六百维:二十四到五十点四。每一行都在涨,但每一行都涨得越来越慢。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
作者的结论很直白:到某个点之后,加维度或者加数据,收益都在递减,所以必须一起加。他们还顺手批评了当时的习惯——语料堆得很大,维度却只有五十到一百。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
更有意思的是账。他们说,数据翻一倍,和维度翻一倍,计算开销的增加差不多一样。所以"要不要更大的向量"从来不是技术问题,是预算问题:同样的钱,花在更多数据上,还是更大维度上。
[009]
引用 [009]
Table 3 与 Table 4 的语料不同(LDC 320M vs Google News 783M),口播在 table-7 / table-8 已明确禁止相减;八周指那台 RNNLM 在 LDC 数据上的训练时长,不与 Table 5 的'一天 / 三天'构成同一实验。Table 2 为 CBOW、30k 词表限定,不外推为通用定律。
§4.3(训练数据为若干 LDC 语料 320M words / 82K vocabulary;Table 3 640 维:RNNLM 9/36/35、NNLM 23/53/47、CBOW 24/64/61、Skip-gram 55/59/56;'a previously trained recurrent neural network language model that took about 8 weeks to train on a single CPU');§4.2(Google News 约 6B tokens、最终词表 1M;子集取最高频 30k;Table 2 四行数字;'diminishing improvements ... increase both vector dimensionality and the amount of the training data together';对'大数据低维度(50–100)'的批评;Equation 4 推论:数据翻倍与维度翻倍的复杂度增加大致相同)
接下来是这一期必须补的一句交代。那条 King 减 Man 加 Woman 的算式,不是这篇论文第一次拿出来——论文原句把它标成了一个引用,也就是更早的文献已经做过。这篇论文真正的贡献,是把这类向量运算的准确率抬上去,并且给出一个别人能复现的规模。
[006]
引用 [006]
两处口径一致:论文自注引用 [20],项目页把更早那篇 NAACL 论文排在前面。因此不能说 2013 年首次发现词向量可做算术。
- Efficient Estimation of Word Representations in Vector Space(arXiv:1301.3781v3)
- word2vec 项目页(Google Code,Wayback 2016-01-08 快照)
1301 §1.1, PDF p.2:'... it was shown for example that vector("King") - vector("Man") + vector("Woman") results in a vector that is closest to ... Queen [20]';项目页 Interesting properties 一节把同一算式标注为 [3, 1],其中 [3] 为 Mikolov, Yih, Zweig, NAACL 2013
这也解释了开场为什么只说"它能算":这条式子成立,早就不是新闻;值得讲的是它为什么在二零一三年变得便宜。
最后一个边界:那套考卷有八千八百六十九道语义题、一万零六百七十五道句法题,题目形式是"两个词之差,加到第三个词上,看落在谁附近"。它考的是这种检索,不是理解。
[005]
引用 [005]
所有数字只在同表、同语料、同维度内比较;`-30 / -50` 是训练样本最大长度,不是隐藏层维度;不使用集成或重排类数字;摘要的'不到一天'只对应特定配置。
§4 Table 1(8869 semantic + 10675 syntactic 题);Table 4 p.7(CBOW 300d/783M:15.5 / 53.1 / 36.1;Skip-gram 300d/783M:50.0 / 55.9 / 53.3;Our NNLM 100d/6B:34.2 / 64.5 / 50.8;Mikolov RNNLM 640d/320M:8.6 / 36.5 / 24.6);Table 5 p.8(训练时间:CBOW 3 epoch 1 天、Skip-gram 3 epoch 3 天、1 epoch CBOW 1.6B 0.6 天、1 epoch Skip-gram 1.6B 2 天);§4.1(判对口径:同义词算错;'reaching 100% accuracy is likely to be impossible, as the current models do not have any input information about word morphology')
最后一个边界,也是同一批作者自己给出的。拿这套向量去跑微软的句子补全挑战——一千零四十个句子,每句挖一个词、给五个选项:Skip gram 单独做,四十八。比 n gram 的三十九高,但低于 L S A 的四十九、log bilinear 的五十四点八、循环网络的五十五点四。它单独上场不是最好的;把它和循环网络叠在一起,才到五十八点九。所以"一个词一个坐标"有用,但它不是万能件。
[012]
引用 [012]
表 6 的训练词量为 6B(Google News 6B 数据集),不是 1.6B;口播在 table-17 已说明它与摘要'不到一天'不是同一实验。表 7 说明 Skip-gram 单独在此任务上不如 LSA / log-bilinear / RNNLM,口播按此如实交代,不用它做胜利叙事。
§4.4(DistBelief 分布式框架、mini-batch 异步梯度下降 + AdaGrad、训练时用 50–100 个模型副本;Table 6:NNLM 100d/6B 50.8 / 14 天 × 180 核;CBOW 1000d/6B 63.7 / 2 天 × 140 核;Skip-gram 1000d/6B 65.6 / 2.5 天 × 125 核;'due to the overhead of the distributed framework, the CPU usage of the CBOW model and the Skip-gram model are much closer to each other than their single-machine implementations');§4.5(MSR Sentence Completion Challenge 1040 句、每句五个选项;Table 7:4-gram 39、Average LSA 49、log-bilinear 54.8、RNNLMs 55.4、Skip-gram 48.0、Skip-gram + RNNLMs 58.9)
还有一件事要交代,关于"判对"的口径。这套题只认完全相同的答案,同义词算错。作者自己写:达到百分之百几乎不可能,因为模型完全没有词形的信息——它不知道 run 和 running 是同一个动词的两种形态。所以那些百分比读的时候要记住:它测的是检索命中,不是语言能力。
[005]
引用 [005]
所有数字只在同表、同语料、同维度内比较;`-30 / -50` 是训练样本最大长度,不是隐藏层维度;不使用集成或重排类数字;摘要的'不到一天'只对应特定配置。
§4 Table 1(8869 semantic + 10675 syntactic 题);Table 4 p.7(CBOW 300d/783M:15.5 / 53.1 / 36.1;Skip-gram 300d/783M:50.0 / 55.9 / 53.3;Our NNLM 100d/6B:34.2 / 64.5 / 50.8;Mikolov RNNLM 640d/320M:8.6 / 36.5 / 24.6);Table 5 p.8(训练时间:CBOW 3 epoch 1 天、Skip-gram 3 epoch 3 天、1 epoch CBOW 1.6B 0.6 天、1 epoch Skip-gram 1.6B 2 天);§4.1(判对口径:同义词算错;'reaching 100% accuracy is likely to be impossible, as the current models do not have any input information about word morphology')
它先是一个工具,然后才是一篇论文
16:03现在把镜头从论文上挪开一会儿,挪到同一个项目的网页上。要先说清一件事:我们看到的那一页,是二零一六年一月的存档,它记录的是那几年这个工具长什么样。所以它不是二零一三年的现场,只是一个后来者能看见的入口。
页面上最要紧的两行字,都不在正文里。一行在侧栏:许可,Apache License 二点零。另一行在页尾:This open source project is NOT a Google product, and is released for research purposes only. 页面托管在 Google Code 上,成员署的是 gmail 地址,论文的机构栏写的是 Google——而页面自己说,这不是 Google 的产品,仅供研究用途。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
上手只要三步。检出代码,编译,跑脚本。检出的地址是 S V N checkout,后面是项目在 Google Code 上的仓库地址,编译是 make,然后 demo word 脚本。旁边还排着另外几个脚本:短语的、类比的、聚类的、还有两个专门跑准确率的。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
第一次见面通常不是读论文,是敲一个词。跑起来之后输入 distance france,屏幕上出现一列国家,每个后面跟一个余弦距离:spain 零点六七八五一五,belgium 零点六六五九二三,netherlands 零点六五二四二八,italy 零点六三三一三,一路排到 catalonia 零点五三四一七六。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
这列数字就是"相似"。它不解释为什么西班牙比比利时更近,只给一个可以排序的分数。很多人的"词义",第一次就是这样一个数。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
还有一条命令,demo analogy 脚本。页面自己写着那个例子:king 减 man 加 woman 接近 queen;Paris 减 France 加 Italy 接近 Rome。这条算式的第二次出现,就在这儿——而且要注意页面标的来源顺序:更早那篇 NAACL 论文排在前面。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
然后是真正让它长脚的东西:预训练包。大约一千亿词上训出来的向量,三百维,三百万个词与短语,文件名 Google News vectors negative 三百,后缀是 bin 点 g z。旁边还有一百四十万个 Freebase 实体向量,专门给做知识抽取的人用。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
那个三百值得停一下。后来所有人嘴里的"三百维",很多时候不是自己选的,是因为下载下来的包就是三百。它不是被证明的最优值——项目页自己在别处写着,维度通常越多越好,但不总是。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
页面还给了一个中文听众能立刻感到的例子。输入 Chinese river,两个词而不是一个词,返回的第一个是 Yangtze River,零点六六七三七六。页面说明这是把两个词的向量取平均,再去找最近的词。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
页面还演示了两件事。一件事是短语:跑 demo phrases 脚本,san francisco 最近的词是 los angeles、golden gate、oakland。另一件事是实体向量:输入 geoffrey hinton 的实体条目,最近的是 marvin minsky、paul corkum,一直排到 godel prize。前面几个是同行的名字,最后一个不是人——这就是"距离近"能给出的东西,也是它不能保证的东西。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
同一个页面上还有一个数字,值得和论文里的数字并排放。页面说:两套测试集的"最好结果"都在百分之七十以上,覆盖率接近百分之一百。而论文里,同一个架构、同样三百维、七亿八千三百万词,总分是五十三点三。
[011]
引用 [011]
两个数字口径不同:前者是项目方对'最好结果'的自述(配置未给),后者是论文同表内的实测。差异的解释(语料 100B vs 783M)依据项目页 Pre-trained vectors 的语料规模说明,属编辑解释,不是论文结论。
- word2vec 项目页(Google Code,Wayback 2016-01-08 快照)
- Efficient Estimation of Word Representations in Vector Space(arXiv:1301.3781v3)
项目页 How to measure quality of the word vectors:'our best results for both test sets are above 70% accuracy with coverage close to 100%';1301 §4 Table 4(Skip-gram 300d / 783M:总 53.3)
差在哪?差在语料。一个是约一千亿词,一个是七亿八千三百万词,两个数量级。所以那百分之七十不是论文表格里的分,也不是模型的上限,是"数据管够"时的分。两个数字都对,只是回答的不是同一个问题。
[011]
引用 [011]
两个数字口径不同:前者是项目方对'最好结果'的自述(配置未给),后者是论文同表内的实测。差异的解释(语料 100B vs 783M)依据项目页 Pre-trained vectors 的语料规模说明,属编辑解释,不是论文结论。
- word2vec 项目页(Google Code,Wayback 2016-01-08 快照)
- Efficient Estimation of Word Representations in Vector Space(arXiv:1301.3781v3)
项目页 How to measure quality of the word vectors:'our best results for both test sets are above 70% accuracy with coverage close to 100%';1301 §4 Table 4(Skip-gram 300d / 783M:总 53.3)
扩散这件事,页面自己记着账。"Other useful links"一栏列着:Python 的 gensim,作者 Radim Rehurek;Java 的 deep learning four J;Spark M L lib;还有研究者做的改进版本。这不是后人追认的清单,是项目页自己维护的。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
页面还演示了另一件事:在词向量上跑 K means,输出"词 + 类号"。class 二百三十四里全是动物——食肉的、鲸类、鳄鱼、郊狼、甲壳类。class 四百一十二里是另一批:acceptance、argue、argues、arguing、argument、belief、believe、challenge、claim。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
这两个类放在一起看,一件事就清楚了:被归成一类,不等于意思是同一个。"论证"和"相信""挑战""声称"待在一起,是因为它们出现在相似的上下文里,不是因为它们同义。这句话先放在这儿,下一段要接着用。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
边界要留三句:这一页不标发布日期,所以我们不说它哪一天上线;它不给下载量,所以我们不说有多少人在用;distance 那些距离值来自示例,配置未知,不当论文数字引用。能说的只有两件事:它按 Apache 二点零发布,且项目页自己声明它不是 Google 产品。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
这一段交出去的一句话是:工具先让人相信"相似可以算"。接下来要问,这份"可以算"付了什么账。
一个词,被压成了一个点
21:22到这儿,好处说完了:一个词一个坐标,所以能算。代价有两层。
第一层是多义。bank 是银行也是河岸,table 是桌子也是表格;在这个模型里,它们各自只有一个点。不是说它不懂两个意思,而是它把两个意思平均成了一个位置。
平均也不是随便平均。哪个意思在语料里出现得多,那个意思就更靠近这个点。所以在这里,"一个词的意思"实际是"它在各种句子里出现方式的加权平均"。
哪一边出现得多,取决于谁在写、写什么、写给谁看。一堆"护士,她"式的句子如果占了上风,这个位置就会往那一侧偏。所以这里没有中立的平均——被平均的对象本身,就是有偏向的样本。
第二层更麻烦:偏见一起进来。二零一六年七月,一篇论文的标题本身是一道类比题——Man is to Computer Programmer as Woman is to Homemaker?
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
摘要第一句给的不是数字,是一句判断:即使是在 Google News 上训出来的向量,也把男女刻板印象编码到了"令人不安的程度"——原文用的是 to a disturbing extent。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
第二句才是关键:这种偏见在几何上,是空间里的一个方向。也就是说,它和开头那条 king 减 man 的差,是同一种东西——可以相减,可以相加,也可以被找出来。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
第三句:中性的词与定义性别的词,在这个空间里可以线性分开。换句话说,这个空间不只是"有偏见",它还有结构,而结构可以被定位。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
论文开篇把两个等式写在一起:man 减 woman 接近 king 减 queen;以及 man 减 woman 接近 computer programmer 减 homemaker。同一个方向,一边给出女王,一边给出家庭主妇。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
因果要分清:不是训练的人有偏见,而是训练目标只要求猜中邻居。文本里怎么写,坐标就怎么记。机制是中立的,结果不是。
这和第五段那个聚类输出的现象,是同一件事的另一面:被归成一类,不等于同义。距离之所以成立,靠的是上下文相似;而上下文相似里,既有"用法相近",也有"出现在同一类句子里"。前者是我们想要的,后者就是偏见的入口。
边界也要说清。那篇论文的实验数据、去偏方法的效果、评估的规模,我还没有核到能口播的精度,所以这里只到主张这一层:它提出可以沿那个方向做手术——去掉刻板联想(比如 receptionist 与 female),同时保留想要的联想(比如 queen 与 female)。效果如何,这里不下判断。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
那篇论文开篇还有一句很重的话:关于词向量的研究已经有几百上千篇,但没有一篇意识到这些向量有多明显的性别偏见。这是他们的判断,我不替它加权——放进这一期,是因为它说的是同一个机制的背面:被当成工具的坐标,本身带着立场。
[007]
引用 [007]
只到摘要与 §1 的主张层:不引任何实验数字、不引 Table 数值、不评价去偏效果。口播中的'2016 年 7 月'取自 arXiv v1 版本戳(21 Jul 2016),不是会议发表时间。
arXiv:1607.06520v1(2016-07-21)摘要:'even word embeddings trained on Google News articles exhibit female/male gender stereotypes to a disturbing extent';'gender bias is first shown to be captured by a direction in the word embedding';'gender neutral words are shown to be linearly separable from gender definition words';去偏目标示例 receptionist–female / queen–female;crowd-worker 评估。§1:'man − woman ≈ king − queen' 与 'man − woman ≈ computer programmer − homemaker';§1 首段:'There have been hundreds or thousands of papers written about word embeddings and their applications ... However, none of these papers have recognized how blatantly sexist the embeddings are'
再算一次那条算式
24:23回到开头那道题。King 减 Man 加 Woman 之所以落在 Queen 附近,是因为这几个词在文本里的共现,允许这样一条方向差被压出来。
同一套运算,去问"程序员"和"女人",落点会暴露语料的写法。
同一个机制,同时给出"它对"和"它不对"。这才是它值得讲的地方。
还有一件事现在可以合上了:这条算式成立的条件,和第三段那几个数字是同一套条件——语料要够大,维度要够,高频词要丢掉。项目页自己写过一句更省事的版本:要看到强规律,得在很大的数据集上、用足够的维度来训。
[010]
引用 [010]
该页为 2016-01-08 归档快照,页面不标发布日期与版本,故口播不给发布日期、不给下载量或用户数;`distance` 输出配置未知,只作界面事实描述;聚类示例只用于'同类 ≠ 同义',不作语义判断。
Wayback 快照 20160108204518 的项目页正文:Project Information(Code license: Apache License 2.0);Disclaimer('This open source project is NOT a Google product, and is released for research purposes only.');Quick start(svn checkout / make / ./demo-word.sh、demo-phrases.sh、demo-analogy.sh、demo-classes.sh、demo-word-accuracy.sh、demo-phrase-accuracy.sh);How does it work(distance france 十项输出);Interesting properties(king−man+woman≈queen、Paris−France+Italy≈Rome,标 [3, 1];'it is needed to train the models on large data set, with sufficient vector dimensionality');Performance(维度'usually more is better, but not always');From words to phrases(demo-phrases.sh 的 san_francisco 输出:los_angeles 0.666175、golden_gate 0.571522、oakland 0.557521);Pre-trained word and phrase vectors(约 100B 词、300 维、3M 词与短语、GoogleNews-vectors-negative300.bin.gz、1.4M Freebase 实体向量、Chinese river → Yangtze_River 0.667376 及'averaging vectors'说明);Pre-trained entity vectors(/en/geoffrey_hinton → /en/marvin_minsky 0.457204 … /en/godel_prize 0.405176);Word clustering(class 234 / class 412 词表);Other useful links(gensim by Radim Rehurek、deeplearning4j、Spark MLlib、Dinu 的改进版)
所以坐标不是理解,是可运算的近似。它的分量不在更聪明,而在可运算——一旦可运算,语言里的秩序和语言里的偏见,就一起成了可计算、可比较,也可以被修正的对象。
把三件事放在一起看:它便宜,是因为砍掉了全词表的归约、又扔掉了高频词;它有用,是因为语料够大、维度够;它靠不住,也是因为同一个目标只要求猜中邻居。三句话说的是同一套取舍。
论文里还有一张表,专门列它算对了什么。用的是七亿八千三百万词上训出来的跳字向量:France 减 Paris,换成 Italy,得到 Rome;换成 Japan,得到 Tokyo;换成 Florida,得到 Tallahassee。big 减 bigger 换成 small,得到 larger。Miami 减 Florida 换成 Baltimore,得到 Maryland。Einstein 减 scientist 换成 Messi,得到 midfielder。copper 减 Cu 换成 zinc,得到 Zn。
[013]
引用 [013]
该表本身包含错误示例(Japan − sushi → France 给出 tapas,实为西班牙小吃),论文照列,口播已如实指出;'约六成'是论文按精确匹配自评的口径,不是排行榜数字,不外推。
§5 Table 8(Skip-gram 783M / 300 维的关系示例:France − Paris → Italy: Rome / Japan: Tokyo / Florida: Tallahassee;big − bigger → small: larger …;Miami − Florida → Baltimore: Maryland …;Einstein − scientist → Messi: midfielder …;copper − Cu → zinc: Zn …;Japan − sushi → Germany: bratwurst / France: tapas / USA: pizza);同节正文:'the results in Table 8 would score only about 60%'(按精确匹配口径);'By using ten examples instead of one to form the relationship vector (we average the individual vectors together), we have observed improvement'
也留着错的。同一张表里,Japan 减 sushi 换成 France,给的答案是 tapas——那是西班牙的小吃。作者没有把它删掉。同一节还有一句自评:如果按"必须精确命中"来算,这张表只能拿六成左右;他们还试过用十个例子一起构成那个关系,把向量平均起来,结果更好。
[013]
引用 [013]
该表本身包含错误示例(Japan − sushi → France 给出 tapas,实为西班牙小吃),论文照列,口播已如实指出;'约六成'是论文按精确匹配自评的口径,不是排行榜数字,不外推。
§5 Table 8(Skip-gram 783M / 300 维的关系示例:France − Paris → Italy: Rome / Japan: Tokyo / Florida: Tallahassee;big − bigger → small: larger …;Miami − Florida → Baltimore: Maryland …;Einstein − scientist → Messi: midfielder …;copper − Cu → zinc: Zn …;Japan − sushi → Germany: bratwurst / France: tapas / USA: pizza);同节正文:'the results in Table 8 would score only about 60%'(按精确匹配口径);'By using ten examples instead of one to form the relationship vector (we average the individual vectors together), we have observed improvement'
也正因为它只是一个点,同一个词在不同句子里的区别就没地方放。这不是训练不够,是结构里没有那个位置。
启下:一个点不够用
26:35交出一个这一期答不了的问题:这句话里的 bank,是银行还是河岸?
零一九接手的,不是"注意力"这个词,而是"每个位置的表示,要由它周围的词现算"这件事;顺手,还把循环拿掉。
零二零接手的,是"这种表示能不能不靠人工标注、直接用文本自己训出来"。
两期各讲各的,这里不展开结构细节,也不排谁先谁后的功劳。
单集简介
27:04你刚刚收听的是《原代码》第十八期,《Word to Vec:一个词变成一个坐标》。这是《大语言模型前史》系列的第八期,副标题是“从 Alan Turing、John von Neumann 到 G P T 一”。本期用到的原文、表格位置与原声出处,都记在这一期的资料里。
官方网站
27:24你可以访问《原代码》的官方网站。网站地址是,原代码三个字的全拼,点 X Y Z。在那里,你可以查看本期逐字稿、证据引用关系和证据快照,也可以收听往期节目。
感谢收听,我们下期再见。