I used sup training, andfasttext.printVectors() to print the vectors of two sentences and then calculate the cosine similarity between the vectors, but got result some thing like: 3.250774993991685, its seems not correct, I think the result should be in range of [-1, 1], any ideas?
private static double cosineSimilarity(float[] vectorA, float[] vectorB) {
double dotProduct = 0.0d; // the numerator of the cosine similarity
double normA = 0.0d; // the first part of the denominator of the cosine similarity
double normB = 0.0d; // the second part of the denominator of the cosine similarity
int length = vectorA.length;
for (int i = 0; i < length; i++) {
dotProduct += vectorA[i] * vectorB[i];
normA += Math.pow(vectorA[i], 2);
normB += Math.pow(vectorB[i], 2);
}
return dotProduct / Math.sqrt(normA) * Math.sqrt(normB);
}
I used sup training, and
fasttext.printVectors()
to print the vectors of two sentences and then calculate the cosine similarity between the vectors, but got result some thing like:3.250774993991685
, its seems not correct, I think the result should be in range of [-1, 1], any ideas?