code: private float cosineSimilarity(float[] target, int pos, float[] vecs) {
      float dotProd = 0, tsqr = 0, csqr = 0;
      for(int i = 0; i < target.length; i++) {
        dotProd += target[i] * vecs[pos + i];
        tsqr += Math.pow(target[i], 2);
        csqr += Math.pow(vecs[pos + i], 2);
      }
      return (float) (dotProd / (Math.sqrt(tsqr) * Math.sqrt(csqr)));
    }
docs: Basic calculation of cosine similarity
  @param target - a word vector
  @param pos - position in vecs
  @param vecs - learned word vectors
  @return cosine similarity between the two word vectors