<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dave MacDonald on Medium]]></title>
        <description><![CDATA[Stories by Dave MacDonald on Medium]]></description>
        <link>https://medium.com/@dave_macdonald?source=rss-f92f10d091f2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ftcNMBcYgRiw5gxZa83LTg.png</url>
            <title>Stories by Dave MacDonald on Medium</title>
            <link>https://medium.com/@dave_macdonald?source=rss-f92f10d091f2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 07:12:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dave_macdonald/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Magnetosphere for Neural Networks]]></title>
            <link>https://medium.com/@dave_macdonald/a-magnetosphere-for-neural-networks-3686668a29b5?source=rss-f92f10d091f2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3686668a29b5</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Dave MacDonald]]></dc:creator>
            <pubDate>Sat, 31 Mar 2018 04:12:08 GMT</pubDate>
            <atom:updated>2018-04-01T01:06:25.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>The LogAdam Optimizer</h3><p><em>Planetary defence against massive gradient spikes</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fDkzMydV3zBeD5pLFaSaMA.jpeg" /></figure><p>Neural networks learn by iteratively updating their weights.</p><p>This is usually not a problem — an amount based on the gradient of the error is back-propagated through the network, weights are updated and progress is made. All is peaceful for the AI.</p><p>Occasionally, however, the neural network can enter an area where the loss function has an immense sharp gradient. This amount, when propagated back through the network, destroys the delicate patterns found in earlier steps and the damage seriously sets back training and the performance of the model.</p><p>Drawing an analogy to the Sun, the Sun allows for life to evolve on Earth, and at the same time we have a magnetosphere that protects the planet from the occasional massive solar flare. In the same way, neural networks need a magnetosphere.</p><p>One approach is to cap extreme gradients by just clipping them, setting a maximum limit to the gradient. However this has a couple drawbacks — the first is that it is challenging to find an appropriate limit (an extra hyperparameter to worry about), and secondly, the neural network loses information about the magnitude of the gradient if it is beyond that limit.</p><p>Instead, what if we just scaled the gradient to its logarithm? In that case, each order of magnitude increase in the gradient only adds a <em>constant</em> amount to the back-propagated signal. This is the magnetosphere for your neural network. It can handle massive gradients with ease.</p><p>Specifically, we join the two logarithmic functions below at the origin to create a smooth monotonic scale that we use to dampen the gradient, and, in doing so, we protect the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qsfr-qMQsdPpGYNDhYtZXg.png" /><figcaption>Instead of sending back the value itself (represented by the y=x blue line) we send back the the logarithm of it (+1) instead.</figcaption></figure><p>In TensorFlow, the gradient of the loss function can be dampened as follows, before sending it back through the network:</p><p><strong>TensorFlow:</strong></p><blockquote>protected_grad = tf.sign(<strong><em>grad</em></strong>) * tf.log( tf.abs(grad) + 1. )</blockquote><p>You can use this technique with any optimizer but often one of the best is the AdamOptimizer. Extending it in this simple way gives us the LogAdamOptimizer.</p><p>Does it work? Absolutely! I am using this approach in a 46-layer GAN to generate flowers, here are some samples from around iteration 140k where all gradients are ‘log-dampened’ gradients (i.e. using a LogAdam optimizer):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sGBBkTgtDcEE4zSyfx_ghQ.png" /></figure><p>Enjoy, happy training.</p><p>I’ll have more to post about GAN training — follow if you are interested in learning more about them!</p><p>Dave MacDonald</p><h4>Toronto AI</h4><p><a href="https://www.meetup.com/Toronto-AI/">Toronto AI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3686668a29b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>