Skip to content

Commit f8d9dce

Browse files
authored
Adding small numbers to feature counter
to avoid divide-by-zero, we can add 1e-5 to 'count_for_this' variable. (or add such condition at the end of the nested for-loop) if count_for_this == 0: count_for_this += 1e-5
1 parent c9b86f9 commit f8d9dce

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Ch4/03_Word2Vec_Example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
" feats = []\n",
211211
" for tokens in list_of_lists:\n",
212212
" feat_for_this = np.zeros(DIMENSION)\n",
213-
" count_for_this = 0\n",
213+
" count_for_this = 0 + 1e-5 # to avoid divide-by-zero \n",
214214
" for token in tokens:\n",
215215
" if token in w2v_model:\n",
216216
" feat_for_this += w2v_model[token]\n",

0 commit comments

Comments
 (0)