我是新来的人,这实际上是我的第二篇文章。
当前的问题围绕着我在Java中实现神经网络文本分类器的实现,其中矩阵是使用ArrayList>构建的。
该实现基于“ https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6”中的代码,而这仅仅是我试图将代码传输至Java。
我的代码正在运行,但是训练不佳。我收到的均值(abs(layer_2_error))= 0.5,同时我在python中运行原始代码时,我收到的均值(abs(layer_2_error))<0.004,表明我在学习操作中做错了,而不是代码明智的(我希望)。
这是训练循环:
for (int iteration=0; iteration < epochs; iteration++) {
if (iteration%10000 == 0 && iteration > 5000) {
System.out.println(matrixComputations.absoluteMeanOfAllValues(layer2Error));
}
// Feed forward through layers 0,1,2
layer1 = (saf.sigmoid(matrixComputations.multiplication(layer0,synapse0)));
layer2 = saf.sigmoid(matrixComputations.multiplication(layer1,synapse1));
layer2Error = matrixComputations.subtraction(outputData,layer2);
layer2Delta = matrixComputations.elementWiseMultiplication(layer2Error,saf.sigmoidDerivative(layer2));
layer1Error = matrixComputations.multiplication(layer2Delta,matrixComputations.transpose(synapse1));
layer1Delta = matrixComputations.elementWiseMultiplication(layer1Error,saf.sigmoidDerivative(layer1));
synapse1WeightUpdate = matrixComputations.multiplication(matrixComputations.transpose(layer1),layer2Delta);
synapse0WeightUpdate = matrixComputations.multiplication(matrixComputations.transpose(layer0),layer1Delta);
synapse1temp = matrixComputations.addition(synapse1,matrixComputations.multiplicationWithSingleValue(alpha,synapse1WeightUpdate));
synapse0temp = matrixComputations.addition(synapse0,matrixComputations.multiplicationWithSingleValue(alpha,synapse0WeightUpdate));
prevSynapse0WeightUpdate = synapse0WeightUpdate;
prevSynapse1WeightUpdate = synapse1WeightUpdate;
synapses.setSynapse0(synapse0);
synapses.setSynapse1(synapse1);
}
return synapses;
}
谢谢!