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

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

Introduction

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

Prototype

public static void writeParagraphVectors(ParagraphVectors vectors, OutputStream stream) throws IOException 

Source Link

Document

This method saves ParagraphVectors model into compressed zip file and sends it to output stream

Usage

From source file:dollar.learner.smart.ParagraphVectorsClassifierExample.java

License:Apache License

public void stop() {
    log.info("Saving to " + serializeFile().getAbsolutePath());
    WordVectorSerializer.writeParagraphVectors(paragraphVectors, serializeFile());
}

From source file:org.knime.ext.textprocessing.dl4j.util.WordVectorPortObjectUtils.java

License:Open Source License

/**
 * Writes {@link WordVectors} to specified {@link ZipInputStream}. Calling this method will close the stream (closed
 * by WordVectorSerializer)./*from ww  w. j a  v  a  2  s .c  om*/
 *
 * @param wordVectors {@link WordVectors} to write
 * @param out stream to write to
 * @throws IOException
 */
public static void writeWordVectors(final WordVectors wordVectors, final ZipOutputStream out)
        throws IOException {
    final ZipEntry entry = new ZipEntry("word_vectors");
    out.putNextEntry(entry);
    //first check if ParagraphVectors because it extends Word2Vec
    if (wordVectors instanceof ParagraphVectors) {
        ParagraphVectors d2v = (ParagraphVectors) wordVectors;
        WordVectorSerializer.writeParagraphVectors(d2v, out);
    } else if (wordVectors instanceof Word2Vec) {
        Word2Vec w2v = (Word2Vec) wordVectors;
        WordVectorSerializer.writeWord2VecModel(w2v, out);
    } else {
        throw new IllegalStateException("No serialization method defined for WordVectors of type: "
                + wordVectors.getClass().getSimpleName());
    }
}