Skip to content

Commit

Permalink
skip gram added
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanAbouelenin committed Mar 2, 2020
1 parent dd427f6 commit 4d2f992
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion assignment 2/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def negSamplingLossAndGradient(
return loss, gradCenterVec, gradOutsideVecs



def skipgram(currentCenterWord, windowSize, outsideWords, word2Ind,
centerWordVectors, outsideVectors, dataset,
word2vecLossAndGradient=naiveSoftmaxLossAndGradient):
Expand Down Expand Up @@ -200,6 +199,24 @@ def skipgram(currentCenterWord, windowSize, outsideWords, word2Ind,

### YOUR CODE HERE

center_word_index=word2Ind[currentCenterWord]
center_word_vec=centerWordVectors[center_word_index]

for outside_word in outsideWords:

outside_word_index= word2Ind[outside_word]
loss_from_1_word, grad_center_word, grad_outside= word2vecLossAndGradient(centerWordVec=center_word_vec,
outsideWordIdx=outside_word_index,outsideVectors=outsideVectors,dataset=dataset)
loss += loss_from_1_word


gradCenterVecs[center_word_index] += grad_center_word

gradOutsideVectors += grad_outside




### END YOUR CODE

return loss, gradCenterVecs, gradOutsideVectors
Expand Down

0 comments on commit 4d2f992

Please sign in to comment.