Include metadata words into negative sampling training
TODO: add test
Change-Id: I834e27a74d95e85f1d3fc0cb10330fc1a23ca05d
diff --git a/src/dereko2vec.c b/src/dereko2vec.c
index 33b8d03..0e2e230 100644
--- a/src/dereko2vec.c
+++ b/src/dereko2vec.c
@@ -1510,6 +1510,43 @@
capParam(syn1neg_window,
c + l2 + window_offset);
}
+ if (d == 0) {
+ for (int m=0; m < metadata_index; m++) {
+ f = 0;
+ int meta_word = metadata[m];
+ if (meta_word == -1)
+ continue;
+ int meta_l1 = meta_word * layer1_size;
+ for (c = 0; c < layer1_size; c++)
+ f +=
+ syn0[c + meta_l1]
+ * syn1neg_window[c + l2
+ + window_offset];
+ if (f > MAX_EXP)
+ g = (label - 1) * alpha;
+ else if (f < -MAX_EXP)
+ g = (label - 0) * alpha;
+ else
+ g =
+ (label
+ - expTable[(int) ((f + MAX_EXP)
+ * (EXP_TABLE_SIZE
+ / MAX_EXP / 2))])
+ * alpha;
+ for (c = 0; c < layer1_size; c++)
+ neu1e[c] +=
+ g
+ * syn1neg_window[c + l2
+ + window_offset];
+ for (c = 0; c < layer1_size; c++)
+ syn1neg_window[c + l2 + window_offset] += g
+ * syn0[c + l1];
+ if (cap == 1)
+ for (c = 0; c < layer1_size; c++)
+ capParam(syn1neg_window,
+ c + l2 + window_offset);
+ }
+ }
// Noise Constrastive Estimation
if (nce > 0)
for (d = 0; d < nce + 1; d++) {