<?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 Melissa on Medium]]></title>
        <description><![CDATA[Stories by Melissa on Medium]]></description>
        <link>https://medium.com/@melissamaouche305?source=rss-41287492762a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*In9hZZ7Uby-f7GnlfpWFrQ.jpeg</url>
            <title>Stories by Melissa on Medium</title>
            <link>https://medium.com/@melissamaouche305?source=rss-41287492762a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:03:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@melissamaouche305/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[Exploring Convolutional Neural Networks: From Pixels to Predictions]]></title>
            <link>https://ai.plainenglish.io/exploring-convolutional-neural-networks-from-pixels-to-predictions-bd2904e8eb07?source=rss-41287492762a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd2904e8eb07</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[cnn-model]]></category>
            <dc:creator><![CDATA[Melissa]]></dc:creator>
            <pubDate>Wed, 17 Sep 2025 08:43:57 GMT</pubDate>
            <atom:updated>2025-09-17T08:47:13.139Z</atom:updated>
            <content:encoded><![CDATA[<p>You’ve likely heard the term Convolutional Neural Network or CNN. It’s the powerhouse behind the biggest leaps in computer vision over the last decade, from unlocking your phone with Face ID to the algorithms that power self-driving cars.</p><p>But if you’ve ever wondered how a computer can go from a grid of numbers to identifying a cat, a car, or a cancerous cell, you’re in the right place. Let’s break down this seemingly complex concept into an intuitive journey from pixels to predictions.</p><h3><strong>How does a machine “see” these things? The answer is CNNs.</strong></h3><h4>The Problem: Why Can’t We Just Use a Regular Neural Network?</h4><p>At its heart, an image is just a grid of pixels. A small 200x200 color image is represented as 200 x 200 x 3 = 120,000 numbers (red, green, and blue values for each pixel).</p><p>If you fed this directly into a standard neural network (a “fully connected” network), you’d run into immediate problems:</p><ol><li><strong>Computational Nightmare</strong>: The first layer alone would have a monstrous number of parameters (weights), leading to insane memory and processing requirements.</li></ol><p>2. <strong>Spatial Ignorance</strong>: It would treat a pixel in the top-left corner exactly the same as a pixel in the bottom-right. It has no built-in understanding that nearby pixels are related ! To a network, it’s just a list of 120,000 unrelated numbers.</p><p>We need a smarter architecture, one designed to understand the spatial hierarchy of images. Enter the CNN.</p><h4>The Core Idea: A Hierarchy of Patterns</h4><p>Think about how you recognize a face. You don’t process every pixel at once. You subconsciously detect:<br><strong> Simple patterns:</strong> edges, dark spots, light spots.<br><strong>These edges form (more complex patterns):</strong> eyes, noses, corners.<br>These complex patterns assemble into a face.</p><p>A CNN mimics this process through a series of specialized layers. Let’s walk through them.</p><h4>### 1. The Convolutional Layer: The Pattern Detector</h4><p>This is the heart of the CNN. Its job is to detect features.</p><p><strong>The Kernel (or Filter)</strong>: Imagine a small flashlight (say, 3x3 pixels) that you slide over every part of the image. This flashlight isn’t looking for brightness; it’s looking for a specific pattern, like a vertical edge.</p><p><strong>The Convolution Operation</strong>: As the kernel slides (or “convolves”) across the image, it performs a dot product between its values and the pixel values underneath it. A high output value means the pattern was detected in that spot; a low value means it wasn’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*wvwT9LlHcDfexIiv7fWWxA.gif" /></figure><p>A kernel detecting vertical edges. The output is a “feature map” showing where those edges are strong.</p><p>A single convolutional layer uses many different kernels (32, 64, 128…), each learning to detect a different feature. The output of this layer is a stack of these “feature maps.”</p><h4>2. The Activation Function: Adding Non-Linearity</h4><p>After convolution, we pass the data through an activation function. The most common one is the ReLU (Rectified Linear Unit). It’s brilliantly simple: it replaces all negative values in the feature map with zero.</p><p>f(x) = max(0, x)</p><p>Why? It introduces non-linearity into the network. The real world is non-linear (an edge is either there or it isn’t), and ReLU allows the model to learn these complex patterns. It also helps with computational efficiency.</p><h4>3. The Pooling Layer: Downsampling and Summarizing</h4><p>The pooling layer simplifies the output. Its main goal is to reduce the spatial sizeof the representation, which:<br>* Makes computation faster.<br>* Helps prevent overfitting.<br>* Makes the detection of features somewhat invariant to scale and orientation (a cat ear is a cat ear, whether it’s in the top-left or center of the image).</p><p>The most common type is Max Pooling. It works by sliding a window (e.g., 2x2) over the feature map and only keeping the maximum value in that window.</p><p>Max Pooling: It keeps the most activated feature and throws away the rest, reducing the data size.*</p><h4>The Magic: Stacking Layers</h4><p>This is where the true power emerges. We stack multiple sets of Convolution -&gt; Activation -&gt; Pooling layers.</p><p>* Early layers learn simple features: edges, blobs, colors.<br>* Deeper layers combine these simple features to detect more complex ones: textures, shapes (e.g., circles, squares).<br>* Even deeper layers combine those to detect even more complex patterns: a dog’s eye, a car’s wheel, a bird’s beak.</p><p>The network automatically learns the most useful features for the task at hand through training.</p><p>4.<strong> The Final Stretch: Classification</strong></p><p>After going through several convolutional blocks, we have a set of high-level feature maps. Now we need to convert this into a prediction.</p><p>Flattening: The 3D block of feature maps is flattened into a 1D vector of numbers.</p><p>* Fully Connected Layers: This vector is fed into a traditional neural network (one or more “fully connected” layers). This network’s job is to learn the combinations of these high-level features that define each class. (e.g., “if high-level feature #87 (whiskers) and #243 (pointy ears) are present, it’s probably a cat”).</p><p>* Output Layer: The final layer typically uses a Softmax activation function, which converts the scores into probabilities that sum to 1. The class with the highest probability is the network’s prediction.</p><p>The next time your phone seamlessly organizes photos by who’s in them, or your camera recognizes a face to auto-focus, you’ll know there’s a complex yet elegant hierarchy of pattern detectors working behind the scenes — a Convolutional Neural Network, transforming pixels into predictions.</p><p>What’s the most interesting application of computer vision you’ve encountered? Share your thoughts in the comments!</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd2904e8eb07" width="1" height="1" alt=""><hr><p><a href="https://ai.plainenglish.io/exploring-convolutional-neural-networks-from-pixels-to-predictions-bd2904e8eb07">Exploring Convolutional Neural Networks: From Pixels to Predictions</a> was originally published in <a href="https://ai.plainenglish.io/">Artificial Intelligence in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond the Black Box: Why Explainable AI is Non-Negotiable for Our Future]]></title>
            <link>https://ai.plainenglish.io/beyond-the-black-box-why-explainable-ai-is-non-negotiable-for-our-future-c33259192727?source=rss-41287492762a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c33259192727</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <dc:creator><![CDATA[Melissa]]></dc:creator>
            <pubDate>Sun, 14 Sep 2025 17:52:34 GMT</pubDate>
            <atom:updated>2025-09-14T17:52:34.778Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZL_tnqYV5X6CgQvi" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You’ve seen the headlines: “Neural network forecasts stock market trends” or “AI model diagnoses cancer more accurately than doctors.” It seems magical. However, if you simply inquire, “How?” you frequently receive a shrug. A black box contains the solution. <br> <br> Even its designers may find it difficult to unravel this black box, which is a complicated network of weights, matrices, and algorithms. It is no longer possible to blindly trust AI as it becomes more and more integrated into our daily lives, making crucial choices in areas like healthcare, banking, and justice. Transparency must be demanded. Explainable AI (XAI) is what we must demand.</p><h3>1.Explainable AI (XAI): What Is It?</h3><p>A collection of methods and technologies known as explainable AI (XAI) are intended to help humans comprehend the results of AI models. It involves looking into the black box and providing important answers to the following questions:</p><p>Why did the model predict this particular outcome? <br> <br> Which aspects of the decision were most crucial? <br> <br> Can we rely on this outcome? <br> <br> Dumbing down AI is not the goal of XAI. The goal is to provide a bridge of knowledge between those who use, control, and are impacted by complicated models.</p><h3>2.The Immediate Need for XAI: Beyond Curiosity</h3><p>The need for explainability is motivated by practical concerns rather than scholarly ones.</p><p><strong>Adoption and believe</strong>: If a doctor told you, “Take this medication, my gut tells it will work,” without providing any further details, would you believe them? Most likely not. In a similar vein, a bank cannot deny a loan application without a good reason. In crucial sectors, XAI offers the “why” that fosters trust and permits broad adoption.</p><p><strong>Debugging and Bias Detection</strong>: AI models are trained on data, and human biases are frequently present in our data. One well-known example is an HR tool that was discontinued after it discovered that resumes with the word “women’s” (such as “women’s chess club captain”) were devalued. By identifying which attributes the model is unjustly depending on, XAI approaches can expose these biases and enable developers to address them. <br> <strong><br> Regulatory Compliance:</strong> A “right to explanation” has been established by laws such as the General Data Protection Regulation (GDPR) of the EU. This implies that people are legally entitled to know how an automated algorithm arrived at a conclusion that impacts them. Without XAI, companies simply cannot comply.</p><p><strong>Model Improvement:</strong> Understanding how a model works helps data scientists improve it. If a model for predicting house prices is heavily relying on a seemingly irrelevant feature (like the type of garden gnome in the photo), it’s a sign that the model is flawed and needs retraining.</p><h3>3.How Do We Make AI Explainable? A Look at the Toolbox</h3><p>The field of XAI has exploded with innovative techniques, generally falling into two categories:</p><h4>1. Intrinsically Interpretable Models</h4><p>Sometimes, the best explanation is a simple model. Linear regression, decision trees, and rule-based systems are inherently interpretable. You can see exactly how they combine inputs to get an output. The trade-off? They are often less powerful and accurate than their complex counterparts for very complicated tasks.</p><h4>2. Post-Hoc Explanation (After-the-Fact)</h4><p>This is where the magic happens for deep learning. We use a second model or technique to explain the first one after it has made a prediction. Some popular methods include:</p><ul><li><strong>LIME (Local Interpretable Model-agnostic Explanations): </strong>Imagine trying to understand a complex painting by zooming in on one small brushstroke. LIME works similarly. It creates a simple, local explanation for a single prediction by slightly perturbing the input and seeing how the output changes.</li></ul><p><em>Example: LIME might show you that an image was classified as a “dog” primarily because of the pixel patterns defining the ears and nose.</em></p><ul><li><strong>SHAP (SHapley Additive exPlanations)</strong>: Based on cooperative game theory, SHAP assigns each feature an importance value for a particular prediction. It brilliantly shows how each feature contributed to pushing the prediction from the base (average) value to the final output.</li></ul><p>Example: For a loan application rejection, SHAP can quantify that “low credit score” contributed -60% to the decision, while “short employment history” contributed -40%.*</p><ul><li><strong>Saliency Maps and Attention Mechanisms (for Computer Vision):</strong> These techniques highlight the parts of an image that were most “salient” or important for the model’s decision. They literally create a heatmap over the input image.</li></ul><p><em>Example: A saliency map for a medical AI might show that it correctly diagnosed a tumor by focusing on a specific cluster of pixels in an X-ray, giving a doctor a precise area to examine.</em></p><h3>4.The Road Ahead: Challenges and The Future</h3><p>XAI is not a solved problem. There’s a inherent tension between model performance (complexity) and interpretability (simplicity). The most accurate models are often the hardest to explain.</p><p>Furthermore, an explanation itself must be understandable to its audience. A technical explanation for a data scientist is very different from one for a doctor, a loan applicant, or a judge.</p><p>The future of XAI lies in creating more robust, reliable, and user-centric explanation systems. It’s about building AI that is not just intelligent, but also respectful, transparent, and collaborative.</p><h3>5.Conclusion: Explainability is a Feature, Not an Afterthought</h3><p>As we stand on the brink of an AI-driven era, the choices we make today will define our future. Building powerful AI is an incredible feat of engineering. But building AI that is fair, accountable, and understandable is a feat of wisdom.</p><p>Explainable AI is the key to moving from blind faith to informed trust. It’s the non-negotiable foundation for ethical, sustainable, and beneficial artificial intelligence for all.</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c33259192727" width="1" height="1" alt=""><hr><p><a href="https://ai.plainenglish.io/beyond-the-black-box-why-explainable-ai-is-non-negotiable-for-our-future-c33259192727">Beyond the Black Box: Why Explainable AI is Non-Negotiable for Our Future</a> was originally published in <a href="https://ai.plainenglish.io/">Artificial Intelligence in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Learning Techniques:]]></title>
            <link>https://medium.com/@melissamaouche305/deep-learning-techniques-d429b1cf3706?source=rss-41287492762a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d429b1cf3706</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[deep-learning-theory]]></category>
            <dc:creator><![CDATA[Melissa]]></dc:creator>
            <pubDate>Mon, 01 Sep 2025 20:47:18 GMT</pubDate>
            <atom:updated>2025-09-01T20:47:18.208Z</atom:updated>
            <content:encoded><![CDATA[<p>Powering the Next Wave of AI Artificial Intelligence (AI) is transforming how we live, work, and interact with technology and at the heart of this transformation lies deep learning. As a specialized branch of machine learning, deep learning uses multi-layered artificial neural networks to analyze complex data, learn patterns, and make intelligent predictions.</p><p>From powering self-driving cars to enabling medical image analysis, deep learning has become one of the most impactful technologies of our time.</p><h3><strong>What is Deep Learning?</strong></h3><p>Deep learning (DL) mimics how the human brain processes information. Unlike traditional machine learning models that rely on manual feature engineering, deep learning automatically extracts features from raw data. This ability allows it to handle massive datasets across domains like computer vision, natural language processing, and cybersecurity.</p><p><strong>The process involves:</strong></p><p><strong>Forward Propagation</strong> : passing inputs through layers of neurons.</p><p><strong>Backpropagation</strong> : adjusting weights and biases to minimize errors.</p><p><strong>Optimization</strong> : using algorithms like gradient descent to refine predictions.</p><p><strong>Training and Evaluation</strong> : iteratively improving performance on large datasets.</p><p><strong>Inference</strong> : applying the trained model to make predictions on new data.</p><h4>Why Deep Learning Stands Out</h4><p>Several key factors make deep learning uniquely powerful:</p><p>Data-driven learning: The more data, the better it performs.</p><p>Automated feature extraction: No need for manual feature engineering.</p><p>Scalability: Excels with large-scale, complex problems.</p><p>Speed: Once trained, deep learning models perform inference rapidly.</p><p>Versatility: Works with images, text, audio, tabular, and sequential data.</p><h4><strong>The Main Types of Deep Learning :</strong></h4><p>Deep learning techniques can be grouped into three categories:</p><p>Supervised Learning Models learn from labeled data to predict outcomes.</p><p>Examples:</p><p>Convolutional Neural Networks (CNNs) for image recognition.</p><p>Recurrent Neural Networks (RNNs) for sequential data like speech and text.</p><p>Multi-Layer Perceptrons (MLPs) for general classification and regression tasks.</p><p>Unsupervised Learning Models explore patterns in unlabeled data.</p><p><strong>Examples:</strong></p><p>Autoencoders for dimensionality reduction and anomaly detection.</p><p>Generative Adversarial Networks (GANs) for creating realistic synthetic data.</p><p>Clustering algorithms for grouping similar items (e.g., customer segmentation).</p><p>Hybrid Learning – Combines supervised and unsupervised methods.</p><p><strong>Examples:</strong></p><p>Transfer Learning to adapt pre-trained models to new tasks.</p><p>Semi-Supervised Learning for scenarios with limited labeled data.</p><p>Self-Supervised Learning, the backbone of modern large language models.</p><p>Real-World Applications</p><p>Deep learning is no longer confined to research labs—it powers technologies we use every day:</p><p>Healthcare: Diagnosing diseases from medical images with expert-level accuracy.</p><p>Finance: Detecting fraud and predicting market trends.</p><p>Autonomous vehicles: Interpreting sensor data for safe navigation.</p><p>Voice assistants: Understanding and generating natural language.</p><p>Entertainment: Recommending personalized content on streaming platforms.</p><h4>Challenges Ahead</h4><p>Despite its successes, deep learning faces some hurdles:</p><p>Interpretability: Models are often “black boxes” with unclear decision processes.</p><p>Resource intensity: Training requires powerful GPUs and vast datasets.</p><p>Vulnerabilities: Susceptible to adversarial attacks and bias in data.</p><p>The future of deep learning lies in explainable AI, efficient architectures, and data-efficient training methods such as self-supervised learning. These advances will make AI more accessible, trustworthy, and sustainable.</p><h4>Conclusion</h4><p>Deep learning has already transformed industries, but its journey is just beginning. As researchers and developers refine techniques and overcome current limitations, we’ll see even more innovative applications emerge unlocking the next era of intelligent systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d429b1cf3706" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a neural network from scratch to Recognize HandWritten Digits]]></title>
            <link>https://medium.com/@melissamaouche305/building-a-neural-network-from-scratch-to-recognize-handwritten-digits-fb11dd04aa76?source=rss-41287492762a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb11dd04aa76</guid>
            <category><![CDATA[neural-network-algorithm]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Melissa]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 14:56:51 GMT</pubDate>
            <atom:updated>2025-06-20T14:56:51.672Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how neural networks actually work under the hood? while modern frameworks like TensorFlow and Keras make te process of building neural networks easier , implementing one from scratch gives you more insights on what’s really happening .</p><p>in this blog I will showcase the steps I followed to build a neural network to classify handwritten digits from MINST dataset using only numpy.</p><h3><strong>1-Understanding the dataset:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ygqsBOqhZO_nTQSvcOT1Mw.png" /></figure><h4>what is MINST dataset ?</h4><p>The <strong>MNIST dataset</strong> (Modified National Institute of Standards and Technology) is one of the most popular and widely used datasets in the field of machine learning and deep learning. It serves as the “Hello World” for image classification — a simple yet powerful benchmark for beginners and researchers alike.</p><p>it containes :</p><ul><li>60,000 training images</li><li>10.000 testing images</li></ul><p>each image is a 28×28 grayscale pixle image of handwritten for 0 to 9 which means each images contain 784 pixels( 28×28) ,where each pixel is a value between 0 (black) and 255 (white) these images are :</p><ul><li>size-normalised all digits scaled to a common size.</li><li>centred: all digits are positioned in the center of the image.</li><li>Anti-aliased: Pixels have gray levels to smooth the image edges.</li></ul><h4>How we will use the data ?</h4><p>before feeding the data into the neural network we need to first , flatten each image into a 1D vector .second , we normalize the values so the input features lie in the range of [0,1].</p><h4>Why MNIST matters?</h4><p>Despite being a relatively simple dataset, MNIST is:</p><ul><li>A solid baseline for testing image classification algorithms</li><li>Complex enough to illustrate the power of neural networks</li><li>Clean and well-structured, making it ideal for prototyping and learning.</li></ul><h4>Data preparation :</h4><p>we start by importing the dataset which is available in many libraries like Keras, TensorFlow, and also downloadable directly .</p><p>To begin, we first import the dataset using the <strong>Keras</strong> library, which simplifies loading the data and splitting it into training and testing sets.</p><p>from keras.datasets import mnist</p><p>(X_train, y_train), (X_test, y_test) = mnist.load_data()</p><p>Once the MNIST dataset is loaded, the next important step is <strong>normalization</strong>. By default, each image contains pixel values ranging from <strong>0 to 255</strong>, where:</p><ul><li>0 = black</li><li>255= white</li></ul><p>These values are too large for a neural network to learn efficiently. Most models perform better when inputs are scaled to a <strong>smaller, consistent range</strong>, typically between <strong>0 and 1</strong>.</p><pre># Normalize pixel values to the range [0, 1]<br>X_train = X_train / 255.0<br>X_test = X_test / 255.0</pre><p>Each image in the MNIST dataset is a <strong>2D matrix of shape (28×28)</strong>. That’s perfect for viewing, but our custom-built neural network expects each input to be a <strong>1D vector</strong> — one long list of numbers, not a grid.</p><p>To fix that, we <strong>flatten</strong> each image from a 2D array into a 1D array of <strong>784 values</strong> (since 28 × 28 = 784). We also <strong>transpose</strong> the data so that:</p><ul><li>Each <strong>column</strong> represents a single image (example)</li><li>Each <strong>row</strong> represents a pixel (feature)</li></ul><pre># Flatten the 28x28 images into 784-length vectors and transpose<br>X_train = X_train.reshape(X_train.shape[0], 784).T # Shape: (784, 60000)<br>X_test = X_test.reshape(X_test.shape[0], 784).T # Shape: (784, 10000)</pre><p>With those steps :importing the dataset, normalizing the pixel values, flattening the images, and reshaping the data we conclude the essential data preprocessing phase. The data is now clean, consistent, and perfectly structured to feed into our neural network for trainin</p><h3>2-building the neural network :</h3><h4>what is a neural network ?</h4><p>Before we dive into building our model from scratch, let’s take a moment to understand what a <strong>neural network</strong> actually is.</p><p>A <strong>neural network</strong> is a computational model inspired by the human brain. It consists of layers of interconnected units called <strong>neurons</strong>. Each neuron receives input, processes it, and passes it to the next layer. The goal of the network is to learn patterns in the data like recognizing the shape of digits in an image.</p><p>A typical <strong>feedforward neural network</strong> (also called a multi-layer perceptron or MLP) has:</p><ul><li><strong>Input Layer</strong>: Takes in the raw data. In our case, this is a vector of 784 pixels (flattened from a 28×28 image).</li><li><strong>Hidden Layer(s)</strong>: These layers do most of the learning. Each neuron applies a mathematical function to the inputs and passes the result forward.</li><li><strong>Output Layer</strong>: Produces the final prediction. Since we’re classifying digits from 0 to 9, we need <strong>10 output neurons</strong>.</li></ul><h4>Forward Propagation How a Neural Network Makes Predictions</h4><p>Imagine a neural network as a chain of decision-making layers. Each layer takes in information, processes it, and passes it to the next just like neurons in the brain.</p><p>Here’s what happens during <strong>forward propagation</strong>:</p><ol><li><strong>Input Comes In</strong><br> We start with the raw data. For example, if we’re working with a 28×28 grayscale image from the MNIST dataset, we flatten it into a vector of 784 pixel values and feed it into the network.</li><li><strong>Each Neuron Calculates Something</strong><br> In every layer, each neuron receives values from the previous layer. It multiplies those values by weights, adds a bias (a small number that lets it shift the result), and then applies an <strong>activation function</strong> like ReLU to decide what to pass forward.</li></ol><ul><li>ReLU says: <em>“If the result is negative, drop it to zero. If it’s positive, keep it.”</em></li><li>This helps the network stay simple and fast while keeping important signals.</li></ul><ol><li><strong>Data Moves Through the Layers</strong><br> The processed outputs from one layer become the inputs for the next. This continues layer by layer.</li><li><strong>The Output Layer Makes a Decision</strong><br> At the end, we reach the output layer — for digit classification, it usually has 10 neurons (for digits 0 through 9).<br> Here we use the <strong>softmax function</strong>, which turns the final values into probabilities. The highest one is the network’s “guess.”</li></ol><p>You can think of forward propagation like asking the network: <em>“Given this input, what do you think the answer is?”</em><br> The network replies: <em>“I’m 95% sure it’s a 3.”</em></p><p>In forward propagation, as said before , the idea is to compute the output of each layer using the inputs, weights, and biases. For a given layer lll, here’s how we do it:</p><ol><li><strong>Pre-activation (linear transformation):</strong></li></ol><pre>z[l] = W[l] * a[l-1] + b[l]</pre><ul><li>z[l]: the input to the activation function for layer l</li><li>W[l]: weights matrix of layer l</li><li>a[l-1]: activation/output from the previous layer</li><li>b[l]: bias vector for layer l</li></ul><p>2. <strong>Activation (applying non-linearity):</strong></p><pre>a[l] = activation(z[l])</pre><p>This is where we apply functions like ReLU (in hidden layers) or softmax (in output layer).</p><p><strong>Common activation functions:</strong></p><ul><li><strong>ReLU</strong> (Rectified Linear Unit):</li></ul><pre>ReLU(x) = max(0, x)</pre><ul><li><strong>Softmax</strong> (used in output layer for classification):</li></ul><pre>softmax(z[i]) = exp(z[i]) / sum(exp(z[j]) for j in range(K))</pre><h3>Backpropagation — How a Neural Network Learns</h3><p>Once the network makes a prediction, we compare it with the correct answer. If it’s wrong, we need a way to adjust the internal connections (weights and biases) so that next time, it does better.</p><p>That’s where <strong>backpropagation</strong> comes in.</p><p>We Calculate the Error<br> We use a <strong>loss function</strong> (like cross-entropy) to measure how far the prediction was from the true answer.<br> Example: If the correct digit is “5” but the network said “3,” the loss will be high.</p><ol><li><strong>We Work Backwards</strong> We then go layer by layer <em>backward</em> from the output to the input:We figure out which neurons were most responsible for the mistake. The idea is: “If I change this weight just a little, will it reduce the error?”</li><li><strong>We Calculate How Much to Change (Gradients)</strong><br> Using a process called the <strong>chain rule</strong> (from calculus), the network figures out how each weight and bias contributed to the error. These are called <strong>gradients</strong>.</li><li><strong>We Update the Parameters</strong><br> Finally, we tweak the weights and biases using those gradients. This step is called <strong>gradient descent</strong>.<br> The model learns by repeating this process over and over: make a guess, measure the error, adjust.</li></ol><p>Backpropagation is what allows a network to learn complex tasks — from recognizing handwritten digits to translating languages or even driving cars. It’s not magic, just a systematic way to improve based on feedback.</p><p>Let’s break down how backpropagation actually works, step by step, using the core mathematical formulas that guide the learning process.</p><ol><li>Compute the error at the output layer:</li></ol><pre>dz[L] = a[L] - y</pre><ul><li>a[L]: output of the last layer</li><li>y: true label (one-hot encoded)</li></ul><p>2. Compute gradients for weights and biases at the output layer:</p><pre>dW[L] = dz[L] * a[L-1].T<br>db[L] = dz[L]</pre><p>3. Repeat for hidden layers (looping backwards):</p><pre>for l in range(L-1, 0, -1):<br>    da[l] = W[l+1].T * dz[l+1]<br>    dz[l] = da[l] ∘ activation_derivative(z[l])<br>    dW[l] = dz[l] * a[l-1].T<br>    db[l] = dz[l]</pre><ul><li>∘ means element-wise multiplication (Hadamard product)</li><li>activation_derivative is the derivative of ReLU, which is:</li></ul><pre>ReLU&#39;(x) = 1 if x &gt; 0 else 0</pre><p>4-Update the Parameters — Gradient Descent</p><p>After computing gradients, we update weights and biases like this:</p><pre>W[l] = W[l] - learning_rate * dW[l]<br>b[l] = b[l] - learning_rate * db[l]</pre><p>Now that we’ve covered the theory, let’s walk through the actual process of <strong>building a neural network from scratch</strong> using only Python and NumPy. We’ll use the MNIST dataset (handwritten digits).</p><p>For this model, we’ll use:</p><ul><li><strong>Input Layer</strong>: 784 neurons (28×28 image flattened)</li><li><strong>Hidden Layer</strong>: 128 neurons, ReLU activation</li><li><strong>Output Layer</strong>: 10 neurons, Softmax activation</li></ul><h3><strong>Step 1 : Initialization of Weights and Biases</strong></h3><p>Each connection between neurons holds a weight, and each neuron (except in the input layer) has a bias.</p><p>The shape of the <strong>weight matrix</strong> W[l] for layer l is:</p><pre>(number of neurons in current layer, number of neurons in previous layer)</pre><p>The shape of the <strong>bias vector</strong> b[l] is:</p><pre>(number of neurons in current layer, 1)</pre><p>These shapes ensure that during forward propagation, the matrix multiplication works correctly:</p><pre>Z[l] = W[l] · A[l-1] + b[l]<br></pre><p>Instead of creating a separate variable for every layer manually, we use a <strong>dictionary</strong> to store them, like params[&quot;W1&quot;], params[&quot;b1&quot;], params[&quot;W2&quot;], and so on.<br> This makes the code scalable and easier to manage especially for deeper networks.</p><pre>import numpy as np<br><br>def init_params(layer_dims):<br>    &quot;&quot;&quot;<br>    Initializes weights and biases for each layer.<br>    <br>    Arguments:<br>    layer_dims -- List of layer sizes, e.g., [784, 128, 10]<br>    <br>    Returns:<br>    params -- Dictionary of initialized weights and biases<br>    &quot;&quot;&quot;<br>    params = {}<br>    for l in range(1, len(layer_dims)):<br>        params[f&quot;W{l}&quot;] = np.random.randn(layer_dims[l], layer_dims[l - 1]) * 0.01<br>        params[f&quot;b{l}&quot;] = np.zeros((layer_dims[l], 1))<br>    return params</pre><h3>Step 2: Forward Propagation</h3><p>Now that our parameters are initialized, we’ll implement <strong>forward propagation</strong> — the step where input data flows through the network to generate predictions.</p><p>At each layer, we:</p><ul><li>Compute the weighted sum using the previous layer’s activations, weights, and biases.</li><li>Apply an activation function:</li><li>ReLU for the hidden layers</li><li>Softmax for the output layer</li></ul><p>We also store all intermediate values (activations and pre-activations) in a cache dictionary, which will be used later during backpropagation.</p><p>Defining the activation functions Relu and softmax:</p><pre>def relu(z):<br>    return np.maximum(0, z)<br><br>def softmax(z):<br>    exp = np.exp(z - np.max(z, axis=0, keepdims=True))  # numerical stability<br>    return exp / np.sum(exp, axis=0, keepdims=True)</pre><p>the forward function :</p><pre>def forward(X, params):<br>    &quot;&quot;&quot;<br>    Forward propagation across all layers.<br><br>    Arguments:<br>    X -- input data (samples, features)<br>    params -- dictionary of weights and biases<br><br>    Returns:<br>    activ -- dictionary of all pre-activations and activations (Z and A)<br>    &quot;&quot;&quot;<br>    activ = {}<br>    activ[&quot;A0&quot;] = X.T  # each column is one sample<br>    L = len(params) // 2  # total number of layers<br><br>    for l in range(1, L):<br>        Z = np.dot(params[f&quot;W{l}&quot;], activ[f&quot;A{l-1}&quot;]) + params[f&quot;b{l}&quot;]<br>        A = relu(Z)<br>        activ[f&quot;Z{l}&quot;] = Z<br>        activ[f&quot;A{l}&quot;] = A<br><br>    # Output layer with softmax<br>    Z_final = np.dot(params[f&quot;W{L}&quot;], activ[f&quot;A{L-1}&quot;]) + params[f&quot;b{L}&quot;]<br>    A_final = softmax(Z_final)<br>    activ[f&quot;Z{L}&quot;] = Z_final<br>    activ[f&quot;A{L}&quot;] = A_final<br><br>    return activ</pre><h3>Step 3: Compute the Loss (Cross-Entropy)</h3><p>After performing forward propagation, we get the final output activations from the last layer — these represent the <strong>predicted probabilities</strong> for each class. Now, we need a way to <strong>measure how good or bad these predictions are</strong>.</p><p>That’s where the <strong>loss function</strong> comes in.</p><h4>Purpose of the Loss Function</h4><p>The loss tells us how far off our model’s predictions are from the actual labels. The <strong>higher the loss</strong>, the worse the prediction. Our goal during training is to <strong>minimize this value</strong>.</p><p>Since we’re dealing with multi-class classification (digits 0–9), we use the <strong>cross-entropy loss</strong> — it works well when outputs are probabilities (like softmax outputs).</p><h3>What Is Cross-Entropy?</h3><p>Cross-entropy compares the predicted probabilities from the output layer (produced by softmax) with the actual labels (which are one-hot encoded).</p><p>Here’s what it does:</p><ul><li>If the model predicts <strong>high probability for the correct class</strong>, the loss is <strong>low</strong>.</li><li>If it assigns <strong>low probability to the correct class</strong>, the loss is <strong>high</strong>.</li></ul><p>This helps the model learn by penalizing wrong predictions more harshly and rewarding correct ones.</p><pre>def compute_loss(Y, activ, L):<br>    &quot;&quot;&quot;<br>    Computes the cross-entropy loss.<br><br>    Arguments:<br>    Y -- true labels (one-hot encoded), shape: (samples, classes)<br>    activ -- dictionary returned from forward() containing A[L]<br>    L -- total number of layers<br><br>    Returns:<br>    loss -- average loss over all examples<br>    &quot;&quot;&quot;<br>    Y_hat = activ[f&quot;A{L}&quot;]<br>    m = Y.shape[0]<br>    loss = -np.sum(Y.T * np.log(Y_hat + 1e-8)) / m  # add epsilon to avoid log(0)<br>    return loss</pre><h3>Step 4: Backpropagation — How the Model Learns</h3><p>In code, we:</p><ol><li>Start at the output layer<br> We calculate the error between the predicted output and the true label.</li><li>Move backward through the hidden layers<br> We use the chain rule to calculate the gradient of the loss with respect to each layer’s weights and biases.</li><li>Store the gradients<br> These values (dW and db) are stored in a dictionary so we can use them during parameter updates.</li></ol><pre>def relu_derivative(z):<br>    return (z &gt; 0).astype(float)<br><br>def backward(Y, activ, params):<br>    &quot;&quot;&quot;<br>    Performs backpropagation through the entire network.<br><br>    Arguments:<br>    Y -- true labels (one-hot), shape (samples, classes)<br>    activ -- dictionary of activations and pre-activations (from forward pass)<br>    params -- dictionary of weights and biases<br><br>    Returns:<br>    grads -- dictionary containing gradients for all weights and biases<br>    &quot;&quot;&quot;<br>    grads = {}<br>    L = len(params) // 2<br>    m = Y.shape[0]<br>    Y = Y.T<br>    A_final = activ[f&quot;A{L}&quot;]<br>    dZ = A_final - Y  # derivative of cross-entropy loss with softmax<br><br>    # Output layer gradients<br>    grads[f&quot;dW{L}&quot;] = (1 / m) * np.dot(dZ, activ[f&quot;A{L - 1}&quot;].T)<br>    grads[f&quot;db{L}&quot;] = (1 / m) * np.sum(dZ, axis=1, keepdims=True)<br><br>    # Backpropagate through hidden layers<br>    for l in reversed(range(1, L)):<br>        dA = np.dot(params[f&quot;W{l + 1}&quot;].T, dZ)<br>        dZ = dA * relu_derivative(activ[f&quot;Z{l}&quot;])<br>        grads[f&quot;dW{l}&quot;] = (1 / m) * np.dot(dZ, activ[f&quot;A{l - 1}&quot;].T)<br>        grads[f&quot;db{l}&quot;] = (1 / m) * np.sum(dZ, axis=1, keepdims=True)<br><br>    return grads</pre><h3>Step 5: Updating Parameters (Gradient Descent)</h3><p>After calculating how each weight and bias contributed to the error, we now <strong>adjust</strong> them slightly to reduce that error in future predictions.</p><p>This is done using <strong>gradient descent</strong>, a simple yet powerful optimization algorithm.</p><p>Gradient descent takes the calculated gradients and uses them to <strong>move the parameters in the direction that reduces the loss</strong>.</p><p>Think of it like this:</p><blockquote><em>The loss function is a hill, and we want to roll down to the bottom. The gradient tells us which direction is downhill.</em></blockquote><pre>def update(params, grads, learning_rate):<br>    &quot;&quot;&quot;<br>    Updates the weights and biases using gradient descent.<br><br>    Arguments:<br>    params -- current weights and biases<br>    grads -- gradients from backpropagation<br>    learning_rate -- step size for updating<br><br>    Returns:<br>    params -- updated weights and biases<br>    &quot;&quot;&quot;<br>    L = len(params) // 2<br>    for l in range(1, L + 1):<br>        params[f&quot;W{l}&quot;] -= learning_rate * grads[f&quot;dW{l}&quot;]<br>        params[f&quot;b{l}&quot;] -= learning_rate * grads[f&quot;db{l}&quot;]<br>    return params</pre><h3>Step 6: The Training Loop</h3><p>Now that we’ve defined:</p><ul><li>how to initialize parameters</li><li>how to do forward propagation</li><li>how to compute the loss</li><li>how to perform backpropagation</li><li>how to update parameters</li></ul><p>…it’s time to <strong>put it all together</strong> into a loop that trains the model over many iterations.</p><p>Training a neural network means <strong>repeating the same cycle</strong> (forward → loss → backward → update) many times — each repetition is called an <strong>iteration</strong>.</p><p>During each iteration:</p><ol><li>We send the data forward through the network to get predictions.</li><li>We calculate the loss.</li><li>We compute the gradients using backpropagation.</li><li>We update the parameters to improve the model.</li></ol><p>We also track the loss (and optionally accuracy) to monitor progress.</p><pre>def train(X, Y, layer_dims, learning_rate=0.1, iterations=1000):<br>    &quot;&quot;&quot;<br>    Trains the neural network.<br><br>    Arguments:<br>    X -- input data<br>    Y -- true labels (one-hot encoded)<br>    layer_dims -- list of layer sizes, e.g. [784, 128, 10]<br>    learning_rate -- how big the update steps should be<br>    iterations -- number of training cycles<br><br>    Returns:<br>    params -- trained weights and biases<br>    &quot;&quot;&quot;<br>    params = init_params(layer_dims)<br>    L = len(layer_dims) - 1  # total number of layers<br>    losses = []<br><br>    for i in range(iterations):<br>        activ = forward(X, params)<br>        loss = compute_loss(Y, activ, L)<br>        grads = backward(Y, activ, params)<br>        params = update(params, grads, learning_rate)<br><br>        if i % 100 == 0:<br>            print(f&quot;Iteration {i} -- Loss: {loss:.4f}&quot;)<br>            losses.append(loss)<br><br>    return params</pre><h4>Training our model</h4><pre># Define the architecture: Input (784), one hidden layer (128), Output (10)<br>layer_dims = [784, 128, 10]<br><br># Train the model<br>trained_params = train(X_train, Y_train, layer_dims, learning_rate=0.1, iterations=1000)</pre><p>After running the training loop, our model has learned from the data by adjusting its internal weights and biases over many iterations.</p><p>We can now ask:</p><blockquote><strong><em>How well did it learn?</em></strong><em><br> Did it just memorize the training data, or can it actually generalize to new, unseen data?</em></blockquote><p>To answer this, we’ll move on to the final step: <strong>evaluating the model’s performance</strong> using the test dataset.Step 7: Model Evaluation</p><p>Once the training is complete, we want to evaluate how well our model performs — not just on the training data, but especially on <strong>unseen test data</strong>.</p><p>This step helps us answer:</p><blockquote><em>“Did the model actually learn to generalize, or did it just memorize the training data?”</em></blockquote><h3>We Measure</h3><ul><li><strong>Accuracy</strong>: How many predictions the model got right out of all test samples.</li><li><strong>Confusion matrix</strong> <em>(optional)</em>: Shows which digits are most often confused with others.</li><li><strong>Loss on the test set</strong> <em>(optional)</em>: To see how well the model performs on unseen data.</li></ul><p>prediction and accuracy code</p><pre>def predict(X, params):<br>    &quot;&quot;&quot;<br>    Makes predictions using the trained model.<br>    <br>    Arguments:<br>    X -- input data<br>    params -- trained weights and biases<br><br>    Returns:<br>    predictions -- predicted class for each input<br>    &quot;&quot;&quot;<br>    activ = forward(X, params)<br>    A_final = activ[f&quot;A{len(params)//2}&quot;]<br>    predictions = np.argmax(A_final, axis=0)<br>    return predictions</pre><pre>def accuracy(predictions, Y):<br>    &quot;&quot;&quot;<br>    Computes the accuracy of predictions.<br><br>    Arguments:<br>    predictions -- predicted class indices<br>    Y -- true class indices<br><br>    Returns:<br>    acc -- accuracy as a percentage<br>    &quot;&quot;&quot;<br>    true_labels = np.argmax(Y, axis=1)<br>    acc = np.mean(predictions == true_labels) * 100<br>    return acc</pre><p>making prediction on our test set</p><pre>preds = predict(X_test, trained_params)<br>acc = accuracy(preds, Y_test)<br>print(f&quot;Test Accuracy: {acc:.2f}%&quot;)</pre><p>And that’s it!</p><p>We just built a neural network from scratch step by step using nothing but Python and NumPy.</p><p>If you followed along, I hope this helped you not just write the code, but actually understand what’s going on under the hood:<br> How the data flows forward, how the model learns through backpropagation, and how everything fits together into a training loop.</p><p>If you have any questions, feel free to reach out or leave a comment.<br> I’d love to know if this helped you, or what you’d like to see next!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb11dd04aa76" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>