<?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 Deepesh Padala on Medium]]></title>
        <description><![CDATA[Stories by Deepesh Padala on Medium]]></description>
        <link>https://medium.com/@DS3a?source=rss-58815670d327------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vaemZunNOaPSTp5gx6RezQ.png</url>
            <title>Stories by Deepesh Padala on Medium</title>
            <link>https://medium.com/@DS3a?source=rss-58815670d327------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:34:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DS3a/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 Robot That Wakes You Up When You’re Asleep]]></title>
            <link>https://medium.com/@DS3a/a-robot-that-wakes-you-up-when-youre-asleep-870465757b65?source=rss-58815670d327------2</link>
            <guid isPermaLink="false">https://medium.com/p/870465757b65</guid>
            <category><![CDATA[funny]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Deepesh Padala]]></dc:creator>
            <pubDate>Wed, 04 Aug 2021 09:34:19 GMT</pubDate>
            <atom:updated>2021-08-04T09:54:31.886Z</atom:updated>
            <content:encoded><![CDATA[<h4>It’s completely harmless… Mostly</h4><p>Duuude, isn’t that just an alarm? Guess we’re done here. Oh, wait, it doesn’t work. All it does is wake my parents up, who come and yell at me. But I can’t depend on them to wake me up forever, can I? So I recorded their voice, and tried playing that… But that didn’t work either. Also, an alarm doesn’t wake me up when I’m up late in the night trying to complete my project just before the due date, but suddenly fall asleep.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fUZQFnzTJOAZ9e1H.jpg" /></figure><p>There had got to be some way to hack into my brain or something to force me to stay up. Maybe by sticking electrodes into the pineal gland and zapping it to stop production of melatonin. But, I didn’t know if it’d work. Also, I was afraid of the whole frying my brain and dying thingi.</p><p>A google search ensued, to find a less invasive method.</p><blockquote>And that, my friends, is how I got addicted to…</blockquote><p>Sorry, wrong blog;- Anyhoo. I came across the legendary <a href="https://www.youtube.com/watch?v=d5d02U5YYfk">Michael Reeves</a>, the king of tasers. Except, he didn’t use a taser to wake him up (Whyy??!!)</p><p>I read an article online, that said that our skin is the most sensitive sense organ. And four others that said that pointed at the other four senses. I don’t know why, but the prospect of getting to e̶l̶e̶c̶t̶r̶o̶c̶u̶t̶e̶ shock people sounded funnier. And, with a controlled shock, one can also contract muscles, forcing sleepy drivers to grip the steering wheel tighter, preventing a lot of accidents. And so, I chose that. Maybe I’ll add flashing lights and like, a 100 db buzzer in the future, and sell it to the <strong><em>*redacted*</em></strong> as a torture device.</p><p>If you’ve come this far, and still don’t think I’m a maniac, this would be the right time to warn you about the risks. I can’t tell you not to try this at home, cuz I did… And I’m no hypocrite. But do it at your own risk. <strong>I don’t want your mom calling my mom, and then yelling at her, saying her kid read my blog, and now he’s dead. </strong>Or she. Girls can do stupid stuff too, I just used the most generic pronoun that came to my head, having been brought up in a patriarchal society. Please don’t report me, I am not being sexist.</p><p>But I digress. Getting back to the robot. It had to have 2 modes. One to wake me up at a given time (ez claps), and one to see if I’m drowsy, and zap me awake. So, here were my goals:</p><ul><li>A way for the computer to detect when I’m drowsy, so that it can trigger the taser</li><li>A taser, that I can wear</li></ul><p>Now, unfortunately, I don’t live in the US, so, buying weapons might not be that easy. So, I had to search for alternatives. I called up every shady person I knew, and finally ended up at clipfart.com, looking at a mosquito zapper, and a toy-pen-zapping prank thingy. I ordered the pen, cuz it delivered the next day, and looked less scary. But more of the first thing (I’m just <strong>very </strong>impatient).</p><p>Now, for the drowsiness detection I thought of doing it with a CNN, for which I needed training data.</p><pre>import cv2<br>import matplotlib.pyplot as plt<br>import numpy as np<br>import time                                                                       DATASET_FOLDER = &quot;./datasets&quot;<br>IMGS_FOLDER = &quot;./datasets/imgs&quot;         <br>TIME_TO_CAPTURE = 20 # Seconds<br>CAM_NO = 2 <br>init_index=0<br>cap = cv2.VideoCapture(CAM_NO)                       cap.set(cv2.CAP_PROP_FRAME_WIDTH, 480)                       cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)</pre><pre><br>def capture_imgs(time_to_cap, folder, save_as, ind=1):<br>    time_init = time.time()<br>    while time.time() - time_init &lt;= time_to_cap:              <br>         ret, frame = cap.read()                      <br>         filename = str(ind) + &quot;.jpg&quot;                      <br>         ind += 1                      <br>        cv2.imshow(&#39;frame&#39;, frame)                      <br>        cv2.imwrite(<br>        str(folder)+&#39;/&#39;+str(save_as)+&#39;/&#39;+filename,frame)                            <br>        <br>        if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):                           <br>            break                                             <br>            cap.release()                   <br>            cv2.destroyAllWindows()     </pre><pre><br>if __name__ == &quot;__main__&quot;:                       <br>    capture_imgs(TIME_TO_CAPTURE, IMGS_FOLDER, &quot;drowsy&quot;, init_index)</pre><p>I used the above script to take pictures of me when I was drowsy, it took about 500 images, in 20 seconds with my 25fps webcam. I took about 3000 images of my face under different lighting conditions.</p><p>20 cans of red bull, and 2000x10⁻³ pushups later, I was wide awake, and proceeded to take 3000 more images to be saved in the “awake” folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*wluYdvojw-iM4iz6AfA8iA.png" /></figure><p>Then, I built a CNN using tensorflow and trained it with the collected data. to tell whether I was awake or asleep.</p><p>After about an hour of hyperparameter tuning I was about to reach a 93% validation accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*s6TiBrmFLM1mK6LH1WyVDw.png" /></figure><p>Yes sirrrrr, I’m awake and listening in class, you can see the estimated probability of me being awake</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*QPaFhxlIJtF4LYkb5-RJ9w.png" /></figure><p>And, here, you can see me dozing off… No, I’m not concerned about privacy, and all that crap, I just don’t want creeps deriving pleasure from my pain in the subsequent picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*cdXZn15uy-SizdHoI5ccJA.png" /></figure><p>As you can see, I am <strong>wide </strong>awake… Oh wait, you can’t. Too bad; you’re just gonna have to take my word for it i guess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfIPUhpwNJNuutDxG-Mf9Q.png" /></figure><p>This messy circuit over here is the relay board connected to the “tazer” which is connected to an arduino uno, which is connected to my laptop via serial.</p><p>My laptop uses it’s camera to tell whether I’m sleepy or not and decides whether to jolt me or not.</p><h4>Outro</h4><p>Well, I probably can’t use this while driving. The intensity of the shock is too high, and will probably cause my hand to jerk. But a controlled shock, from say; a TENS unit, would probably be the way to improve this. Feel free to reach out to me if, unlike others you see the potential in this awesome product lol.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=870465757b65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Next Gen of Computing]]></title>
            <link>https://medium.com/student-technical-community-vit-vellore/the-next-gen-of-computing-a31f6578e1f4?source=rss-58815670d327------2</link>
            <guid isPermaLink="false">https://medium.com/p/a31f6578e1f4</guid>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[quantum-physics]]></category>
            <dc:creator><![CDATA[Deepesh Padala]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 12:42:15 GMT</pubDate>
            <atom:updated>2021-04-18T12:42:15.919Z</atom:updated>
            <content:encoded><![CDATA[<h4>Quantum Computers</h4><p>Something truly remarkable has happened in the field of technology over the past ten years, and some of you might not be aware of it. It is that the time taken to solve a problem and also the time taken in making a prediction has drastically reduced. When we think of complex problems, we think of Computers, but what about problems tougher than complex problems, where do we go for them, and that’s where Quantum Computers and Quantum Computing come in.</p><p>In this article, I shall present to you the quintessential features of Quantum Computing necessary to gain a better understanding of the ever-growing topic.</p><figure><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.scientificamerican.com%2Farticle%2Fis-the-u-s-lagging-in-the-quest-for-quantum-computing%2F&amp;psig=AOvVaw3igv_vGt4I8zzgo66XvkU_&amp;ust=1618490620332000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCPjcksfh_e8CFQAAAAAdAAAAABAD"><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*mDTPLCFxMrYkaGDT.jpg" /></a></figure><p>In a quantum computer, a <strong>qubit</strong>, or a <strong>quantum bit</strong>, is the most basic unit of information, quite like how a <strong>bit </strong>is the basic unit of information in a conventional computer. In order to understand qubits better, you need to know about two of the basic principles of quantum mechanics, i.e., <strong><em>superposition</em></strong>, and <strong><em>entanglement.</em></strong></p><h4>Quantum Superposition</h4><p>Let’s perform a thought experiment. Imagine you have 10 bucks in hand, and you’re to go buy a snack. Assume that there are 2 different kinds of lays available, Blue, and Orange, and you’re quite torn apart as to what you want to get. Your mind is currently in a superposed state, you can denote it as <strong><em>Blunge</em></strong><em>.</em><strong><em> </em></strong>Imagine yourself taking the 10 rupees out of your pocket and placing it on the counter. You then ask the shopkeeper for … That is the moment when the superposition collapses. You either get Blue, or Orange. Taking a new chip out of the bag is analogous to measuring the quantum state again with the same apparatus. You’ll get the same output. Now, let’s say some one gives you 10 more rupees, and are made to choose between the two again. Maybe you just got Blue and you’re tired of it. The super position changes as the probability of you choosing blue decreases, i.e., your brain enters a new superposition. i.e., the configuration of the measuring apparatus has been changed.</p><figure><a href="https://i.imgur.com/p0AG3Da.png"><img alt="" src="https://cdn-images-1.medium.com/max/695/0*U4WOAH0YF_XvqWKC.png" /></a></figure><blockquote>“A system is in superposition”, means that it is in multiple states at the same time.</blockquote><p>Do note that all the states are of the same energy. <strong>A qubit is a superposition of 1 and 0</strong>, when measured, it collapses to either of those values, depending on it’s configuration.</p><figure><a href="https://miro.medium.com/max/700/1*4kallW1DR8WMfo1ryycttQ.jpeg"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gv-AagDZNEJlOAAV.jpeg" /></a><figcaption>The Difference Between classical Bits and Qubits</figcaption></figure><p>That means that, when the qubit on the right is measured, it will collapse to either of the conventional Bits. This is known as the <a href="http://www.pitt.edu/~jdnorton/teaching/HPS_0410/chapters/quantum_theory_measurement/">measurement barrier</a>. Note that this isn’t because the apparatus used to measure the qubit is flawed, or too intrusive, it is one of the basic principles of quantum mechanics. That we know of.</p><blockquote><strong>Measuring a quantum system changes</strong> <strong>it</strong></blockquote><p>The notation used above to denote the states is called the bra-ket notation, you can learn more about that over <a href="https://ocw.mit.edu/courses/physics/8-05-quantum-physics-ii-fall-2013/lecture-notes/MIT8_05F13_Chap_04.pdf">here</a>.</p><p>Now, since we’re redefining Bits, one of the basic building blocks of a computer, we need new logic gates as well. Using normal logic gates on these qubits will, cause it to collapse, and the normal bits go through the gate. One can denote that as a superposition as well, the NOT gate is one example. Let’s say we have a qubit which has a 75% chance of being 1 and 25% chance of being 0. The NOT gate will turn that into a qubit which has a 75% chance of being 0, and consequently, a 25% chance of being 1.</p><p>Apart from the conventional logic gates, quantum gates are also being developed. Some of the most common ones are the <a href="https://www.quantum-inspire.com/kbase/hadamard/">Hadamard Gate</a>, the CNOT Gate or the Controlled-NOT Gate, which acts on 2 qubits. It basically performs the NOT operation on one of the qubits depending on the measurement of the other. There’s also the Tiffoli gate, or the CCNOT gate. You can learn more about these gates by experimenting with the <a href="https://quantum-computing.ibm.com/composer/">IBM Quantum Composer</a> or the Qiskit library for Python.</p><h4>Quantum Entanglement</h4><p>The main prowess of a quantum computer, lies in the fact that its qubits can be entangled.</p><figure><a href="https://i.imgur.com/iOfl7VP.png"><img alt="" src="https://cdn-images-1.medium.com/max/600/0*xzH1PJMlcbunrSmh" /></a></figure><p>Basically, what that means is, the states of two or more qubits can be intertwined. Measuring/Changing one will instantaneously affect the other qubits which are entangled with it. How it affects the qubits depends on how they are entangled. One can set it so that if one of them is measured to be one, all of them become 1, or 0, or some 1 and some 0, depending on their use case. Entanglement is a really interesting, and mind boggling concept which can be explored further over <a href="https://www.youtube.com/watch?v=qd-tKr0LJTM">here</a>.</p><p>Now, talking about how entanglement can make quantum computers faster. Think about a conventional computer, which works with transistors. Each transistor has 3 legs, which can be connected, and can <strong><em>talk</em> </strong>to 3 other transistors, which then make up gates, or memory modules, etc. If a transistor needs to send a signal to another, which is across the CPU, the electric signal has to go through a lot of transistors. This takes time, and energy, a huge amount of which is dissipated as heat. This can be made more efficient by making the transistors smaller. But then if we make it too small, <a href="http://abyss.uoregon.edu/~js/glossary/quantum_tunneling.html">quantum tunneling</a>, makes the entire chip a conductor, thereby rendering it useless as a processing device. (Keep in mind that quantum tunneling is a totally different concept, which isn’t used in quantum computers, as of now)</p><p>Quantum computers don’t have such drawbacks. Imagine a computer, where every bit can talk to every other bit, instantaneously, or a little less than every other bit depending on the architecture. It is definite that each bit can communicate instantaneously with much more than 3 bits, which is the limit in a traditional computer. This reduces processing time by a large amount and makes tasks like searching for database values much easier.</p><h4>Conclusion</h4><p>Quantum Computers, if implemented properly, can change the field of computing radically. Researchers as of now, have been able to build systems with up to 18 fully entangled photon qubits (happened in 2018). Studies predict that within 5–10 years, quantum computers can break the RSA encryption algorithm, which is one of the strongest ones the cryptography field has seen. This will give rise to a new age of security, with quantum based cryptography, as well as the quantum internet, which will send quantum information, instead of classical. This new network will have unprecedented capabilities. Quantum computing may also change the way analog signals are processed, and the way data is stored. Searching algorithms will become much faster, and may just lead to the next giant technological leap after AI.</p><p>Stay tuned for further articles to enlighten your understanding of Quantum Computing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a31f6578e1f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/student-technical-community-vit-vellore/the-next-gen-of-computing-a31f6578e1f4">The Next Gen of Computing</a> was originally published in <a href="https://medium.com/student-technical-community-vit-vellore">Student Technical Community — VIT Vellore</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fine Tuning your Deep Learning Model]]></title>
            <link>https://medium.com/student-technical-community-vit-vellore/fine-tuning-your-deep-learning-model-36e8e94133f5?source=rss-58815670d327------2</link>
            <guid isPermaLink="false">https://medium.com/p/36e8e94133f5</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[optimization-algorithms]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Deepesh Padala]]></dc:creator>
            <pubDate>Fri, 19 Mar 2021 15:14:59 GMT</pubDate>
            <atom:updated>2021-03-19T15:14:59.742Z</atom:updated>
            <content:encoded><![CDATA[<p>While a lot of us have played around with neural networks, very few have the intuition, or know the logic behind how they work. I’m going to focus on the training algorithms. Basically what the tensorflow/pytorch library facilitates when you run “<em>model.fit(…)”</em>. You don’t really need to know this. The same way a driver doesn’t need to know how a car works to drive it. But it could prove helpful when you’re trying to optimize your model. Because each algorithm has its pros and cons, and its own hyper-parameters. Hopefully, you’ll learn how to tweak them to get a better accuracy score. (Doesn’t mean you should go and over-fit your model. Don’t do that)</p><p>What you’re basically doing by training your model is, adjusting the parameters to better emulate the required output. Each neuron in the network has some parameters associated with it, i.e., the weights and the bias. The weight is a 2D tensor (fancy word for a vector), which has a shape which is the same as the input layer, or the previous hidden layer, depending on the placement of the neuron, It can also be a 1D variable, if there’s only one hidden layer or input.</p><blockquote>For the sake of simplicity, I’ll be assuming that there’s only one input, and one hidden layer (i.e, one weight, and one bias in the neuron) while explaining the algorithms.</blockquote><p>The dot product of the weight tensor and the previous hidden layer, or the input layer, is added to the bias to this to give us the pre-activation value. This value is passed to the activation function, which introduces a non-linearity. There are many kinds of activation functions; like RELU, Leaky RELU, sigmoid, or tanh. These activation functions ensure that we can emulate any relation between the input and the output, provided, the hidden layers are complex, and the weights, and the biases are set accordingly.</p><p>There are many algorithms which can be used to update the various parameters in the neural network, the base algorithm remains the same:</p><ol><li><em>Initialize the weights and biases randomly (There are better initialization methods, but let’s stick to random initialization for this article)</em></li><li><em>Iterate over the data</em></li><li><em>Calculate the output of the neural network with the randomly chosen parameters</em></li><li><em>Calculate the loss of the neural network</em></li><li><em>Update the weights, and the biases using the update rules which will be discussed below</em></li><li><em>Repeat steps 2 to 5, till you’re satisfied with the loss</em></li></ol><h3>Terminology before we get started:</h3><ul><li>L represents the loss function, which takes in the parameters of the neural network as parameters. Normally, the loss function just takes the value the model was supposed to predict, and the actual prediction of the model, but, since the actual prediction is a function of the neural network’s parameters, we can take it to be a function of the weights and the biases. Some common loss functions are the Cross Entropy loss function, or the Root Mean Squared Error loss function. Both of these functions give us a measure of the inaccuracy. Higher the value of the function, higher the inaccuracy. Our goal while training the network is to minimize the output of this function.</li><li>θ represents the vector containing the weights and biases</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/70/1*i1A4_QyyOMJRM7pSvcgCuQ.png" /><figcaption>the vector θ</figcaption></figure><ul><li>Δθ represents the change in the vector of weights and biases, usually to reduce the loss</li></ul><h4>The difference between parameters and hyper-parameters:</h4><blockquote>Hyper-parameters are set by the user, who is training the network, examples are the learning rate, decay, momentum, etc.<br>Parameters, are trained by the learning algorithm, their training is affected by the various hyper-parameters defined. Examples are weights, biases.</blockquote><p>There are many different ways to update the parameters so as to reduce the loss, they will be discussed in depth below. The most fundamental update algorithm is the gradient descent algorithm.The more complex optimizers discussed after that is just stuff that is built upon it, for further optimization. There’s also the Newton’s optimization technique, which uses second order Taylor polynomials. But that just over-complicates stuff, both for the user, and the computer. It doesn’t provide that much of an improvement over gradient descent because, the second term is really small.So, by convention, most ML engineers, use the optimizers based on the gradient descent algorithm, and it’s inbuilt in most Deep Learning frameworks like Tensorflow, or Pytorch. Most libraries don’t have the option to use newton’s algorithm, you’ll probably have to code it yourself (it’ll be a nice exercise… or, if you just want to see how it works, you can check this out: <a href="https://diffsharp.github.io/DiffSharp/examples-newtonsmethod.html">https://diffsharp.github.io/DiffSharp/examples-newtonsmethod.html</a>).</p><h3>Gradient Descent:</h3><p>The gradient descent algorithm works by estimating the loss function using the Taylor series. We can use the formula to find a value for Δθ such that the loss reduces when we add it to the weights, and the bias.<br>The Taylor series can be used to estimate the value of f(x + Δx) if we know the value of f(x).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1FzNP-AuHBGCet6KcnNNA.png" /><figcaption>the general equation for the Taylor series</figcaption></figure><p>The same way, we can use the Taylor series to approximate the Loss function, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUAaXHb9iYREQ7S_KC_O7A.png" /></figure><p>The terms after Δθ∇θL(θ) are so small that we can equate them to 0. Finally, we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*tYDZNJZ_X2hMRrw14x0iqg.png" /></figure><p>Now, we want the new loss to be reduced. i.e., L(θ + Δθ) — L(θ) &lt; 0 . So we need to find a value of Δθ which will satisfy this inequality. Upon solving, we arrive at the conclusion that Δθ = ∇θL(θ) i.e.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*Xxs50xHXBwiE5Uay8MGDDA.png" /></figure><p>As you can see above, the correct value for Δθ is the gradient of the loss function with respect to the gradient. This also makes geometrical sense, the gradient (derivative, in 2D, is the slope of the loss function, with respect to the parameters)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*QnW-yJx3auK3FuDAZgfn9w.png" /></figure><p>This here, is an assumption of how the loss function might look as a function of θ , it doesn’t always, look like this, the shape varies depending on the data.<br>The algorithm works fine with any shape.</p><p>As you can see in the image, θ₀ is the ideal parameter, as it has the lowest loss. So no matter how we initialize our parameters, we need the learning algorithm to bring us closer to the ideal parameter(s).</p><p>If our parameters are initialized to θ₁ the slope will be positive, so, subtracting a positive number<br>from θ will bring us closer to θ₀.</p><p>Now, Imagine that our parameters are<br>initialized to θ₂, the slope at that point will be negative.<br>Subtracting a negative number from the value of θ, will,<br>again, bring us closer to θ₀, which is/are the ideal<br>parameter(s).</p><p>We multiply the gradient of the loss function with a learning rate η so as to<br>prevent the neural network from overshooting the value of the least loss. Thereby increasing accuracy</p><h4>The importance of a learning rate</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*5R1_EhC0hydsaZDoVki_Pw.gif" /></figure><p>As you can see, in the GIF on the left, if we don’t include a learning rate, the gradient descent algorithm will keep jumping about the ideal values, and never fully reach them. the inclusion of a learning rate (𝜂→0.0001, basically a really small number. It’ll dampen the effect of the subtraction and help us reach the ideal parameter in a more steady, and efficient manner).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*hSW7FUnxaxTKs4glNAcdSw.gif" /></figure><p>The introduction of a learning rate makes the gradient descent algorithm much more accurate but it takes more steps to reach there. One must set a learning rate, such that it doesn’t take too much time to reach the ideal point, and at the same time, it shouldn’t be so high that it overshoots.</p><p>The learning rate 𝜂 is known as a hyper parameter. These are values that we can tweak while training the neural network, which will affect the speed and the efficiency of the training algorithm. They are very powerful tools for people who are trying to optimize their network, and get better fits.</p><p>The Gradient Descent algorithm can be classified into 3 types depending on when you update it. The most common one is the <strong>Stochastic Gradient Descent </strong>algorithm, which updates the parameters, after calculating the loss, and finding the gradient for each data-point, and then updates the parameter. Then there’s <strong>Batch Gradient Descent</strong>, which calculates the loss for each data-point without updating the parameters, and then adds all of those gradients together, and updates the parameter. And moves on to the next epoch. (ML engineers usually make the model go over the entire data-set multiple times, so as to get higher accuracy, like how kids are forced to learn the textbook by heart by reading it like a 1000 times. But the ML guys don’t make the model go over too many epochs, because then the model will just memorize the data-set, which is called over-fitting, if this happens, the model won’t perform well, when it’s introduced to new data). Getting back to the topic on hand. The final type is the <strong>Mini-batch Gradient Descent</strong>. Which divides the entire data-set into small batches of say 64 or 128 or any random number of data-points. And then runs the batch gradient descent algorithm over it. The batch size is a hyper-parameter (more on that below). And you can use any of these types with any of the other optimizers, eg. Batch GD with ADAM, or Mini-batch with RMSProp, or Stochastic, with ADAM, or some other combination.</p><h3>Momentum based gradient Descent algorithm:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*4ilz4uC0zfHy7MA3pw8jkg.png" /></figure><p>Imagine the loss function being something like this graph on the left. And the random initializer puts us at 𝜃₁, the derivative at that point, i.e. the slope, is not zero, but it’ll still be very small. Due to this, it’ll take many steps to reach 𝜃₂ from 𝜃₁. And then it’ll proceed like normal to 𝜃₀. Which is the most accurate value. This is highly inefficient, and will waste both computing resources, and time. In order to jump over that, we are going to introduce a new hyper-parameter called acceleration (𝛾). It must be a value between 1 and 0, or else, it’ll cause chaos. This hyper-parameter is used to provide momentum to the algorithm by looking at the history of all the updates to the parameters. If many small steps are taken in the same direction, it’ll get more confident, and start taking larger steps. A change indirection will reduce the algorithm’s confidence, and make it take smaller steps till it gains confidence, and the same loop is repeated till we reach the optimal parameter (𝜃₀). This is how the momentum based gradient descent algorithm works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*X-3EKBGYGy4H_nk9jQ4EmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*5so6ohfnkNtZoxNbdgRLzQ.png" /></figure><p>Here you can see the difference between Vanilla GD and Momentum based GD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*A3N0PldG0jMVW01_keg8NQ.gif" /><figcaption>The vanilla gradient descent algorithm</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*HR6xDRl1owpmSl0-fzvXAA.gif" /><figcaption>The momentum based gradient descent algorithm</figcaption></figure><p>This is a pretty elegant solution, if you calculate the values of History for each step, you’ll notice that because of the value of 𝛾 being between 1 and 0, the older updates will start to decay, and, the algorithm will take into consideration the latest update, so that the larger steps will have a better precedent backing it, i.e., the confidence of the algorithm is justified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwlVnQ8oovvaS7912S_ChA.png" /></figure><h3>Nesterov Accelerated Gradient Descent:</h3><p>While the momentum based gradient descent algorithm is much faster, and efficient at training the neural network than the vanilla gradient descent, it still has the problem of overshooting, when it gets near the optimal point. This is because the history forces the update to go further than it has to. The algorithm isn’t capable of looking ahead before jumping. That being said, it’s still better than the vanilla gradient descent algorithm, but we can do better. In order to do so, we have the Nesterov’s Accelerated Gradient Descent or NAG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*xSp5g_tJhbyr8-e-Mm9klQ.gif" /><figcaption>The overshooting problem of the accelerated gradient descent algorithm</figcaption></figure><p>Nesterov Accelerated Gradient Descent algorithm works on the same principle of the momentum based gradient descent, but with one main difference. Instead of adding the history, and the gradient (derivative) at the same time, it first adds the history, then calculates the gradient at the new point reached, and then updates the gradient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*xV9WrpTZTmZeBTxQJiymNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*0CIDwMqz_o1CW_ZxEzItBw.png" /><figcaption>The update rule for the NAG algorithm</figcaption></figure><blockquote>This doesn’t get rid of the overshooting problem completely, but it does reduce it significantly, by making the algorithm look ahead, before jumping blindly.</blockquote><p>It makes the jump as warranted by the history, and then, calculates the gradient at the new point, and then makes the second jump. This is a more calculated acceleration, which, for more complex neural networks, saves a lot of time.</p><p>Now… Let’s say, we have a data-set where one of the parameters is mostly zero, a great example would be a medical study, where one of the symptoms is really rare. i.e the Boolean value associated with it,will be 0 most of the time. Or, say, we have another data-set, where one input is 1 much more often than the rest. For example, a feature in a data-set about lung cancer. Most patients who have cancer are probably smokers. In both these situations, the corresponding inputs are very important, (the symptom in the first case, and whether the person is a smoker or not in the lung cancer data-set).</p><blockquote>The weighs associated with the first parameter will learn very scarcely, because, the value being zero, will mean that, for most of the cases, the gradient will be zero as well. And in the second case, the weights might be over-fitted, which again, is not a good thing, because, though smoking plays a very important role in whether the person is affected or not, there are other factors which come into play as well, which the neural network may not learn, because they don’t seem to have as high a correlation.</blockquote><p>One doesn’t have to be a medical professional to know that those inputs play a huge role in study, and the weights attached to those must be trained properly.</p><h3>Adagrad:</h3><p>To overcome the aforementioned obstacle, we could try setting different learning rates for each input. i.e., for the variable in the first case, we could set a very high learning rate, and for the second one, we could set a small learning rate. But that will become very cumbersome, especially while dealing with datasets which have many features (sometimes close to 100, or 1000, or even more)… You can’t set each learning rate manually. That’s where the Adagrad algorithm comes in. We introduce a new hyper-parameter (∈), called the decay.</p><blockquote>This algorithm starts with the same learning rate for every input, and starts decaying it, in proportion to its update history. We have a new parameter (𝜈), let’s call it the adaptive learning rate.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*Cozewb5Fgn_xusTEaGGI9w.png" /><figcaption>The update rule for the Adagrad algorithm</figcaption></figure><p>Here every 𝜃, is a different parameter. And every parameter has it’s own set of adaptive learning rates. Though 𝜂, and ∈, remain the same for all of them.As you can see, the adaptive learning rate keeps getting larger with more updates, (we’re squaring them to avoid reduction in case the update is negative). And then we divide the learning rate by the root of the sim of the adaptive learning rate, and the decay. They decay plays two roles.It regulates speed at which we decay the learning rate.Moreover, it avoid errors in the initial steps, when the adaptive learning rate is (or is close to)zero, and we try to divide the learning rate by it.</p><p>The problem with Adagrad is that the subjugation of the learning rate is too extreme, because the <strong>denominator increases at a very fast pace</strong>, which renders a large part of the data-set obsolete, as the updates warranted by them will become so small, in the later stages, that it’ll be close to zero. This might lead to improper training, and will waste a lot of computing time as well. Sometimes, the neural network will not even be able to reach the optimal point, because the learning rate is so low, that it’s close to zero, and, any update that would have taken the vanilla gradient descent algorithm closer to the optimal point will have no effect in the AdaGrad algorithm. In order to get over that issue, the RMSProp algorithm was introduced. Which decays the denominator (At a slower pace, it doesn’t decay it to the level that the learning rate increases, but it decays it so that the decay to the learning rate isn’t that aggressive).</p><h3>RMSProp (RootMean Squared Propagation):</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7VlWns53rxLHnPQTi7tMQ.png" /><figcaption>The update rule for the RMSProp algorithm</figcaption></figure><p>RMSProp introduces a new hyper-parameter (𝛽), which is the decay rate for the adaptive learning algorithm. It is constrained to stay in the range (0, 1), or else the results will be catastrophic, you can figure out why by looking at the given formula.</p><h3>ADAM (Adaptive moment estimation):</h3><p>We just saw two different types of algorithms. One (Momentum based and Nesterov Accelerated) which accelerates the learning based on the cumulative history, and one(Adagrad, and RMSProp) which decays it based on the cumulative history, to prevent some weights from getting over-fitted, and some from learning very less. At first glance it might seem that these two are countering each other.One uses the history to slow down the learning, and one uses the history to increase the pace of learning. But, upon retrospection, you’ll come to realize that their effects, although on the same parameters, and using the same bit of information, are different. And we can use both in conjunction to get an algorithm that both accelerates and decelerates the learning rate, at different paces.</p><blockquote>Their effects rarely cancel out, most of the times, it accelerates it when needed, or decelerates, or it keeps the momentum constant it when the situation warrants it.</blockquote><p>The conglomeration of both these types is done by the ADAM optimizer. This takes in 4 parameters, 2 for the decay, 1 for the acceleration, and 1 for the learning rate. The formulae have been optimized further to ensure more efficient coalescence between the two different types… You can read the research paper which introduced the ADAM optimizer to get a better insight into the algorithm.</p><h3>Outro:</h3><p>After reading this, you must be really confused as to which algorithm you should use to get the best results. Well.If you’re new to this and want to learn the math before you start fitting models then.I’d suggest that you use the vanilla gradient descent algorithm,because, there’s only one hyper-parameter that you’ll have to tune. And once you master that, try the accelerated ones, and then the decay ones, and then ADAM. ADAM with Mini-batch is the staple choice for most of the machine learning engineers all around the world.There are many more algorithms out there.They’re mostly different implementations of the same idea, while some may be different. I’ve just mentioned the ones which are widely used.The general consensus there isn’t one best algorithm.As each one has its own pros and cons.I can’t think of any example, but there must be some data-set out there, where you’ll probably not require an adaptive learning rate (maybe a data-set in which the number of inputs are less?). Or something which doesn’t need you to accelerate.For some datasets, SGD yields better results, but for some others, Batch or Mini-batch works better.</p><blockquote><strong>That being said. The only way to learn is to experiment.</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36e8e94133f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/student-technical-community-vit-vellore/fine-tuning-your-deep-learning-model-36e8e94133f5">Fine Tuning your Deep Learning Model</a> was originally published in <a href="https://medium.com/student-technical-community-vit-vellore">Student Technical Community — VIT Vellore</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>