<?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 Dhaval Dholakia on Medium]]></title>
        <description><![CDATA[Stories by Dhaval Dholakia on Medium]]></description>
        <link>https://medium.com/@dhaval.dholakia04?source=rss-4c5597884b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qva7-zu5OjFjVeqom0erTg.jpeg</url>
            <title>Stories by Dhaval Dholakia on Medium</title>
            <link>https://medium.com/@dhaval.dholakia04?source=rss-4c5597884b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:41:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhaval.dholakia04/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[Gradient Descent — A Beginners Guide]]></title>
            <link>https://medium.com/data-science/gradient-descent-a-beginners-guide-fa0b5d0a1db8?source=rss-4c5597884b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa0b5d0a1db8</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Dhaval Dholakia]]></dc:creator>
            <pubDate>Wed, 09 May 2018 16:53:15 GMT</pubDate>
            <atom:updated>2018-05-09T17:11:00.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DuFS854z2avtDs3VciPp9w.jpeg" /></figure><h3><strong>Introduction:</strong></h3><p>Recently, during my coursework, I have been left in awe of the advancements in the field of science in general. In just about a decade, we have completely revolutionized the way we look at the capabilities of machines, the way we build software and much more. Tasks that seemed impossible just a decade ago have become accessible and effortless. Long story short, we have made the machines think!! Sounds cool, isn’t it?<br>Artificial Intelligence has truly entered the mainstream consciousness. These days every person has heard or read about the two magical words “machine learning” in their day to day life. But how clearly do any of us understand what AI really is? Although, the idea of making machines think and learn sounds fascinating and overwhelming, for aspiring Data Scientists like me to get our heads around; very few understand or know some of the basic concepts that lead to making machines learn.In this blog post, I am simply putting my understanding of one of the most important and the basic technique that is at the core of many machine learning algorithms — Gradient Descent.<br>One of the most critical parts of any machine learning algorithm is optimization. How to make your learning algorithm learn faster? Gradient descent is one of the most powerful optimization algorithm used in machine learning. Many of us have been pretty much familiar with what gradient descent is but when it comes to understanding it, all of us have gone through the process of seeing scary mathematical equations and plots that look something like –</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*keGmXIpPG5khFASpTxSdIw.jpeg" /><figcaption>Source: Google</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*5PKONrVCj6MnMRo6_I7ShQ.png" /><figcaption>Source: Google</figcaption></figure><p>Don’t worry, it is easier than it looks!</p><blockquote>As Chris Pine says, “The only thing you sometimes have control over is perspective. You don’t have control over your situation. But you have a choice about how you view it.”</blockquote><p>Now, let us change our perspective here and see the above plot as something like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3m8O9Osc1yxU9E_1JL_Z3g.jpeg" /></figure><p>Now, to understand gradient descent, let us imagine the path of the river originating from the top of the mountain. The job of gradient descent is exactly that of what the river aims to achieve; to reach the bottom-most point of the mountain. Now, as we know there is a gravitational force on the earth and hence the river will keep flowing downwards until it reaches the foothill. Here we would be making certain assumptions saying that the mountain will be shaped in such a way that the river will not be stopping at any place and will straightaway arrive at the foothill. In machine learning, this is the ideal case we desire and you can say that we have achieved our “global minima” (in this analogy, it means we have reached the ‘foothill’.). However, in real-life, this is not the case. The way the mountain is, the river may face a lot of pits on its way down and there is a possibility of the water getting trapped in the pits and fail to move downwards. In machine learning terms, this is called “local minima” which is always harmful to any of our learning algorithms. Gradient Descent is prone to arriving at such local minima’s and failing to converge. However, when the mountain terrain is designed in such a particular way i.e. a bowl shape (in machine learning we call such functions as convex functions) then we are guaranteed to arrive at the global minimum (foothill). Now, there are two important points when it comes to gradient descent; initial values and learning rate. To give a general idea about them, we know that depending on where the river initially originates, it will follow a different path to reach the foothill. Also, depending on the speed of the river (learning rate) you might arrive at the foothill in a different manner. These values are important in determining whether you will reach the foothill (global minima) or get trapped in the pits (local minima).</p><p>As highlighted above, one of the major reason helping the river flow downwards is the earth’s gravitational force. Sadly in coding/mathematics, we don’t have the leverage of using earth’s gravitational force!! Hence, to overcome this, we need turn to mathematics and need to know two ways to help us move towards the foothill. We do this by calculating 1) the gradient which gives us the direction of the slope and 2) calculating our step-size (i.e. by how many units does the river need to move in a particular direction)<br>Now, let us consider the formula of gradient descent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*ot2sqnZqKUCOHlWwdjwEjA.png" /></figure><p>From the above formula, there are two things that we can set on our own; α and the current position of Ɵ. The only thing we need to learn here is, how to calculate the gradient? To calculate the gradient of a function for a point Ɵ, we have to differentiate the function once with respect to Ɵ. Let us understand how to do this with an example:</p><p>Consider a function:</p><p>f(x, y) = x + y</p><p>- We set initial values of x = 2 and y = 6</p><p>- The output of the function is 8</p><p>- The question here is, how to tweak the values of the inputs to decrease the output? Let us start by differentiating the above function with respect to its inputs; x and y:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*58A9IrcTe1l2utjSMOlRAg.jpeg" /></figure><p>These derivatives can be thought of as the force on each input as we want to pull the output to become as small as possible; forces that tell us how x and y want to change to decrease the output.</p><p>Let us see how the update rule works here with our above calculations (let α= 0.001)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*rte3SkXUOnq5l-mIkZLIOQ.jpeg" /></figure><p>This intuitively makes sense! To decrease the output of our function, we need to tweak the inputs x and y with a positive force of magnitude 1. For example, changing the value of x from 2 to 1.999 would give an output of 7.99, which is less than 8 and similarly, by changing the value of y from 6 to 5.999 will give us the output of 7.998, which is less than 8!! The next important characteristic of the gradient descent algorithm is that it is an iterative algorithm! Meaning, we repeat the above steps until convergence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*DEHc9xF4AAvvMvFJALdeTg.jpeg" /></figure><p>So, if we repeat the above process for 4000 times we will get the value of x = -2 and y = 2.0 leading us to give the output of our function f(x, y) = 0. So we have got the expected values of x and y that cause our function to give the minimum value of 0.<br>This is the intuition behind gradient descent algorithm — one of the “greatest hit” optimization technique that is at the core of most of the machine learning algorithm. I told you, it’s easier than it looks Here, just to make things easy, we have worked with an example that is trivial and low-dimensional. In reality, we will be dealing with non-linear, high-dimensional functions where it is impossible to solve anything by hand analytically. However, the approach works exactly the same there!<br>Does this make sense? Yep? Nope? Although this post is aimed to help beginners get an intuition behind the working of gradient descent, it is by no means a comprehensive overview. Till then, keep chilling and keep innovating!</p><p>Lastly, as my friend <a href="https://www.linkedin.com/in/gosuddin-siddiqi/">Gosuddin</a> says “Jeet k aaenge!” (Will win)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa0b5d0a1db8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/gradient-descent-a-beginners-guide-fa0b5d0a1db8">Gradient Descent — A Beginners Guide</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activation Functions]]></title>
            <link>https://medium.com/data-science/activation-functions-b63185778794?source=rss-4c5597884b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b63185778794</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[activation-functions]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Dhaval Dholakia]]></dc:creator>
            <pubDate>Fri, 27 Apr 2018 03:27:54 GMT</pubDate>
            <atom:updated>2018-05-08T21:59:57.535Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mh9EU3R3WFiLSyXs-bVrPA.jpeg" /></figure><h4><strong>So why do we need Activation functions in our neural networks?</strong></h4><p>Welcome to my first post! I am a Data Scientist and have been an active reader of Medium blogs. Now, I am planning to use Medium blog to document my journey in learning Deep Learning and share my experiences through the projects I have been working on. Hopefully, by sharing my views on the subjects I can also learn from the fantastic data science/deep learning community on Medium! I would love to hear your feedback on my first post here. With that said, let’s get started …</p><p>The basic idea of how a neural network learns is — We have some input data that we feed it into the network and then we perform a series of linear operations layer by layer and derive an output. In a simple case for a particular layer is that we multiply the input by the weights, add a bias and apply an activation function and pass the output to the next layer. We keep repeating the process until we reach the last layer. The final value is our output. We then compute the error between the “calculated output” and the “true output” and then calculate the partial derivatives of this error with respect to the parameters in each layer going backwards and keep updating the parameters accordingly!</p><p>Neural networks are said to be universal function approximators. The main underlying goal of a neural network is to learn complex non-linear functions. If we do not apply any non-linearity in our multi-layer neural network, we are simply trying to seperate the classes using a linear hyperplane. As we know, in the real-world nothing is linear!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lVHsIz_rQeku7XlUQ73n-w.jpeg" /><figcaption>Source: Google</figcaption></figure><p>Also, imagine we perform simple linear operation as described above, namely; multiply the input by weights, add a bias and sum them across all the inputs arriving to the neuron. It is likely that in certain situations, the output derived above, takes a large value. When, this output is fed into the further layers, they can be transformed to even larger values, making things computationally uncontrollable. This is where the activation functions play a major role i.e. squashing a real-number to a fix interval (e.g. between -1 and 1).</p><p>Let us see different types of activation functions and how they compare against each other:</p><h3><strong>Sigmoid:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXCBO-Wx5XhuY_OwMl0Phw.png" /></figure><p>The sigmoid activation function has the mathematical form `sig(z) = 1/ (1 + e^-z)`. As we can see, it basically takes a real valued number as the input and squashes it between 0 and 1. It is often termed as a squashing function as well. It aims to introduce non-linearity in the input space. The non-linearity is where we get the wiggle and the network learns to capture complicated relationships. As we can see from the above mathematical representation, a large negative number passed through the sigmoid function becomes 0 and a large positive number becomes 1. Due to this property, sigmoid function often has a really nice interpretation associated with it as the firing rate of the neuron; from not firing at all (0) to fully-saturated firing at an assumed maximum frequency (1). However, sigmoid activation functions have become less popular over the period of time due to the following two major drawbacks:</p><ul><li><strong>Killing gradients:</strong><br>Sigmoid neurons get saturated on the boundaries and hence the local gradients at these regions is almost zero. To give you a more intuitive example to understand this, consider the inputs to the sigmoid function to be +15 and -15. The derivative of sigmoid function is `sig(z) * (1 — sig(z))`. As mentioned above, the large positive values are squashed near 1 and large negative values are squashed near 0. Hence, effectively making the local gradient to near 0. As a result, during backpropagation, this gradient gets multiplied to the gradient of this neurons’ output for the final objective function, hence it will effectively “kill” the gradient and no signal will flow through the neuron to its weights. Also, we have to pay attention to initializing the weights of sigmoid neurons to avoid saturation, because, if the initial weights are too large, then most neurons will get saturated and hence the network will hardly learn.</li><li><strong>Non zero-centered outputs:</strong><br>The output is always between 0 and 1, that means that the output after applying sigmoid is always positive hence, during gradient-descent, the gradient on the weights during backpropagation will always be either positive or negative depending on the output of the neuron. As a result, the gradient updates go too far in different directions which makes optimization harder.</li></ul><p>The python implementation looks something similar to:</p><pre>import numpy as np</pre><pre>def sigmoid(z):<br> return 1 / (1 + np.exp(-z))</pre><h3><strong>Tanh:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*ILo_eGNCb92nlrP7NtpOug.png" /><figcaption>Source: Google</figcaption></figure><p>The tanh or hyperbolic tangent activation function has the mathematical form `tanh(z) = (e^z — e^-z) / (e^z + e^-z)`. It is basically a shifted sigmoid neuron. It basically takes a real valued number and squashes it between -1 and +1. Similar to sigmoid neuron, it saturates at large positive and negative values. However, its output is always zero-centered which helps since the neurons in the later layers of the network would be receiving inputs that are zero-centered. Hence, in practice, tanh activation functions are preffered in hidden layers over sigmoid.</p><pre><br>import numpy as np</pre><pre>def tanh(z):<br> return np.tanh(z)<br></pre><h3><strong>ReLU:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*Xul22nQfzRNFFeICETrZxA.jpeg" /><figcaption>Source: Google</figcaption></figure><p>The ReLU or Rectified Linear Unit is represented as `ReLU(z) = max(0, z)`. It basically thresholds the inputs at zero, i.e. all negative values in the input to the ReLU neuron are set to zero. Fairly recently, it has become popular as it was found that it greatly accelerates the convergence of stochastic gradient descent as compared to Sigmoid or Tanh activation functions. Just to give an intuition, the gradient is either 0 or 1 depending on the sign of the input. Let us discuss some of the advantages of ReLU:</p><ul><li><strong>Sparsity of Activations</strong>:<br>As we studied above, ReLU and Tanh activation functions would almost always get fired in the neural network, resulting in the almost all the activations getting processed in calculating the final output of the network. Now surely this is a good thing but only if our network is small or we had unlimited computational power. Imagine we have a very deep neural network with a lot of neurons, we would ideally want only a section of neurons to fire and contribute to the final output of the network and hence, we want a section of the neurons in the network to be passive. ReLU gives us this benefit. Hence, due to the characteristics of ReLU, there is a possibility that 50% of neurons to give 0 activations and thus leading to fewer neurons to fire as a result of which the network becomes lighter and we can compute the output faster.</li></ul><p>However, it has a drawback in terms of a problem called as dying neurons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*0_sAdw2qSGhs6PAKTynQDQ.gif" /></figure><ul><li><strong>Dead Neurons:</strong><br>ReLU units can be fragile during training and can “die”. That is, if the units are not activated initially, then during backpropagation zero gradients flow through them. Hence, neurons that “die” will stop responding to the variations in the output error because of which the parameters will never be updated/updated during backpropagation. However, there are concepts such as Leaky ReLU that can be used to overcome this problem. Also, having a proper setting of the learning rate can prevent causing the neurons to be dead.</li></ul><pre>import numpy as np</pre><pre>def relu(z):<br> return z * (z &gt; 0)</pre><h3><strong>Leaky ReLU:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*2yzgQ4CrDENrdjImdZaydg.png" /><figcaption>Source: Google</figcaption></figure><p>The Leaky ReLU is just an extension of the traditional ReLU function. As we saw that for values less than 0, the gradient is 0 which results in “Dead Neurons” in those regions. To address this problem, Leaky ReLU comes in handy. That is, instead of defining values less than 0 as 0, we instead define negative values as a small linear combination of the input. The small value commonly used is 0.01. It is represented as `LeakyReLU(z) = max(0.01 * z, z)`. The idea of Leaky ReLU can be extended even further by making a small change. Instead of multiplying `z` with a constant number, we can learn the multiplier and treat it as an additional hyperparameter in our process. This is known as Parametric ReLU. In practice, it is believed that this performs better than Leaky ReLU.</p><pre>import numpy as np</pre><pre>def leaky_relu(z):<br> return np.maximum(0.01 * z, z)</pre><p>Thank you for reading. In this article I tried to lay down my understanding of some of the most commonly used activation functions, why we use them in the first place and which activation function should one use. Keep chilling and keep innovating!</p><p>Misc:</p><p>If you are working in Data Science or Deep Learning field do not hesitate to reach out if you think there is an opportunity to collaborate. I am looking for full-time opportunities and would love to discuss.</p><p>References:</p><p>[1]: <a href="http://cs231n.github.io/neural-networks-1/#actfun">http://cs231n.github.io/neural-networks-1/#actfun</a></p><p>[2]: <a href="http://www.deeplearningbook.org/">http://www.deeplearningbook.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b63185778794" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/activation-functions-b63185778794">Activation Functions</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>