From f8d9dce592aae377974b4836ea0453876c22208d Mon Sep 17 00:00:00 2001 From: Shawn Jonghyuck Jung <41564982+shawn-jung@users.noreply.github.com> Date: Fri, 27 Nov 2020 11:23:47 -0800 Subject: [PATCH] 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 --- Ch4/03_Word2Vec_Example.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ch4/03_Word2Vec_Example.ipynb b/Ch4/03_Word2Vec_Example.ipynb index 8c026cd..03a5016 100644 --- a/Ch4/03_Word2Vec_Example.ipynb +++ b/Ch4/03_Word2Vec_Example.ipynb @@ -210,7 +210,7 @@ " feats = []\n", " for tokens in list_of_lists:\n", " feat_for_this = np.zeros(DIMENSION)\n", - " count_for_this = 0\n", + " count_for_this = 0 + 1e-5 # to avoid divide-by-zero \n", " for token in tokens:\n", " if token in w2v_model:\n", " feat_for_this += w2v_model[token]\n",