提交 737d9c1a 编写于 作者: S ShusenTang

fix bug #17: randn -> rand

上级 97df5349
......@@ -9,7 +9,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.4.1\n"
"1.2.0\n"
]
}
],
......@@ -40,7 +40,7 @@
" # 这种情况下把全部元素都丢弃\n",
" if keep_prob == 0:\n",
" return torch.zeros_like(X)\n",
" mask = (torch.randn(X.shape) < keep_prob).float()\n",
" mask = (torch.rand(X.shape) < keep_prob).float()\n",
" \n",
" return mask * X / keep_prob"
]
......@@ -54,7 +54,7 @@
"data": {
"text/plain": [
"tensor([[ 0., 1., 2., 3., 4., 5., 6., 7.],\n",
" [ 8., 9., 10., 11., 12., 0., 14., 15.]])"
" [ 8., 9., 10., 11., 12., 13., 14., 15.]])"
]
},
"execution_count": 3,
......@@ -75,8 +75,8 @@
{
"data": {
"text/plain": [
"tensor([[ 0., 0., 4., 0., 8., 0., 12., 14.],\n",
" [ 0., 18., 20., 0., 24., 0., 0., 30.]])"
"tensor([[ 0., 0., 4., 6., 0., 0., 12., 14.],\n",
" [ 0., 18., 20., 22., 0., 0., 28., 0.]])"
]
},
"execution_count": 4,
......@@ -184,11 +184,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"epoch 1, loss 0.0044, train acc 0.574, test acc 0.648\n",
"epoch 2, loss 0.0023, train acc 0.786, test acc 0.786\n",
"epoch 3, loss 0.0019, train acc 0.826, test acc 0.825\n",
"epoch 4, loss 0.0017, train acc 0.839, test acc 0.831\n",
"epoch 5, loss 0.0016, train acc 0.849, test acc 0.850\n"
"epoch 1, loss 0.0045, train acc 0.561, test acc 0.662\n",
"epoch 2, loss 0.0023, train acc 0.783, test acc 0.786\n",
"epoch 3, loss 0.0019, train acc 0.823, test acc 0.773\n",
"epoch 4, loss 0.0017, train acc 0.838, test acc 0.847\n",
"epoch 5, loss 0.0016, train acc 0.848, test acc 0.809\n"
]
}
],
......@@ -231,11 +231,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"epoch 1, loss 0.0045, train acc 0.553, test acc 0.715\n",
"epoch 2, loss 0.0023, train acc 0.784, test acc 0.793\n",
"epoch 3, loss 0.0019, train acc 0.822, test acc 0.817\n",
"epoch 4, loss 0.0018, train acc 0.837, test acc 0.830\n",
"epoch 5, loss 0.0016, train acc 0.848, test acc 0.839\n"
"epoch 1, loss 0.0048, train acc 0.526, test acc 0.743\n",
"epoch 2, loss 0.0023, train acc 0.779, test acc 0.764\n",
"epoch 3, loss 0.0020, train acc 0.815, test acc 0.819\n",
"epoch 4, loss 0.0018, train acc 0.836, test acc 0.814\n",
"epoch 5, loss 0.0016, train acc 0.848, test acc 0.842\n"
]
}
],
......@@ -256,7 +256,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
......@@ -270,7 +270,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
"version": "3.6.2"
}
},
"nbformat": 4,
......
......@@ -49,7 +49,7 @@ def dropout(X, drop_prob):
# 这种情况下把全部元素都丢弃
if keep_prob == 0:
return torch.zeros_like(X)
mask = (torch.randn(X.shape) < keep_prob).float()
mask = (torch.rand(X.shape) < keep_prob).float()
return mask * X / keep_prob
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册