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

该篇博客仅仅是对word2vec使用两个embedding矩阵的原因进行资料的探索和整理,自己暂时不会给出任何确切的思考和解释,待日后有机会整理清楚后会填上这个坑

引言:word2vec在我们使用TensorFlow还是pytorch进行复现的时候,都会遇到一个问题,就是为什么会存在两个embedding去计算条件概率,为什么我们选择将两个embedding矩阵进行mean的方式作为final embedding,针对这个问题的思考,我将目前所能查阅到的资料记录如下


问题一:为什么训练过程中使用两种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,具体可不可以用,有没有什么改进,有兴趣的同学可以自行尝试


问题二:为什么我们使用mean的方式作为final embedding?

这个以后写!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值