ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[转] word2vec对each word使用两个embedding的原因

2021-06-09 23:04:21  阅读:199  来源: 互联网

标签:use word embedding dog vector context each word2vec


from: https://blog.csdn.net/weixin_42279926/article/details/106403211

相关stackflow: https://stackoverflow.com/questions/29381505/why-does-word2vec-use-2-representations-for-each-word

问题一:为什么训练过程中使用两种embedding表达?
参考于Stack Overflow中的Why does word2vec use 2 representations for each word?
,其中一个大佬HediBY引用论文word2vec Explained: Deriving Mikolov et al.’s
Negative-Sampling Word-Embedding Method中的一个脚注去做了一点直觉性的解释,现在我把论文中的脚注放在下面:

Throughout this note, we assume that the words and the contexts come from distinct vocabularies, so that, for example, the vector associated with the word dog will be different from the vector associated with the context dog. This assumption follows the literature, where it is not motivated. One motivation for making this assumption is the following: consider the case where both the word dog and the context dog share the same vector v. Words hardly appear in the contexts of themselves, and so the model should assign a low probability to p(dog|dog), which entails assigning a low value to v · v which is impossible.

该脚注中提到一个假设,即作者认为,如果dog这个词作为中心词时,其对应的关联词为A,dog作为窗口词时,对应的关联词为B,此时A和B是不同的。事实上这个还算好理解,因为我们用dot product去表达的是一种条件概率,在条件概率里,p(A|dog)和p(dog|B)是完全不同的。举例来说,就是一个箱子里有红白蓝三种小球,数量分别是1,2,3,此时我们假设红色就是那个dog,白蓝球此时就是红球的关联词,所以p(白|红)和p(蓝|红)的概率是2/5和3/5,而p(红|白)和p(红|蓝)的概率是1/15和1/10,从这里就可以看到,如果我们用v·u去表达一个条件概率的话,那么自然会出现p(白|红)和p(红|白)的概率没有任何区别,这就和我们刚刚的例子有所出入,所以基于这个假设,使用了两个embedding,前者是中心词下的embedding,后者是context时下的embedding,他所表征的是两种不同的分布

除此之外,文章的脚注中还提到了一个motivation,在他给到的case中,我们可以知道p(dog|dog)应该是一个低概率的(我也想到了啊啊啊这种文本,但是这种词似乎可以看做一个语气词,也就是一个词),因为是低概率的,我们必须在v·v中表达的条件概率里给予一个很低的数值,但是,如果我们用一个embedding矩阵而不是两个,那么就会出现dog的vector每个维度的数值很低(因为我们是用的dot,自身乘自身,再用loss去优化,自然会让dog的vector数值变低),这种情况下,就严重影响到了dog和其他关联词用dot product描述的条件概率,因此,这也是使用了两个embedding矩阵的重要解释之一

现在我们回到大佬HediBY的解释,引用如下:

IMHO, the real reason why you use different representations is because you manipulate entities of different nature. “dog” as a context is not to be considered the same as “dog” as a center word because they are not. You basicly manipulate big matrices of occurences (word,context), trying to maximize the probability of these pairs that actually happen. Theoreticaly you could use as contexts bigrams, trying to maximize for instance the probability of (word=“for”, context=“to maximize”), and you would assign a vector representation to “to maximize”. We don’t do this because there would be too many representations to compute, and we would have a reeeeeally sparse matrix, but I think the idea is here : the fact that we use “1-grams” as context is just a particular case of all the kinds of context we could use.

可以看到,这位大佬的解释有两点,第一就是dog作为center word和作为context word是完全不同的,这点和刚刚的脚注说法一致,第二就是提出了为什么我们不用bigram而是用了unigram,原因在于会出现稀疏矩阵,而unigram也只是一种特殊情况,这完全是另一个话题了,已经在我想讨论的范围外,因此就不继续钻研了

最后,另外一位大佬dust也提出了这篇论文,他表示we can also use only one vector to represent a word.,这个是源自Stanford CS 224n,具体可不可以用,有没有什么改进,有兴趣的同学可以自行尝试
————————————————
版权声明:本文为CSDN博主「Sheep_0913」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42279926/article/details/106403211

标签:use,word,embedding,dog,vector,context,each,word2vec
来源: https://www.cnblogs.com/Arborday/p/14869252.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有