我正在尝试为CNN实现一个频道,这个频道是将一个句子分成x个部分。然后,这些部分中的每一部分都获得情绪分数,并且部分被馈送到CNN。但是我不明白如何将这些部分分数变成CNN的INDArray。
我目前的代码:
public INDarray getFeatureVectors(List<String> sentences) {
// nParts is the number of parts to split the sentence into
// sentences are a list of sentences in the current batch
// int[] featureShape = new int[]{sentences.size(), nParts};
int[] featureShape = new int[4];
featureShape[0] = sentences.size();
featureShape[1] = 1;
featureShape[2] = nParts;
featureShape[3] = nParts;
INDArray features = Nd4j.create(sentences.size());
for (int i = 0; i < sentences.size(); i++) {
List<String> tokens = // tokenize sentence
double[] partScores = // calculate the score for each part
// e.g. for nParts = 2, partScores = {-1.0, 1.0}
INDArray vector = Nd4j.create(partScores, featureShape);
INDArrayIndex[] indices = new INDArrayIndex[4];
indices[0] = NDArrayIndex.point(i);
indices[1] = NDArrayIndex.point(0);
indices[2] = NDArrayIndex.all();
indices[3] = NDArrayIndex.all();
features.put(indices, vector);
}
return features;
}
我刚刚尝试过不同的功能形状和指数,但我真的不知道自己在做什么,所以任何帮助都会非常感激!
我将代码基于Deeplearning4js CnnSentenceDataSetIterator,它将句子转换为单词嵌入。