Example usage for org.deeplearning4j.models.embeddings.wordvectors WordVectors getWordVector

List of usage examples for org.deeplearning4j.models.embeddings.wordvectors WordVectors getWordVector

Introduction

In this page you can find the example usage for org.deeplearning4j.models.embeddings.wordvectors WordVectors getWordVector.

Prototype

double[] getWordVector(String word);

Source Link

Document

Get the word vector for a given matrix

Usage

From source file:edu.polyu.comp5412.word2vec.Word2VecTestEng.java

public static void main(String[] args) throws Exception {
    WordVectors vec = WordVectorSerializer.loadTxtVectors(new File("gov-annc-vec.txt"));
    String[] testwords = new String[] { "police", "mtr", "typhoon", "economy" };
    for (String s : testwords) {
        Collection<String> lst = vec.wordsNearest(s, 5);
        List<SimWord> simwords = new ArrayList();
        for (String w : lst) {
            SimWord sw = new SimWord();
            sw.word = w;//  w w  w .  j  a  v a2s. c o m
            sw.similarlity = vec.similarity(s, w);
            simwords.add(sw);
        }
        System.out.println(s);
        System.out.println("=====================");
        for (SimWord sw : simwords) {
            System.out.println(sw.word + "\t" + sw.similarlity);
        }
    }

    double[] wordVector = vec.getWordVector("typhoon");
    for (double d : wordVector) {
        System.out.print(d + ", ");
    }
    System.out.println();

    System.out.println(vec.wordsNearest(Arrays.asList("apple", "blue"), Arrays.asList("red"), 5));
    System.out.println(vec.wordsNearest(Arrays.asList("doctor", "school"), Arrays.asList("hospital"), 5));

}