XOR neural network does not learn

女生的网名这么多〃 提交于 2019-12-06 14:54:15

I am not sure what results you are getting, as the code you have posted in the question doesn't work (It gives errors with pytorch 0.4.1 like predicted not defined etc). But syntax issues apart, there are other problems.

Your model is not actually two layer as it does not use non-linearity after the first output. Effectively this is one layer network and to fix that you can modify your model's forward as follows:

def forward(self, out):
    out = torch.nn.functional.relu(self.fc1(out))
    out = self.fc2(out)
    out = self.sigmoid(out)
    return out

You can try sigmoid or tanh non-linearity as well... but the non-linearity is a must. This should fix the problem.

I also see that you are using only 2 hidden units. This might be restrictive and you might want to increase that to something like 5 or 10.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!