Example usage for org.deeplearning4j.models.word2vec VocabWord getWord

List of usage examples for org.deeplearning4j.models.word2vec VocabWord getWord

Introduction

In this page you can find the example usage for org.deeplearning4j.models.word2vec VocabWord getWord.

Prototype

public String getWord() 

Source Link

Usage

From source file:org.knime.ext.textprocessing.dl4j.nodes.embeddings.extract.VocabularyExtractorNodeModel2.java

License:Open Source License

@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final WordVectorFileStorePortObject portObject = (WordVectorFileStorePortObject) inObjects[0];
    WordVectors wordVec = portObject.getWordVectors();
    WordVectorsImpl<VocabWord> wvImpl = null;

    if (wordVec instanceof WordVectorsImpl) {
        wvImpl = (WordVectorsImpl) wordVec;
    } else {//from w w  w . ja v a 2s  .co  m
        throw new IllegalStateException(
                "Word Vector model expected to be at least of type: " + WordVectorsImpl.class);
    }

    final List<String> vocabulary = new ArrayList<>();
    final List<String> labels = new ArrayList<>();

    for (VocabWord vw : wvImpl.getVocab().tokens()) {
        if (vw.isLabel()) {
            labels.add(vw.getWord());
        } else {
            vocabulary.add(vw.getWord());
        }
    }

    m_maxProgress = vocabulary.size() + labels.size();

    PortObject[] outputTables = new PortObject[2];
    outputTables[0] = createWordVectorTableFromWordList((DataTableSpec) m_outputSpec[0], vocabulary, wordVec,
            exec);

    if (labels.isEmpty()) {
        outputTables[1] = InactiveBranchPortObject.INSTANCE;
    } else {
        outputTables[1] = createWordVectorTableFromWordList((DataTableSpec) m_outputSpec[1], labels, wordVec,
                exec);
    }

    return outputTables;
}