mfaruqui / retrofitting

Retrofitting Word Vectors to Semantic Lexicons

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hi @mfaruqui ,

rajivgrover009 opened this issue · comments

Hi @mfaruqui ,

I came across your paper recently. Thanks for your work.

I am trying to wrap my head around the python code. I have question on line# 74 in retrofit.py file. Why do we need to divide the newVec by 2*numNeighbors?

newWordVecs[word] = newVec/(2*numNeighbours)

Can you or anybody help me understand this? Much appreciated.

Thanks!

Originally posted by @rajivgrover009 in #1 (comment)

commented

Hey @rajivgrover009,
As I understand the relevant snippet (posted below), he intends for the distributional component (i.e. the existing, non-retrofitted vector) to have a 50/50 weight with the overall contribution of the lexicon neighbours, on the final retrofitted result.

Thus, the vector to-be-modified is initialized by scaling the existing values with a numNeighbours factor (line 70), moving on to add each of the vectors of the semantically neighbouring words (line 73).
The process is finished by averaging all the component values (line 74), which are 2 * numNeighbours in total: half (numNeighbours) for the duplicated initial values, and another numNeighbours for each neighbouring vector.

      # the weight of the data estimate if the number of neighbours
      newVec = numNeighbours * wordVecs[word] # line 70
      # loop over neighbours and add to new vector (currently with weight 1)
      for ppWord in wordNeighbours:
        newVec += newWordVecs[ppWord]  # line 73
      newWordVecs[word] = newVec/(2*numNeighbours)  # line 74

Hope this helps!

Thanks @npit !