deeplearning4j-scaleout/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/wordvectors/WordVectorsImpl.java
/**
     * Get the top n words most similar to the given word
     * @param word the word to compare
     * @param n the n to get
     * @return the top n words
     */
Get the top n words most similar to the given word
@param word the word to compare
@param n the n to get
@return the top n words
Get the top n words most similar to the given word @param word the word to compare @param n the n to get @return the top n words
public Collection<String> wordsNearest(String word,int n) {
        /*
            TODO: This is temporary solution and we should get rid of flat array scan. Probably, after VPTree implementation gets fixed
         */
        if (!vocab.hasToken(word)) return new ArrayList<>();
        INDArray mean = getWordVectorMatrix(word);
        Counter<String> distances = new Counter<>();
        for (String s : vocab().words()) {
            if (s.equals(word)) continue;
            INDArray otherVec = getWordVectorMatrix(s);
            double sim = Transforms.cosineSim(mean, otherVec);
            distances.incrementCount(s, sim);
        }
        distances.keepTopNKeys(n-1);
        return distances.keySet();
    }
public Collection < String > wordsNearest ( String word , int n ) { /*
            TODO: This is temporary solution and we should get rid of flat array scan. Probably, after VPTree implementation gets fixed
         */ if ( ! vocab . hasToken ( word ) ) return new ArrayList < > ( ) ; INDArray mean = getWordVectorMatrix ( word ) ; Counter < String > distances = new Counter < > ( ) ; for ( String s : vocab ( ) . words ( ) ) { if ( s . equals ( word ) ) continue ; INDArray otherVec = getWordVectorMatrix ( s ) ; double sim = Transforms . cosineSim ( mean , otherVec ) ; distances . incrementCount ( s , sim ) ; } distances . keepTopNKeys ( n - 1 ) ; return distances . keySet ( ) ; }
Get the top n words most similar to the given word
 @param word the word to compare
 @param n the n to get
 @return the top n words
Get the top n words most similar to the given word @param word the word to compare @param n the n to get @return the top n words
//        return wordsNearest(Arrays.asList(word),new ArrayList<String>(),n);