Example usage for org.deeplearning4j.models.embeddings.loader WordVectorSerializer loadTxtVectors

List of usage examples for org.deeplearning4j.models.embeddings.loader WordVectorSerializer loadTxtVectors

Introduction

In this page you can find the example usage for org.deeplearning4j.models.embeddings.loader WordVectorSerializer loadTxtVectors.

Prototype

@Deprecated
public static WordVectors loadTxtVectors(File vectorsFile) throws IOException 

Source Link

Document

Loads an in memory cache from the given path (sets syn0 and the vocab)

Deprecation note: Please, consider using readWord2VecModel() or loadStaticModel() method instead

Usage

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

public static void main(String[] args) throws Exception {
    WordVectors vec = WordVectorSerializer.loadTxtVectors(new File("poem-vec.txt"));

    Collection<String> words = vec.wordsNearest(Arrays.asList("", ""), Arrays.asList(""), 5);
    System.out.println(words);/*from   w  ww  .  j a  v  a2 s  .  co  m*/

    words = vec.wordsNearest(Arrays.asList("", ""), Arrays.asList(""), 5);
    System.out.println(words);

    String[] testwords = new String[] { "", "", "", "", "" };
    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;
            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);
        }
    }
}

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;//from www.  j  av a  2  s  .  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));

}

From source file:indexer.DocVecSequenceFileGenerator.java

public DocVecSequenceFileGenerator(String propFile) throws Exception {
    prop = new Properties();
    prop.load(new FileReader(propFile));
    File indexDir = new File(prop.getProperty("index"));
    reader = DirectoryReader.open(FSDirectory.open(indexDir.toPath()));

    String docVecFile = prop.getProperty("dvec.out.file");
    wvecs = WordVectorSerializer.loadTxtVectors(new File(docVecFile));

    prepareOutputFolders();/*from w  ww. j a v a2  s .  c  o m*/
}