java deeplearning4j为CNN培训创建数据仓库
我正在为CNN制作一个频道,这个频道将一个句子分成x个部分。然后,这些部分中的每一部分都会获得情绪分数,这些部分会被输入CNN。然而,我不明白我怎样才能把这些分数变成CNN的一个数组
我当前的代码:
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;
}
我刚刚尝试了不同的特征形状和索引,但我真的不知道我在做什么,所以任何帮助都将不胜感激
我的代码基于Deeplearning4jsCnnSentenceDataSetIterator,它将句子转换为单词嵌入
共 (0) 个答案