public INDArray sequencesToMatrix(Integer[][] sequences, TokenizerMode mode) {
        if (numWords == null) {
            if (!wordIndex.isEmpty()) {
                numWords = wordIndex.size();
            } else {
                throw new IllegalArgumentException("Either specify numWords argument" +
                        "or fit Tokenizer on data first, i.e. by using fitOnTexts");
            }
        }
        if (mode.equals(TokenizerMode.TFIDF) && documentCount == null) {
            throw new IllegalArgumentException("To use TFIDF mode you need to" +
                    "fit the Tokenizer instance with fitOnTexts first.");
        }
        INDArray x = Nd4j.zeros(sequences.length, numWords);
        for (int i=0; i< sequences.length; i++) {
            Integer[] sequence = sequences[i];
            if (sequence == null)
                continue;
            HashMap<Integer, Integer> counts = new HashMap<>();
            for (int j: sequence) {
                if (j >= numWords)
                    continue;
                if (counts.containsKey(j))
                    counts.put(j, counts.get(j) + 1);
                else
                    counts.put(j, 1);
            }
            for (int j: counts.keySet()) {
                int count = counts.get(j);
                switch (mode) {
                    case COUNT:
                        x.put(i, j, count);
                        break;
                    case FREQ:
                        x.put(i, j, count / sequence.length);
                        break;
                    case BINARY:
                        x.put(i, j, 1);
                        break;
                    case TFIDF:
                        double tf = 1.0 + Math.log(count);
                        int index = indexDocs.containsKey(j) ? indexDocs.get(j) : 0;
                        double idf = Math.log(1 + documentCount / (1.0 + index));
                        x.put(i, j, tf * idf);
                        break;
                }
            }
        }
        return x;
    }
public INDArray sequencesToMatrix ( Integer [ ] [ ] sequences , TokenizerMode mode ) { if ( numWords == null ) { if ( ! wordIndex . isEmpty ( ) ) { numWords = wordIndex . size ( ) ; } else { throw new IllegalArgumentException ( "Either specify numWords argument" + "or fit Tokenizer on data first, i.e. by using fitOnTexts" ) ; } } if ( mode . equals ( TokenizerMode . TFIDF ) && documentCount == null ) { throw new IllegalArgumentException ( "To use TFIDF mode you need to" + "fit the Tokenizer instance with fitOnTexts first." ) ; } INDArray x = Nd4j . zeros ( sequences . length , numWords ) ; for ( int i = 0 ; i < sequences . length ; i ++ ) { Integer [ ] sequence = sequences [ i ] ; if ( sequence == null ) continue ; HashMap < Integer , Integer > counts = new HashMap < > ( ) ; for ( int j : sequence ) { if ( j >= numWords ) continue ; if ( counts . containsKey ( j ) ) counts . put ( j , counts . get ( j ) + 1 ) ; else counts . put ( j , 1 ) ; } for ( int j : counts . keySet ( ) ) { int count = counts . get ( j ) ; switch ( mode ) { case COUNT : x . put ( i , j , count ) ; break ; case FREQ : x . put ( i , j , count / sequence . length ) ; break ; case BINARY : x . put ( i , j , 1 ) ; break ; case TFIDF : double tf = 1.0 + Math . log ( count ) ; int index = indexDocs . containsKey ( j ) ? indexDocs . get ( j ) : 0 ; double idf = Math . log ( 1 + documentCount / ( 1.0 + index ) ) ; x . put ( i , j , tf * idf ) ; break ; } } } return x ; }
Turns an array of index sequences into an ND4J matrix of shape
(number of texts, number of words in vocabulary)

@param sequences input sequences
@param mode TokenizerMode that controls how to vectorize data
@return resulting matrix representatio