deeplearning4j-scaleout/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/loader/WordVectorSerializer.java
/**
     * Write the tsne format
     *
     * @param vec
     *            the word vectors to use for labeling
     * @param tsne
     *            the tsne array to write
     * @param csv
     *            the file to use
     * @throws Exception
     */
Write the tsne format
@param vec
the word vectors to use for labeling
@param tsne
the tsne array to write
@param csv
the file to use
@throws Exception
Write the tsne format @param vec the word vectors to use for labeling @param tsne the tsne array to write @param csv the file to use @throws Exception
public static void writeTsneFormat(Word2Vec vec, INDArray tsne, File csv)
            throws Exception
    {
        BufferedWriter write = new BufferedWriter(new FileWriter(csv));
        int words = 0;
        InMemoryLookupCache l = (InMemoryLookupCache) vec.vocab();
        for (String word : vec.vocab().words()) {
            if (word == null) {
                continue;
            }
            StringBuilder sb = new StringBuilder();
            INDArray wordVector = tsne.getRow(l.wordFor(word).getIndex());
            for (int j = 0; j < wordVector.length(); j++) {
                sb.append(wordVector.getDouble(j));
                if (j < wordVector.length() - 1) {
                    sb.append(",");
                }
            }
            sb.append(",");
            sb.append(word);
            sb.append(" ");
            sb.append("\n");
            write.write(sb.toString());
        }
        log.info("Wrote " + words + " with size of " + vec.lookupTable().layerSize());
        write.flush();
        write.close();
    }
public static void writeTsneFormat ( Word2Vec vec , INDArray tsne , File csv ) throws Exception { BufferedWriter write = new BufferedWriter ( new FileWriter ( csv ) ) ; int words = 0 ; InMemoryLookupCache l = ( InMemoryLookupCache ) vec . vocab ( ) ; for ( String word : vec . vocab ( ) . words ( ) ) { if ( word == null ) { continue ; } StringBuilder sb = new StringBuilder ( ) ; INDArray wordVector = tsne . getRow ( l . wordFor ( word ) . getIndex ( ) ) ; for ( int j = 0 ; j < wordVector . length ( ) ; j ++ ) { sb . append ( wordVector . getDouble ( j ) ) ; if ( j < wordVector . length ( ) - 1 ) { sb . append ( "," ) ; } } sb . append ( "," ) ; sb . append ( word ) ; sb . append ( " " ) ; sb . append ( "\n" ) ; write . write ( sb . toString ( ) ) ; } log . info ( "Wrote " + words + " with size of " + vec . lookupTable ( ) . layerSize ( ) ) ; write . flush ( ) ; write . close ( ) ; }
Write the tsne format
 @param vec
            the word vectors to use for labeling
 @param tsne
            the tsne array to write
 @param csv
            the file to use
 @throws Exception
Write the tsne format @param vec the word vectors to use for labeling @param tsne the tsne array to write @param csv the file to use @throws Exception