<?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 Kirthi Shankar Sivamani on Medium]]></title>
        <description><![CDATA[Stories by Kirthi Shankar Sivamani on Medium]]></description>
        <link>https://medium.com/@smkirthishankar?source=rss-957a65500fb5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*xSYZP76IRSJAdRDk6EfCxA.jpeg</url>
            <title>Stories by Kirthi Shankar Sivamani on Medium</title>
            <link>https://medium.com/@smkirthishankar?source=rss-957a65500fb5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 18:15:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@smkirthishankar/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[Neural Style Transfer]]></title>
            <link>https://medium.com/data-science/neural-style-transfer-4d7c8138e7f6?source=rss-957a65500fb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d7c8138e7f6</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[neural-style-transfer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Kirthi Shankar Sivamani]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 23:56:23 GMT</pubDate>
            <atom:updated>2019-08-10T08:35:41.362Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*888T0SaOdteDNcajK24TLg.png" /></figure><p>Style transfer is an excited sub-field of computer vision. It aims to transfer the style of one image onto another image, known as the content image. This technique allows us to synthesize new images combining the content and style of different images. Several developments have been made in this sub-field but the most notable initial work (neural style transfer) was done by <a href="https://arxiv.org/abs/1508.06576">Gatys et al.</a> in 2015. Some of the results I got by applying this technique can be seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*Wk9s43d4IsXbuaVhEKY1YA.png" /><figcaption>Left to right: Content image, Style image, Generated image</figcaption></figure><p>This method is fairly intuitive and this article is a simple guide to implementing neural style transfer in Pytorch and Python, along with an explanation of the method upfront. The complete code for this article <a href="https://github.com/ksivaman/Transfer-image-styling">can be found on my github</a>.</p><h4>Understanding style and content</h4><p>Neural style transfer involves transferring the style of one image onto the content of the other. What are these things?</p><p><strong><em>Content </em></strong>is literally what the image is made up of. It might be a scenery, a beach environment, a cat in a garden, a giraffe in a zoo…..etc. In your typical image classification network, this is basically the <em>label</em> of your image. Content is a high level representation of what an image is made up of. conv</p><p><strong><em>Style </em></strong>of an image involves the more intricate details: the brush strokes, the color contrast, the overall texture..etc. Say the content of the image is a dog, the way you and I draw this ‘content’ i.e. dog will be different. This difference is what the style of the image is. Your brush strokes might be thicker and vibrant and mine would be thin and dull.</p><p>These definitions are good for understanding purposes, but a more mathematical definition is needed for actually realizing the algorithm. These quantitative definitions can be obtained using a standard image classification network outlined below.</p><p>Convolutional neural networks (CNN) are popular for image classification tasks. For classification, they take in the image as the input and apply a bunch of convolution filters, max pooling, and non-linear activations to give a more dense representation the input image. I will assume that the reader is familiar with CNNs: a more comprehensive guide to CNNs is provided <a href="https://towardsdatascience.com/convolutional-neural-networks-from-the-ground-up-c67bb41454e1">here</a>.</p><p>These convolutional networks lose out on a lot of the input image information (especially the pooling layers). This lost information mostly relates to the style of the image as style is useless information when dealing with image classification tasks. By default, these classification pipelines (CNNs) are very good at representing the content of an image. The dense output representations is terms of feature maps and fully connected layers obtained out of these CNNs preserve most of the content from the input image but lose out on a lot of the style. This is because the task of the CNNs is to classify the image which naturally relates to the content of the image and not really the style. The content of an image can thus be directly defined as the output from the last convolutional feature map obtained from any pretrained image classification network.</p><p>For this article, we will use the original <strong>pretrained </strong><a href="https://arxiv.org/abs/1409.1556"><strong>VGG19</strong></a><strong> network</strong> as used by the authors originally. Thus, the content representation of an image would be the output from the last convolutional layer (block 5, layer 4) in the VGG19 network. The target image, i.e. the image we want to finally achieve, would start of as the content image, and we will iteratively modify it to incorporate the style of our style image onto this target image. However, as we proceed through this modification, we would want to preserve the content representation of the image. We would do this minimizing a loss function that represents the content loss of the two images, content image and target image. This content loss can simply be taken as the mean squared error (MSE) loss of the content representation of the two images (the VGG19 feature map output mentioned above).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*P9jSWvENwonKGtBwz-4m8g.png" /><figcaption>The content loss, the term T_subC is the target image content feature map, and the term C_subC is the content image content feature map, L_sub(Content) represents the MSE of the two. The term is divided by 2 only for obtaining lower numerical value.</figcaption></figure><p>The style on an image is a little more complicated to represent quantitatively because the network does not preserve this style information inherently. But as we did with the content image, we would come up with a style representation and minimize the style loss between the style image and target image during the iterative transformation.</p><p>The style representation is obtained using the correlation of outputs of different vectors that are a part of the convolutional feature maps. The idea here is that for different styles, the features vectors in different feature maps of different layers would be correlated in different ways. This correlation would represent the style of the image, i.e. different brush strokes, color palettes and textures. Mathematically, this correlation for a specific feature map is obtained using by multiplying the feature map with a transpose of itself. This is intuitive to understand as this multiplication would give the correlation values between each sets of vectors in the outputs from the original feature maps. The resultant matrix obtained is called the <strong>gram matrix</strong>. The overall style of the image is obtained by taking into account all the gram matrices of the 5 convolutional layers in VGG19. The style loss, similar to the content loss, is defined as the MSE of the gram matrices of the target image and the corresponding gram matrices of the style image. However, this time, there are 5 feature maps, i.e. 5 gram matrices, i.e. 5 losses for style instead of just 1 (for content). Thus, the overall style loss is taken as a linear combination of the losses from the content.</p><p>The main intuition behind generating these gram matrices for style comparison is to compare the relation between different feature maps with different contents, to see if the style of the feature maps is similar or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*pal8SCyjC66cYzrEqEkidw.png" /><figcaption>The style loss, w_subi correspond to the weights given to each of the 5 gram matrix losses, T_sub(s, i) represents the target image style feature map, S_sub(s, i) represents the style image style feature map, a is the weight hyperparameter to assign relative importance of style and content losses, L_sub(style) is the overall weighted MSE.</figcaption></figure><p>We now have our overall loss equal to the style loss plus the content loss. Using this loss as our objective function, we can start to optimize our target image (initialized as content image) using standard back-propagation and gradient descent. This is all that’s required for neural style transfer!</p><h4>The implementation</h4><p><strong>First</strong>: Include all necessary libraries</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1899c7d7a5088ab6c466cbf025498bf5/href">https://medium.com/media/1899c7d7a5088ab6c466cbf025498bf5/href</a></iframe><p><strong>Second</strong>: Initialize the pretrained VGG19 model in Pytorch and freeze all model parameters as we will not be training the network. Move model to cuda if NVIDIA GPUs are available.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b1c771b8832e38334775457df986b84/href">https://medium.com/media/2b1c771b8832e38334775457df986b84/href</a></iframe><p><strong>Third</strong>: Define a function to extract the features from the VGG19 network. The names of the layers in the <em>layers </em>dictionary are the predefined names in the Pytorch pretrained VGG19 model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc4daee185d75889d647b33b48f55af4/href">https://medium.com/media/bc4daee185d75889d647b33b48f55af4/href</a></iframe><p><strong>Fourth</strong>: Define a function to calculate the gram matrix given the feature map as a tensor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a564c441b72cf903cc3c97edd277f1e5/href">https://medium.com/media/a564c441b72cf903cc3c97edd277f1e5/href</a></iframe><p><strong>Fifth</strong>: Obtain the features for style and content images, obtain the gram matrices for the style loss, initialize target image as the style image, set style weights for the linear combination of losses from the 5 gram matrices’ MSE, set the content weight and style weight (‘<em>a’ </em>in the style loss image above) for relative importance of the two losses, select the optimizer for back-propagation and set the number of steps for iterating and modifying the target image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1ef6ba2fe7964f859e777146320617e/href">https://medium.com/media/a1ef6ba2fe7964f859e777146320617e/href</a></iframe><p><strong>Sixth</strong>: Iteratively modify the target image while keeping the loss minimal. Modify for ‘<em>steps’</em> number of steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e4fa07c973a5c6188e8372d98960de5/href">https://medium.com/media/9e4fa07c973a5c6188e8372d98960de5/href</a></iframe><p>That’s pretty much it! The complete implementation and explanation of neural style transfer. You can view the results and the whole code on <a href="https://github.com/ksivaman/Transfer-image-styling">my github</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d7c8138e7f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/neural-style-transfer-4d7c8138e7f6">Neural Style Transfer</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[The unusual effectiveness of adversarial attacks]]></title>
            <link>https://medium.com/swlh/the-unusual-effectiveness-of-adversarial-attacks-e1314d0fa4d3?source=rss-957a65500fb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1314d0fa4d3</guid>
            <category><![CDATA[adversarial-attack]]></category>
            <category><![CDATA[adversarial-example]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[adversarial-network]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kirthi Shankar Sivamani]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 15:01:18 GMT</pubDate>
            <atom:updated>2019-07-31T15:01:18.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*cSUXBnM0pYNR3dpOjwvQ1g.png" /></figure><p>There has been a growing security concern in the machine learning community with the advent of deep neural networks. People have questioned the interpretability of neural networks and naturally, questions have been raised regarding the security consequences of a deep learning model. <a href="https://arxiv.org/abs/1312.6199"><em>Adversarial attacks</em></a> are a used to find examples of images/data on which the machine learning model behaves completely randomly. Moreover, the output of the network on these adversarial examples can be crafted to be any desired output class. This later outcome is particularly disturbing.</p><p>This post talks about the most basic form of adversarial attacks and an intuition as to why they are so effective, and more importantly, why they are so hard to defend against.</p><p>Advancements in this field have yielded the development of mathematically crafted attacks on these deep neural networks that result in mis-classification of images. These are called adversarial examples. A very famous example can be seen on the top on the post where the classifier classifies the stop sign as a clock with an extremely high confidence (99%). This can clearly be a huge threat to autonomous vehicles. Other fields are also not robust to these attacks.</p><h4>How is it done?</h4><p>The discovery of constructing adversarial examples was particularly interesting. Researchers at google were using the CIFAR-10 dataset for certain image classification purpose. They tried to transform an image of truck class into the image of an airplane class. They were doing so by iteratively changing the pixel values of the truck image to resemble an airplane. They tweaked the pixel values of the input image (truck) using back-propagation by using a pretrained image classifier to incorrectly classify the input image as an airplane. By the end of this exercise, they noticed that the classifier was classifying this image as airplane with a pretty high confidence.</p><p>The had assumed that the network must have transformed the input image to resemble an airplane for the classifier to label it as one. Seems fairly straightforward, no?</p><p>However, this was not the case. The input image still very much looked like a truck. This little lucky experiment gave birth to the idea of adversarial examples and adversarial attacks.</p><h4>What makes these examples adversarial?</h4><p>The adversarial part about these types of attacks is that the predicted class looks nothing like the actual class. These tiny changes made to the input network are imperceptible to humans, making them adversarial in nature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i52xqXAc4qUn5qh7m47iKA.png" /></figure><p>The image above shows an example of an adversarial attack, wherein adding a little bit of noise completely changes the class of the image. A pig, that was correctly classified as a pig by the classifier, is now classified as an airliner after the attack. The noise added looks random to you and I, but it is infact carefully constructed to cause the network to classify the image as an ‘airliner’.</p><p>This type of attack, wherein the attacker can optimize a single image directly by using the weights and gradients of the neural network are called white box attacks. White box here signifies the attacker’s complete and open access of the neural network. These attacks are <strong>extremely</strong> hard to prevent and drive the accuracy of state of the art image classifiers down to <strong>absolute 0%</strong> on adversarial examples. More shocking however, is what follows:</p><p>These attacks have shown to be extremely effective even under not so white box (open access) settings. <em>Black box adversarial attacks </em>encompass a set of methods wherein the attacker does not have access to the network parameters. Under such cases, attackers train their own image classification (or any machine learning model) network and construct adversarial examples on their own network. These adversarial examples are <a href="https://arxiv.org/abs/1602.02697">transferred to unknown networks with a very high attacking accuracy</a>. Methods of doing so are fairly advanced but extremely interesting. I wouldn’t go into too much detail in this post but I encourage you to read more about them <a href="https://arxiv.org/pdf/1804.00097.pdf">here</a>. What I want to discuss here is why these attacks are so effectively and what makes them so hard to defend against.</p><h4>The intuition</h4><p>There have been a relatively large number of defenses for tackling the problem of adversarial attacks. However, it seems that any new defense mechanism that is proposed seems to be broken by a more advanced form of attack the following year. A good summary of CVPR papers from over the years relating to adversarial attacks and defenses has been provided in <a href="https://github.com/BardOfCodes/adv_summaries/tree/master/cvpr_2018">this repository</a>. See for yourself!</p><h4>There are a few reasons why this might happen:</h4><ol><li><strong>Attacker always has the edge</strong>. In this game of attacking and defending a machine learning model, it’s the defense that makes the first move. People come up with new adversarial defenses and equip their networks using this defense. But the black box attacker doesn’t care! For the attacker, the defense is just another part of the black box that can be broken by a smarter optimization technique or more compute. Moreover, there can be attacks created specifically to break certain defense mechanisms, but the defense has to be strong enough to fend all types of attacks (<a href="https://nicholas.carlini.com/writing/2019/all-adversarial-example-papers.html">there are so many</a>) to be truly robust.</li><li><strong>Attacking is much easier</strong>: Optimizing an input image is much easier than training a neural network. It is natural to assume that finding such a specific adversarial example in such a high dimensional space (number of pixels in an image) would be hard. But using back-propagation, this task is fairly trivial. This is because the output of a network with respect to it’s input is linear when using the ReLU activation function. “But…but…neural networks are highly nonlinear, that’s what makes them so effective…blah blah.” Yes, but the non-linearity of neural networks is with respect to its parameters, not the inputs (again, for ReLU). For the inputs, the neural network is just a piece-wise linear function. Each pixel gets multiplied by a number (weight), a number is added to it (bias) and the max of pixel value and 0 is retained. This happens over and over again. This in fact, is perfectly piece-wise linear. This linearity makes it easy to optimize the linear input space (image) to generate adversarial examples. Moreover, small changes caused in each pixel does not make a visual difference (thus, adversarial), but causes the <a href="https://en.wikipedia.org/wiki/Euclidean_distance">L-2 norm</a> of the image to change drastically for the network to misclassify it.</li><li>The third, and one of the main reasons for this is that it is extremely hard to construct a theoretical model of the process of attack on a neural network. To solve any problem, it is very important to have a good problem statement, and a theoretical model of what causes the problem. A problem statement such as ‘<em>making neural networks robust to all adversarial attacks</em>’ does sound appealing, but is extremely vague. As of now, we do not have a set model for attacks. They come in all sorts and forms; Randomly formulating defensive strategies against a few of these attacks is not a good approach. Current defenses propose a method to shut down one particular attack, but in the same process, leave the model vulnerable to 10 more. It is very important to first construct a theoretical model that encompasses all adversarial attacks, i.e. using which all attacks can be explained. This model has to be concentrated around the attacking procedure in general, and not specific forms of attack, so that it is also immune to new attacks that are developed in the future.</li></ol><h4>Final remarks</h4><p>Overall, as of today, defending adversarial attacks on neural networks is a hard problem. The linearity between the inputs and outputs and the mostly non-interpretable parameters, coupled with a vast pool of adversarial attacks are a major reason behind this.</p><p>Currently, the attacking community holds a significant advantage over the defending community in the field of adversarial examples. When we are able to find the unified logic behind all adversarial attacks, the one thing that makes them all work so effectively, we can think about creating a truly robust adversarial defense. This might take some time, but it can be done. Inspiration can be taken from fields such as differential privacy and cryptography, where the defender holds upper ground.</p><p>Thank you!</p><h4>Resources</h4><ol><li><a href="https://www.youtube.com/watch?v=CIfsB_EYsVI">https://www.youtube.com/watch?v=CIfsB_EYsVI</a></li><li><a href="https://nicholas.carlini.com/writing/2019/all-adversarial-example-papers.html">https://nicholas.carlini.com/writing/2019/all-adversarial-example-papers.html</a></li><li><a href="http://www.cleverhans.io/security/privacy/ml/2017/02/15/why-attacking-machine-learning-is-easier-than-defending-it.html">http://www.cleverhans.io/security/privacy/ml/2017/02/15/why-attacking-machine-learning-is-easier-than-defending-it.html</a></li><li><a href="https://nicholas.carlini.com/writing/2018/adversarial-machine-learning-reading-list.html">https://nicholas.carlini.com/writing/2018/adversarial-machine-learning-reading-list.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1314d0fa4d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-unusual-effectiveness-of-adversarial-attacks-e1314d0fa4d3">The unusual effectiveness of adversarial attacks</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing the right classification metric]]></title>
            <link>https://medium.com/swlh/choosing-the-right-classification-metric-3ad723218f7a?source=rss-957a65500fb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ad723218f7a</guid>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[evaluation]]></category>
            <dc:creator><![CDATA[Kirthi Shankar Sivamani]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 23:20:45 GMT</pubDate>
            <atom:updated>2019-07-26T07:58:12.170Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*gGT8RlgVpb41nm7dMEsHQw.png" /></figure><p>If you tell any data scientist that you created a machine learning model with a <strong>99.9% classification accuracy</strong>, they would approach you, take the model, hug you and deploy it…….Well, not really.</p><p>Classification is a machine learning task where you try to classify each point in your data-set into one of a given number of classes. Metrics are often used to evaluate the performance of your machine learning model. Many of the classification metrics/statistics about your data and your model can give a really incomplete picture about what’s actually happening. In this post, I break down some cases in which your machine learning model can be created to fool some of the most popular classification metrics and not really perform the actual classification task. This article is not a thorough analysis of all metrics that exist, but a simple explanation as to why it is very important to pick the correct evaluation metric specific to your task.</p><p>There are many evaluation metrics to choose from when creating a classification model in machine learning. You could choose the accuracy, precision, recall, F1 score and many others. In this article, we will focus on a binary classification task: where we try to put our data into one of two classes (let’s say negative and positive).</p><p>For this, it’s important to understand certain terminology:</p><p><strong>True positives (TP)</strong>: Positive data points that were classified as positive.<br><strong>True negatives (TN)</strong>: Negative data points that were classified as negative.<br><strong>False positives (FP)</strong>: Negative data points that were classified as positive.<br><strong>False negatives (FN)</strong>: Positive data points that were classified as negative.</p><p><em>With this base, we can go ahead and fool some popular metrics.</em></p><h4>Fooling the accuracy</h4><p>Accuracy in simple words is defined as:</p><blockquote>Of all the points that you classified, how many of them were classified correctly.</blockquote><p>Mathematically:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*CgVHLM4aOx0aDhss9EZPaQ.png" /></figure><p>Consider a task where you are predicting whether a person has a very rare disease or not. Of the 10000 people whose data you have, only 10 people have this disease. Your task is to classify each person as positive (has the disease) or negative (does not have the disease).</p><p><strong>Your model</strong>: Classify all points as negative.</p><p>Since obtaining positive samples is an extremely rare case, you can leverage this to classify all samples as negative and obtain a mouthwatering accuracy <strong>of 99.9%</strong>. (9990/10000)</p><p><strong>Is this a good model</strong>? Absolutely not. Completely useless.</p><h4>Fooling the recall</h4><p>Recall in simple words is defined as:</p><blockquote>Of all the positives in the data-set, how many did you classify as positive.</blockquote><p>Mathematically: *<em>Recall is also called sensitivity</em>*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*aHQzbiGvHx7wGxbXuw1GPQ.png" /></figure><p>Notice that in the denominator of the above formula, <strong>FN </strong>accounts for the actual positive samples as well. Now consider the same task as before of classifying patients.</p><p><strong>Your model</strong>: Classify all points as positive.</p><p>Notice how this metric does not penalize you for however many false positives you have. You can leverage this to classify all samples as positive and guarantee obtaining a <strong>100%</strong> recall. (10/10)</p><p><strong>Is this a good model</strong>? Not at all, again absolutely useless.</p><h4>Fooling the precision</h4><p>Precision in simple words in defined as:</p><blockquote>Of all the examples you classified as positive, how many were actually positive?</blockquote><p>Mathematically:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*mhS8i6IM7Jy1qGMsrhLBzw.png" /></figure><p>Fooling the precision is perhaps the most interesting case out of all, and we would do it using the exact same example as above!</p><p>This time, if we classify all data points as negative, our precision metric would be undefined (0/0) and if we classify all points as positive, our precision would be <strong>0.1% (</strong>10/10000<strong>),</strong>which is abysmal….</p><p><em>Or, is it?</em></p><p>When it comes to binary classification, i.e., classification into two categories, a really bad accuracy isn’t that bad after all because we can just flip the labels, i.e. cheating.</p><p>Consider in the same classification example but with a minor change: This time we want to classify all people who have the disease as negative and all people who don’t as positive. The logistics of the task do not change according to you and I, but this gives us a neat way to fool the precision metric.</p><p><strong>Now our new model</strong>: Classify all points as positive.</p><p>This would correctly classify all 9990 patients without the disease as positive, giving us a precision of <strong>99.9%</strong> (9990/10000).</p><p>Again, this high precision model <em>is worth nothing</em> and does not give us any meaningful information.</p><h4>Some of the other common metrics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*-0UvPEwXuOSb6BF7sDYH6Q.png" /></figure><p>If you get the gist of the article until this point, you understand that it is also not hard to fool these other metrics for certain classification cases, the details of which I will omit here.</p><h4>Conclusion</h4><p>Overall, the point of this article is not to say that classification metric are unreliable or that you shouldn’t use them. Most of the time, your results for these metrics will not be as extreme as the example given above. The main idea is to understand that you should not be extremely cheerful after obtaining a great performance, and verify that the outputs are actually meaningful. Using some of the more robust evaluations such as area under the receiver operating characteristic (AUC-ROC) gives a good starting point for evaluating most models.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ad723218f7a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/choosing-the-right-classification-metric-3ad723218f7a">Choosing the right classification metric</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The great AI debate: Interpretability]]></title>
            <link>https://medium.com/swlh/the-great-ai-debate-interpretability-1d139167b55?source=rss-957a65500fb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d139167b55</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[interpretability]]></category>
            <dc:creator><![CDATA[Kirthi Shankar Sivamani]]></dc:creator>
            <pubDate>Fri, 19 Jul 2019 03:28:19 GMT</pubDate>
            <atom:updated>2019-07-19T14:03:04.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*dWxOfV4xDqYLZXz2jhe6lQ.png" /></figure><p>Deep learning (DL) has crept into <em>almost</em> all parts of Artificial Intelligence. DL methods constitute the state of the art for almost all tasks in image processing, natural language processing, recommendation systems…etc. Consequently, as more and more of these models are being deployed, the interpretability of these models is coming into question. Deep learning is a form of machine learning based on learning hierarchical, distributed models to solve difficult AI problems. Broadly speaking, these models work extremely well for most tasks, but because they have so many learnable parameters (order of millions), it’s hard to predict what the effect of 1 single parameter, or a few of them, would be on the overall neural network.</p><p>Numerous amount of research effort has been put into discovering fancy methods of visualizing network connections, feature maps from convolutional neural nets etc. to enhance neural network interpretability. ‘<em>Feature visualization</em>’, ‘<em>Building blocks of interpretability</em>’, ‘<em>Activation atlases</em>’, and ‘<em>Visualizing memorization in RNNs</em>’ are some excellent articles on <a href="https://distill.pub/">distill</a>. These show that a lot of information about these <strong>black box</strong> models can be uncovered ‘if truly required’.</p><p>Whether this is required or not, is one of the hottest topics in contemporary AI. To throw further light on this topic, 2017 held the first ever NeurIPS debate on the topic: <strong>Interpretability is necessary in machine learning</strong>. But before I talk more about the debate, I have one fundamental question to answer, what does it mean to have an interpretable model? What makes a model understandable or explainable?</p><p>This question can be answered in several ways, but what I think people mean most often when they say ‘interpretable ML model’, they mean that the decisions of the model can be well explained by its parameters, working, and structure. Two models immediately come to my mind when I say this: Linear regression and decision trees.</p><h4><strong>Explaining linear regression predictions</strong></h4><p>Linear regression is often used to model the behavior of one target variable with respect to one or more inputs. Once the model is trained (although coefficients can be computed in a closed form), we get something like this:</p><p><strong>Target </strong>= <strong>A</strong>*<strong>Features </strong>+ <strong>B</strong></p><p>Here, A is the vector of learnt coefficients and B is the bias term. Whenever this model is used to make a prediction, it is extremely easy to see why those decisions can be explained. All one has to do is look at the coefficients! Features corresponding to higher coefficients are more important in the prediction, simple.</p><h4>Explaining decision tree predictions</h4><p>It is also fairly obvious to see why this type of model is explainable. The decision tree can be visualized and the decision taken by every node in the tree can be seen. An example of this can be seen in the image below where the target variable is number of bedrooms. The features are number of family members, marital status and salary. Any decision made by the tree can be traced back using this visualization and thus can be explained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jc0Z4GZ4YM8uTzvOkTfi3Q.png" /></figure><p>However, using ensemble methods of multiple trees and using techniques such as gradient boosting does significantly reduce this interpretability factor.</p><p>These explainable models are decent for low-scale low-cost machine learning using small datasets. However, when solving more complex problems requiring use of more data and dimensions, they significantly fall short of their ‘<em>not so interpretable</em>’ counterparts, i.e. neural networks. In general, the rough estimate of <strong>accuracy vs interpretability trade-off</strong> chart is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*WyHSz8GxqIB50pe7x7Qngg.png" /></figure><p>This makes us wonder, do we actually need our results to be explainable if we’re able to achieve better accuracy? This brings us back to the original NeurIPS 2017 debate: I<strong>nterpretability is necessary in machine learning.</strong></p><p>Both sides in the debate (<strong>2 vs 2</strong>) had excellent points by renowned people in the field of AI.</p><p><strong>FOR</strong>: Rich Caruana (Senior researcher at Microsoft)<br><strong>FOR</strong>: Patrice Simart ( Deputy Managing Director at Microsoft Research)<br><strong>AGAINST</strong>: Kilian Weinberger, Associate professor at Cornell University<br><strong>AGAINST</strong>: Yann LeCun, VP and Chief AI Scientist at Facebook</p><p><strong>AGAINST</strong>: Me, but unfortunately I wasn’t invited to the debate 😐</p><h3>FOR</h3><p>The main point was put forth using a real world example of the Pneumonia risk prediction problem. It goes like this:</p><p>A lot of pneumonia patients are looking for treatment but not all of them can be treated at once due to limitation of resources. Thus, a deep neural network is trained to distinguish between the low-risk vs the high-risk patients to determine whom to treat first. This model is <strong><em>extremely accurate</em> on the <em>training data</em></strong> and is used to carry out the predictions. After thorough inspection by experts, it is found out that the neural network has learnt something unusual from the dataset: Patients with a history of asthma are extremely low-risk and do not require immediate treatment. This sounds counter intuitive because pneumonia is a lung disease and asthmatic patients would tend to be more susceptible to it, thus being high-risk patients. After further detailed analysis, it was found out that asthmatic patients in the training data were low risk for pneumonia because they tend to get professional treatment much earlier than patients without asthma. This is because they know their lungs are not in perfect condition, and seek professional advice even if they feel something very small going wrong. But people without asthma tend to delay getting treatment until the problem becomes more grave.</p><p>So in fact, it was the <strong>time to treatment</strong> due to which asthmatic patients were low risk in the training data, and not due to the fact that they had asthma! Thus during training, the variable ‘is asthmatic or not’ acted as a proxy for ‘time-to-treatment’. Had experts not been involved to identify this obvious mistake, it would have been impossible to point this out and asthmatic patients would be neglected, leading to fatal consequences.</p><p>Overall, this shows that machine learning models tend to learn the characteristics of the training data, are not easy to interpret. High accuracy should not be mistaken for good performance. ML models’ decisions need to be explained so that such mistakes made by any model can be caught easily.</p><h3>AGAINST</h3><p>Here, the debaters did acknowledge the importance of experts in sensitive fields such as medicine, law, crime etc. However, the fact is: Even today, machine learning systems make millions of decisions per second without anyone wanted to recheck them, look at them, or interpret them. No one has the time, and users are extremely happy. Examples include recommendation engines, machine to machine translation, and to a certain extent, autonomous driving. The whole point of automated systems is to free the human mind of making trivial decisions and doing typical work (driving!), and the point of this would be futile if we instead spend this free time trying to interpret the decisions made by these models. What is important however, is the accurate and safe functioning of these systems at test time, and users of these systems to be satisfied.</p><p>Yann LeCun pointed out that when working in industry, clients would ask for models that are extremely explainable, interpretable and that they don’t care about anything else. However, when these clients were presented with two models (one being extremely explainable and 90% accurate, and the other behaving completely like a black box but having a superior accuracy of 99%), they would always choose the more accurate one. This just shows that people don’t really care about interpretability but just want some sort of reassurances from the working model.</p><p>Overall, interpretability is not important if you can prove that the model works well in the condition it is supposed to work in (i.e. test time). Good testing procedures such as A/B testing, gradually increasing deployment etc. are useful to confirm the ability of a model to perform. Moreover, neural networks are <em>not really</em> black boxes and a thorough sensitivity analysis can be done to look at the effect of all variables. The analysis might not be as explicit as, “This coefficient is extremely large, this feature must be important”, but it can be done.</p><p>As a final thought, I also feel that interpretability is overrated, and is just a measure of reassurance that people seek before using the ML model. However, I do concede that certain domains such as law and medicine require expert analysis of ML models before being used at a large scale. This too will not be required when AI reaches a stage when models are <em>intelligent enough</em> to be able to interpret latent meanings in training data (such as variables acting as proxies for other missing variables in the example given in the <strong>FOR </strong>section).</p><h3>Resources</h3><ol><li><a href="https://www.youtube.com/watch?v=93Xv8vJ2acI">https://www.youtube.com/watch?v=93Xv8vJ2acI</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d139167b55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-great-ai-debate-interpretability-1d139167b55">The great AI debate: Interpretability</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Back-Propagation simplified]]></title>
            <link>https://medium.com/data-science/back-propagation-simplified-218430e21ad0?source=rss-957a65500fb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/218430e21ad0</guid>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[backpropagation]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kirthi Shankar Sivamani]]></dc:creator>
            <pubDate>Sun, 14 Jul 2019 01:18:30 GMT</pubDate>
            <atom:updated>2019-07-31T16:18:18.933Z</atom:updated>
            <content:encoded><![CDATA[<p>This post explains what is probably the most basic implementation of back-propagation. I assume that the reader has a <em>solid theoretical understanding</em> of back-propagation (+ gradient descent) and is just confused about how to start with implementing it.</p><p>Back-prop is one of those algorithms that is somewhat easy to understand but much harder to actually code. Often times, you just understand the math behind it, feel comfortable (it’s not that hard if you understand basic multivariate calculus and linear algebra) and move on to training neural nets using pre-defined versions of back-prop. And why wouldn’t you? Essentially all deep learning frameworks (TensorFlow, Chainer, Caffe…etc.) come with back-prop already implemented. With fancy things like Automatic Differentiation (PyTorch!), there is basically nothing you have to do as the user. And this is where half of the problems arise when training your own neural networks. One simply assumes that inter-connecting any combination of layers is cool. Using back-prop, gradients will magically flow backward and yield the next state of the art predictor!</p><p>But sadly, that doesn’t happen too often. Which is why it is critical to understand back-prop. For me personally, since I implemented back-prop myself, I have had much higher success rate of getting my neural nets to do what I want them to do in the first few attempts. Andrej Karpathy has an excellent <a href="https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b">article</a> about this you should definitely look at. Enough convincing, let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*DcLWqOojI1b9jzQaLibUkQ.png" /><figcaption>Summary of back-prop at one particular neuron (<a href="https://www.youtube.com/watch?v=i94OvYb6noo">Source</a>)</figcaption></figure><p>The image above explains the algorithm from the perspective of one neuron. Here, <strong>L </strong>is the cost value for the predictions made in the previous forward pass. The gradient(<strong>δL/δz</strong>) is received by this neuron from layers forward of it in the network. We get an idea from this image that the local gradients(<strong>δz/δx</strong> and <strong>δz/δy</strong>), outputs(<strong>z</strong>), and activations(<strong>x </strong>and <strong>y</strong>) for each neuron need to be stored in memory for later calculation. These are used to calculate the gradients(<strong>δL/δx</strong> and <strong>δL/δy</strong>) to pass backward that will be received by neurons of previous layers. Exactly how this is done is given in sections below.</p><p>The entire code for this post can be found <a href="https://github.com/ksivaman/simple-net">here</a>. The important parts are explained in this article and rest of it is just boilerplate code to get everything running. We will create a simple feed forward neural network with only linear layers (+ activations) to classify whether a bank note is counterfeit or not. We will use <a href="http://archive.ics.uci.edu/ml/datasets/banknote+authentication">this</a> data-set having 4 features based on the image of the note: variance of wavelet, skewness of wavelet, curtosis of wavelet, and entropy. The target is 0 or 1 based on whether the note is counterfeit or not. There are a total of <strong>1372 observations </strong>in this dataset that can be split into training and validation sets.</p><p>The variable names are self explanatory and a prefix of ‘<em>d_’ </em>in front of a variable indicates that it stores the derivative of the variable following the ‘<em>d_</em>’ (‘<em>d_this’ </em>stores the gradient of ‘<em>this’</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*drNTpW_cO1JZGEzw8NcGyQ.png" /><figcaption>Fig 1: A simple linear feed-forward network we will use (<a href="https://pdfs.semanticscholar.org/f7fe/6ef2feff4eb014fedc5a6a5ff14a94892f81.pdf"><strong>Source</strong></a><strong>)</strong></figcaption></figure><p>The image above shows the network we will use for our classification. The 4 inputs correspond to the features, and the output is the prediction of the classifier (0 or 1). The hidden layer will be activated by relu and the output layer will be activated by the sigmoid (to get class probabilities).</p><h3>Parameter Initialization</h3><p>The first thing before getting started is to initialize the values of parameters for our network. The weights and biases for different layers will be saved as key value pairs in separate dictionaries. This is fairly basic and can be done using the following code snippet:</p><ul><li>The parameter ‘<em>layers’</em> is a list containing integer values for number of neurons in each layer. So according to the architecture in Fig 1, this will be a list of 4, 5, and 1 (default).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/025a58727745a6a58641b834693cafc0/href">https://medium.com/media/025a58727745a6a58641b834693cafc0/href</a></iframe><h3>Cost function and Metrics</h3><p>The next thing to do is formulate the loss function and find out a metric to check the performance of our network at each forward pass. We will use the simple binary cross entropy loss as the cost function and accuracy as the evaluation metric. These are fairly easy to calculate and can be done the following way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/760d61f8d973ffaeaa496ce36836534b/href">https://medium.com/media/760d61f8d973ffaeaa496ce36836534b/href</a></iframe><p>“y_pred ” are the predicted classes and “<em>train_Y”</em> is the ground truth.</p><p><em>“get_class_from_probs</em> ”is a utility function used to get predicted class values (0 or 1) instead of the probabilities obtained from the sigmoid function.</p><h3>Activations and Derivatives</h3><p>Simple utility functions to calculate the activations and their derivatives is important. In our case, we will have 4 such functions: Sigmoid, Relu, derivative of sigmoid, and derivative of relu. This can be done using the code snippet below. Note that the derivative of relu is just a unit step function<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93c136f5102752cd5ee1d16ed3f99f43/href">https://medium.com/media/93c136f5102752cd5ee1d16ed3f99f43/href</a></iframe><p>The ‘<em>d_init</em>’ parameter is the initialization gradient. For the last layer, this value would be 1, and the value would be a cumulative product of gradients up to the current layer for all previous layers.</p><h3>Forward Pass</h3><p>This is the straightforward part, where we carry out the matrix multiplications, add the biases at each stage, run the outputs through an activation function, and get to our final result. The code is divided into two parts: one-layer forward pass and the entire forward pass. The code for one layer forward pass is given below. The parameters for a layer consisting of n neurons:</p><ul><li><em>input_activations</em>: Represents the activation values coming into this layer. Is a matrix of dimensions (n, x), where x is the number of training data samples (1097 in our case, using an 80% train split from a total of 1372 observations)</li><li><em>weights</em>: Weight matrix for this layer. Is a matrix of dimensions (m, n), where m is the number of neurons in the next layer.</li><li><em>bias</em>: Bias matrix for this layer. Is a matrix of dimensions (m, 1)</li><li><em>activation</em>: The activation for this layer, can either be a sigmoid or a relu (in our case).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4fe0c7e0caac65dbd84f1b575ce5979/href">https://medium.com/media/e4fe0c7e0caac65dbd84f1b575ce5979/href</a></iframe><p>Next step is to create the entire forward pass using the previous function, the code for which is given below. The key here is to <strong>save the values of the outputs</strong> from this layer in dictionaries, both before and after passing it through the activation function. These would be required when passing gradients backward using the chain rule. The parameters are:</p><ul><li><em>train_X</em>: Training data. Is a matrix of dimensions (n, x), where n is the number of neurons in the first layer while x is the number of training data samples.</li><li><em>params_w</em>: Dictionary storing the weight matrices of different layers along with their corresponding keys. The keys are of the form ‘weight1’, ‘weight2&#39;…and the values are the matrices themselves.</li><li>params_b: dictionary storing the weight matrices of different layers along with their corresponding keys. The keys are of the form ‘bias1’, ‘bias2’…and the values are the matrices themselves.</li><li><em>layers</em>: Same as in <strong>init</strong> in Parameter Initialization section.</li><li>activate: Activation values of the different hidden layers and the output layer. For our case, the default is what we’ll use, ‘R’ for relu (hidden layer) and ‘S’ for sigmoid (output layer).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44f7a06c3ce287cdf5daeab7748f74e3/href">https://medium.com/media/44f7a06c3ce287cdf5daeab7748f74e3/href</a></iframe><h3>Backward Pass</h3><p>This is the most tricky part here. This too, like the forward pass, can be broken down to single layer pass, and an overall backward pass. The single layer backward pass involves a few steps:</p><ul><li>Find out the activation function used in the current layer (lines 7-12).</li><li>Calculate the local gradient using the cumulative gradient passed down until this point and the output values from this layer (line 15). (Remember saving them in dictionaries earlier?)</li><li>Calculate the gradient of weight matrix for current layer (line 18).</li><li>Calculate the gradient of bias matrix for current layer (line 21).</li><li>Calculate the gradient of activations coming into this layer matrix for current layer (line 24).</li></ul><p>Notice the use of <em>chain rule</em> for calculation of gradients. The code snippet is given below with the following parameters:</p><ul><li><em>curr_grad</em>: Current cumulative gradients passed down to this layer from all layers ahead of it. Is a matrix of shape(n, x), where n is the number of neurons in the current layer, and x is the number of training samples.</li><li><em>curr_weight</em>: A matrix of weights for transformation from previous layer to current layer. Is a matrix of shape (n, p), where p is number of neurons in the previous layer.</li><li><em>curr_bias</em>: A matrix of biases for transformation from previous layer to current layer. Is a matrix of shape (n, 1).</li><li><em>curr_out</em>: The output matrix during forward propagation from this layer. Is a matrix of shape (n, x).</li><li><em>prev_act</em>: The activations coming into this layer during forward propagation. Is a matrix of shape (p, x).</li><li><em>activation</em>: The type of activation used by this layer. (‘R’: relu, ‘S’:sigmoid)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d31ee0b49ba90cf92abfa08ce2ffc17/href">https://medium.com/media/1d31ee0b49ba90cf92abfa08ce2ffc17/href</a></iframe><p>Now that we have the means to compute gradients from one layer, we can easily back-prop through the network by repeatedly using this function for all layers in our feed forward neural network (in reverse order obviously). The gradients calculated from one_layer_backward_pass function are saved in the ‘<em>gradients</em>’ dictionary. These gradients will later be used to update the parameters (weights + biases) while performing gradient descent.</p><p>Note: The gradient of the loss function with respect to the predictions made by the network has to be calculated outside the main loop. This has been done in line 10 of the snippet below. It is trivial to come up with this formula by taking the derivative of the ‘<em>cross_entropy_loss </em>’ function (parameterized by predictions and actual labels) with respect to the predictions ‘<em>y_pred’</em>.</p><p>The parameters are:</p><ul><li><em>y_pred</em>: An array of predictions for the target value made by the network during the forward pass. An array of length n, where n is the number of training samples.</li><li><em>train_Y</em>: The labels for the training data (0 or 1). An array of length n.</li><li><em>activation_dict</em>: A dictionary storing activations coming into all layers. Indexed according to keys of of the form ‘act0’, ‘act1’, act2&#39;…for all layers <strong>but the last</strong>.</li><li><em>output_dict</em>: A dictionary storing outputs from all layers. Indexed according to keys of of the form ‘out1, ‘out2’, out3&#39;…for all layers <strong>but the first</strong>.</li><li><em>params_w, params_b, layers, activate</em>:<em> </em>These parameters have the same meaning as in the function <em>forward_pass</em> in the Forward Pass section.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaf5b1469bcc2ba3e02368f6104b32a7/href">https://medium.com/media/aaf5b1469bcc2ba3e02368f6104b32a7/href</a></iframe><p>The important things to note here:</p><ul><li>Reverse iteration of layers in backward pass.</li><li>Activations come into a layer, outputs go out from it. Output of one layer is the activation for the next. For this reason, activation indices in the ‘<em>activation_dict</em>’ go from 0 to n-2, and output indices in ‘<em>output_dict</em>’ go from 1 to n-1 for an n-layered network.</li></ul><h3>Parameter Updates and Training</h3><p>The hard part is done! Now all we have to do is update the parameters and train the network using gradient descent. In this toy example, we will use batch gradient descent, but you’re better off using mini-batch gradient descent for efficiency when training data is abundant. The weights and biases are updated using the following function. The parameters are:</p><ul><li><em>params_w</em>, <em>params_b</em>, <em>layers</em>: These parameters have the same meaning as in the function <em>forward_pass</em> in the Forward Pass section.</li><li><em>gradients</em>: The dictionary containing gradients of biases and weights, using which they are updates. This is calculated in the ‘<em>backward_pass’ </em>function. The keys are ‘d_weight1’, d_weight2&#39;… etc. and ‘d_bias1’, ‘d_bias2’..etc.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/148657ad11d64a357da908b99bc07fa1/href">https://medium.com/media/148657ad11d64a357da908b99bc07fa1/href</a></iframe><p>The network can finally be trained using the following steps:</p><ul><li>Initialize the parameters.</li><li>Complete one forward pass.</li><li>Calculate the loss.</li><li>Complete one backward pass.</li><li>Update the parameters.</li></ul><p>Here is the code for training the network:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0911ac54870db8d862d187c912d021b/href">https://medium.com/media/b0911ac54870db8d862d187c912d021b/href</a></iframe><p>That’s it! It’s really that simple. Now all left to do is test our network on unseen data. For a more thorough understanding, it is important to try it yourself, run the math and calculations in your head and look at the dimensions of gradients, weights, and biases at different stages of the network. It is key not to get confused between back-prop and gradient descent. Back-prop is just used to calculate gradients at various stages of the network whereas gradient descent uses these gradients to update the parameters of the network. I am omitting the testing code here (essentially just one forward pass) but you can look at my full implementation <a href="https://github.com/ksivaman/simple-net">here</a> (including train-validation splits and testing the network). Thank you for making it all the way through!</p><h3>Other resources</h3><ul><li><a href="https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b">https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b</a></li><li><a href="https://www.youtube.com/watch?v=i94OvYb6noo">https://www.youtube.com/watch?v=i94OvYb6noo</a></li><li><a href="https://towardsdatascience.com/lets-code-a-neural-network-in-plain-numpy-ae7e74410795">https://towardsdatascience.com/lets-code-a-neural-network-in-plain-numpy-ae7e74410795</a></li><li><a href="https://www.cs.cmu.edu/~mgormley/courses/10601-s17/slides/lecture20-backprop.pdf">https://www.cs.cmu.edu/~mgormley/courses/10601-s17/slides/lecture20-backprop.pdf</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218430e21ad0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/back-propagation-simplified-218430e21ad0">Back-Propagation simplified</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>