<?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: Ali Raza</title>
    <description>The latest articles on DEV Community by Ali Raza (@ali_raza_1ce2540f37e01a91).</description>
    <link>https://dev.to/ali_raza_1ce2540f37e01a91</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%2F4031383%2Fc036ff88-bf13-4e5a-9b0d-5f1e2f7ed3ef.jpg</url>
      <title>DEV Community: Ali Raza</title>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ali_raza_1ce2540f37e01a91"/>
    <language>en</language>
    <item>
      <title>Tutorial: Padding &amp;amp; Edge Detection in CNNs (Hands-on)</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 02 Aug 2026 11:35:44 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/tutorial-padding-amp-edge-detection-in-cnns-hands-on-3fe</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/tutorial-padding-amp-edge-detection-in-cnns-hands-on-3fe</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Futdm4gh46pgm6f87rj63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Futdm4gh46pgm6f87rj63.png" alt=" " width="800" height="498"&gt;&lt;/a&gt;&lt;br&gt;
This is a hands-on tutorial that builds directly on the convolution and padding concepts from the previous article. We'll walk through &lt;strong&gt;normalizing filter output values&lt;/strong&gt; and applying &lt;strong&gt;edge-detection filters&lt;/strong&gt; step by step.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Normalizing Output Values (Min-Max)
&lt;/h2&gt;

&lt;p&gt;When you apply a filter to an image, the resulting values aren't always valid pixel intensities. For instance, a convolution operation might produce values like &lt;code&gt;-4&lt;/code&gt; or numbers greater than &lt;code&gt;255&lt;/code&gt; — but a pixel can only be between &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;255&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is where a &lt;strong&gt;min-max function&lt;/strong&gt; comes in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if value &amp;lt; 0   → set to 0
if value &amp;gt; 255 → set to 255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This clips the output back into a valid image range (this is conceptually very similar to what a &lt;strong&gt;ReLU&lt;/strong&gt; activation does later in the network, followed by clipping at the maximum pixel value).&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Edge Detection Filters
&lt;/h2&gt;

&lt;p&gt;Two of the most fundamental 3×3 filters in image processing are used to detect &lt;strong&gt;horizontal&lt;/strong&gt; and &lt;strong&gt;vertical edges&lt;/strong&gt; — this is essentially a simplified version of the classic &lt;strong&gt;Sobel operator&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Horizontal Edge Filter
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Vertical Edge Filter
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;When either of these filters slides across an image, it produces a strong response wherever there's a sharp change in pixel intensity in that direction — which is exactly what an "edge" is: a sudden jump in brightness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Applying Padding in Practice
&lt;/h2&gt;

&lt;p&gt;Continuing from our padding discussion — say we take a 6×6 grayscale image and want to preserve its size after convolution with a 3×3 filter. We calculated earlier that we need &lt;code&gt;p = 1&lt;/code&gt; (one row/column of zero-padding on every side).&lt;/p&gt;

&lt;p&gt;This transforms our 6×6 image into an &lt;strong&gt;8×8 padded image&lt;/strong&gt; before the filter is applied:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Zeros are added to the top and bottom rows.&lt;/li&gt;
&lt;li&gt;Zeros are added to the left and right columns.&lt;/li&gt;
&lt;li&gt;The original 6×6 image data sits untouched in the center.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the 3×3 filter now slides across this 8×8 padded image, the output comes back out as &lt;strong&gt;6×6&lt;/strong&gt; — matching the original size, with every pixel (including the edges) properly represented in the output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting It All Together
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Take the raw image (grayscale or RGB).&lt;/li&gt;
&lt;li&gt;Apply zero-padding based on your desired output size.&lt;/li&gt;
&lt;li&gt;Slide the filter (e.g., horizontal or vertical edge detector) across the padded image, computing the convolution at each step.&lt;/li&gt;
&lt;li&gt;Apply min-max clipping to keep pixel values within the valid &lt;code&gt;0–255&lt;/code&gt; range.&lt;/li&gt;
&lt;li&gt;The result is a &lt;strong&gt;feature map&lt;/strong&gt; that highlights edges — the very first building block CNNs use to eventually recognize full objects.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the foundation every CNN architecture builds on — stacking many of these convolution + padding + activation steps to go from raw pixels to full image understanding.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is Part 3 (Tutorial) of a CNN fundamentals series, based on lecture notes from a Deep Learning course.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>cnn</category>
      <category>computervision</category>
    </item>
    <item>
      <title>What Is Convolution? Breaking Down How CNNs Process Images</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 02 Aug 2026 11:30:54 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/what-is-convolution-breaking-down-how-cnns-process-images-21g</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/what-is-convolution-breaking-down-how-cnns-process-images-21g</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv1llrn8ues32m6sv5xhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv1llrn8ues32m6sv5xhu.png" alt=" " width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the previous article, we saw why CNNs are inspired by the human visual cortex. Now let's get into the actual mechanics: &lt;strong&gt;what does "convolution" mean, and how does a CNN process an image pixel by pixel?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Images Are Just Numbers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Grayscale images
&lt;/h3&gt;

&lt;p&gt;A grayscale (black &amp;amp; white) image is really just a grid of numbers. Each cell in the grid is a &lt;strong&gt;pixel&lt;/strong&gt;, and its value ranges from &lt;strong&gt;0 to 255&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; → completely black&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;255&lt;/code&gt; → completely white&lt;/li&gt;
&lt;li&gt;Anything in between → a shade of gray&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a small 4×4 grayscale image might look like a matrix of pixel intensities. You can resize this grid — reduce or increase the number of pixels — depending on how much detail you want to keep.&lt;/p&gt;

&lt;h3&gt;
  
  
  Color images
&lt;/h3&gt;

&lt;p&gt;A color image adds two more layers on top: &lt;strong&gt;Red, Green, and Blue (RGB)&lt;/strong&gt;. So instead of a single 2D grid, a color image is a 3D volume — for example, a &lt;strong&gt;6×6×3&lt;/strong&gt; image means 6×6 pixels across &lt;strong&gt;3 color channels&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Convolution Operation
&lt;/h2&gt;

&lt;p&gt;Convolution is the process of sliding a small matrix — called a &lt;strong&gt;filter&lt;/strong&gt; or &lt;strong&gt;kernel&lt;/strong&gt; (commonly 3×3) — across the image, and at each position, performing an element-wise multiplication followed by a sum. The result becomes one pixel in the &lt;strong&gt;output feature map&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is how a CNN detects patterns: different filters are designed (or learned) to highlight specific features like edges, corners, or textures. When you apply a filter across a grayscale image, you get a new, smaller grid where certain regions light up — these are the features the filter was designed to catch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem: Shrinking Output
&lt;/h2&gt;

&lt;p&gt;Here's something important to notice: after applying a filter, the output is &lt;strong&gt;smaller&lt;/strong&gt; than the input. There's a formula for this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output size = n − f + 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;n&lt;/code&gt; = input size (e.g., 6 for a 6×6 image)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;f&lt;/code&gt; = filter size (e.g., 3 for a 3×3 filter)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So a 6×6 image with a 3×3 filter gives a 4×4 output — we've lost information at the borders! Pixels at the edges of the image get "seen" by the filter far fewer times than pixels in the center.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix: Padding
&lt;/h2&gt;

&lt;p&gt;To prevent this loss of information, we use &lt;strong&gt;padding&lt;/strong&gt; — adding extra rows and columns (usually filled with zeros) around the border of the image before applying the filter.&lt;/p&gt;

&lt;p&gt;There are two common ways to fill padding:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fill with the value of the neighboring pixel.&lt;/li&gt;
&lt;li&gt;Fill with &lt;strong&gt;zero&lt;/strong&gt; — this is the standard, best-practice approach.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With padding added, the formula becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output size = n + 2p − f + 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;p&lt;/code&gt; is the padding amount. Let's verify with an example: &lt;code&gt;n = 6&lt;/code&gt;, &lt;code&gt;f = 3&lt;/code&gt;, &lt;code&gt;p = 1&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6 + 2(1) − 3 + 1 = 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output stays &lt;strong&gt;6×6&lt;/strong&gt; — exactly the same as the input! No information is lost, because padding adds new rows and columns on the top, bottom, left, and right sides of the original image before the filter slides over it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coming Up Next
&lt;/h2&gt;

&lt;p&gt;In the next (tutorial) article, we'll actually build &lt;strong&gt;edge-detection filters&lt;/strong&gt; — horizontal and vertical — and see step by step how padding is applied in practice, along with how output pixel values are normalized back into a valid 0–255 range.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is Part 2 of a CNN fundamentals series, based on lecture notes from a Deep Learning course.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>cnn</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>CNN vs Human Brain — Why Convolutional Neural Networks Learn to "See"</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 02 Aug 2026 11:22:13 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/cnn-vs-human-brain-why-convolutional-neural-networks-learn-to-see-311d</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/cnn-vs-human-brain-why-convolutional-neural-networks-learn-to-see-311d</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv5pql04i6gr6h04qjs74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv5pql04i6gr6h04qjs74.png" alt=" " width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  From ANN to CNN
&lt;/h2&gt;

&lt;p&gt;In our earlier lectures, we studied &lt;strong&gt;Artificial Neural Networks (ANNs)&lt;/strong&gt; and how they solve two broad categories of problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classification&lt;/strong&gt; — for example, predicting whether a tumor is benign or malignant (breast cancer detection).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regression&lt;/strong&gt; — for example, predicting a continuous value like an air quality index.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those problems mostly dealt with structured, tabular data. Starting from this lecture, we shift focus to a different kind of data: &lt;strong&gt;images&lt;/strong&gt;. This is where &lt;strong&gt;Convolutional Neural Networks (CNNs)&lt;/strong&gt; come in — a specialized type of neural network built for &lt;strong&gt;image classification&lt;/strong&gt; and &lt;strong&gt;object detection&lt;/strong&gt;, the core tasks of computer vision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why "Convolutional"? A Brain-Inspired Design
&lt;/h2&gt;

&lt;p&gt;Here's the interesting part: CNNs aren't just an arbitrary architecture — they take direct inspiration from how the human brain processes visual information.&lt;/p&gt;

&lt;p&gt;At the back of our brain sits a region called the &lt;strong&gt;cerebral cortex&lt;/strong&gt;. Within it lies the &lt;strong&gt;visual cortex&lt;/strong&gt; — the part specifically responsible for interpreting what our eyes see. When light hits our retina, the signal isn't processed all at once. Instead, it passes through &lt;strong&gt;multiple layers&lt;/strong&gt; of neurons, each layer responsible for extracting a specific kind of information — edges, shapes, textures, and eventually complete objects.&lt;/p&gt;

&lt;p&gt;CNNs mimic this exact idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An image is broken down into smaller regions.&lt;/li&gt;
&lt;li&gt;Each &lt;strong&gt;layer&lt;/strong&gt; of the network is trained to detect specific patterns within those regions (like edges in earlier layers, and complex shapes/objects in deeper layers).&lt;/li&gt;
&lt;li&gt;The layers work together, each one confirming and refining what the previous layer detected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Big Picture
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Human Brain&lt;/th&gt;
&lt;th&gt;CNN&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cerebral Cortex&lt;/td&gt;
&lt;td&gt;Full Network&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visual Cortex&lt;/td&gt;
&lt;td&gt;Convolutional Layers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple processing layers of neurons&lt;/td&gt;
&lt;td&gt;Multiple convolutional + pooling layers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Detects edges → shapes → objects&lt;/td&gt;
&lt;td&gt;Detects edges → patterns → objects&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This biological analogy is the reason CNNs are so effective at image-related tasks — they don't look at an entire image as one giant block of numbers. Instead, just like our visual cortex, they scan it piece by piece, layer by layer, building up understanding gradually.&lt;/p&gt;

&lt;p&gt;In the next article, we'll get hands-on and answer the core question: &lt;strong&gt;what is convolution, mathematically?&lt;/strong&gt; We'll break down grayscale images, RGB channels, filters, and how a CNN actually "reads" pixels.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is Part 1 of a CNN fundamentals series, based on lecture notes from a Deep Learning course.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>neuralnetworks</category>
      <category>ai</category>
      <category>humanmind</category>
    </item>
    <item>
      <title>Batch, Stochastic, and Mini-Batch Gradient Descent: What's Actually Different</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Mon, 20 Jul 2026 11:51:04 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/batch-stochastic-and-mini-batch-gradient-descent-whats-actually-different-42pa</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/batch-stochastic-and-mini-batch-gradient-descent-whats-actually-different-42pa</guid>
      <description>&lt;p&gt;Part 13 of my "revisiting my AI/ML notes" series. Every post in this series so far used gradient descent conceptually, without asking a fairly important question: when we compute the gradient of the loss, how much of the data are we actually using at once? The answer has three different flavors, and today almost nobody uses the simplest one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Batch Gradient Descent
&lt;/h2&gt;

&lt;p&gt;The most direct approach: compute the gradient of the loss using &lt;strong&gt;every single data point&lt;/strong&gt; in the training set before making one weight update.&lt;/p&gt;

&lt;p&gt;dLoss/dw = gradient computed across all n data points&lt;br&gt;
This gives a smooth, accurate estimate of the true gradient direction on every step. The catch is cost: for a large dataset, one single weight update requires a full pass over all the data, which makes training painfully slow and memory-hungry at scale.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft2yffwesauxskmpbkdw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft2yffwesauxskmpbkdw6.png" alt=" " width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stochastic Gradient Descent (SGD)
&lt;/h2&gt;

&lt;p&gt;The opposite extreme: compute the gradient using just &lt;strong&gt;one data point at a time&lt;/strong&gt;, and update the weights immediately.&lt;/p&gt;

&lt;p&gt;dLoss/dw = gradient computed from a single data point&lt;/p&gt;

&lt;p&gt;This is fast per step and needs almost no memory, but the path toward the minimum is noisy — each individual data point gives a rough, sometimes-misleading estimate of where the true gradient points, so the weight trajectory jitters around rather than moving smoothly downhill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mini-Batch Stochastic Gradient Descent
&lt;/h2&gt;

&lt;p&gt;The practical middle ground, and what's actually used almost everywhere today: compute the gradient over a small &lt;strong&gt;batch&lt;/strong&gt; of &lt;code&gt;k&lt;/code&gt; data points at a time.&lt;/p&gt;

&lt;p&gt;dLoss/dw = gradient averaged over k data points, where 1 &amp;lt; k &amp;lt; n&lt;/p&gt;

&lt;p&gt;This captures most of batch gradient descent's stability while keeping most of SGD's speed and memory efficiency — and it maps naturally onto GPU-parallelized computation, which is a big part of why it's the default in virtually every modern deep learning framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  The loss landscape isn't always a simple bowl
&lt;/h2&gt;

&lt;p&gt;All three variants are trying to reach the same destination: a point where the gradient is zero. But that destination isn't guaranteed to be unique or even reachable in one obvious direction, which depends on the shape of the loss function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;convex&lt;/strong&gt; function has exactly one minimum — the global minimum — and no matter where you start, gradient descent reliably finds it.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;non-convex&lt;/strong&gt; function — which is what most deep networks actually have — can have multiple local minima and &lt;strong&gt;saddle points&lt;/strong&gt; scattered across the loss surface. Critically, the gradient is exactly zero at &lt;em&gt;all&lt;/em&gt; of these points, not just the true global minimum, which means an optimizer can genuinely get stuck somewhere that only looks optimal locally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is precisely why the choice between batch, SGD, and mini-batch matters beyond just speed: the noise in SGD and mini-batch updates, which looks like a downside on a simple convex bowl, actually helps the optimizer bounce out of shallow local minima and saddle points on the messier, non-convex surfaces real networks actually have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;"Gradient descent" isn't one algorithm with one fixed behavior — it's a family, and the choice of how much data goes into each gradient estimate directly trades off convergence speed, memory use, and the ability to escape bad local minima. Mini-batch SGD winning out as the default isn't an accident; it's the version that best fits how modern hardware and modern (non-convex) loss surfaces actually behave.&lt;/p&gt;

&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq1cvk66oir2banxkuv56.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq1cvk66oir2banxkuv56.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgd7zabt06d4t1p3k0gr7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgd7zabt06d4t1p3k0gr7.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwwyumx5z5dcgiu5bbvhu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwwyumx5z5dcgiu5bbvhu.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>neuralnetworks</category>
      <category>gradientdescent</category>
    </item>
    <item>
      <title>Weight Initialization: Why Random Isn't Random Enough</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Mon, 20 Jul 2026 11:47:43 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/weight-initialization-why-random-isnt-random-enough-3dl9</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/weight-initialization-why-random-isnt-random-enough-3dl9</guid>
      <description>&lt;p&gt;Part 12 of my "revisiting my AI/ML notes" series. Every post so far in this series has assumed weights already have reasonable values. This one covers the step before any of that: how weights get their starting values in the first place, and why that choice matters more than it sounds like it should.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why initialization isn't a minor detail
&lt;/h2&gt;

&lt;p&gt;There are a few hard constraints on a good initialization scheme:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Weights should be &lt;strong&gt;small&lt;/strong&gt;, but not vanishingly small — too small, and the earlier posts in this series on vanishing gradients explain exactly what goes wrong.&lt;/li&gt;
&lt;li&gt;Weights should &lt;strong&gt;not all be the same value&lt;/strong&gt;. If every neuron in a layer starts identical, they all compute the same gradient during backpropagation and stay identical forever — the layer never actually differentiates into useful, distinct feature detectors.&lt;/li&gt;
&lt;li&gt;Weights need &lt;strong&gt;good variance&lt;/strong&gt; — enough spread that different neurons can learn different things, without being so spread out that outputs blow up as they pass through many layers (the exploding gradient problem, also covered earlier).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxiryswbz1oktiyy3e4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxiryswbz1oktiyy3e4k.png" alt=" " width="800" height="263"&gt;&lt;/a&gt;&lt;br&gt;
Too-small variance is functionally the same starting point as the vanishing gradient problem — the signal barely moves through the network. Too-large variance heads straight toward the exploding gradient problem. The right initialization scheme depends on which activation function the layer uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Xavier / Glorot initialization
&lt;/h2&gt;

&lt;p&gt;Designed for &lt;strong&gt;sigmoid and tanh&lt;/strong&gt; activations. Two common variants:&lt;br&gt;
Xavier Normal: W ~ N(0, sigma^2), where sigma^2 = 2 / (fan_in + fan_out)&lt;br&gt;
Xavier Uniform: W ~ Uniform[-limit, limit], where limit = sqrt(6 / (fan_in + fan_out))&lt;br&gt;
Here &lt;code&gt;fan_in&lt;/code&gt; is the number of input connections to a neuron, and &lt;code&gt;fan_out&lt;/code&gt; is the number of output connections. Balancing the initialization around both keeps the variance of activations (and gradients) roughly consistent as they flow forward and backward through the network — which is specifically what sigmoid and tanh, with their easily-saturating curves, need to avoid vanishing gradients from the very first forward pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  He initialization
&lt;/h2&gt;

&lt;p&gt;Designed for &lt;strong&gt;ReLU and its variants&lt;/strong&gt; (Leaky ReLU, ELU, PReLU — all covered in the previous post):&lt;br&gt;
He Normal: W ~ N(0, sigma^2), where sigma^2 = 2 / fan_in&lt;br&gt;
He Uniform: W ~ Uniform[-limit, limit], where limit = sqrt(6 / fan_in)&lt;br&gt;
He initialization only accounts for &lt;code&gt;fan_in&lt;/code&gt;, using a larger variance than Xavier. This compensates for the fact that ReLU zeroes out roughly half its inputs (everything negative) — a larger starting variance keeps the &lt;em&gt;surviving&lt;/em&gt; signal at a healthy scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;Picking Xavier for a ReLU network, or vice versa, isn't a fatal mistake, but it does make training measurably harder — slower convergence, or a higher chance of hitting vanishing/exploding gradients early, before the optimizer has had a chance to correct course. Matching the initialization scheme to the activation function is one of the cheapest, most reliable wins available before training even starts.&lt;/p&gt;




&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe19t5a9t70v3li1q9mtd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe19t5a9t70v3li1q9mtd.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmdpgn5qvy7813hw94mbh.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmdpgn5qvy7813hw94mbh.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>neuralnetworks</category>
      <category>weightinitialization</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>Beyond Sigmoid and ReLU: Leaky ReLU, ELU, Swish, and Softmax</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Mon, 20 Jul 2026 11:42:57 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/beyond-sigmoid-and-relu-leaky-relu-elu-swish-and-softmax-jnc</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/beyond-sigmoid-and-relu-leaky-relu-elu-swish-and-softmax-jnc</guid>
      <description>&lt;p&gt;Part 11 of my "revisiting my AI/ML notes" series. Earlier in this series I covered sigmoid and plain ReLU. ReLU fixed sigmoid's vanishing gradient problem for positive inputs — but it introduced a new failure mode of its own, and there's a whole family of activation functions built to fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with plain ReLU: dying neurons
&lt;/h2&gt;

&lt;p&gt;ReLU is &lt;code&gt;max(0, z)&lt;/code&gt; — for any negative input, the output is exactly zero, and so is the gradient. If a neuron's weights drift into a state where its input is consistently negative, that gradient stays zero forever: the neuron stops updating completely, no matter how much more training happens. This is called the &lt;strong&gt;dying ReLU problem&lt;/strong&gt;, and it can silently remove a meaningful chunk of a network's capacity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv8x91szbhqjvndrwilnr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv8x91szbhqjvndrwilnr.png" alt=" " width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Leaky ReLU
&lt;/h2&gt;

&lt;p&gt;The fix is almost embarrassingly small: instead of outputting exactly 0 for negative inputs, output a small fraction of the input.&lt;br&gt;
LeakyReLU(z) = z if z &amp;gt; 0, else 0.01 * z&lt;/p&gt;

&lt;p&gt;That tiny non-zero slope for negative values is enough to keep a small gradient flowing, so a neuron that drifts negative can still recover instead of dying permanently.&lt;/p&gt;

&lt;h2&gt;
  
  
  ELU (Exponential Linear Unit)
&lt;/h2&gt;

&lt;p&gt;ELU(z) = z if z &amp;gt; 0, else alpha * (e^z - 1)&lt;br&gt;
ELU takes a different approach for negative inputs — an exponential curve that smoothly approaches &lt;code&gt;-alpha&lt;/code&gt; instead of a straight line. This gives it smoother gradients around zero, which can help training stability. The tradeoff: computing &lt;code&gt;e^z&lt;/code&gt; on every negative input is meaningfully more expensive than Leaky ReLU's simple multiplication, so it's a real speed-vs-quality tradeoff, not a strict upgrade.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PReLU (Parametric ReLU)&lt;/strong&gt; takes Leaky ReLU one step further by making that slope (the &lt;code&gt;alpha&lt;/code&gt;) a &lt;em&gt;learnable&lt;/em&gt; parameter instead of a fixed 0.01 — the network figures out the best slope for itself during training.&lt;/p&gt;

&lt;h2&gt;
  
  
  Swish
&lt;/h2&gt;

&lt;p&gt;Swish(z) = z * sigmoid(z)&lt;br&gt;
Swish is a newer activation, generally recommended for very deep networks (notes mention 40+ layers). Unlike ReLU, it's smooth everywhere and slightly non-monotonic near zero, which empirically tends to help gradient flow in very deep architectures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Softmax: for the output layer, not hidden layers
&lt;/h2&gt;

&lt;p&gt;Everything above is a hidden-layer activation. &lt;strong&gt;Softmax&lt;/strong&gt; is different — it's used specifically at the output layer for multi-class classification, converting a set of raw scores into a valid probability distribution that sums to 1:&lt;br&gt;
softmax(z_i) = e^(z_i) / sum over j of e^(z_j)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsv727ara0ibck4jl9pah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsv727ara0ibck4jl9pah.png" alt=" " width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If a model outputs raw scores across four classes and softmax turns them into something like &lt;code&gt;[0.6, 0.2, 0.1, 0.1]&lt;/code&gt;, the class with the highest probability (0.6) is the model's prediction — and unlike sigmoid, this generalizes naturally beyond two classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;There's no single "best" activation function — each one trades off gradient behavior, computational cost, and training stability differently. What matters is recognizing &lt;em&gt;which problem&lt;/em&gt; a given activation function was built to solve, so the choice for a specific architecture is deliberate rather than just "whatever the tutorial used."&lt;/p&gt;




&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjgalokyjtqxakxjlw9f3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjgalokyjtqxakxjlw9f3.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fceqlz1zpa3i1u8xmzrls.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fceqlz1zpa3i1u8xmzrls.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbrlwe36mtibfsqhfm88y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbrlwe36mtibfsqhfm88y.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv33wudkjuuxuyzd4iizd.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv33wudkjuuxuyzd4iizd.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>neuralnetworks</category>
      <category>activationfunctions</category>
    </item>
    <item>
      <title>Dropout and Regularization: How Neural Networks Avoid Overfitting</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Mon, 20 Jul 2026 11:28:21 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/dropout-and-regularization-how-neural-networks-avoid-overfitting-51k</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/dropout-and-regularization-how-neural-networks-avoid-overfitting-51k</guid>
      <description>&lt;p&gt;Part 10 of my "revisiting my AI/ML notes" series. Everything so far has been about getting a network to learn at all. This post is about a different problem: getting it to learn the &lt;em&gt;right&lt;/em&gt; things, instead of just memorizing the training data.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: overfitting
&lt;/h2&gt;

&lt;p&gt;A network with enough capacity can, given enough training time, essentially memorize its training set — including its noise and quirks — instead of learning patterns that generalize to new data. It looks great on training metrics and falls apart on anything it hasn't seen before. Two standard techniques exist specifically to prevent this: &lt;strong&gt;regularization&lt;/strong&gt; (L1, L2) and &lt;strong&gt;dropout&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dropout
&lt;/h2&gt;

&lt;p&gt;Dropout, introduced by Nitish Srivastava and Geoffrey Hinton in 2014, is disarmingly simple: during training, randomly "turn off" a fraction of neurons in a given layer on every forward pass.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjw4nw3iu7d62iimztv3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjw4nw3iu7d62iimztv3n.png" alt=" " width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A dropout probability like &lt;code&gt;p = 0.5&lt;/code&gt; means roughly 50% of neurons in that layer are randomly zeroed out on each pass.&lt;/li&gt;
&lt;li&gt;Which specific neurons get dropped changes every single pass — no neuron can become over-reliant on always being present, and no neuron can "specialize" in memorizing one specific training quirk, because it might not even be active next time.&lt;/li&gt;
&lt;li&gt;At test time, no neurons are dropped — the full network is used. To keep the overall signal strength consistent between training and testing, the weights (or activations, depending on implementation) are scaled by &lt;code&gt;(1 - p)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This forces the network to spread useful information across many neurons instead of concentrating it in a few, which is exactly what generalization needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the dropout rate
&lt;/h2&gt;

&lt;p&gt;The dropout probability &lt;code&gt;p&lt;/code&gt; is a hyperparameter, and it needs tuning like any other:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Too high, and you're removing so much of the network on each pass that it struggles to learn anything useful — underfitting.&lt;/li&gt;
&lt;li&gt;Too low, and you're barely regularizing at all — the overfitting problem you were trying to solve doesn't really go away.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Standard practice is to search over this value (hyperparameter tuning) rather than guessing, checking performance on validation data to find where the tradeoff actually lands for your specific problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;Dropout and its cousin, weight regularization, are two of the most reliable tools for keeping a network's performance on unseen data close to its performance on training data. Without them, deep networks — which have enormous capacity to memorize — very often look excellent on paper and fail quietly in production.&lt;/p&gt;

&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5up5crc995sw673pg8f.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5up5crc995sw673pg8f.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aiops</category>
      <category>deeplearning</category>
      <category>dropoutpvalue</category>
      <category>neuralnetworks</category>
    </item>
    <item>
      <title>The Exploding Gradient Problem, Explained</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 19 Jul 2026 07:39:17 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/the-exploding-gradient-problem-explained-3a0</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/the-exploding-gradient-problem-explained-3a0</guid>
      <description>&lt;p&gt;Part 9 of my "revisiting my AI/ML notes" series, and the last one in the backpropagation arc. The previous post covered gradients shrinking to nothing across many layers. This one covers the mirror-image problem: gradients that grow instead, until training becomes unstable.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same chain rule, the opposite direction
&lt;/h2&gt;

&lt;p&gt;Vanishing gradients happen when the per-layer terms in the chain rule product are consistently less than 1. Exploding gradients happen for the exact opposite reason: when those per-layer terms — usually driven by weight values — are consistently &lt;strong&gt;greater than 1&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;gradient_at_early_layer ~= 2.5 x 2.5 x 2.5 x ... (once per layer)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9uc7rk4p0scx26fv9vyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9uc7rk4p0scx26fv9vyo.png" alt=" " width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of shrinking toward zero, this product grows exponentially with depth. A gradient that should be a small, well-behaved correction instead becomes enormous by the time it reaches the earlier layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this makes training unstable
&lt;/h2&gt;

&lt;p&gt;Recall the update rule again: &lt;code&gt;w_new = w_old - lr * gradient&lt;/code&gt;. If the gradient is huge, the weight update is huge too — even a modest learning rate can't fully compensate for a gradient that's grown by several orders of magnitude. In practice this looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loss swinging wildly between iterations instead of decreasing smoothly&lt;/li&gt;
&lt;li&gt;Weights growing to extremely large values, sometimes overflowing into &lt;code&gt;NaN&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Training that was progressing fine suddenly diverging with no clear warning&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common fixes
&lt;/h2&gt;

&lt;p&gt;A few standard techniques exist specifically to keep this under control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gradient clipping&lt;/strong&gt; — cap the gradient's magnitude at a fixed threshold before applying the update, regardless of how large the raw computed value is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Careful weight initialization&lt;/strong&gt; — techniques like Xavier/Glorot or He initialization choose starting weight scales specifically to avoid values that compound into explosion (or vanishing) across layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Batch normalization&lt;/strong&gt; — normalizing activations between layers keeps values in a consistent, well-behaved range, which indirectly keeps gradients from spiraling in either direction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up the backpropagation arc
&lt;/h2&gt;

&lt;p&gt;Across these last few posts: forward propagation produces a prediction, the loss measures how wrong it is, the chain rule propagates that error backward through every layer, and gradient descent uses it to update every weight. Vanishing and exploding gradients are what happens when that backward chain of multiplications isn't kept in a healthy range — too small and early layers stop learning, too large and the whole network becomes unstable. Every architecture that comes after this in a deep learning curriculum — CNNs, RNNs, transformers — is still built on this exact same core loop underneath.&lt;/p&gt;

&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl1peilcea7ofyxg97dl0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl1peilcea7ofyxg97dl0.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>explodinggradientdescent</category>
      <category>neuralnetwork</category>
    </item>
    <item>
      <title>The Vanishing Gradient Problem, Explained</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 19 Jul 2026 07:36:13 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/the-vanishing-gradient-problem-explained-4p0k</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/the-vanishing-gradient-problem-explained-4p0k</guid>
      <description>&lt;p&gt;Part 8 of my "revisiting my AI/ML notes" series. The last post ended on a warning: multiplying several small numbers together, as the chain rule does, shrinks the result fast. This post is about what happens when that shrinking gets out of hand — the vanishing gradient problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the shrinking comes from
&lt;/h2&gt;

&lt;p&gt;Sigmoid is the culprit here. Its derivative — the local gradient the chain rule multiplies at every layer it passes through — has a maximum value of exactly &lt;strong&gt;0.25&lt;/strong&gt;, and drops toward zero for large positive or negative inputs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5v6b5c2xcj7n4uanplw0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5v6b5c2xcj7n4uanplw0.png" alt=" " width="799" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now apply the chain rule across a deep network. If every layer contributes a local derivative that's at best 0.25 (and realistically often smaller, once you multiply in typically-small weight values too), then the gradient reaching a weight near the input is the product of many of these small numbers, layer after layer:&lt;/p&gt;

&lt;p&gt;gradient_at_layer_1 ~= 0.25 x 0.25 x 0.25 x ... (once per layer)&lt;/p&gt;

&lt;p&gt;That product shrinks toward zero shockingly fast as depth increases.&lt;/p&gt;

&lt;p&gt;[PASTE DIAGRAM IMAGE HERE - SECOND HALF]&lt;/p&gt;

&lt;h2&gt;
  
  
  The practical consequence
&lt;/h2&gt;

&lt;p&gt;Recall the weight update rule: &lt;code&gt;w_new = w_old - lr * gradient&lt;/code&gt;. If the gradient is effectively zero by the time it reaches an early layer, the update is effectively zero too — that weight barely changes, no matter how many training iterations run. &lt;strong&gt;The layers closest to the input stop learning&lt;/strong&gt;, while the layers closest to the output keep updating more or less normally. The network ends up with a large chunk of its capacity permanently under-trained.&lt;/p&gt;

&lt;p&gt;This is a genuinely serious problem for deep networks — it's part of why very deep sigmoid-based networks were historically hard to train, and it's a big part of why ReLU (covered earlier in this series) became the default for hidden layers: ReLU's derivative is either 0 or exactly 1, so it doesn't shrink the gradient the way sigmoid does for positive inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;Vanishing gradients are a direct, mechanical consequence of the chain rule and the shape of sigmoid — not a mysterious training instability. Once you see it as "multiplying many numbers less than 1 together," several standard deep learning fixes suddenly make sense: switching activation functions, using residual/skip connections, and normalization techniques all exist specifically to keep this product from collapsing to zero.&lt;/p&gt;

&lt;p&gt;Next up: the opposite failure mode — what happens when that same chain of multiplications grows instead of shrinks.&lt;/p&gt;

&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3nalsxx2zhvjscyuu585.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3nalsxx2zhvjscyuu585.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>vanishinggradientdescent</category>
      <category>neuralnetworks</category>
    </item>
    <item>
      <title>The Chain Rule: How Backpropagation Reaches Every Layer</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 19 Jul 2026 07:32:25 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/the-chain-rule-how-backpropagation-reaches-every-layer-2k24</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/the-chain-rule-how-backpropagation-reaches-every-layer-2k24</guid>
      <description>&lt;p&gt;Part 7 of my "revisiting my AI/ML notes" series. The last post left off with a question: gradient descent needs the slope of the loss with respect to a weight, but in a multilayer network, most weights aren't directly connected to the loss at all — they're several layers removed from it. This is exactly what the chain rule solves.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: weights are buried inside the network
&lt;/h2&gt;

&lt;p&gt;In a single-neuron example, computing &lt;code&gt;dLoss/dw&lt;/code&gt; is direct — the weight feeds straight into the output, which feeds straight into the loss. But in a multilayer network, an early weight influences the loss only indirectly: it affects a neuron's output, which affects the next layer's neurons, which eventually affects the final output, which determines the loss.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0eadmkyq2t43vk32mo1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0eadmkyq2t43vk32mo1p.png" alt=" " width="799" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The chain rule is exactly this: multiply the local effects together
&lt;/h2&gt;

&lt;p&gt;The chain rule from calculus says that if &lt;code&gt;w1&lt;/code&gt; affects &lt;code&gt;a1&lt;/code&gt;, &lt;code&gt;a1&lt;/code&gt; affects &lt;code&gt;a2&lt;/code&gt;, and &lt;code&gt;a2&lt;/code&gt; affects the loss, then the total effect of &lt;code&gt;w1&lt;/code&gt; on the loss is the product of each individual step's effect:&lt;br&gt;
dLoss/dw1 = (dLoss/da2) x (da2/da1) x (da1/dw1)&lt;/p&gt;

&lt;p&gt;Each term on the right is a &lt;em&gt;local&lt;/em&gt; derivative — easy to compute on its own, because it only involves two directly-connected quantities. The chain rule is what lets you stitch these small, local calculations together into the one number you actually need: how much this specific weight, buried deep in the network, is responsible for the final error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this is the actual mechanism behind "backpropagation"
&lt;/h2&gt;

&lt;p&gt;This is also where the name comes from. To compute &lt;code&gt;dLoss/dw1&lt;/code&gt; for a weight near the input, you need &lt;code&gt;dLoss/da2&lt;/code&gt; first — which itself needs to be computed from the output side. So the computation naturally flows &lt;strong&gt;backward&lt;/strong&gt;, from the output toward the input, computing each local derivative and multiplying it into the running product as it goes. That backward flow of derivatives, layer by layer, is backpropagation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;This chain-multiplication is elegant, but it has a real consequence worth flagging early: if each individual local derivative is small, multiplying several of them together makes the result &lt;em&gt;very&lt;/em&gt; small very fast. If each one is large, the product explodes just as fast. That single observation is the root cause behind two of the most well-known training problems in deep learning — vanishing and exploding gradients — which are exactly what the next two posts in this series cover.&lt;/p&gt;

&lt;p&gt;Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdu9f5z3q4wn8ci65wus1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdu9f5z3q4wn8ci65wus1.jpeg" alt=" " width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>chainrule</category>
      <category>neuralnetwork</category>
    </item>
    <item>
      <title>Multilayer Neural Networks and Gradient Descent, Explained</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sun, 19 Jul 2026 07:29:07 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/multilayer-neural-networks-and-gradient-descent-explained-1njo</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/multilayer-neural-networks-and-gradient-descent-explained-1njo</guid>
      <description>&lt;p&gt;Part 6 of my "revisiting my AI/ML notes" series. Everything so far in this series used a single hidden layer as an example. Real networks almost always stack multiple hidden layers — this post covers what changes when you do that, and revisits gradient descent from a more visual angle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going from one hidden layer to many
&lt;/h2&gt;

&lt;p&gt;A multilayer network just repeats the same input -&amp;gt; weighted sum -&amp;gt; activation pattern, but chains multiple hidden layers back to back before reaching the output. The structure looks like:&lt;br&gt;
Input layer -&amp;gt; Hidden layer 1 -&amp;gt; Hidden layer 2 -&amp;gt; Output layer&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F14vur1fc9sy7wx7dodtj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F14vur1fc9sy7wx7dodtj.png" alt=" " width="799" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the number of weights grows so fast
&lt;/h2&gt;

&lt;p&gt;Every layer is fully connected to the next, so the number of weights is the product of the neuron counts on each side. With 4 input neurons feeding into a hidden layer of 3 neurons, that's &lt;code&gt;4 x 3 = 12&lt;/code&gt; weights just for that one connection. If that hidden layer of 3 then feeds into a second hidden layer of 2 neurons, that's another &lt;code&gt;3 x 2 = 6&lt;/code&gt; weights.&lt;/p&gt;

&lt;p&gt;This is worth sitting with for a second: weight count isn't linear in the number of neurons, it's closer to combinatorial across layer boundaries. This is exactly why deep networks have millions (or billions) of parameters — it's not that any single layer is huge, it's that the connections between layers multiply fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the slope to know which way to move
&lt;/h2&gt;

&lt;p&gt;Gradient descent works by looking at the slope (derivative) of the loss curve at the weight's current position, and using that slope to decide which direction to move the weight:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the slope is &lt;strong&gt;negative&lt;/strong&gt; (the curve is heading downward to the right), the weight needs to move &lt;strong&gt;up&lt;/strong&gt; to get closer to the minimum.&lt;/li&gt;
&lt;li&gt;If the slope is &lt;strong&gt;positive&lt;/strong&gt; (the curve is heading upward to the right), the weight needs to move &lt;strong&gt;down&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is exactly why the update rule has a minus sign in it — &lt;code&gt;w_new = w_old - lr * gradient&lt;/code&gt; — subtracting a positive gradient moves the weight down, and subtracting a negative gradient moves it up. The sign of the gradient is doing the steering; the minus sign is what makes the steering point toward lower loss instead of higher loss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;A single neuron's math (covered earlier in this series) is simple enough to compute by hand. A real network with multiple hidden layers is not — and that's precisely why backpropagation needs the chain rule to work, which is the topic of the next post. Understanding gradient descent visually first, as a ball rolling down a curve based on the local slope, makes the chain-rule math that follows feel like a natural extension rather than an arbitrary formula.&lt;/p&gt;

&lt;p&gt;The Original Notes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqnlz9jsq0p1ahdwo7o95.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqnlz9jsq0p1ahdwo7o95.jpeg" alt=" " width="702" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>deeplearning</category>
      <category>multilayeredneuralnetworks</category>
      <category>gradientdescent</category>
    </item>
    <item>
      <title>Backpropagation Explained: How a Neural Network Actually Learns</title>
      <dc:creator>Ali Raza</dc:creator>
      <pubDate>Sat, 18 Jul 2026 11:30:59 +0000</pubDate>
      <link>https://dev.to/ali_raza_1ce2540f37e01a91/backpropagation-explained-how-a-neural-network-actually-learns-3bgn</link>
      <guid>https://dev.to/ali_raza_1ce2540f37e01a91/backpropagation-explained-how-a-neural-network-actually-learns-3bgn</guid>
      <description>&lt;p&gt;Part 5 of my "revisiting my AI/ML notes" series. So far this series has covered the ANN structure, forward propagation, and activation functions — all the machinery for a network to produce a prediction. This post covers the other half: how the network actually learns from being wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem forward propagation doesn't solve
&lt;/h2&gt;

&lt;p&gt;Forward propagation gives you a prediction. On its own, that prediction is basically a random guess — the weights start out essentially arbitrary. Backpropagation is the algorithm that takes the error in that prediction and uses it to adjust every single weight in the network, so the next prediction is a little bit better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: measure how wrong the prediction is
&lt;/h2&gt;

&lt;p&gt;This is the &lt;strong&gt;loss function&lt;/strong&gt;. A simple and common one is squared error:&lt;br&gt;
Loss = (y - y_hat)^2&lt;/p&gt;

&lt;p&gt;Where &lt;code&gt;y&lt;/code&gt; is the actual/true value and &lt;code&gt;y_hat&lt;/code&gt; is the network's prediction. We square the difference for two reasons: it makes the loss positive regardless of whether the prediction was too high or too low, and it penalizes bigger errors disproportionately more than smaller ones.&lt;/p&gt;

&lt;p&gt;Across a full dataset of &lt;code&gt;n&lt;/code&gt; examples, the total loss is just the sum of this across every example:&lt;/p&gt;

&lt;p&gt;Loss = sum over i=1 to n of (y_i - y_hat_i)^2&lt;/p&gt;

&lt;h3&gt;
  
  
  A worked example from my notes
&lt;/h3&gt;

&lt;p&gt;Say a model is predicting whether someone passes an exam based on hours spent on Play (2h), Study (4h), and Sleep (8h), where 1 = pass. The true label is &lt;code&gt;y = 1&lt;/code&gt;, but the network's current (untrained) prediction is &lt;code&gt;y_hat = 0&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  A worked example from my notes
&lt;/h3&gt;

&lt;p&gt;Say a model is predicting whether someone passes an exam based on hours spent on Play (2h), Study (4h), and Sleep (8h), where 1 = pass. The true label is &lt;code&gt;y = 1&lt;/code&gt;, but the network's current (untrained) prediction is &lt;code&gt;y_hat = 0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Loss = (1 - 0)^2 = 1&lt;/p&gt;

&lt;p&gt;A loss of 1 here is about as bad as this particular setup gets — the prediction is completely wrong. That's the signal backpropagation uses to correct the weights.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7vyysp0r1som7dhsjlly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7vyysp0r1som7dhsjlly.png" alt=" " width="799" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: figure out which direction to adjust each weight
&lt;/h2&gt;

&lt;p&gt;This is the actual "backward" part. For every weight in the network, backpropagation computes the &lt;strong&gt;partial derivative of the loss with respect to that weight&lt;/strong&gt; — written &lt;code&gt;dLoss/dw&lt;/code&gt;. This derivative tells you two things: which direction increasing the loss lies in, and how sensitive the loss is to that particular weight.&lt;/p&gt;

&lt;p&gt;The update rule is the same for every weight in the network:&lt;/p&gt;

&lt;p&gt;w_new = w_old - learning_rate * (dLoss / dw)&lt;/p&gt;

&lt;p&gt;Notice the minus sign — you always move the weight in the &lt;em&gt;opposite&lt;/em&gt; direction of the gradient, because you want to walk downhill toward lower loss, not uphill toward more of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: repeat, many times
&lt;/h2&gt;

&lt;p&gt;One update rarely gets a weight anywhere close to optimal. Backpropagation runs this update for every weight, over and over across many training examples and many passes through the dataset, gradually walking every weight toward the values that minimize total loss — what's usually called the &lt;strong&gt;global minimum&lt;/strong&gt; of the loss function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the learning rate matters so much
&lt;/h2&gt;

&lt;p&gt;The learning rate (&lt;code&gt;lr&lt;/code&gt; in the formula above) controls how big each step is. This is a genuine balancing act:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Too high&lt;/strong&gt;, and updates overshoot the minimum — the loss can bounce around or even diverge instead of settling down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Too low&lt;/strong&gt;, and training crawls: technically correct, but painfully slow, and it can get stuck in a shallow local dip instead of finding the true global minimum.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A small, carefully chosen learning rate is what lets training descend smoothly toward the minimum instead of overshooting past it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;Backpropagation is the algorithm that makes "deep learning" actually mean something — it's the mechanism that turns a randomly initialized network into one that's genuinely learned patterns from data. Every architecture covered so far in this series (and every architecture still to come — CNNs, RNNs, transformers) relies on this exact same core loop: predict, measure the error, propagate it backward, update the weights, repeat.&lt;/p&gt;




&lt;p&gt;Original Note:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flisfczh58o7044t107we.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flisfczh58o7044t107we.jpeg" alt=" " width="702" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>backpropogation</category>
      <category>chainrule</category>
      <category>neuralnetworks</category>
    </item>
  </channel>
</rss>
