deeplearning4j-scaleout/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/loader/WordVectorSerializer.java
/**
     * Writes the word vectors to the given path. Note that this assumes an in memory cache
     *
     * @param lookupTable
     * @param cache
     *
     * @param path
     *            the path to write
     * @throws IOException
     */
Writes the word vectors to the given path. Note that this assumes an in memory cache
@param lookupTable
@param cache

@param path
the path to write
@throws IOException
Writes the word vectors to the given path . Note that this assumes an in memory cache @param lookupTable @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();
    }
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 ( ) ; }
Writes the word vectors to the given path.
Writes the word vectors to the given path .