Gensim: subtle errors in gradient descent update step in word2vec.py

Created on 28 Jan 2015  路  3Comments  路  Source: RaRe-Technologies/gensim

I haven't looked in the Cython implementation, but in the Python implementation, it seems that the saved error term In train_sg_pair() line 188 and train_cbow_pair() line 217,

neu1e += dot(gb, l2b)

should be moved to the place _before_ the update for syn1neg (189-190, 215-216) is performed,

    if train_w1:
        model.syn1[word.point] += outer(ga, l1)  # learn hidden -> output

because l2b is a _reference_ to the corresponding values in syn1neg, which will be changed after executing the update of syn1neg.

However, the update of syn0 is supposed to be independent from that of syn1neg.

Of course, as the update for syn1neg itself is very small, this error does not adversely affect the final results much.

Most helpful comment

@Jianqiang Ping - is this resolved by the reply above?

All 3 comments

My understanding is that l2b is a copy rather than a reference/view: it's created via numpy "advanced indexing" using the word_indices list, and per http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html that indexing always results in a copy. (Are you sure it's otherwise?)

@Jianqiang Ping - is this resolved by the reply above?

@gojomo thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlad17 picture vlad17  路  4Comments

Laubeee picture Laubeee  路  3Comments

chengrufeng picture chengrufeng  路  4Comments

sairampillai picture sairampillai  路  3Comments

dancinghui picture dancinghui  路  4Comments