Skip to content

Commit

Permalink
Fixed bug in loss computation for Word2Vec with hierarchical softmax (#…
Browse files Browse the repository at this point in the history
…3397)

* fixed loss computation for sg, hs

* fixed loss computation for cbow, hs
  • Loading branch information
TalIfargan committed Nov 3, 2022
1 parent fdf40eb commit c93eb0b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gensim/models/word2vec_inner.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cdef void w2v_fast_sentence_sg_hs(

if _compute_loss == 1:
sgn = (-1)**word_code[b] # ch function: 0-> 1, 1 -> -1
lprob = -1*sgn*f_dot
lprob = sgn*f_dot
if lprob <= -MAX_EXP or lprob >= MAX_EXP:
continue
lprob = LOG_TABLE[<int>((lprob + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]
Expand Down Expand Up @@ -326,7 +326,7 @@ cdef void w2v_fast_sentence_cbow_hs(

if _compute_loss == 1:
sgn = (-1)**word_code[b] # ch function: 0-> 1, 1 -> -1
lprob = -1*sgn*f_dot
lprob = sgn*f_dot
if lprob <= -MAX_EXP or lprob >= MAX_EXP:
continue
lprob = LOG_TABLE[<int>((lprob + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]
Expand Down

1 comment on commit c93eb0b

@Vincent-Azoon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

Please sign in to comment.