Skip to content

Commit

Permalink
fix bug ShusenTang#17: randn -> rand
Browse files Browse the repository at this point in the history
  • Loading branch information
ShusenTang committed Oct 24, 2019
1 parent 97df534 commit 737d9c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions code/chapter03_DL-basics/3.13_dropout.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.4.1\n"
"1.2.0\n"
]
}
],
Expand Down Expand Up @@ -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"
]
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand All @@ -256,7 +256,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -270,7 +270,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
"version": "3.6.2"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/chapter03_DL-basics/3.13_dropout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit 737d9c1

Please sign in to comment.