<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: karki vasagnavi</title>
    <description>The latest articles on DEV Community by karki vasagnavi (@karki_vasagnavi).</description>
    <link>https://dev.to/karki_vasagnavi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4040330%2Faff9ff79-117f-4a55-a86d-0f27771accb6.jpg</url>
      <title>DEV Community: karki vasagnavi</title>
      <link>https://dev.to/karki_vasagnavi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karki_vasagnavi"/>
    <language>en</language>
    <item>
      <title>I Finally Understood Why Neural Networks Need Activation Functions</title>
      <dc:creator>karki vasagnavi</dc:creator>
      <pubDate>Tue, 21 Jul 2026 15:06:14 +0000</pubDate>
      <link>https://dev.to/karki_vasagnavi/i-finally-understood-why-neural-networks-need-activation-functions-2cm6</link>
      <guid>https://dev.to/karki_vasagnavi/i-finally-understood-why-neural-networks-need-activation-functions-2cm6</guid>
      <description>&lt;h1&gt;
  
  
  Today I Finally Understood Why We Plot the Derivative of Activation Functions
&lt;/h1&gt;

&lt;p&gt;When I started learning Deep Learning, I thought activation functions were just mathematical equations we had to memorize.&lt;/p&gt;

&lt;p&gt;Today, while implementing &lt;strong&gt;Sigmoid, Tanh, ReLU, Leaky ReLU, and Softmax from scratch in Python&lt;/strong&gt;, I realized something much more interesting.&lt;/p&gt;

&lt;p&gt;The activation function itself is only &lt;strong&gt;half of the story&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;derivative&lt;/strong&gt; is what actually teaches the neural network how to learn.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Experiment
&lt;/h2&gt;

&lt;p&gt;I generated &lt;strong&gt;100 equally spaced values between -10 and 10&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;linspace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I implemented:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sigmoid&lt;/li&gt;
&lt;li&gt;Tanh&lt;/li&gt;
&lt;li&gt;ReLU&lt;/li&gt;
&lt;li&gt;Leaky ReLU&lt;/li&gt;
&lt;li&gt;Softmax&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the first four, I plotted &lt;strong&gt;both the activation function and its derivative&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Initially, I wondered:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Why am I plotting the derivative? Isn't the activation function enough?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After learning about &lt;strong&gt;backpropagation&lt;/strong&gt;, the answer became clear.&lt;/p&gt;




&lt;h2&gt;
  
  
  What the Activation Function Tells Us
&lt;/h2&gt;

&lt;p&gt;The activation function answers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"What output should this neuron produce?"&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, Sigmoid compresses any input into a value between &lt;strong&gt;0 and 1&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;ReLU outputs &lt;strong&gt;0&lt;/strong&gt; for negative inputs and passes positive inputs unchanged.&lt;/p&gt;

&lt;p&gt;This is what happens during the &lt;strong&gt;forward pass&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
   ↓
Weighted Sum
   ↓
Activation Function
   ↓
Prediction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What the Derivative Tells Us
&lt;/h2&gt;

&lt;p&gt;The derivative answers a completely different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"How much should this neuron change to reduce the error?"&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;During the &lt;strong&gt;backward pass&lt;/strong&gt;, the neural network computes gradients.&lt;/p&gt;

&lt;p&gt;Those gradients come directly from the &lt;strong&gt;derivatives of the activation functions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Without derivatives, the model wouldn't know how to update its weights.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prediction
     ↓
Calculate Error
     ↓
Compute Derivatives
     ↓
Update Weights
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was the moment when the plots finally made sense to me.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Biggest Observation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Sigmoid
&lt;/h3&gt;

&lt;p&gt;Beautiful S-shaped curve.&lt;/p&gt;

&lt;p&gt;But its derivative almost becomes &lt;strong&gt;zero&lt;/strong&gt; for very large positive or negative inputs.&lt;/p&gt;

&lt;p&gt;That means learning slows down because the gradients almost disappear.&lt;/p&gt;

&lt;p&gt;This is called the &lt;strong&gt;vanishing gradient problem&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Tanh
&lt;/h3&gt;

&lt;p&gt;At first glance, it looked almost identical to Sigmoid.&lt;/p&gt;

&lt;p&gt;But I noticed something important:&lt;/p&gt;

&lt;p&gt;Its output is centered around &lt;strong&gt;zero&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That small difference helps optimization because the gradients are more balanced around the origin.&lt;/p&gt;




&lt;h3&gt;
  
  
  ReLU
&lt;/h3&gt;

&lt;p&gt;The simplest graph was also the most surprising.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f(x)=max(0,x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its derivative is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0   (negative inputs)

1   (positive inputs)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This explains why ReLU trains deep neural networks much faster than Sigmoid.&lt;/p&gt;




&lt;h3&gt;
  
  
  Leaky ReLU
&lt;/h3&gt;

&lt;p&gt;ReLU has one weakness.&lt;/p&gt;

&lt;p&gt;Negative neurons completely stop learning because the derivative becomes zero.&lt;/p&gt;

&lt;p&gt;Leaky ReLU fixes that with a tiny negative slope.&lt;/p&gt;

&lt;p&gt;Instead of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Gradient = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it becomes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Gradient = 0.01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A small change mathematically—but an important one during training.&lt;/p&gt;




&lt;h3&gt;
  
  
  Softmax
&lt;/h3&gt;

&lt;p&gt;Softmax was different from the others.&lt;/p&gt;

&lt;p&gt;It doesn't transform a single value.&lt;/p&gt;

&lt;p&gt;It transforms an &lt;strong&gt;entire vector into probabilities&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;Input&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;↓&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;Output&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.114&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="mf"&gt;0.844&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="mf"&gt;0.042&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every probability depends on every other input.&lt;/p&gt;

&lt;p&gt;That explains why we usually don't visualize Softmax as a simple curve.&lt;/p&gt;

&lt;p&gt;Today I stopped thinking of activation functions as just formulas.&lt;/p&gt;

&lt;p&gt;Now I see them as two complementary ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The activation function decides what a neuron outputs.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its derivative decides how that neuron learns.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The graph explains the prediction.&lt;/p&gt;

&lt;p&gt;The derivative explains the learning.&lt;/p&gt;

&lt;p&gt;My next goal is to implement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forward propagation from scratch&lt;/li&gt;
&lt;li&gt;Backpropagation from scratch&lt;/li&gt;
&lt;li&gt;Gradient Descent&lt;/li&gt;
&lt;li&gt;A simple neural network without TensorFlow or PyTorch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I want to understand the mathematics before relying on deep learning frameworks.&lt;/p&gt;

&lt;p&gt;When you first learned neural networks, what concept changed your understanding the most—activation functions, backpropagation, or gradient descent?&lt;/p&gt;

&lt;h1&gt;
  
  
  DeepLearning #MachineLearning #Python #ArtificialIntelligence #NeuralNetworks #LearningInPublic #Bioinformatics #100DaysOfCode #DevCommunity
&lt;/h1&gt;

</description>
      <category>beginners</category>
      <category>deeplearning</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
