Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 深入学习4J为CNN培训创建数据仓库_Java_Multidimensional Array_Deeplearning4j_Nd4j - Fatal编程技术网

Java 深入学习4J为CNN培训创建数据仓库

Java 深入学习4J为CNN培训创建数据仓库,java,multidimensional-array,deeplearning4j,nd4j,Java,Multidimensional Array,Deeplearning4j,Nd4j,我正在为CNN制作一个频道,这个频道将一个句子分成x个部分。然后,这些部分中的每一部分都会获得情绪分数,这些部分会被输入CNN。然而,我不明白我怎样才能把这些分数变成CNN的一个数组 我当前的代码: public INDarray getFeatureVectors(List<String> sentences) { // nParts is the number of parts to split the sentence into // sentences are

我正在为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;
}
public-INDarray-getFeatureVector(列出句子){
//nParts是将句子分成的部分数
//句子是当前批次中的句子列表
//int[]featureShape=newint[]{sequences.size(),npart};
int[]featureShape=新int[4];
featureShape[0]=句子.size();
特征形状[1]=1;
featureShape[2]=NPart;
featureShape[3]=NPart;
INDArray features=Nd4j.create(句子.size());
for(int i=0;i<句子.size();i++){
列表标记=//标记化句子
double[]partScores=//计算每个部分的分数
//例如,对于npart=2,partScores={-1.0,1.0}
INDArray vector=Nd4j.create(零件分数、特征形状);
INDArrayIndex[]索引=新的INDArrayIndex[4];
指数[0]=NdarayIndex.点(i);
指数[1]=NdarayIndex.点(0);
索引[2]=NDArrayIndex.all();
索引[3]=NDArrayIndex.all();
特征.put(索引、向量);
}
返回特性;
}
我刚刚尝试了不同的特征形状和索引,但我真的不知道我在做什么,所以任何帮助都将不胜感激

我的代码基于Deeplearning4js,它将句子转换为单词嵌入