diff --git a/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelBinSrch.java b/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelBinSrch.java index 5a0d243..32aec58 100644 --- a/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelBinSrch.java +++ b/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelBinSrch.java @@ -193,7 +193,9 @@ private String getClosestEntry(float[] vector, String subKey) { } tl.printTime(1, "Setting Bits"); tl.logTime(1); - int[] nearbyIndexes = new int[finBitSet.cardinality()]; + int nearbyWordsCount = finBitSet.cardinality(); + LOG.info("Number of nearby words: "+nearbyWordsCount); + int[] nearbyIndexes = new int[nearbyWordsCount]; int j = 0; for (int i = finBitSet.nextSetBit(0); i >= 0; i = finBitSet.nextSetBit(i + 1), j++) { // operate on index i here diff --git a/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelKMeans.java b/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelKMeans.java index 08e2a5b..e0c025d 100644 --- a/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelKMeans.java +++ b/src/main/java/org/aksw/word2vecrestful/word2vec/W2VNrmlMemModelKMeans.java @@ -198,7 +198,9 @@ private String getClosestEntry(float[] vector, String subKey) { } tl.printTime(1, "Setting Bits"); tl.logTime(1); - int[] nearbyIndexes = new int[finBitSet.cardinality()]; + int nearbyWordsCount = finBitSet.cardinality(); + LOG.info("Number of nearby words: "+nearbyWordsCount); + int[] nearbyIndexes = new int[nearbyWordsCount]; int j = 0; for (int i = finBitSet.nextSetBit(0); i >= 0; i = finBitSet.nextSetBit(i + 1), j++) { // operate on index i here diff --git a/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java b/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java index 318022a..a661d7a 100644 --- a/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java +++ b/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java @@ -5,6 +5,7 @@ import java.util.List; import org.aksw.word2vecrestful.utils.Cfg; +import org.aksw.word2vecrestful.utils.Word2VecMath; import org.aksw.word2vecrestful.word2vec.W2VNrmlMemModelKMeans; import org.aksw.word2vecrestful.word2vec.Word2VecFactory; import org.aksw.word2vecrestful.word2vec.Word2VecModel; @@ -81,12 +82,18 @@ public void testNbmTime() throws IOException { totTime += diff; LOG.info("Query time recorded for Centroid " + (i + 1) + " is " + diff + " milliseconds."); } - LOG.info( - "Average query time for W2VNrmlMemModelKMeans is : " + (totTime / centroids.length) + " milliseconds"); + LOG.info("Average query time for W2VNrmlMemModelKMeans is : " + (totTime / centroids.length) + " milliseconds"); LOG.info("Predicted Words are :" + lrModelWords); float percVal = NrmlzdMdlPrfmncTester.calcPercScore(correctWords, lrModelWords); LOG.info("Score for Test is : " + percVal + "%"); lrModelWords.clear(); + + String word1 = "By_Jonas_Elmerraji"; + String word2 = "%_#F########_3v.jsn"; + float[] word1Vec = nbm.word2vec.get("By_Jonas_Elmerraji"); + float[] word2Vec = nbm.word2vec.get("%_#F########_3v.jsn"); + LOG.info("Cosine Similarity between " + word1 + " & " + word2 + " is : " + + Word2VecMath.cosineSimilarity(word1Vec, word2Vec)); } private static float[][] fetchWordsVec(String[] words, Word2VecModel nbm) {