deeplearning4j-scaleout/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/loader/WordVectorSerializer.java
/**
     * Writes the word vectors to the given BufferedWriter. Note that this assumes an in memory cache.
     * BufferedWriter can be writer to local file, or hdfs file, or any compatible to java target.
     *
     * @param vec
     *            the word2vec to write
     * @param writer - BufferedWriter, where all data should be written to
     *            the path to write
     * @throws IOException
     */
Writes the word vectors to the given BufferedWriter. Note that this assumes an in memory cache.
BufferedWriter can be writer to local file, or hdfs file, or any compatible to java target.

@param vec
the word2vec to write
@param writer - BufferedWriter, where all data should be written to
the path to write
@throws IOException
Writes the word vectors to the given BufferedWriter . Note that this assumes an in memory cache . BufferedWriter can be writer to local file or hdfs file or any compatible to java target . @param vec the word2vec to write @param writer - BufferedWriter where all data should be written to the path to write @throws IOException
public static void writeWordVectors(@NonNull Word2Vec vec, @NonNull BufferedWriter writer) throws IOException  {
        int words = 0;
        for (String word : vec.vocab().words()) {
            if (word == null) {
                continue;
            }
            StringBuilder sb = new StringBuilder();
            sb.append(word.replaceAll(" ", "_"));
            sb.append(" ");
            INDArray wordVector = vec.getWordVectorMatrix(word);
            for (int j = 0; j < wordVector.length(); j++) {
                sb.append(wordVector.getDouble(j));
                if (j < wordVector.length() - 1) {
                    sb.append(" ");
                }
            }
            sb.append("\n");
            writer.write(sb.toString());
            words++;
        }
        log.info("Wrote " + words + " with size of " + vec.lookupTable().layerSize());
    }
public static void writeWordVectors ( @ NonNull Word2Vec vec , @ NonNull BufferedWriter writer ) throws IOException { int words = 0 ; for ( String word : vec . vocab ( ) . words ( ) ) { if ( word == null ) { continue ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( word . replaceAll ( " " , "_" ) ) ; sb . append ( " " ) ; INDArray wordVector = vec . getWordVectorMatrix ( word ) ; for ( int j = 0 ; j < wordVector . length ( ) ; j ++ ) { sb . append ( wordVector . getDouble ( j ) ) ; if ( j < wordVector . length ( ) - 1 ) { sb . append ( " " ) ; } } sb . append ( "\n" ) ; writer . write ( sb . toString ( ) ) ; words ++ ; } log . info ( "Wrote " + words + " with size of " + vec . lookupTable ( ) . layerSize ( ) ) ; }
Writes the word vectors to the given BufferedWriter.
Writes the word vectors to the given BufferedWriter .