List of usage examples for org.deeplearning4j.models.embeddings.inmemory InMemoryLookupTable vector
@Override
public INDArray vector(String word)
From source file:de.mpii.docsimilarity.mr.utils.io.WordVectorSerializer.java
License:Apache License
/** * Writes the word vectors to the given path. Note that this assumes an in memory cache * * @param lookupTable/*from w ww . jav a2 s . com*/ * @param cache * * @param path * the path to write * @throws IOException */ public static void writeWordVectors(InMemoryLookupTable lookupTable, InMemoryLookupCache cache, String path) throws IOException { BufferedWriter write = new BufferedWriter(new FileWriter(new File(path), false)); for (int i = 0; i < lookupTable.getSyn0().rows(); i++) { String word = cache.wordAtIndex(i); if (word == null) { continue; } StringBuilder sb = new StringBuilder(); sb.append(word.replaceAll(" ", "_")); sb.append(" "); INDArray wordVector = lookupTable.vector(word); for (int j = 0; j < wordVector.length(); j++) { sb.append(wordVector.getDouble(j)); if (j < wordVector.length() - 1) { sb.append(" "); } } sb.append("\n"); write.write(sb.toString()); } write.flush(); write.close(); }