{"action":"opened","issue":{"url":"https://api.github.com/repos/guevara/read-it-later/issues/4887","repository_url":"https://api.github.com/repos/guevara/read-it-later","labels_url":"https://api.github.com/repos/guevara/read-it-later/issues/4887/labels{/name}","comments_url":"https://api.github.com/repos/guevara/read-it-later/issues/4887/comments","events_url":"https://api.github.com/repos/guevara/read-it-later/issues/4887/events","html_url":"https://github.com/guevara/read-it-later/issues/4887","id":474910103,"node_id":"MDU6SXNzdWU0NzQ5MTAxMDM=","number":4887,"title":"Lei Mao's Log Book  Dropout Explained","user":{"login":"guevara","id":228309,"node_id":"MDQ6VXNlcjIyODMwOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/228309?v=4","gravatar_id":"","url":"https://api.github.com/users/guevara","html_url":"https://github.com/guevara","followers_url":"https://api.github.com/users/guevara/followers","following_url":"https://api.github.com/users/guevara/following{/other_user}","gists_url":"https://api.github.com/users/guevara/gists{/gist_id}","starred_url":"https://api.github.com/users/guevara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guevara/subscriptions","organizations_url":"https://api.github.com/users/guevara/orgs","repos_url":"https://api.github.com/users/guevara/repos","events_url":"https://api.github.com/users/guevara/events{/privacy}","received_events_url":"https://api.github.com/users/guevara/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-07-31T02:56:51Z","updated_at":"2019-07-31T02:56:51Z","closed_at":null,"author_association":"OWNER","body":"Lei Mao's Log Book – Dropout Explained<br>\n<br>\nhttps://ift.tt/2YaGWBc<br>\n<br>\nTwitter<br>\n<br>\n<div>\n<div> <h3>Introduction</h3> <p>Dropout has been widely used in deep learning to prevent overfitting. Recently I found that I have misunderstood dropout for many years. I am writing this blog post to remind myself as well as all the people about the math and the caveats of dropout.</p> <h3>Dropout Implementations</h3> <h4>Original Implementation</h4> <p>In the original implementation of dropout, dropout does work in both training time and inference time.</p> <div> <figure><img src=\"https://leimao.github.io/images/blog/2019-06-04-Dropout-Explained/dropout.png\"><figcaption>Original Dropout</figcaption></figure>\n</div> <p>During training time, dropout randomly sets node values to zero. In the original implementation, we have “keep probability” $p_{\\text{keep}}$. So dropout randomly kills node values with “dropout probability” $1-p_{\\text{keep}}$. During inference time, dropout does not kill node values, but all the weights in the layer were multiplied by $p_{\\text{keep}}$. One of the major motivations of doing so is to make sure that the distribution of the values after affine transformation during inference time is close to that during training time. Equivalently, This multiplier could be placed on the input values rather than the weights.</p> <p><br></p> <p>Concretely, say we have a vector $x = \\{1,2,3,4,5\\}$ as the input to certain fully connected layer and $p_{\\text{keep}} = 0.8$. During training time, $x$ could be set to $\\{1,0,3,4,5\\}$ due to dropout. During inference time, $x$ would be set to $\\{0.8,1.6,2.4,3.2,4.0\\}$ while the weights remain unchanged.</p> <p><br></p> <p>Things are similar if you placed the multiplier to the output values rather than the input values or weights. However, in any of the implementations mentioned above, you have to make changes to the values in the neural network during both training time and inference time. This seems to be undesirable to TensorFlow. So TensorFlow has its own implementation of dropout which only does work during training time.</p> <h4>TensorFlow Implementation</h4> <p>To avoid doing work during inference time, $p_{\\text{keep}}$ has to be removed during inference time. To make sure that the distribution of the values after affine transformation during inference time remains almost the same, all the values that remains after dropout during training has to be multiplied by $\\frac{1}{p_{\\text{keep}}}$.</p> <p><br></p> <p>Concretely, say we have a vector $x = \\{1,2,3,4,5\\}$ as the input to certain fully connected layer and $p_{\\text{keep}} = 0.8$. During training time, $x$ could be set to $\\{1.25,0,3.75,5,6.25\\}$ due to dropout. During test time, $x$ and the weights remain unchanged.</p> <h4>Equivalence?</h4> <p>Mathematically these two implementations does not look the same. These two are off by an constant value in both forward propagation and back propagation. However, regarding the optimization goal, these two implementations are equivalent, at least for linear regressions with mean square loss. Here I will show my proof below.</p> <p><br></p> <p>Let $X \\in \\mathbb{R}^{N \\times D}$ be the data matrix, where $N$ is the number of data points, and $D$ is the number of features, $\\mathbf{y} \\in \\mathbb{R}^{N}$ be the target values, and $\\mathbf{w} \\in \\mathbb{R}^{D}$ be the weights. We have the following optimization goal.</p> <p>In the original dropout paper, the authors have shown that using their specific dropout implementation in this optimization task is equivalent to optimize the following formula.</p> <p>where $\\Gamma = (\\text{diag}(X^T X))^{\\frac{1}{2}}$</p> <p><br></p> <p>When we have a multiplier of $\\frac{1}{p_{\\text{keep}}}$ for $X$ during training, with dropout, it is equivalent to have the following optimization goal.</p> <p>Because $p_{\\text{keep}}$ is a constant value, this is equivalent to optimize</p> <p>It is further equivalent to optimize</p> <p>Assume the optimal $\\mathbf{w}$ from the original dropout implementation is $\\mathbf{w}^{\\ast}_{\\text{original}}$ and the optimal $\\mathbf{w}$ from the TensorFlow dropout implementation is $\\mathbf{w}^{\\ast}_{\\text{TensorFlow}}$. It is not hard to see that</p> <p>The output of the two implementations are also identical given their optimial $\\mathbf{w}$.</p> <p><br></p> <p>Therefore, the two implementations are equivalent, at least for linear regressions with mean square loss.</p> <h4>More General Equivalence?</h4> <p>In the forward propagation of the TensorFlow dropout implementation during training time, it is equivalent to multiply all the weights in the layer by $\\frac{1}{p_{\\text{keep}}}$ while keeping all the inputs unchanged.</p> <div> <figure><img src=\"https://leimao.github.io/images/blog/2019-06-04-Dropout-Explained/dropout_tensorflow.png\"><figcaption>TensorFlow Dropout</figcaption></figure>\n</div> <p>We can see that for whatever optimization goal with the respect to $\\mathbf{w}$, it is equivalent to optimize with the respect to $\\frac{\\mathbf{w}}{p_{\\text{keep}}}$. It is also not hard to see that</p> <p>The output of the two implementations are also identical given their optimial $\\mathbf{w}$.</p> <p><br></p> <p>The conclusion is that the two dropout implementations are exactly identical.</p> <h3>Dropout in Convolutional Neural Network</h3> <p>The original dropout was discussed in the scope of fully connected layers. But dropout in convolutional layers are hardly seen. There are some debates about the dropout effects in convolutional neural networks.</p> <p><br></p> <p>Some people think dropout should not be used in convolutional layers because convolutional layers have fewer parameters and are less likely to overfit. Because the gradient update for the weights of convolutional layers are the average of all the gradients from all the convolutions, randomly killing nodes will slow down the training process.</p> <p><br></p> <p>In my opinion, dropout does provide regularization for any kind of neural network architectures. It also provides additional benefits from the perspective of Bayesian learning, which I might discuss in the future. But in practice, depending on the task, dropout may or may not affect the accuracy of your model. If you want to apply dropout in convolutional layers, just make sure that you test the training with and without dropout to see if it makes a difference.</p> <h3>Caveats</h3> <ol>\n<li>It should be noted that doing dropout during inference time is equivalent to doing dropout during training time with $p_{\\text{keep}} = 1.0$.</li> <li>In general, the order of the layers are X -&gt; Dropout Layer -&gt; Fully Connected Layer -&gt; Activation Layer, where X could be any layer.</li> </ol>\n<h3>References</h3> <hr>\n<footer><div> <img alt=\"Lei Mao bio photo\" src=\"https://leimao.github.io/images//author_images/Lei-Bio-Medium.jpg\"><h3>Lei Mao</h3> <p>Machine Learning, Artificial Intelligence. On the Move.</p> <a href=\"http://twitter.com/matchaleimao\" target=\"_blank\"> Twitter</a> <a href=\"http://facebook.com/dukeleimao\" target=\"_blank\"><i></i> Facebook</a> <a href=\"http://linkedin.com/in/lei-mao\" target=\"_blank\"><i></i> LinkedIn</a> <a href=\"http://github.com/leimao\" target=\"_blank\"><i></i> GitHub</a> <a href=\"http://scholar.google.com/citations?user=R2VUf7YAAAAJ\" target=\"_blank\"><i></i>  G. Scholar</a> <a href=\"mailto:dukeleimao@gmail.com\" target=\"_blank\"><i></i> E-Mail</a> </div> <p><strong>Dropout Explained</strong> was published on <time datetime=\"2019-06-04T00:00:00-05:00\">June 04, 2019</time> and last modified on <time datetime=\"2019-06-04\">June 04, 2019</time> by <a title=\"About Lei Mao\" href=\"https://leimao.github.io\">Lei Mao</a>.</p> </footer>\n</div> </div><br>\n<br>\n<br>\n<br>\n<br>\n<br>\nvia Lei Mao's Log Book https://ift.tt/2MtcO1I<br>\n<br>\nJuly 31, 2019 at 10:55AM"}}
{"actor":{"display_login":"guevara"}}