<?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 Just S (JS) on Medium]]></title>
        <description><![CDATA[Stories by Just S (JS) on Medium]]></description>
        <link>https://medium.com/@justs0076?source=rss-056b031e9596------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7yH9keddyRHakWxjsGpJDQ.jpeg</url>
            <title>Stories by Just S (JS) on Medium</title>
            <link>https://medium.com/@justs0076?source=rss-056b031e9596------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:56:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@justs0076/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[JSON Looks Simple Until One Small Mistake Breaks Everything]]></title>
            <link>https://medium.com/@justs0076/json-looks-simple-until-one-small-mistake-breaks-everything-d910590dc3b6?source=rss-056b031e9596------2</link>
            <guid isPermaLink="false">https://medium.com/p/d910590dc3b6</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Just S (JS)]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 07:57:28 GMT</pubDate>
            <atom:updated>2026-10-09T07:57:28.744Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever worked with APIs, backend development, configuration files, or web applications, you have probably encountered JSON.</p><p>JSON (JavaScript Object Notation) is one of the most widely used formats for exchanging structured data between applications. It is lightweight, readable, and supported by almost every modern programming language.</p><p>Yet, despite its simplicity, JSON can be surprisingly frustrating.</p><p>A single missing comma, an extra quotation mark, or an incorrectly placed bracket can turn an otherwise valid document into something your application cannot parse. And when you are debugging an API response or working with a large configuration file, finding that tiny mistake can waste more time than you would expect.</p><p>So, why does JSON cause these problems, and how can we make working with it easier?</p><h3>Why JSON Errors Are So Common</h3><p>JSON is designed to be easy to read, but it follows strict syntax rules. Unlike ordinary text, every object, array, string, number, and separator must follow a defined structure.</p><p>Consider this example:</p><pre>{ <br>  &quot;name&quot;: &quot;Just S&quot;, <br>  &quot;website&quot;: &quot;https://jsonchecker.in&quot;, <br>  &quot;skills&quot;: [&quot;Python&quot;, &quot;FastAPI&quot;, &quot;JavaScript&quot;] <br>}</pre><p>This is valid JSON. The keys are enclosed in double quotation marks, the values follow the correct format, and the array is properly structured.</p><p>Now consider a slightly different version:</p><pre>{ <br>  &quot;name&quot;: &quot;Just S&quot;, <br>  &quot;website&quot;: &quot;https://jsonchecker.in&quot;, <br>  &quot;skills&quot;: [&quot;Python&quot;, &quot;FastAPI&quot;, &quot;JavaScript&quot;,] <br>}</pre><p>Did you notice the problem?</p><p>There is an extra comma after &quot;JavaScript&quot;. While some programming languages and data formats allow trailing commas in certain situations, standard JSON does not.</p><p>A parser expecting valid JSON will reject this input.</p><p>This is only one example. Developers frequently encounter several other common issues:</p><ul><li><strong>Missing commas:</strong> Two properties are placed next to each other without the required separator.</li><li><strong>Single quotation marks:</strong> JSON strings must use double quotation marks.</li><li><strong>Unquoted keys:</strong> Object property names must be enclosed in double quotation marks.</li><li><strong>Mismatched brackets:</strong> An object or array is not properly closed.</li><li><strong>Invalid escape sequences:</strong> Special characters inside strings are not escaped correctly.</li><li><strong>Incorrect data types:</strong> A value is represented differently from what the application expects.</li></ul><p>These errors may look insignificant, but they can interrupt API requests, prevent applications from loading configuration files, and cause unexpected failures during development.</p><h3>Why Manually Checking JSON Is Not Always Practical</h3><p>For a small JSON object, finding an error manually is usually straightforward.</p><p>However, imagine working with a JSON response containing hundreds of properties and deeply nested objects. The file may include customer records, product information, application settings, API results, or other structured data.</p><p>When something goes wrong, manually checking every bracket and comma becomes tedious.</p><p>The challenge is not necessarily understanding JSON. It is identifying exactly where the structure stops being valid.</p><p>This is where a JSON validator becomes useful.</p><p>Instead of repeatedly scanning the document yourself, you can use a tool to check whether the input follows JSON syntax rules and help identify errors that need attention.</p><h3>Meet JSONChecker.in</h3><p>To make this process simpler, I built <a href="https://jsonchecker.in/">JSONChecker.in</a>, a web-based tool designed to help developers and anyone working with JSON validate their data more conveniently.</p><p>The idea is straightforward: when you are dealing with JSON and are unsure whether it is valid, you should have an easy way to check it without turning the task into a debugging session of its own.</p><p>You can visit the website, use it to check your JSON, and return to your actual development work with less unnecessary friction.</p><p>Whether you are learning your first programming language, testing an API response, or working on a backend application, having a dedicated JSON-checking tool can be a useful addition to your workflow.</p><p><strong>Try it here: </strong><a href="https://jsonchecker.in/"><strong>https://jsonchecker.in/</strong></a></p><h3>Who Can Benefit From a JSON Checker?</h3><p>JSON validation is useful across many areas of software development.</p><p><strong>Backend developers</strong> regularly handle JSON request bodies, API responses, and configuration data. Validating the structure can help identify syntax problems before they interfere with other parts of an application.</p><p><strong>Frontend developers</strong> often work with data received from APIs. When a response cannot be parsed, checking the JSON is a sensible first troubleshooting step.</p><p><strong>Students and beginners</strong> can use a validator to understand JSON syntax more clearly. Seeing which structures are accepted and which are rejected helps reinforce the rules.</p><p><strong>DevOps engineers and system administrators</strong> may encounter JSON in configuration files, automation scripts, deployment settings, and cloud-service integrations. A quick validation check can help prevent avoidable syntax errors.</p><p>Of course, a valid JSON document does not automatically mean that its data is correct or that it meets an API’s requirements. Validation checks syntax; application-specific validation is still necessary.</p><h3>Valid JSON Is Only the Beginning</h3><p>It is important to distinguish between valid JSON and correct application data.</p><p>For example:</p><pre>{ <br>  &quot;age&quot;: &quot;twenty-five&quot; <br>}</pre><p>This is valid JSON because the value is a properly formatted string.</p><p>However, if an application expects age to be a number, the document may still fail application-level validation.</p><p>Similarly, JSON can be syntactically valid while containing missing fields, incorrect identifiers, unexpected values, or information that violates business rules.</p><p>A JSON checker helps with the first layer of the problem: ensuring the document follows JSON syntax. Developers must still verify that the data itself makes sense for the application consuming it.</p><p>Understanding this distinction makes debugging more systematic. Rather than investigating every part of the application immediately, start by confirming that the data can be parsed, then examine its structure and meaning.</p><h3>A Small Tool Can Save Time</h3><p>Good developer tools do not always need to be complicated. Sometimes, solving a small recurring problem is enough to make a workflow more convenient.</p><p>JSON is a fundamental part of modern development, and syntax mistakes are an ordinary part of working with structured data. The goal is not to eliminate every mistake but to make identifying and fixing them easier.</p><p>That is the idea behind JSONChecker.in: providing a straightforward place to check JSON when you need it.</p><p>If you work with APIs, write backend code, manage configuration files, or are simply learning JSON, give it a try.</p><p><strong>Visit </strong><a href="https://jsonchecker.in/"><strong>JSONChecker.in</strong></a><strong> and make JSON validation a simpler part of your development workflow.</strong></p><p><strong><em>Written by Just S (JS)<br>Software Engineer | Technical Writer</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d910590dc3b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks Explained from Scratch (Without TensorFlow)]]></title>
            <link>https://medium.com/@justs0076/neural-networks-explained-from-scratch-without-tensorflow-0011d4940dd1?source=rss-056b031e9596------2</link>
            <guid isPermaLink="false">https://medium.com/p/0011d4940dd1</guid>
            <category><![CDATA[aritificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Just S (JS)]]></dc:creator>
            <pubDate>Sat, 08 Aug 2026 06:41:55 GMT</pubDate>
            <atom:updated>2026-08-08T06:41:55.869Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever used TensorFlow or PyTorch, you may have written something like this:</p><pre>model = Sequential([<br>    Dense(10, activation=&quot;relu&quot;),<br>    Dense(1, activation=&quot;sigmoid&quot;)<br>])</pre><p>And somehow, a neural network appears.</p><p>But what is actually happening inside those Dense layers?</p><p>Where do the weights come from?</p><p>How does the network learn?</p><p>What exactly is a gradient?</p><p>And what is backpropagation actually doing?</p><p>In this article, we are going to answer all of those questions by building a neural network <strong>from scratch using only NumPy</strong>.</p><p>No TensorFlow.</p><p>No PyTorch.</p><p>No Keras.</p><p>Just Python, NumPy, mathematics, and a little patience.</p><p>The goal isn’t to build the world’s most powerful neural network. The goal is to understand what is happening inside one.</p><h3>1. What is a Neural Network?</h3><p>Let’s start with the simplest possible idea.</p><p>Suppose we want a computer to determine whether a number is positive or negative.</p><p>We could give it:</p><pre>-5 → 0<br>-3 → 0<br>-1 → 0<br> 1 → 1<br> 3 → 1<br> 5 → 1</pre><p>Here:</p><ul><li>0 means negative</li><li>1 means positive</li></ul><p>A neural network tries to learn the relationship between the input and the output.</p><p>Instead of explicitly programming:</p><pre>if x &gt;= 0:<br>    return 1<br>else:<br>    return 0</pre><p>we give the network examples and allow it to learn parameters that approximate this relationship.</p><p>Those parameters are mainly:</p><ul><li>weights</li><li>biases</li></ul><p>The fundamental building block that learns these parameters is called a <strong>neuron</strong>.</p><h3>2. The Simplest Neural Network: One Neuron</h3><p>A neuron can be surprisingly simple.</p><p>It takes some inputs, multiplies them by weights, adds a bias, and produces an output.</p><p>Mathematically:</p><pre>[<br>z = wx + b<br>]</pre><p>Where:</p><ul><li>x = input</li><li>w = weight</li><li>b = bias</li><li>z = result before activation</li></ul><p>For example:</p><pre>x = 5<br>w = 2<br>b = 1<br><br>#Then <br><br>z = (2)(5) + 1<br>z = 11</pre><p>That’s it.</p><p>The neuron calculated a weighted input plus a bias.</p><p>In Python:</p><pre>x = 5<br>w = 2<br>b = 1</pre><pre>z = w * x + b</pre><pre>print(z)</pre><p>Output:</p><pre>11</pre><p>So why do we need activation functions?</p><h3>3. Activation Functions</h3><p>If a neuron only calculated:</p><pre>z = wx+b</pre><p>then the entire network would essentially be a collection of linear equations.</p><p>Activation functions introduce <strong>non-linearity</strong>.</p><p>One of the most common activation functions is the sigmoid function.</p><h3>Sigmoid</h3><p>The sigmoid function is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*gzGmJHsdE3k2Qsw9w9KOcg.png" /></figure><p>It converts a number into a value between 0 and 1.</p><p>For example:</p><pre>z = -5  → approximately 0.0067<br>z =  0  → 0.5<br>z =  5  → approximately 0.9933</pre><p>In NumPy:</p><pre>import numpy as np</pre><pre>def sigmoid(x):<br>    return 1 / (1 + np.exp(-x))</pre><p>We can test it:</p><pre>print(sigmoid(-5))<br>print(sigmoid(0))<br>print(sigmoid(5))</pre><p>The output will be approximately:</p><pre>0.0067<br>0.5<br>0.9933</pre><p>This makes sigmoid useful when our output represents a probability.</p><p>For example:</p><pre>0.02 → probably negative<br>0.91 → probably positive</pre><h3>4. A Complete Neuron</h3><p>Now let’s combine the weighted sum and activation function.</p><pre>import numpy as np<br><br>def sigmoid(x):<br>    return 1 / (1 + np.exp(-x))<br><br>x = 5<br>w = 2<br>b = 1<br>z = w * x + b<br>output = sigmoid(z)<br>print(output)</pre><p>The process is:</p><pre>Input<br>  ↓<br>Multiply by weight<br>  ↓<br>Add bias<br>  ↓<br>Activation function<br>  ↓<br>Output</pre><p>Mathematically:</p><p>z = wx+b</p><p>then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*Q5hEtMY6uHGFESte-Jz68w.png" /></figure><p>where a is the activated output.</p><p>This tiny piece of mathematics is one of the foundations of neural networks.</p><h3>5. Why Do We Need Weights?</h3><p>Imagine our neuron receives:</p><pre>x = 5</pre><p>If the weight is:</p><pre>w = 10</pre><p>then:<br>w*x = 50</p><p>If the weight is:</p><pre>w = 0.1</pre><p>then:</p><p>w*x = 0.5</p><p>The weight determines how strongly the input affects the neuron.</p><p>You can think of weights as the network’s learned importance values.</p><p>A large positive weight means:</p><blockquote><em>This input strongly pushes the neuron upward.</em></blockquote><p>A negative weight means:</p><blockquote><em>This input pushes the neuron downward.</em></blockquote><p>A weight close to zero means:</p><blockquote><em>This input has relatively little influence.</em></blockquote><h3>6. Why Do We Need Bias?</h3><p>Consider:</p><pre>z = wx</pre><p>The output is completely controlled by the input.</p><p>Adding a bias gives us:</p><pre>z = wx+b</pre><p>The bias allows the neuron to shift its decision boundary.</p><p>A simple analogy is a straight line:</p><p>y=mx+c</p><p>Here:</p><ul><li>m controls the slope</li><li>c shifts the line</li></ul><p>In a neuron:</p><ul><li>weight controls the influence of the input</li><li>bias shifts the result</li></ul><p>So weights and biases give the network flexibility.</p><h3>7. From One Neuron to a Layer</h3><p>One neuron is useful, but neural networks normally contain many neurons.</p><p>Suppose we have two inputs:</p><pre>x₁<br>x₂</pre><p>and three neurons.</p><p>Each neuron has its own weights and bias.</p><pre>             ┌── Neuron 1<br>x₁ ──────────┤<br>x₂ ──────────┤<br>             ├── Neuron 2<br>             │<br>             └── Neuron 3</pre><p>Neuron 1 might calculate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*ASL-cQKFNW_2HCCsdvNy1A.png" /></figure><p>Neuron 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*fO5UG75oonNGMhfYs_Mj8Q.png" /></figure><p>Neuron 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*Yb7kM8VrBXVzxEslBmMnUA.png" /></figure><p>Doing this manually is inconvenient.</p><p>This is where NumPy becomes extremely useful.</p><h3>8. Matrix Multiplication</h3><p>We can represent our inputs as a vector:</p><p>X =[x1 ,x2]</p><p>and weights as a matrix:</p><p>W =[<br>w11 , w12 ,w13,<br>w21 ,w22 ,w23<br>]</p><p>Then:</p><p>Z = XW+B</p><p>Instead of calculating every neuron separately, NumPy can perform the entire operation.</p><pre>X = np.array([[2, 3]])</pre><pre>W = np.array([<br>    [0.5, 0.2, 0.1],<br>    [0.4, 0.7, 0.3]<br>])</pre><pre>B = np.array([[0.1, 0.2, 0.3]])</pre><pre>Z = X @ W + B</pre><pre>print(Z)</pre><p>The @ operator performs matrix multiplication.</p><p>This single line:</p><pre>Z = X @ W + B</pre><p>is doing a huge amount of work.</p><p>It calculates the weighted input for all three neurons simultaneously.</p><h3>9. What Does a Layer Actually Do?</h3><p>A layer can therefore be represented as:</p><p>Z = XW+B</p><p>followed by an activation function:</p><p>A=f(Z)</p><p>So a layer is essentially:</p><pre>Input<br>  ↓<br>Matrix multiplication<br>  ↓<br>Add bias<br>  ↓<br>Activation<br>  ↓<br>Output</pre><p>In code:</p><pre>Z = X @ W + B<br>A = sigmoid(Z)</pre><p>That’s the basic operation performed by a dense neural-network layer.</p><h3>10. Building Multiple Layers</h3><p>Now we can connect layers together.</p><p>For example:</p><pre>Input Layer<br>     ↓<br>Hidden Layer<br>     ↓<br>Output Layer</pre><p>Suppose our input contains two values.</p><p>The first layer has three neurons.</p><p>The second layer has one neuron.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8R1qvtghwr7gvpkBffNAJw.png" /></figure><p>Mathematically:</p><p>First layer:</p><pre>Z1=X*W1+B1<br>A1=f(Z1)</pre><p>Second layer:</p><pre>Z2=A1 * W2+B2<br>A2=f(Z2)</pre><p>The output of one layer becomes the input to the next.</p><p>This is where the term <strong>neural network</strong> starts making sense.</p><h3>11. Forward Propagation</h3><p>When information travels from the input to the output, we call this <strong>forward propagation</strong> or <strong>forward pass</strong>.</p><p>For our network:</p><pre>Input<br>  ↓<br>Layer 1<br>  ↓<br>Activation<br>  ↓<br>Layer 2<br>  ↓<br>Activation<br>  ↓<br>Prediction</pre><p>For example:</p><pre>Z1 = X @ W1 + B1<br>A1 = sigmoid(Z1)</pre><pre>Z2 = A1 @ W2 + B2<br>A2 = sigmoid(Z2)</pre><p>A2 is our prediction.</p><p>At this point, however, the network doesn’t know whether its prediction is correct.</p><p>We need a way to measure its error.</p><h3>12. Loss Function</h3><p>Suppose the correct answer is:</p><pre>y = 1</pre><p>but our network predicts:</p><pre>prediction = 0.2</pre><p>That’s not very good.</p><p>We need a number that tells us how wrong the prediction is.</p><p>This number is called the <strong>loss</strong>.</p><p>One common loss function for binary classification is binary cross-entropy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwjJMSjFtqsfZTCE6Ch-0Q.png" /></figure><p>where:</p><ul><li>y = actual answer</li><li>ŷ = predicted probability</li></ul><p>If:</p><pre>y = 1</pre><p>and:</p><pre>ŷ = 0.99</pre><p>the loss is very small.</p><p>But if:</p><pre>y = 1</pre><p>and:</p><pre>ŷ = 0.01</pre><p>the loss is very large.</p><p>So the network wants to minimize this value.</p><p>In NumPy:</p><pre>def binary_cross_entropy(y, prediction):<br>    epsilon = 1e-8<br>    prediction = np.clip(<br>        prediction,<br>        epsilon,<br>        1 - epsilon<br>    )<br>    return -np.mean(<br>        y * np.log(prediction)<br>        + (1 - y) * np.log(1 - prediction)<br>    )</pre><p>The tiny epsilon prevents us from calculating:</p><pre>log(0)</pre><p>which would cause numerical problems.</p><h3>13. The Network Has a Problem</h3><p>Now imagine our network starts with random weights.</p><p>It makes a prediction:</p><pre>Actual:     1<br>Prediction: 0.32<br>Loss:       high</pre><p>How does it know what to change?</p><p>Should it increase a particular weight?</p><p>Decrease it?</p><p>Change the bias?</p><p>And by how much?</p><p>This is the central learning problem.</p><p>The answer involves <strong>gradients</strong>.</p><h3>14. What Is a Gradient?</h3><p>A gradient tells us how much the loss changes when a parameter changes.</p><p>Imagine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*kJYi6oC8ASH5sSOfDxVehA.png" /></figure><p>If increasing a weight makes the loss larger, we want to move the weight in the opposite direction.</p><p>If increasing a weight makes the loss smaller, we want to increase the weight.</p><p>Mathematically, we calculate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*bMDn_yy2LP8edUV3yHwe-g.png" /></figure><p>This means:</p><blockquote><em>How much does the loss change when the weight changes?</em></blockquote><p>This is a derivative.</p><p>A collection of these derivatives is called a gradient.</p><h3>15. Gradient Descent</h3><p>Once we know the gradient, we can update the parameter.</p><p>The basic equation is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*KnjhOTaEXLFs6gToPkI2Ow.png" /></figure><p>where:</p><ul><li>w = weight</li><li>η = learning rate</li><li>∂L/∂w = gradient</li></ul><p>The learning rate controls how large our step is.</p><p>For example:</p><pre>learning rate = 0.1</pre><p>means we make a relatively small adjustment.</p><p>The process looks like:</p><pre>Make prediction<br>     ↓<br>Calculate loss<br>     ↓<br>Calculate gradients<br>     ↓<br>Update weights<br>     ↓<br>Make another prediction<br>     ↓<br>Calculate loss<br>     ↓<br>...</pre><p>Eventually, the loss should decrease.</p><h3>16. But How Do We Calculate the Gradients?</h3><p>This is where <strong>backpropagation</strong> comes in.</p><p>Backpropagation sounds complicated, but the core idea is surprisingly simple:</p><blockquote><em>Start at the output and work backward through the network using the chain rule.</em></blockquote><p>Consider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LkY12ethgOw2y4UEY9whRg.png" /></figure><p>We calculate how the loss depends on each intermediate value.</p><p>This is the chain rule from calculus.</p><p>If:</p><p>L=f(g(x))</p><p>then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*FqCwDgEOlQJ0lg1KAP9qVQ.png" /></figure><p>Neural networks contain many nested functions.</p><p>Backpropagation applies this idea repeatedly.</p><h3>17. The Sigmoid Derivative</h3><p>To perform backpropagation, we need the derivative of our activation function.</p><p>Recall:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*gzGmJHsdE3k2Qsw9w9KOcg.png" /><figcaption>Sigmoid function</figcaption></figure><p>Its derivative has a particularly convenient form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*eXzQyZzWciJ4_I37k2HSFw.png" /></figure><p>In Python:</p><pre>def sigmoid_derivative(x):<br>    s = sigmoid(x)<br>    return s * (1 - s)</pre><p>Notice something important.</p><p>We don’t actually need to calculate sigmoid twice if we already have its output.</p><p>If:</p><pre>a = sigmoid(z)</pre><p>then:</p><pre>sigmoid_derivative = a * (1 - a)</pre><p>This is useful during backpropagation.</p><h3>18. A Small Network We Can Actually Train</h3><p>Let’s build a network for a simple classification problem.</p><p>We’ll use the famous XOR problem.</p><p>The dataset is:</p><pre>Input       Output<br>0 0           0<br>0 1           1<br>1 0           1<br>1 1           0</pre><p>XOR is interesting because a single linear neuron cannot solve it.</p><p>We need a hidden layer.</p><p>Our network will look like:</p><pre>2 inputs<br>   ↓<br>4 hidden neurons<br>   ↓<br>1 output neuron</pre><h3>19. Creating the Dataset</h3><pre>import numpy as np</pre><pre>X = np.array([<br>    [0, 0],<br>    [0, 1],<br>    [1, 0],<br>    [1, 1]<br>])</pre><pre>y = np.array([<br>    [0],<br>    [1],<br>    [1],<br>    [0]<br>])</pre><p>We have four training examples.</p><p>Each example contains two features.</p><h3>20. Initialize the Weights</h3><p>We’ll create:</p><pre>2 input neurons<br>4 hidden neurons<br>1 output neuron</pre><p>Therefore:</p><pre>W1 = np.random.randn(2, 4)<br>b1 = np.zeros((1, 4))</pre><pre>W2 = np.random.randn(4, 1)<br>b2 = np.zeros((1, 1))</pre><p>The shapes are important.</p><p>W1:</p><pre>2 × 4</pre><p>W2:</p><pre>4 × 1</pre><p>We can visualize the network:</p><pre>        ┌── H1 ──┐<br>X1 ─────┼── H2 ──┼── Output<br>        ├── H3 ──┤<br>X2 ─────┼── H4 ──┘<br>        └────────┘</pre><h3>21. Forward Pass</h3><p>Let’s write the forward pass.</p><pre>Z1 = X @ W1 + b1<br>A1 = sigmoid(Z1)</pre><pre>Z2 = A1 @ W2 + b2<br>A2 = sigmoid(Z2)</pre><p>Here:</p><pre>X<br> ↓<br>Z1<br> ↓<br>A1<br> ↓<br>Z2<br> ↓<br>A2</pre><p>A2 contains our predictions.</p><h3>22. Calculate the Loss</h3><pre>loss = binary_cross_entropy(y, A2)</pre><pre>print(loss)</pre><p>Because our weights were randomly initialized, the initial loss won’t necessarily be good.</p><p>That’s expected.</p><p>The network hasn’t learned anything yet.</p><h3>23. Backpropagation</h3><p>Now comes the important part.</p><p>For sigmoid output combined with binary cross-entropy, the gradient simplifies nicely.</p><p>For the output layer:</p><p>dZ2=A2-y</p><p>Then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*878-TAOMzrnIT9YUtzzmdA.png" /></figure><p>and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*eEQ_RDmkgIdBILSJmFwDEg.png" /></figure><p>Now we move backward into the hidden layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*7qNyAVuuLwQytxhZGeyvOg.png" /></figure><p>Then:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dtO0N4kTLvpjPiWj9KU8QA.png" /></figure><p>where ⊙ means element-wise multiplication.</p><p>Finally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*NUnXGbeOQI0gYFhZ8f9dfg.png" /></figure><p>and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*UVM5xC2oqTXlDbH9mEd8-w.png" /></figure><p>These equations are the heart of our neural network.</p><h3>24. Implementing Backpropagation</h3><p>In NumPy:</p><pre>dZ2 = A2 - y</pre><pre>dW2 = A1.T @ dZ2<br>db2 = np.sum(dZ2, axis=0, keepdims=True)</pre><pre>dA1 = dZ2 @ W2.T</pre><pre>dZ1 = dA1 * A1 * (1 - A1)</pre><pre>dW1 = X.T @ dZ1<br>db1 = np.sum(dZ1, axis=0, keepdims=True)</pre><p>Now we know how much each parameter contributed to the error.</p><h3>25. Updating the Weights</h3><p>We’ll use gradient descent.</p><pre>learning_rate = 0.1</pre><pre>W2 -= learning_rate * dW2<br>b2 -= learning_rate * db2</pre><pre>W1 -= learning_rate * dW1<br>b1 -= learning_rate * db1</pre><p>The -= is important.</p><p>We’re moving in the direction that reduces the loss.</p><h3>26. Training Loop</h3><p>We repeat the process many times.</p><pre>epochs = 10000<br>learning_rate = 0.1</pre><pre>for epoch in range(epochs):</pre><pre>    # -------------------------<br>    # Forward propagation<br>    # -------------------------</pre><pre>    Z1 = X @ W1 + b1<br>    A1 = sigmoid(Z1)</pre><pre>    Z2 = A1 @ W2 + b2<br>    A2 = sigmoid(Z2)</pre><pre>    # -------------------------<br>    # Loss<br>    # -------------------------</pre><pre>    loss = binary_cross_entropy(y, A2)</pre><pre>    # -------------------------<br>    # Backpropagation<br>    # -------------------------</pre><pre>    dZ2 = A2 - y</pre><pre>    dW2 = A1.T @ dZ2<br>    db2 = np.sum(dZ2, axis=0, keepdims=True)</pre><pre>    dA1 = dZ2 @ W2.T</pre><pre>    dZ1 = dA1 * A1 * (1 - A1)</pre><pre>    dW1 = X.T @ dZ1<br>    db1 = np.sum(dZ1, axis=0, keepdims=True)</pre><pre>    # -------------------------<br>    # Update parameters<br>    # -------------------------</pre><pre>    W2 -= learning_rate * dW2<br>    b2 -= learning_rate * db2</pre><pre>    W1 -= learning_rate * dW1<br>    b1 -= learning_rate * db1</pre><pre>    if epoch % 1000 == 0:<br>        print(<br>            f&quot;Epoch {epoch}, Loss: {loss:.6f}&quot;<br>        )</pre><p>This is our neural network training algorithm.</p><p>No TensorFlow.</p><p>No PyTorch.</p><p>No automatic differentiation.</p><p>Just NumPy.</p><h3>27. Making Predictions</h3><p>After training, we can perform another forward pass.</p><pre>Z1 = X @ W1 + b1<br>A1 = sigmoid(Z1)</pre><pre>Z2 = A1 @ W2 + b2<br>predictions = sigmoid(Z2)</pre><pre>print(predictions)</pre><p>We might get something similar to:</p><pre>[[0.01]<br> [0.98]<br> [0.98]<br> [0.02]]</pre><p>The exact numbers will vary because our weights were randomly initialized.</p><p>We can convert probabilities into classes:</p><pre>classes = (predictions &gt;= 0.5).astype(int)</pre><pre>print(classes)</pre><p>Result:</p><pre>[[0]<br> [1]<br> [1]<br> [0]]</pre><p>Our network has learned XOR.</p><h3>28. The Complete Code</h3><p>Here is the entire implementation in one place.</p><pre>import numpy as np<br></pre><pre># --------------------------------<br># Activation function<br># --------------------------------</pre><pre>def sigmoid(x):<br>    return 1 / (1 + np.exp(-x))<br></pre><pre># --------------------------------<br># Loss function<br># --------------------------------</pre><pre>def binary_cross_entropy(y, prediction):</pre><pre>    epsilon = 1e-8</pre><pre>    prediction = np.clip(<br>        prediction,<br>        epsilon,<br>        1 - epsilon<br>    )</pre><pre>    return -np.mean(<br>        y * np.log(prediction)<br>        + (1 - y) * np.log(1 - prediction)<br>    )<br></pre><pre># --------------------------------<br># Dataset<br># --------------------------------</pre><pre>X = np.array([<br>    [0, 0],<br>    [0, 1],<br>    [1, 0],<br>    [1, 1]<br>])</pre><pre>y = np.array([<br>    [0],<br>    [1],<br>    [1],<br>    [0]<br>])<br></pre><pre># --------------------------------<br># Initialize parameters<br># --------------------------------</pre><pre>np.random.seed(42)</pre><pre>W1 = np.random.randn(2, 4)<br>b1 = np.zeros((1, 4))</pre><pre>W2 = np.random.randn(4, 1)<br>b2 = np.zeros((1, 1))<br></pre><pre># --------------------------------<br># Training<br># --------------------------------</pre><pre>epochs = 10000<br>learning_rate = 0.1</pre><pre>for epoch in range(epochs):</pre><pre>    # Forward propagation</pre><pre>    Z1 = X @ W1 + b1<br>    A1 = sigmoid(Z1)</pre><pre>    Z2 = A1 @ W2 + b2<br>    A2 = sigmoid(Z2)</pre><pre>    # Calculate loss</pre><pre>    loss = binary_cross_entropy(y, A2)</pre><pre>    # Backpropagation</pre><pre>    dZ2 = A2 - y</pre><pre>    dW2 = A1.T @ dZ2<br>    db2 = np.sum(dZ2, axis=0, keepdims=True)</pre><pre>    dA1 = dZ2 @ W2.T</pre><pre>    dZ1 = dA1 * A1 * (1 - A1)</pre><pre>    dW1 = X.T @ dZ1<br>    db1 = np.sum(dZ1, axis=0, keepdims=True)</pre><pre>    # Gradient descent</pre><pre>    W2 -= learning_rate * dW2<br>    b2 -= learning_rate * db2</pre><pre>    W1 -= learning_rate * dW1<br>    b1 -= learning_rate * db1</pre><pre>    if epoch % 1000 == 0:<br>        print(<br>            f&quot;Epoch {epoch}, Loss: {loss:.6f}&quot;<br>        )<br></pre><pre># --------------------------------<br># Prediction<br># --------------------------------</pre><pre>Z1 = X @ W1 + b1<br>A1 = sigmoid(Z1)</pre><pre>Z2 = A1 @ W2 + b2<br>predictions = sigmoid(Z2)</pre><pre>classes = (predictions &gt;= 0.5).astype(int)</pre><pre>print(&quot;\nPredictions:&quot;)<br>print(predictions)</pre><pre>print(&quot;\nClasses:&quot;)<br>print(classes)</pre><h3>29. Let’s Understand the Entire Algorithm</h3><p>At this point, let’s step away from the code.</p><p>The entire training process is essentially:</p><pre>                ┌─────────────────┐<br>                │     Dataset     │<br>                └────────┬────────┘<br>                         ↓<br>                ┌─────────────────┐<br>                │ Forward Pass    │<br>                └────────┬────────┘<br>                         ↓<br>                ┌─────────────────┐<br>                │   Prediction    │<br>                └────────┬────────┘<br>                         ↓<br>                ┌─────────────────┐<br>                │ Calculate Loss  │<br>                └────────┬────────┘<br>                         ↓<br>                ┌─────────────────┐<br>                │ Backpropagation │<br>                └────────┬────────┘<br>                         ↓<br>                ┌─────────────────┐<br>                │ Update Weights  │<br>                └────────┬────────┘<br>                         │<br>                         └──────→ Repeat</pre><p>That loop is the essence of neural-network training.</p><h3>30. What Does the Network Actually Learn?</h3><p>This is an important question.</p><p>We started with random weights.</p><p>For example:</p><pre>W1 =<br>[[ 0.49, -0.13,  0.64,  1.52],<br> [-0.23,  0.23, -0.23, -0.23]]</pre><p>These values initially have no meaningful interpretation.</p><p>During training, the network changes them.</p><p>After thousands of updates, the weights become values that allow the network to transform the inputs into useful representations.</p><p>The network isn’t explicitly learning rules such as:</p><pre>if x1 != x2:<br>    output = 1</pre><p>Instead, it learns numerical parameters that produce the desired behavior.</p><p>This is one of the most important ideas in machine learning.</p><h3>31. Why Do Hidden Layers Matter?</h3><p>Consider XOR again:</p><pre>0 0 → 0<br>0 1 → 1<br>1 0 → 1<br>1 1 → 0</pre><p>A single linear decision boundary cannot separate these examples correctly.</p><p>A hidden layer allows the network to create intermediate representations.</p><p>The hidden neurons transform the original inputs.</p><p>Instead of directly learning:</p><pre>X → output</pre><p>the network learns:</p><pre> X<br> ↓<br>representation<br> ↓<br>output</pre><p>This ability to learn useful representations is one of the reasons neural networks are so powerful.</p><h3>32. What Does “Deep” Mean?</h3><p>A network with one hidden layer is already a neural network.</p><p>When we add more hidden layers:</p><pre>Input<br>  ↓<br>Hidden Layer 1<br>  ↓<br>Hidden Layer 2<br>  ↓<br>Hidden Layer 3<br>  ↓<br>Output</pre><p>we get a deeper network.</p><p>For example:</p><pre>   Input<br>     ↓<br> 64 neurons<br>     ↓<br> 32 neurons<br>     ↓<br> 16 neurons<br>     ↓<br> 1 neuron</pre><p>The word <strong>deep</strong> in deep learning generally refers to having multiple layers of learned transformations.</p><h3>33. What Does NumPy Actually Give Us?</h3><p>NumPy doesn’t give us a neural-network framework.</p><p>It gives us efficient numerical operations.</p><p>For example:</p><pre>X @ W</pre><p>performs matrix multiplication.</p><p>And:</p><pre>A * B</pre><p>performs element-wise multiplication.</p><p>And:</p><pre>np.sum(...)</pre><p>calculates sums.</p><p>That’s enough to implement the basic mathematics ourselves.</p><p>Frameworks such as TensorFlow and PyTorch build much more functionality on top of these kinds of numerical operations.</p><p>They provide things like:</p><ul><li>automatic differentiation</li><li>GPU acceleration</li><li>optimized tensor operations</li><li>neural-network layers</li><li>optimizers</li><li>model serialization</li><li>distributed training</li></ul><p>But underneath all that abstraction are mathematical operations very similar to what we implemented here.</p><h3>34. So Why Do We Use TensorFlow or PyTorch?</h3><p>If we can build a neural network with NumPy, why use frameworks?</p><p>Because real neural networks are much larger.</p><p>Imagine a model with:</p><pre>1,000,000 parameters</pre><p>Calculating and managing everything manually would become painful.</p><p>Modern frameworks provide abstractions such as:</p><pre>Dense(128)</pre><p>instead of making us manually create:</p><pre>W = ...<br>b = ...</pre><p>They also automatically calculate gradients.</p><p>Instead of manually implementing:</p><pre>dW2 = ...<br>db2 = ...<br>dW1 = ...<br>db1 = ...</pre><p>we can use automatic differentiation.</p><p>The frameworks don’t remove the mathematics.</p><p>They automate it.</p><h3>35. The Most Important Equations</h3><p>If you remember only a few equations from this article, remember these.</p><h3>Neuron</h3><p>z = wx+b</p><h3>Layer</h3><p>Z=XW+B</p><h3>Activation</h3><p>A=f(Z)</p><h3>Sigmoid</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*gzGmJHsdE3k2Qsw9w9KOcg.png" /></figure><h3>Binary Cross-Entropy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwjJMSjFtqsfZTCE6Ch-0Q.png" /></figure><h3>Gradient Descent</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*aRhy1mpUNL5-6eOQ92IheA.png" /></figure><h3>Training</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vde2l-L_-9CoQQhqi971Fw.png" /></figure><p>That cycle is the heart of neural-network learning.</p><h3>36. What We Have Built</h3><p>Let’s take a moment to appreciate what we just implemented.</p><p>Starting with nothing but NumPy, we created:</p><ul><li>neurons</li><li>weights</li><li>biases</li><li>an activation function</li><li>a loss function</li><li>forward propagation</li><li>backpropagation</li><li>gradients</li><li>gradient descent</li><li>a hidden layer</li><li>a training loop</li><li>predictions</li></ul><p>And we trained the network to solve XOR.</p><p>The code isn’t particularly large.</p><p>The difficult part isn’t writing the code.</p><p>The difficult part is understanding what every line means.</p><p>Once the mathematics becomes clear, the code becomes much less mysterious.</p><h3>37. The Big Picture</h3><p>A neural network can be viewed as a function with many adjustable parameters.</p><p>Suppose our network is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-OaAxsikHIfeNaVE2fF-3g.png" /></figure><p>Initially, the parameters are random.</p><p>Training tries to find values of:<br> W1, b1,W2,b2</p><p>that minimize the loss.</p><p>In other words:</p><p>[Find parameters that make predictions good.]</p><p>Gradient descent gives us a systematic way of doing that.</p><p>Backpropagation tells us how the loss depends on the parameters.</p><p>Together:</p><pre>Backpropagation<br>      +<br>Gradient Descent<br>      ↓<br>Learning</pre><h3>38. From XOR to Real-World AI</h3><p>Our XOR example is tiny.</p><p>Real-world neural networks follow the same fundamental idea, but at much larger scales.</p><p>For example, an image classifier might look like:</p><pre>Image<br>  ↓<br>Neural Network<br>  ↓<br>Features<br>  ↓<br>More Features<br>  ↓<br>Prediction</pre><p>A language model might process:</p><pre>Text<br> ↓<br>Tokens<br> ↓<br>Embeddings<br> ↓<br>Many neural-network layers<br> ↓<br>Probability distribution<br> ↓<br>Next token</pre><p>Computer vision, speech recognition, recommendation systems, language models, and many other machine-learning systems use variations of the same fundamental principles:</p><pre>Parameters<br>     ↓<br>Forward computation<br>     ↓<br>Loss<br>     ↓<br>Gradients<br>     ↓<br>Parameter updates<br>     ↓<br>Repeat</pre><p>The architecture can become incredibly sophisticated, but the basic learning loop remains recognizable.</p><h3>39. Final Takeaway</h3><p>Neural networks can look intimidating because frameworks hide a huge amount of complexity.</p><p>But at the foundation, we have something much simpler.</p><h3>A neuron:</h3><p><strong>z=wx+b</strong></p><h3>A layer:</h3><p><strong>Z=XW+B</strong></p><h3>An activation:</h3><p><strong>A=f(Z)</strong></p><h3>A loss:</h3><p><strong>L= How wrong are we?</strong></p><h3>Backpropagation:</h3><p><strong>How did each parameter contribute to the error?</strong></p><h3>Gradient descent:</h3><p><strong>How should we change the parameters?</strong></p><h3>And training:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDaUbKNCGbYjHIzChJFR3g.png" /></figure><p>That’s the core idea.</p><p>Once you understand this, a line such as:</p><pre>model.fit(X, y)</pre><p>is no longer magic.</p><p>You know what is happening underneath.</p><p>The framework is simply doing the mathematics we implemented ourselves — faster, more efficiently, and at a much larger scale.</p><p>And that is perhaps the most useful reason to build a neural network from scratch:</p><p><strong>not because we should avoid TensorFlow or PyTorch, but because understanding what happens underneath makes those tools much easier to use.</strong></p><h3>Where to Go Next</h3><p>If you want to continue learning neural networks from the ground up, a natural progression is:</p><ol><li>Build a single perceptron from scratch.</li><li>Build linear regression using NumPy.</li><li>Build logistic regression using NumPy.</li><li>Build a multi-layer neural network.</li><li>Implement different activation functions.</li><li>Implement different loss functions.</li><li>Implement gradient descent from scratch.</li><li>Implement mini-batch training.</li><li>Add optimizers such as Momentum and Adam.</li><li>Implement automatic differentiation.</li><li>Move from NumPy to PyTorch.</li><li>Finally understand CNNs, RNNs, Transformers, and modern deep-learning architectures.</li></ol><p>The deeper you go, the less mysterious neural networks become.</p><p>They are not magic.</p><p>They are mathematics, computation, and a lot of matrix multiplication.</p><p><strong><em>Written by Just S (JS)<br>Software Engineer | Technical Writer</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0011d4940dd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TensorFlow Basics: A Beginner’s Guide to Building Your First AI Model]]></title>
            <link>https://medium.com/@justs0076/tensorflow-basics-a-beginners-guide-to-building-your-first-ai-model-3453818c9096?source=rss-056b031e9596------2</link>
            <guid isPermaLink="false">https://medium.com/p/3453818c9096</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Just S (JS)]]></dc:creator>
            <pubDate>Wed, 29 Jul 2026 05:43:38 GMT</pubDate>
            <atom:updated>2026-07-29T05:43:38.186Z</atom:updated>
            <content:encoded><![CDATA[<p>I remember the first time I opened TensorFlow’s documentation — it felt like staring at a wall of jargon. Tensors, gradients, epochs, optimizers… none of it made sense until I actually sat down and built something. So that’s what we’re going to do here.</p><p>This isn’t a comprehensive reference. It’s the guide I wish someone had handed me when I started: enough to get a real neural network running on your machine today, with just enough theory to know why each step matters.</p><h3>So, what actually is TensorFlow?</h3><p>At its core, TensorFlow is Google’s open-source library for building and training machine learning models. That’s the textbook answer, anyway. In practice, it’s the toolkit that lets your computer find patterns in data instead of you having to hard-code every single rule yourself.</p><p>Here’s the distinction that made it click for me: in traditional programming, you write the rules and the computer produces the output. With TensorFlow, you feed it examples — inputs and the outputs you’d expect — and it works backward to figure out the rules on its own.</p><p>Take handwritten digit recognition. Nobody sits down and writes “if there’s a loop at the top and a loop at the bottom, it’s probably an 8.” That would be a nightmare to maintain. Instead, you show the model thousands of labeled digit images, and it gradually learns what separates a 3 from an 8 on its own.</p><h3>Why people actually reach for it</h3><p>There are other frameworks out there, so why does TensorFlow keep showing up? A few reasons, from what I’ve seen:</p><ul><li>Keras is bundled in, so you’re not writing low-level math by hand</li><li>It runs on GPUs and TPUs without much extra setup, which matters once your models get bigger</li><li>You can ship the same model to production servers, phones (TensorFlow Lite), or even a browser tab (TensorFlow.js)</li><li>The community is enormous, so a Stack Overflow search usually turns something up</li><li>There’s a huge library of pre-trained models you can build on instead of starting from zero</li></ul><p>None of this means TensorFlow is the “best” framework — that’s a debate people have endlessly, and PyTorch fans will make a good case too. But for someone starting out, the combination of an easy API and a mature ecosystem is hard to beat.</p><h3>Getting it installed</h3><p>This part’s quick:</p><pre>pip install tensorflow</pre><p>Then check it actually landed correctly:</p><pre>import tensorflow as tf<br>print(tf.__version__)</pre><p>If a version number prints out, you’re good to go.</p><h3>Tensors: the thing TensorFlow is named after</h3><p>Strip away the fancy name and a tensor is just a multidimensional array. That’s it. People overcomplicate this concept way more than they need to.</p><p>A single number is a <strong>scalar</strong>, or a 0-dimensional tensor:</p><pre>5</pre><p>A list of numbers is a <strong>vector</strong>, 1D:</p><pre>[1, 2, 3]</pre><p>A grid of numbers is a <strong>matrix</strong>, 2D:</p><pre>[<br> [1, 2],<br> [3, 4]<br>]</pre><p>And you can keep nesting further — a 3D tensor is basically a stack of matrices:</p><pre>[<br> [<br>  [1, 2],<br>  [3, 4]<br> ],<br> [<br>  [5, 6],<br>  [7, 8]<br> ]<br>]</pre><p>In code, creating one looks like this:</p><pre>import tensorflow as tf</pre><pre>x = tf.constant([1, 2, 3])<br>print(x)</pre><p>Which gives you:</p><pre>tf.Tensor([1 2 3], shape=(3,), dtype=int32)</pre><p>Once you get comfortable reading that output — the values, the shape, the dtype — a lot of the confusion around TensorFlow starts to fade.</p><h3>Doing math with tensors</h3><p>You can operate on tensors pretty much the way you’d expect from regular arrays:</p><pre>a = tf.constant([1, 2, 3])<br>b = tf.constant([4, 5, 6])</pre><pre>print(a + b)   # addition<br>print(a * b)   # element-wise multiplication</pre><p>Matrix multiplication is its own thing, and it’s everywhere in neural networks, so it’s worth calling out separately:</p><pre>A = tf.constant([[1, 2], [3, 4]])<br>B = tf.constant([[5, 6], [7, 8]])</pre><pre>print(tf.matmul(A, B))</pre><h3>Constants vs. Variables</h3><p>Here’s a subtlety that trips people up early on: tf.constant values are locked in once created. But neural networks need to <em>change</em> their internal numbers as they learn — that&#39;s the whole point of training. That&#39;s what tf.Variable is for:</p><pre>w = tf.Variable(5)<br>w.assign(10)<br>print(w)</pre><p>Every weight and bias in a neural network is a Variable under the hood, quietly getting nudged after each training step.</p><h3>What’s actually happening inside a neural network?</h3><p>Strip away the buzzwords and a neural network is just a chain of fairly simple operations repeated many times. Each neuron:</p><ol><li>takes in some inputs</li><li>multiplies each by a weight</li><li>adds a bias</li><li>runs the result through an activation function</li><li>passes that output forward</li></ol><p>Training is the process of adjusting all those weights and biases so the network’s guesses get closer to the correct answers over time. It sounds almost too simple to work — and yet.</p><h3>Keras makes this genuinely easy</h3><p>Writing all of the above by hand would be tedious. Keras, TensorFlow’s high-level API, collapses it into something you can write in a minute:</p><pre>model = tf.keras.Sequential([<br>    tf.keras.layers.Dense(8, activation=&quot;relu&quot;),<br>    tf.keras.layers.Dense(1)<br>])</pre><p>Two lines, and you’ve defined a working (if untrained) neural network.</p><h3>Let’s build something: the OR gate</h3><p>Theory is fine, but nothing beats watching a model actually learn. Let’s teach one the logical OR function — given two binary inputs, output 1 if either is 1.</p><pre>import tensorflow as tf</pre><pre>x = [<br>    [0, 0],<br>    [0, 1],<br>    [1, 0],<br>    [1, 1]<br>]</pre><pre>y = [<br>    [0],<br>    [1],<br>    [1],<br>    [1]<br>]</pre><pre>x = tf.convert_to_tensor(x, dtype=tf.float32)<br>y = tf.convert_to_tensor(y, dtype=tf.float32)</pre><pre>model = tf.keras.Sequential([<br>    tf.keras.layers.Input(shape=(2,)),<br>    tf.keras.layers.Dense(1, activation=&quot;sigmoid&quot;)<br>])</pre><pre>model.compile(<br>    optimizer=&quot;adam&quot;,<br>    loss=&quot;binary_crossentropy&quot;,<br>    metrics=[&quot;accuracy&quot;]<br>)</pre><pre>model.fit(x, y, epochs=500, verbose=0)</pre><pre>print(model.predict(x))</pre><p>Run this and you should see predictions somewhere around:</p><pre>[[0.01]<br> [0.99]<br> [0.98]<br> [0.99]]</pre><p>Not perfectly 0 and 1, but close enough that the pattern is unmistakable. The model figured out OR logic entirely from four examples — nobody told it the rule directly.</p><h3>What’s going on during training, step by step</h3><p>If you’re curious what model.fit() is actually doing behind the scenes, it loops through roughly this cycle for every batch of data:</p><ol><li>Data goes in, the model makes a prediction</li><li>The loss function measures how wrong that prediction was</li><li>Backpropagation works out how much each weight contributed to the error</li><li>The optimizer nudges the weights to reduce that error</li><li>Repeat — for however many epochs you set</li></ol><p>Do this enough times and the errors shrink. That’s really the entire trick behind “learning.”</p><h3>A few activation functions worth knowing</h3><p><strong>ReLU</strong> — the default choice for hidden layers in most networks:</p><pre>activation=&quot;relu&quot;</pre><p><strong>Sigmoid</strong> — squeezes output between 0 and 1, handy for binary yes/no predictions:</p><pre>activation=&quot;sigmoid&quot;</pre><p><strong>Softmax</strong> — turns raw outputs into a proper probability distribution across multiple classes:</p><pre>activation=&quot;softmax&quot;</pre><p>You don’t need to memorize every activation function that exists. Start with these three and expand later once you hit a case they don’t cover well.</p><h3>Picking a loss function</h3><p>The loss function is how the model measures its own mistakes, and picking the right one matters more than people expect:</p><p>Task Loss function Binary classification binary_crossentropy Multi-class classification categorical_crossentropy Regression mean_squared_error</p><p>Get this wrong and training can go sideways even if everything else about your model is fine.</p><h3>Optimizers</h3><p>The optimizer decides <em>how</em> weights get updated once the loss is calculated. A few common ones: SGD, Adam, RMSProp, Adagrad.</p><p>If you’re not sure which to pick, just use <strong>Adam</strong>. It’s the sensible default almost everyone reaches for, and there’s no shame in sticking with it until you have a specific reason not to.</p><h3>Saving your work</h3><p>Once a model’s trained, you don’t want to retrain it from scratch every time you restart your script:</p><pre>model.save(&quot;model.keras&quot;)</pre><p>And to bring it back later:</p><pre>model = tf.keras.models.load_model(&quot;model.keras&quot;)</pre><h3>Where this stuff shows up in the real world</h3><p>It’s easy to think of neural networks as an academic exercise, but this same core idea — inputs, weights, loss, optimization — powers a lot of what you use daily: face recognition on your phone, speech-to-text, fraud alerts from your bank, recommendation feeds, medical image scans, self-driving perception systems, and plenty more.</p><h3>Where to go from here</h3><p>The OR gate example is deliberately tiny — it’s meant to build intuition, not impress anyone. Once you’re comfortable with it, here’s a reasonable path forward:</p><ul><li>Linear and logistic regression</li><li>Perceptrons and multi-layer networks</li><li>Convolutional Neural Networks (CNNs) — great for images</li><li>Recurrent Neural Networks (RNNs), LSTMs, and GRUs — good for sequences</li><li>Transformers — the architecture behind most modern language models</li><li>Transfer learning — reusing pre-trained models instead of starting over</li><li>Deploying a model behind an API, for instance with FastAPI</li></ul><h3>Closing thoughts</h3><p>TensorFlow looks intimidating from the outside, but the fundamentals — tensors, weights, loss, optimization — really aren’t that many moving parts once you’ve built something with your own hands. The OR gate model above is proof: four data points, a couple lines of Keras, and 500 epochs later, it learned a logical rule on its own.</p><p>Don’t try to learn everything before you start. Pick a small dataset, break your code a few times, fix it, and move on to the next idea. That’s genuinely how most people learn this stuff — not by reading about it, but by getting their hands dirty and debugging their way through it.</p><p>Written by Just S (JS) <br>Software Engineer | Technical Writer</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3453818c9096" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FastAPI: A Beginner’s Guide to Building Modern APIs with Python]]></title>
            <link>https://medium.com/@justs0076/fastapi-a-beginners-guide-to-building-modern-apis-with-python-bfbbac7cbde5?source=rss-056b031e9596------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfbbac7cbde5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Just S (JS)]]></dc:creator>
            <pubDate>Wed, 22 Jul 2026 09:51:50 GMT</pubDate>
            <atom:updated>2026-07-22T09:51:50.836Z</atom:updated>
            <content:encoded><![CDATA[<p>Python has become one of the most popular programming languages for web development, machine learning, automation, and data science. As applications grow, they often need a way to communicate with web browsers, mobile apps, or other services. This is where APIs come in.</p><p>Among the many Python frameworks available today, <strong>FastAPI</strong> has quickly become one of the favorites for developers because it is fast, easy to learn, and designed with modern Python features in mind.</p><p>In this article, we’ll explore what FastAPI is, why developers love it, how it works, and build a complete REST API from scratch.</p><h3>What is FastAPI?</h3><p>FastAPI is a modern web framework for building APIs using Python 3.9+ (or newer). It was created by Sebastián Ramírez and is built on top of two powerful libraries:</p><ul><li><strong>Starlette</strong> — Handles the web framework functionality and asynchronous networking.</li><li><strong>Pydantic</strong> — Provides automatic data validation using Python type hints.</li></ul><p>Instead of writing large amounts of boilerplate code, FastAPI allows developers to define APIs using normal Python functions and type annotations.</p><p>A simple API endpoint can be written in just a few lines.</p><pre>from fastapi import FastAPI<br><br>app = FastAPI()<br><br>@app.get(&quot;/&quot;)<br>def home():<br>    return {&quot;message&quot;: &quot;Hello World&quot;}</pre><p>Running this application instantly creates a working API.</p><h3>Why FastAPI Became Popular?</h3><p>FastAPI became popular because it solves several problems developers commonly face.</p><p>Traditional web frameworks often require writing repetitive validation code, serialization logic, and API documentation manually.</p><p>FastAPI automates much of this.</p><p>Some of its biggest advantages include:</p><ul><li>Excellent performance</li><li>Automatic request validation</li><li>Interactive API documentation</li><li>Easy dependency injection</li><li>Asynchronous programming support</li><li>Modern Python syntax</li><li>Excellent editor support</li></ul><p>These features reduce development time while improving code quality.</p><h3>Installing FastAPI</h3><p>Installing FastAPI is straightforward.</p><pre>pip install fastapi</pre><p>To run the application, you’ll also need an ASGI server.</p><p>The most common choice is Uvicorn.</p><pre>pip install uvicorn</pre><p>Or install both together:</p><pre>pip install &quot;fastapi[standard]&quot;</pre><h3>Creating Your First FastAPI Application</h3><p>Create a file named: main.py</p><p>Add the following code:</p><pre>from fastapi import FastAPI<br><br>app = FastAPI()<br><br>@app.get(&quot;/&quot;)<br>def root():<br>    return {<br>        &quot;message&quot;: &quot;Welcome to FastAPI&quot;<br>    }</pre><p>Run it using:</p><pre>uvicorn main:app --reload</pre><p>or</p><pre>fastapi dev main.py</pre><p>Open your browser:</p><p><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a> or <a href="http://localhost:8000/">http://localhost:8000</a></p><p>Response:</p><pre>{<br>    &quot;message&quot;: &quot;Welcome to FastAPI&quot;<br>}</pre><h3>HTTP Methods in FastAPI</h3><p>REST APIs use different HTTP methods depending on the operation being performed.</p><pre>Method                   Purpose<br>---------------------------------------------------------------------------<br>GET                      Retrieve data<br>POST                     Create new data<br>PUT                      Replace existing data<br>PATCH                    Update existing data<br>DELETE                   Remove data</pre><h3>Path Parameters</h3><p>Suppose we want information about a specific user.</p><pre>@app.get(&quot;/users/{user_id}&quot;)<br>def get_user(user_id: int):<br>    return {<br>        &quot;id&quot;: user_id<br>    }</pre><p>Request:</p><pre>GET /users/25</pre><p>Response:</p><pre>{<br>    &quot;id&quot;: 25<br>}</pre><p>Notice that user_id is declared as an integer. If someone sends:</p><pre>GET /users/abc</pre><p>FastAPI automatically returns a validation error because &quot;abc&quot; is not an integer.</p><h3>Query Parameters</h3><p>Query parameters appear after the question mark.</p><p>Example URL:</p><pre>/products?limit=5</pre><p>Code:</p><pre>@app.get(&quot;/products&quot;)<br>def products(limit: int = 10):<br>    return {<br>        &quot;limit&quot;: limit<br>    }</pre><p>If no value is provided, FastAPI uses the default value of 10.</p><h3>Request Body</h3><p>When creating resources, clients usually send JSON.</p><p>Example request:</p><pre>{<br>    &quot;name&quot;: &quot;Laptop&quot;,<br>    &quot;price&quot;: 85000<br>}</pre><p>First define a model.</p><pre>from pydantic import BaseModel</pre><pre>class Product(BaseModel):<br>    name: str<br>    price: float</pre><p>Use it inside the endpoint.</p><pre>@app.post(&quot;/products&quot;)<br>def create_product(product: Product):<br>    return product</pre><p>FastAPI automatically:</p><ul><li>Parses JSON</li><li>Validates fields</li><li>Converts data into Python objects</li><li>Returns helpful errors if validation fails</li></ul><h3>Automatic Validation</h3><p>Suppose the request is</p><pre>{<br>    &quot;name&quot;: &quot;Laptop&quot;,<br>    &quot;price&quot;: &quot;abc&quot;<br>}</pre><p>Instead of crashing, FastAPI returns:</p><pre>{<br>    &quot;detail&quot;: [<br>        {<br>            &quot;msg&quot;: &quot;Input should be a valid number&quot;<br>        }<br>    ]<br>}</pre><p>This happens without writing any validation code.</p><h3>Response Models</h3><p>Sometimes you don’t want to return everything.</p><pre>class User(BaseModel):<br>    id: int<br>    username: str</pre><pre>@app.get(&quot;/user&quot;, response_model=User)<br>def get_user():<br>    return {<br>        &quot;id&quot;: 1,<br>        &quot;username&quot;: &quot;john&quot;,<br>        &quot;password&quot;: &quot;secret&quot;<br>    }</pre><p>Response:</p><pre>{<br>    &quot;id&quot;: 1,<br>    &quot;username&quot;: &quot;john&quot;<br>}</pre><p>The password is automatically excluded because it isn’t part of the response model.</p><h3>Interactive API Documentation</h3><p>One of FastAPI’s best features is its built-in documentation.</p><p>Swagger UI:</p><pre>http://127.0.0.1:8000/docs</pre><p>ReDoc:</p><pre>http://127.0.0.1:8000/redoc</pre><p>These pages let you:</p><ul><li>Explore endpoints</li><li>Read documentation</li><li>Send requests</li><li>Test APIs</li><li>View schemas</li></ul><p>No extra configuration is required.</p><h3>Asynchronous APIs</h3><p>FastAPI supports asynchronous programming using async.</p><pre>@app.get(&quot;/hello&quot;)<br>async def hello():<br>    return {<br>        &quot;message&quot;: &quot;Hello&quot;<br>    }</pre><p>Async endpoints are useful when waiting for:</p><ul><li>Databases</li><li>External APIs</li><li>File operations</li><li>Network requests</li></ul><p>They help applications handle many concurrent requests efficiently.</p><h3>Project Structure</h3><p>As projects grow, organizing code becomes important.</p><p>A common structure is:</p><pre>project/<br>│<br>├── app/<br>│   ├── main.py<br>│   ├── models.py<br>│   ├── routers/<br>│   ├── database.py<br>│   ├── schemas.py<br>│   └── services.py<br>│<br>├── requirements.txt<br>└── README.md</pre><p>This keeps the codebase modular and easier to maintain.</p><h3>Common Use Cases</h3><p>FastAPI is widely used for:</p><ul><li>REST APIs</li><li>AI and machine learning backends</li><li>Authentication services</li><li>Microservices</li><li>Internal company tools</li><li>Data processing APIs</li><li>Real-time applications</li><li>Backend systems for web and mobile apps</li></ul><p>Its performance and simplicity make it suitable for both small projects and large-scale production systems.</p><h3>Advantages of FastAPI</h3><p>FastAPI offers several benefits:</p><ul><li>High performance comparable to Node.js and Go for many workloads.</li><li>Automatic request validation using Pydantic.</li><li>Interactive API documentation generated automatically.</li><li>Strong type checking with Python type hints.</li><li>Native support for asynchronous programming.</li><li>Easy integration with SQLAlchemy, PostgreSQL, MongoDB, Redis, and many other tools.</li><li>Clean, readable, and maintainable code.</li><li>Excellent support from modern IDEs with autocomplete and type checking.</li></ul><h3>Limitations</h3><p>Although FastAPI is powerful, it’s important to know where it may not be the best fit.</p><ul><li>Beginners may need time to understand asynchronous programming.</li><li>Building server-rendered websites typically requires additional tools like Jinja2.</li><li>Teams unfamiliar with Python type hints may face an initial learning curve.</li><li>Some advanced use cases require understanding ASGI and the asynchronous ecosystem.</li></ul><p>For most API-focused applications, however, these limitations are relatively minor.</p><h3>Conclusion</h3><p>FastAPI has changed how developers build APIs in Python by combining speed, simplicity, and modern development practices. Its automatic validation, interactive documentation, and support for asynchronous programming help reduce boilerplate while encouraging clean, maintainable code.</p><p>Whether you’re building a small personal project, a backend for a mobile app, or a production-grade microservice, FastAPI provides an excellent foundation. With just a few lines of code, you can create APIs that are fast, well-documented, and easy to maintain.</p><p>If you’re starting a new Python API project today, FastAPI is one of the strongest frameworks to consider. As you become more comfortable with its ecosystem, you can extend your applications with features like database integration, authentication, dependency injection, background tasks, WebSockets, testing, and deployment to build robust, scalable services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfbbac7cbde5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>