Fix of sentence_position running over sentence_length in structured skipgram
diff --git a/word2vecExt.c b/word2vecExt.c
index 7de104a..df9dbe6 100644
--- a/word2vecExt.c
+++ b/word2vecExt.c
@@ -790,9 +790,13 @@
continue;
}
word = sen[sentence_position];
- while (word == -2)
- word = sen[++sentence_position];
- if (word == -1)
+ while (word == -2 && sentence_position<sentence_length)
+ word = sen[++sentence_position];
+ if (sentence_position>=sentence_length) {
+ sentence_length=0;
+ continue;
+ }
+ if (word < 0)
continue;
for (c = 0; c < input_len_1; c++)
neu1[c] = 0;
@@ -1311,12 +1315,10 @@
c = sentence_position - window + a;
if (c < 0)
continue;
- if(sen[c] == -2)
- continue;
if (c >= sentence_length)
continue;
last_word = sen[c];
- if (last_word == -1)
+ if (last_word < 0)
continue;
l1 = last_word * layer1_size;
window_offset = a * layer1_size;