public INDArray loadSingleSentence ( String sentence ) { List < String > tokens = tokenizeSentence ( sentence ) ; if ( format == Format . CNN1D || format == Format . RNN ) { int [ ] featuresShape = new int [ ] { 1 , wordVectorSize , Math . min ( maxSentenceLength , tokens . size ( ) ) } ; INDArray features = Nd4j . create ( featuresShape , ( format == Format . CNN1D ? ' ' : ' ' ) ) ; INDArrayIndex [ ] indices = new INDArrayIndex [ 3 ] ; indices [ 0 ] = NDArrayIndex . point ( 0 ) ; for ( int i = 0 ; i < featuresShape [ 2 ] ; i ++ ) { INDArray vector = getVector ( tokens . get ( i ) ) ; indices [ 1 ] = NDArrayIndex . all ( ) ; indices [ 2 ] = NDArrayIndex . point ( i ) ; features . put ( indices , vector ) ; } return features ; } else { int [ ] featuresShape = new int [ ] { 1 , 1 , 0 , 0 } ; if ( sentencesAlongHeight ) { featuresShape [ 2 ] = Math . min ( maxSentenceLength , tokens . size ( ) ) ; featuresShape [ 3 ] = wordVectorSize ; } else { featuresShape [ 2 ] = wordVectorSize ; featuresShape [ 3 ] = Math . min ( maxSentenceLength , tokens . size ( ) ) ; } INDArray features = Nd4j . create ( featuresShape ) ; int length = ( sentencesAlongHeight ? featuresShape [ 2 ] : featuresShape [ 3 ] ) ; INDArrayIndex [ ] indices = new INDArrayIndex [ 4 ] ; indices [ 0 ] = NDArrayIndex . point ( 0 ) ; indices [ 1 ] = NDArrayIndex . point ( 0 ) ; for ( int i = 0 ; i < length ; i ++ ) { INDArray vector = getVector ( tokens . get ( i ) ) ; if ( sentencesAlongHeight ) { indices [ 2 ] = NDArrayIndex . point ( i ) ; indices [ 3 ] = NDArrayIndex . all ( ) ; } else { indices [ 2 ] = NDArrayIndex . all ( ) ; indices [ 3 ] = NDArrayIndex . point ( i ) ; } features . put ( indices , vector ) ; } return features ; } }
Generally used post training time to load a single sentence for predictions