public Collection<String> predictSeveral(List<VocabWord> document, int limit) {
        /*
            This code was transferred from original ParagraphVectors DL4j implementation, and yet to be tested
         */
        if (document.isEmpty())
            throw new IllegalStateException("Document has no words inside");
/*
        INDArray arr = Nd4j.create(document.size(), this.layerSize);
        for (int i = 0; i < document.size(); i++) {
            arr.putRow(i, getWordVectorMatrix(document.get(i).getWord()));
        }
*/
        INDArray docMean = inferVector(document); //arr.mean(0);
        Counter<String> distances = new Counter<>();

        for (String s : labelsSource.getLabels()) {
            INDArray otherVec = getWordVectorMatrix(s);
            double sim = Transforms.cosineSim(docMean, otherVec);
            log.debug("Similarity inside: [" + s + "] -> " + sim);
            distances.incrementCount(s, (float) sim);
        }

        val keys = distances.keySetSorted();
        return keys.subList(0, Math.min(limit, keys.size()));
    }
public Collection < String > predictSeveral ( List < VocabWord > document , int limit ) { if ( document . isEmpty ( ) ) throw new IllegalStateException ( "Document has no words inside" ) ; INDArray docMean = inferVector ( document ) ; Counter < String > distances = new Counter < > ( ) ; for ( String s : labelsSource . getLabels ( ) ) { INDArray otherVec = getWordVectorMatrix ( s ) ; double sim = Transforms . cosineSim ( docMean , otherVec ) ; log . debug ( "Similarity inside: [" + s + "] -> " + sim ) ; distances . incrementCount ( s , ( float ) sim ) ; } val keys = distances . keySetSorted ( ) ; return keys . subList ( 0 , Math . min ( limit , keys . size ( ) ) ) ; }
Predict several labels based on the document.
Computes a similarity wrt the mean of the
representation of words in the document
@param document the document
@return possible labels in descending order