<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged deeplearning</title>
<link>https://coderlegion.com/tag/deeplearning</link>
<description>Powered by Question2Answer</description>
<item>
<title>The New ML Perspective</title>
<link>https://coderlegion.com/32757/the-new-ml-perspective</link>
<description>&lt;p&gt;Artificial intelligence seems like a very complex thing packaged in a simple box. It's this magic concept of creating intelligence from something that otherwise wouldn't have any intelligence at all. Giving machines, just a bunch of 1s and 0s, electrical impulses with no real knowledge, the ability to make informed, complex decisions just like we do.&lt;/p&gt;
&lt;p&gt;But what if we've been looking at AI from the wrong perspective?&lt;/p&gt;
&lt;p&gt;Today, we're talking about the new AI perspective. Which is:&lt;/p&gt;
&lt;p&gt;Drum roll please…&lt;/p&gt;
&lt;p&gt;AI, DL, ML engineers, and all the like are the new teachers.&lt;/p&gt;
&lt;p&gt;On a random Tuesday, I realized that the very first people who thought of Artificial Intelligence weren't trying to create magic. They were just trying to take the idea of human intelligence, one of the most fascinating abilities we have, and give it to machines.&lt;/p&gt;
&lt;p&gt;And if learning is the goal, then someone has to teach.&lt;/p&gt;
&lt;h3 id=&quot;the-classroom&quot;&gt;The Classroom&lt;/h3&gt;
&lt;p&gt;Think about what happens when we build a machine learning model, ranging from linear regression models to complex neural networks.&lt;/p&gt;
&lt;p&gt;After we have the data and have cleaned it, the very first thing we do is create the &quot;brain.&quot; A blank slate walking into a classroom on the first day of school. It doesn't understand house prices. It doesn't know what a cat looks like. It has no idea whether a passenger on the Titanic survived or not.&lt;/p&gt;
&lt;p&gt;It simply has the potential to learn anything and everything.&lt;/p&gt;
&lt;p&gt;It's the same thing with humans. When a teacher receives a student for the very first time, they see a blank slate that knows almost nothing about the subject this teacher is going to teach. And this teacher's goal is to make sure that by the end of the school year, the student is basically a master at this subject.&lt;/p&gt;
&lt;p&gt;In this case, the data is the textbook.&lt;/p&gt;
&lt;h3 id=&quot;the-teaching-process&quot;&gt;The Teaching Process&lt;/h3&gt;
&lt;p&gt;Now our classroom has three things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The engineer (the teacher)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The model (the student)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The data (the textbook)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As the engineer, our job is to feed the textbook to the student over and over again. The student makes mistakes, lots of them, learns from those mistakes, slowly discovers patterns hidden in the data, and eventually gets better at making predictions.&lt;/p&gt;
&lt;p&gt;A good teacher doesn't just hand students a textbook and hope for the best. They organize the lessons, remove confusion, provide examples, and make sure the student learns the underlying concepts instead of just memorizing answers. So, the responsibility shifts back to the teacher. If the teacher fails to frame the knowledge in a way the student can understand, or lets the student learn shortcuts, then the teacher has failed at their objective.&lt;/p&gt;
&lt;p&gt;Machine learning engineers do exactly the same thing. We can't have models with leakage, or models that can't capture anything from the data. So it's up to us to take the data and use the best techniques we know to make sure the model captures actual relationships and learns from it. In engineering terms, this means encoding data, removing unnecessary columns, engineering new features, resizing images, handling missing values, and countless other techniques that help the model focus on what actually matters.&lt;/p&gt;
&lt;p&gt;If a student memorizes answers instead of understanding the material, we question the teaching. If a model memorizes the training data, suffers from leakage, or fails to generalize to new examples, we should question the training process the exact same way.&lt;/p&gt;
&lt;h3 id=&quot;exam-time&quot;&gt;Exam Time&lt;/h3&gt;
&lt;p&gt;Every student eventually sits for a TEST. A teacher gauges how well a student performs by how well they do on it.&lt;/p&gt;
&lt;p&gt;Now, you might ask, &quot;Ruva, how does this equate to my Titanic Survival Rate Prediction model?&quot; Well, the same way we have those stressful exams, models are tested on a small portion of unseen test data, data that's locked away and only brought out when it's time to test the model. One common way to do this is by using scikit-learn's &lt;code&gt;train_test_split()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;The model is then &quot;graded&quot; using evaluation metrics such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;R² score&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mean squared error (MSE)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ROC AUC&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Accuracy&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Precision and recall&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All of these different metrics let us evaluate the model's performance and figure out whether it performed well, is just guessing, or is as confused as it can possibly get.&lt;/p&gt;
&lt;h3 id=&quot;a-different-way-to-see-ai&quot;&gt;A Different Way to See AI&lt;/h3&gt;
&lt;p&gt;Thinking about AI this way changed how I see machine learning.&lt;/p&gt;
&lt;p&gt;We aren't creating intelligence out of thin air. We're creating students. And our responsibility isn't just to build models, it's to teach them well. Just like in a real classroom, the quality of the student depends on the quality of the teaching, the lessons, and the textbook.&lt;/p&gt;
&lt;p&gt;Maybe AI was never about building intelligent machines. Maybe it's always been about learning how to teach them.&lt;/p&gt;
&lt;p&gt;That's all for today. Next time, we'll talk about the magic behind Artificial Intelligence, and how AI is just the child of math and programming.&lt;/p&gt;
&lt;p&gt;See you next time!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/32757/the-new-ml-perspective</guid>
<pubDate>Wed, 28 Oct 2026 00:13:09 +0000</pubDate>
</item>
<item>
<title>Machine Learning VS Deep Learning: What’s the Difference?</title>
<link>https://coderlegion.com/32223/machine-learning-vs-deep-learning-whats-the-difference</link>
<description>&lt;p&gt;Artificial Intelligence (AI) is the new thing on the street. Everyone is talking about it, and everyone wants to be part of it in one way or another. From chatbots that can hold conversations to self-driving cars and systems that can help detect diseases, AI is becoming increasingly integrated into our everyday lives.&lt;/p&gt;
&lt;p&gt;But have you ever stopped to ask yourself: What actually makes Artificial Intelligence intelligent?&lt;/p&gt;
&lt;p&gt;I like to think that the answer to this question lies in its subfields.&lt;/p&gt;
&lt;p&gt;Artificial Intelligence is a broad field of computer science focused on building systems that can perform tasks that typically require human intelligence. Like deciding whether or not that apple is still safe to eat or if it has gone bad. These tasks include reasoning, problem-solving, learning, and understanding language. Yep, it's really cool.&lt;/p&gt;
&lt;p&gt;Within this broad field, we have several related areas, including Natural Language Processing (NLP), Computer Vision, Robotics, and Expert Systems, among others. Each of these explores different approaches to building intelligent systems.&lt;/p&gt;
&lt;p&gt;Today, however, we're focusing on two terms that are often used interchangeably, sometimes even by people working in tech: Machine Learning (ML) and Deep Learning (DL).&lt;/p&gt;
&lt;p&gt;Deep Learning took off in the 2010s because three things came together: much more data, powerful GPUs, and better training techniques. A big moment was 2012, when a deep neural network called AlexNet won the ImageNet image-recognition competition by a wide margin. After that, Deep Learning kept improving results in speech, language, and image-related tasks. This is why Deep Learning is such a huge topic in the tech space.&lt;/p&gt;
&lt;p&gt;Are they the same thing? If not, what makes them different? And why does everyone seem to be talking about Deep Learning?&lt;/p&gt;
&lt;p&gt;Let's break it down.&lt;/p&gt;
&lt;p&gt;First, we need to define Machine Learning and Deep Learning.&lt;/p&gt;
&lt;h3 id=&quot;what-is-machine-learning-&quot;&gt;What Is Machine Learning?&lt;/h3&gt;
&lt;p&gt;Machine Learning is a subfield of Artificial Intelligence that allows computers to learn patterns from data and use those patterns to make predictions or decisions without being explicitly programmed with fixed rules for every possible situation.&lt;/p&gt;
&lt;p&gt;Basically, we're giving a computer a bunch of examples of, for example, houses, their details, and their prices, and allowing it to look for patterns in that data.&lt;/p&gt;
&lt;p&gt;Like the example I mentioned, predicting house prices based on features such as location, size, and number of bedrooms.&lt;/p&gt;
&lt;p&gt;Actually programming this, including all the rules, would be a lot of work. Imagine the number of conditions and scenarios you would have to account for just to produce a model that is somewhat accurate. It would be a lot of work, and that's one of the reasons ML exists.&lt;/p&gt;
&lt;p&gt;Instead of manually writing every rule, we allow an algorithm to learn relationships from examples. The resulting model can then use what it has learned to make predictions about houses it hasn't encountered before.&lt;/p&gt;
&lt;p&gt;Pretty cool, right?&lt;/p&gt;
&lt;h3 id=&quot;what-is-deep-learning-&quot;&gt;What Is Deep Learning?&lt;/h3&gt;
&lt;p&gt;Deep Learning is a specialized branch of Machine Learning that uses artificial neural networks with multiple layers to learn increasingly complex patterns from data.&lt;/p&gt;
&lt;p&gt;Each layer transforms its input into a representation that helps the network learn useful features. For example, in a Convolutional Neural Network (CNN) trained on images, earlier layers might learn to detect edges and simple textures, while deeper layers may learn to recognize more complex shapes and object parts.&lt;/p&gt;
&lt;p&gt;It's called &lt;em&gt;Deep Learning&lt;/em&gt; because of the multiple layers in these neural networks.&lt;/p&gt;
&lt;p&gt;Deep Learning was loosely inspired, in part, by the structure and functioning of the human brain, though artificial neural networks are a hugely simplified version of the real thing.&lt;/p&gt;
&lt;p&gt;HOW COOL IS THAT? Honestly, I need a second to appreciate Deep Learning.&lt;/p&gt;
&lt;p&gt;Anyway, now that I've finished fangirling, let's get back to business.&lt;/p&gt;
&lt;p&gt;Deep Learning uses these artificial neural networks to learn patterns from data, sometimes with very little manual feature engineering.&lt;/p&gt;
&lt;p&gt;A good example is classifying fish species from photographs. Imagine having thousands of photographs of different fish species.&lt;/p&gt;
&lt;p&gt;We want to build a model that can identify the species in a photograph it has never seen before.&lt;/p&gt;
&lt;p&gt;With Deep Learning, we can train a neural network to learn useful visual features from the images and use them to classify the fish.&lt;/p&gt;
&lt;p&gt;In practice, you'd usually start from a pretrained model rather than training from scratch.&lt;/p&gt;
&lt;p&gt;Instead of manually telling the model which edges, colours, textures, or shapes to look for, the network can learn useful combinations of these features during training.&lt;/p&gt;
&lt;p&gt;And that is one of the things that makes Deep Learning so interesting!&lt;/p&gt;
&lt;p&gt;Of course, it doesn't mean we can simply throw data at a neural network and expect magic. We still need suitable data, a carefully designed model, training, and evaluation. The model's performance depends on several factors, including the quality of the data and how well the model is trained.&lt;/p&gt;
&lt;h3 id=&quot;what-s-the-difference-&quot;&gt;What's the Difference?&lt;/h3&gt;
&lt;p&gt;Now that we understand both concepts, let's talk about their differences.&lt;/p&gt;
&lt;p&gt;First, remember this: &lt;strong&gt;Deep Learning is a type of Machine Learning.&lt;/strong&gt; They aren't two completely separate fields competing against each other.&lt;/p&gt;
&lt;p&gt;Think of Artificial Intelligence as a big umbrella. Under that umbrella, we have Machine Learning, and under Machine Learning, we have Deep Learning.&lt;/p&gt;
&lt;p&gt;Yeah, we have an umbrella in an umbrella which is also in a bigger umbrella.&lt;/p&gt;
&lt;p&gt;But before we dive in, we need to define &lt;em&gt;feature engineering&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Feature engineering means choosing or creating the inputs a model learns from. For house prices, that could be turning &lt;code&gt;year built&lt;/code&gt; into &lt;code&gt;age of house&lt;/code&gt;, or calculating &lt;code&gt;price per square metre&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Traditional Machine Learning often relies heavily on this step. Deep Learning can reduce the need for manual feature engineering when working with data like images, audio, and text. However, on tabular data, well-engineered features combined with simpler models can often still perform very well.&lt;/p&gt;
&lt;p&gt;So, what actually makes them different?&lt;/p&gt;
&lt;h4 id=&quot;a-how-they-learn-from-data&quot;&gt;A. How They Learn From Data&lt;/h4&gt;
&lt;p&gt;One major difference is how they learn useful features from data.&lt;/p&gt;
&lt;p&gt;Traditional Machine Learning approaches often rely on people to select or engineer the features that a model uses.&lt;/p&gt;
&lt;p&gt;For example, if we wanted to predict house prices, we might provide a model with the house's size, location, number of bedrooms, and age.&lt;/p&gt;
&lt;p&gt;We decide which information is relevant and give the model that information to learn from.&lt;/p&gt;
&lt;p&gt;The house-price example is called &lt;strong&gt;supervised learning&lt;/strong&gt;, because the model learns from examples with known answers. There are other types, but we'll leave those for another post.&lt;/p&gt;
&lt;p&gt;Deep Learning can go a step further by learning useful features directly from less-processed data.&lt;/p&gt;
&lt;p&gt;Remember our fish classification example? Instead of manually extracting features from each photograph, a Deep Learning model can learn useful visual representations from the images themselves.&lt;/p&gt;
&lt;p&gt;This doesn't mean traditional Machine Learning cannot process images, or that Deep Learning never needs feature engineering. The difference is in how much of the feature-learning process the model can handle.&lt;/p&gt;
&lt;h4 id=&quot;b-data-requirements&quot;&gt;B. Data Requirements&lt;/h4&gt;
&lt;p&gt;Another difference is the amount of data they typically benefit from.&lt;/p&gt;
&lt;p&gt;Many traditional Machine Learning algorithms can perform well on relatively small datasets, particularly when the data is structured and the relevant features are available.&lt;/p&gt;
&lt;p&gt;Deep Learning models often benefit from larger datasets because they may need many examples to learn useful representations and generalize well to new data.&lt;/p&gt;
&lt;p&gt;However, this isn't a strict rule. The amount of data required depends on the problem, the model, and other factors.&lt;/p&gt;
&lt;p&gt;Techniques such as &lt;strong&gt;transfer learning&lt;/strong&gt; can also allow Deep Learning models to perform well when the available dataset is relatively small.&lt;/p&gt;
&lt;h4 id=&quot;c-computational-resources&quot;&gt;C. Computational Resources&lt;/h4&gt;
&lt;p&gt;Let's talk about computing power.&lt;/p&gt;
&lt;p&gt;Traditional Machine Learning models, such as decision trees and logistic regression, can often be trained with relatively modest computing resources.&lt;/p&gt;
&lt;p&gt;Deep Learning models can be much more computationally expensive, particularly when they have many parameters or are trained on large datasets.&lt;/p&gt;
&lt;p&gt;This is one reason why GPUs are commonly used to train Deep Learning models. They can perform the large number of mathematical operations involved in neural network training efficiently.&lt;/p&gt;
&lt;p&gt;This is because GPUs are good at running many calculations in parallel, especially the matrix mathematics neural networks rely on.&lt;/p&gt;
&lt;p&gt;And yes, this can also mean longer training times and higher costs.&lt;/p&gt;
&lt;h4 id=&quot;d-examples-of-algorithms&quot;&gt;D. Examples of Algorithms&lt;/h4&gt;
&lt;p&gt;Machine Learning includes several approaches, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Linear and logistic regression&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Decision trees&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Random forests&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Support Vector Machines (SVMs)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gradient Boosting&lt;/strong&gt;, such as XGBoost&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Deep Learning uses neural network architectures such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Convolutional Neural Networks (CNNs):&lt;/strong&gt; Commonly used in image-related tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Recurrent Neural Networks (RNNs):&lt;/strong&gt; Designed to process sequential data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transformers:&lt;/strong&gt; Widely used in modern language models and other applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is a lot more to explore within these categories, but we'll save that for another day.&lt;/p&gt;
&lt;p&gt;For now, here's a quick comparison:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Feature                &lt;/th&gt;&lt;th&gt;Traditional Machine Learning                                                                 &lt;/th&gt;&lt;th&gt;Deep Learning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Relationship&lt;/strong&gt;       &lt;/td&gt;&lt;td&gt;A subfield of AI                                                                             &lt;/td&gt;&lt;td&gt;A subfield of ML&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feature extraction&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;Often involves manually selecting or engineering features                                    &lt;/td&gt;&lt;td&gt;Can learn features directly from raw or minimally processed data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Data requirements&lt;/strong&gt;  &lt;/td&gt;&lt;td&gt;Can work well with smaller datasets                                                          &lt;/td&gt;&lt;td&gt;Often benefits from larger datasets&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Computing power&lt;/strong&gt;    &lt;/td&gt;&lt;td&gt;Often requires fewer resources                                                               &lt;/td&gt;&lt;td&gt;Can require substantial computing resources&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Interpretability&lt;/strong&gt;   &lt;/td&gt;&lt;td&gt;Some models are relatively easy to interpret, such as linear models and small decision trees &lt;/td&gt;&lt;td&gt;Complex neural networks can be difficult to interpret&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Examples&lt;/strong&gt;           &lt;/td&gt;&lt;td&gt;Decision trees, random forests, logistic regression                                          &lt;/td&gt;&lt;td&gt;CNNs, RNNs, Transformers&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;These are general tendencies rather than absolute rules. The best approach depends on the problem you're trying to solve.&lt;/p&gt;
&lt;h3 id=&quot;can-machine-learning-work-without-deep-learning-&quot;&gt;Can Machine Learning Work Without Deep Learning?&lt;/h3&gt;
&lt;p&gt;YES. Absolutely!&lt;/p&gt;
&lt;p&gt;Remember when I said that Deep Learning is a branch of Machine Learning? That means Machine Learning existed as a field of study long before modern Deep Learning became popular.&lt;/p&gt;
&lt;p&gt;You can build useful Machine Learning systems without using a single neural network.&lt;/p&gt;
&lt;p&gt;For example, imagine you're building a system to predict whether a customer is likely to leave a service.&lt;/p&gt;
&lt;p&gt;You could use logistic regression, a decision tree, or a random forest to learn patterns from historical customer data and predict which customers are at risk of leaving.&lt;/p&gt;
&lt;p&gt;You don't necessarily need a Deep Learning model for this.&lt;/p&gt;
&lt;p&gt;In fact, using a complex neural network when a simpler model can solve the problem effectively may introduce unnecessary computational costs and complexity.&lt;/p&gt;
&lt;p&gt;The goal isn't to use the most complicated algorithm available. The goal is to solve the problem effectively.&lt;/p&gt;
&lt;p&gt;Deep Learning is powerful, but it isn't automatically the best choice for every Machine Learning task.&lt;/p&gt;
&lt;p&gt;Sometimes, a simpler model is all you need.&lt;/p&gt;
&lt;h3 id=&quot;when-should-you-use-each-&quot;&gt;When Should You Use Each?&lt;/h3&gt;
&lt;p&gt;So, how do you decide whether to use traditional Machine Learning or Deep Learning?&lt;/p&gt;
&lt;p&gt;It depends on the problem, the data you have, the resources available to you, and the results you need.&lt;/p&gt;
&lt;h4 id=&quot;consider-traditional-machine-learning-when-&quot;&gt;Consider Traditional Machine Learning When:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;You're working with structured data, such as spreadsheets or databases.&lt;/li&gt;
&lt;li&gt;You have a relatively small dataset.&lt;/li&gt;
&lt;li&gt;You need a model that is easier to interpret.&lt;/li&gt;
&lt;li&gt;You have limited computational resources.&lt;/li&gt;
&lt;li&gt;Simpler algorithms can achieve the performance you need.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;consider-deep-learning-when-&quot;&gt;Consider Deep Learning When:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;You're working with complex data, such as images, audio, or natural language.&lt;/li&gt;
&lt;li&gt;You have enough data or access to a suitable pretrained model.&lt;/li&gt;
&lt;li&gt;The problem may benefit from learning complex representations.&lt;/li&gt;
&lt;li&gt;You have the computational resources needed to train or run the model.&lt;/li&gt;
&lt;li&gt;Traditional approaches aren't achieving the performance you need.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Again, these are guidelines, not strict rules. Traditional Machine Learning can work with images and text, while Deep Learning can work with structured data.&lt;/p&gt;
&lt;p&gt;The important thing is to understand the problem before deciding which approach to use.&lt;/p&gt;
&lt;p&gt;And please, don't use Deep Learning just because it sounds more impressive. Nobody gets bonus points for making a simple problem unnecessarily complicated!&lt;/p&gt;
&lt;h3 id=&quot;final-thoughts&quot;&gt;Final Thoughts&lt;/h3&gt;
&lt;p&gt;Artificial Intelligence is a huge field, and there's so much to explore within it.&lt;/p&gt;
&lt;p&gt;Machine Learning allows us to build systems that learn patterns from data, while Deep Learning takes this further by using multilayered neural networks to learn complex representations.&lt;/p&gt;
&lt;p&gt;Neither is universally better than the other. They have different strengths, limitations, and use cases.&lt;/p&gt;
&lt;p&gt;If you're just getting started with AI, my advice is to build a solid foundation in Machine Learning before diving deep into Deep Learning.&lt;/p&gt;
&lt;p&gt;Understanding concepts such as training, testing, overfitting, loss functions, and model evaluation will make your Deep Learning journey much easier.&lt;/p&gt;
&lt;p&gt;And remember, &lt;strong&gt;you don't have to use the most complex model to solve a problem well. You just need to understand your problem well enough to choose the right tool.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now, go forth and build something cool. &lt;br&gt;
See you next time!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/32223/machine-learning-vs-deep-learning-whats-the-difference</guid>
<pubDate>Fri, 23 Oct 2026 22:07:20 +0000</pubDate>
</item>
<item>
<title>Where do squared error and cross-entropy actually come from?</title>
<link>https://coderlegion.com/30983/where-do-squared-error-and-cross-entropy-actually-come-from</link>
<description>&lt;p&gt;&lt;strong&gt;Short answer: maximum likelihood. Choose a distribution for the output, then:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Read its parameter as the network's output → output function&lt;/li&gt;
&lt;li&gt;Take −log of it → error function&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Gaussian (regression)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Output: ŷ = Wᵀh + b (the mean)&lt;/li&gt;
&lt;li&gt;Error: −log N(y; ŷ, σ²) → squared error (constants drop out)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bernoulli (binary classification)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Output: exponentiate + normalize → ŷ = σ(z)&lt;/li&gt;
&lt;li&gt;Error: −log P(y) → cross-entropy = softplus((1 − 2y)z)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Why the pairing matters: with cross-entropy, the log cancels the sigmoid's exponential, so ∂J/∂z = σ(z) − y. With squared error, σ′(z) stays in the gradient and goes to ~0 when the model is confidently wrong, so learning stalls.&lt;/p&gt;
&lt;p&gt;Full derivations: &lt;a rel=&quot;nofollow&quot; href=&quot;https://husseinmahdi.xyz/writing/series/math-behind-neural-networks/&quot;&gt;https://husseinmahdi.xyz/writing/series/math-behind-neural-networks/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next up: softmax + cross-entropy for k classes.&lt;/p&gt;
</description>
<category>Discussions</category>
<guid isPermaLink="true">https://coderlegion.com/30983/where-do-squared-error-and-cross-entropy-actually-come-from</guid>
<pubDate>Wed, 14 Oct 2026 05:20:00 +0000</pubDate>
</item>
<item>
<title>Neural Networks: Inspired by the Brain, Built for Data</title>
<link>https://coderlegion.com/28356/neural-networks-inspired-by-the-brain-built-for-data</link>
<description>&lt;p&gt;When I first started learning about neural networks, I found the idea both fascinating and slightly intimidating.&lt;/p&gt;
&lt;p&gt;The phrase &lt;em&gt;“neural network”&lt;/em&gt; makes it sound like something extremely complex, and honestly, once you start looking at layers, weights, activation functions, forward propagation, backpropagation, and optimization, it can become overwhelming pretty quickly.&lt;/p&gt;
&lt;p&gt;But beneath all of that mathematics and code is a surprisingly simple idea:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;A neural network learns patterns from data by adjusting itself based on its mistakes.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That idea is what made neural networks interesting to me.&lt;/p&gt;
&lt;p&gt;As I continue exploring data science and machine learning, understanding neural networks has helped me see machine learning from a different perspective. Instead of simply telling a computer what rules to follow, we can give it data and allow it to learn patterns that may be difficult for us to define manually.&lt;/p&gt;
&lt;p&gt;In this article, I'll break down where the inspiration for neural networks came from, what they are, and the major components that make them work.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;where-did-neural-networks-come-from-&quot;&gt;Where Did Neural Networks Come From?&lt;/h3&gt;
&lt;p&gt;The inspiration behind artificial neural networks comes from something we already have:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;the human brain.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Our brains contain billions of neurons that communicate with one another. A biological neuron receives signals, processes them, and passes a signal forward when certain conditions are met.&lt;/p&gt;
&lt;p&gt;Artificial neural networks don't replicate the human brain perfectly. Instead, they borrow a simplified idea from how biological neurons work.&lt;/p&gt;
&lt;p&gt;A biological neuron can be thought of roughly as:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;receive signals → process them → produce a response&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;An artificial neuron follows a similar conceptual process:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;receive inputs → calculate a weighted sum → apply an activation function → produce an output&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This was one of the things I found interesting when learning about neural networks.&lt;/p&gt;
&lt;p&gt;The goal isn't to recreate the brain inside a computer.&lt;/p&gt;
&lt;p&gt;The goal is to take a useful idea from biology and turn it into a mathematical model that can learn from data.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;so-what-exactly-is-a-neural-network-&quot;&gt;So, What Exactly Is a Neural Network?&lt;/h3&gt;
&lt;p&gt;A neural network is a machine learning model made up of interconnected nodes, commonly called &lt;strong&gt;neurons&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;These neurons are organized into layers.&lt;/p&gt;
&lt;p&gt;A basic neural network usually contains:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Input layer&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One or more hidden layers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Output layer&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A simple representation looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Input Layer        Hidden Layer        Output Layer

   x₁  ─────────►    ○
                    │
   x₂  ─────────►    ○ ─────────►     ŷ
                    │
   x₃  ─────────►    ○
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The input layer receives the data.&lt;/p&gt;
&lt;p&gt;The hidden layers transform the data and learn patterns.&lt;/p&gt;
&lt;p&gt;The output layer produces the final prediction.&lt;/p&gt;
&lt;p&gt;The interesting part is that we don't manually program the network to recognize every possible pattern.&lt;/p&gt;
&lt;p&gt;Instead, the network learns the parameters needed to recognize those patterns from examples.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;1-the-input-layer&quot;&gt;1. The Input Layer&lt;/h3&gt;
&lt;p&gt;Everything starts with the input.&lt;/p&gt;
&lt;p&gt;Suppose we want to predict whether a student is likely to pass an exam.&lt;/p&gt;
&lt;p&gt;Our dataset might contain:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hours studied&lt;/li&gt;
&lt;li&gt;Attendance&lt;/li&gt;
&lt;li&gt;Previous test scores&lt;/li&gt;
&lt;li&gt;Assignment completion&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These become our input features.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Hours Studied     = 6
Attendance        = 85%
Previous Score    = 72
Assignments       = 9
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The neural network receives these values through the input layer.&lt;/p&gt;
&lt;p&gt;One important thing I learned is that neural networks generally work best when the input data has been appropriately prepared.&lt;/p&gt;
&lt;p&gt;That can involve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Handling missing values&lt;/li&gt;
&lt;li&gt;Encoding categorical variables&lt;/li&gt;
&lt;li&gt;Scaling numerical features&lt;/li&gt;
&lt;li&gt;Removing irrelevant features&lt;/li&gt;
&lt;li&gt;Splitting data into training and testing sets&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So even though neural networks are powerful, &lt;strong&gt;data preparation still matters.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Garbage in can still mean garbage out.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;2-neurons&quot;&gt;2. Neurons&lt;/h4&gt;
&lt;p&gt;The basic building block of a neural network is the &lt;strong&gt;artificial neuron&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A neuron takes several inputs, assigns different importance to them using weights, adds a bias, and then passes the result through an activation function.&lt;/p&gt;
&lt;p&gt;Mathematically, we can represent this as:&lt;/p&gt;
&lt;p&gt;\[
z = w_1x_1 + w_2x_2 + ... + w_nx_n + b
\]&lt;/p&gt;
&lt;p&gt;Where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;\(x\) = input&lt;/li&gt;
&lt;li&gt;\(w\) = weight&lt;/li&gt;
&lt;li&gt;\(b\) = bias&lt;/li&gt;
&lt;li&gt;\(z\) = weighted sum&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The neuron then applies an activation function:&lt;/p&gt;
&lt;p&gt;\[
a = f(z)
\]&lt;/p&gt;
&lt;p&gt;The result becomes the neuron's output.&lt;/p&gt;
&lt;p&gt;This might look complicated initially, but the basic idea is straightforward:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The neuron combines information from its inputs and decides how strongly to activate.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;3-weights&quot;&gt;3. Weights&lt;/h4&gt;
&lt;p&gt;Weights determine how important different inputs are to a neuron.&lt;/p&gt;
&lt;p&gt;Imagine we're predicting whether a student will pass.&lt;/p&gt;
&lt;p&gt;Perhaps hours studied is more predictive than the number of assignments completed.&lt;/p&gt;
&lt;p&gt;The network can learn this by assigning different weights to those features.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Hours studied       → weight = 0.8
Attendance          → weight = 0.5
Previous score      → weight = 0.9
Assignments         → weight = 0.3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These numbers are only examples.&lt;/p&gt;
&lt;p&gt;During training, the neural network continuously adjusts its weights to improve its predictions.&lt;/p&gt;
&lt;p&gt;This is one of the key ideas behind learning in neural networks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The model isn't explicitly told what the correct weights are. It learns them from data.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;4-bias&quot;&gt;4. Bias&lt;/h4&gt;
&lt;p&gt;Another component is the &lt;strong&gt;bias&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Bias gives the neuron some flexibility in determining when it should activate.&lt;/p&gt;
&lt;p&gt;Without going too deep into the mathematics, you can think of the bias as an additional parameter that allows the activation function to shift.&lt;/p&gt;
&lt;p&gt;The basic equation becomes:&lt;/p&gt;
&lt;p&gt;\[
z = wx + b
\]&lt;/p&gt;
&lt;p&gt;The weights control the influence of the inputs, while the bias helps adjust the overall output.&lt;/p&gt;
&lt;p&gt;Both weights and biases are learned during training.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;5-activation-functions&quot;&gt;5. Activation Functions&lt;/h4&gt;
&lt;p&gt;This was one of the concepts that really helped me understand why neural networks can learn complex patterns.&lt;/p&gt;
&lt;p&gt;After calculating the weighted sum, a neuron applies an &lt;strong&gt;activation function&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Why?&lt;/p&gt;
&lt;p&gt;Because without activation functions, stacking multiple layers of neurons would still result in a fundamentally linear transformation.&lt;/p&gt;
&lt;p&gt;Activation functions introduce &lt;strong&gt;non-linearity&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And real-world data is rarely perfectly linear.&lt;/p&gt;
&lt;p&gt;Some commonly used activation functions include:&lt;/p&gt;
&lt;h5 id=&quot;sigmoid&quot;&gt;Sigmoid&lt;/h5&gt;
&lt;p&gt;The sigmoid function produces values between 0 and 1.&lt;/p&gt;
&lt;p&gt;\[
\sigma(x) = \frac{1}{1 + e^{-x}}
\]&lt;/p&gt;
&lt;p&gt;This makes it useful in certain binary classification problems, particularly as an output activation.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;0.91 → high probability of class 1
0.12 → low probability of class 1
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h5 id=&quot;relu&quot;&gt;ReLU&lt;/h5&gt;
&lt;p&gt;ReLU stands for &lt;strong&gt;Rectified Linear Unit&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It is defined as:&lt;/p&gt;
&lt;p&gt;\[
ReLU(x) = \max(0,x)
\]&lt;/p&gt;
&lt;p&gt;So:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;x = -3 → 0
x =  2 → 2
x =  7 → 7
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ReLU became particularly important in deep learning because it is simple and computationally efficient and helps neural networks model nonlinear relationships.&lt;/p&gt;
&lt;hr&gt;
&lt;h5 id=&quot;softmax&quot;&gt;Softmax&lt;/h5&gt;
&lt;p&gt;Softmax is commonly used in the output layer for multi-class classification.&lt;/p&gt;
&lt;p&gt;Suppose we're classifying an image as:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Cat
Dog
Bird
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Softmax can convert the model's outputs into probabilities that sum to 1.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Cat  → 0.10
Dog  → 0.82
Bird → 0.08
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model would predict &lt;strong&gt;Dog&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;6-hidden-layers&quot;&gt;6. Hidden Layers&lt;/h4&gt;
&lt;p&gt;Now we get to one of the most important parts of a neural network.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;hidden layers&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;These layers sit between the input and output layers.&lt;/p&gt;
&lt;p&gt;A network with only a few layers might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Input → Hidden → Output
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A deeper network could look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Input
  ↓
Hidden Layer 1
  ↓
Hidden Layer 2
  ↓
Hidden Layer 3
  ↓
Hidden Layer 4
  ↓
Output
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each layer can learn different representations of the data.&lt;/p&gt;
&lt;p&gt;This is where the term &lt;strong&gt;deep learning&lt;/strong&gt; comes from.&lt;/p&gt;
&lt;p&gt;A neural network with many hidden layers is generally described as a deep neural network.&lt;/p&gt;
&lt;p&gt;The interesting part is that the network can learn increasingly complex representations as information moves through the layers.&lt;/p&gt;
&lt;p&gt;For example, in an image recognition task:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Pixels
  ↓
Edges
  ↓
Shapes
  ↓
Patterns
  ↓
Objects
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The network isn't necessarily programmed with these exact rules.&lt;/p&gt;
&lt;p&gt;It learns useful representations from the training data.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;7-forward-propagation&quot;&gt;7. Forward Propagation&lt;/h4&gt;
&lt;p&gt;So how does a neural network actually make a prediction?&lt;/p&gt;
&lt;p&gt;This happens through &lt;strong&gt;forward propagation&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The input data moves through the network from the input layer toward the output layer.&lt;/p&gt;
&lt;p&gt;At each neuron:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Inputs are multiplied by weights.&lt;/li&gt;
&lt;li&gt;The results are added together.&lt;/li&gt;
&lt;li&gt;A bias is added.&lt;/li&gt;
&lt;li&gt;An activation function is applied.&lt;/li&gt;
&lt;li&gt;The result is passed to the next layer.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Eventually, the network produces a prediction.&lt;/p&gt;
&lt;p&gt;Conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Input
  ↓
Weighted Sum
  ↓
Activation
  ↓
Next Layer
  ↓
Weighted Sum
  ↓
Activation
  ↓
Prediction
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This happens extremely quickly when implemented computationally.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;8-loss-functions&quot;&gt;8. Loss Functions&lt;/h4&gt;
&lt;p&gt;The network makes a prediction.&lt;/p&gt;
&lt;p&gt;But how does it know whether the prediction is good or bad?&lt;/p&gt;
&lt;p&gt;This is where the &lt;strong&gt;loss function&lt;/strong&gt; comes in.&lt;/p&gt;
&lt;p&gt;A loss function measures the difference between the model's prediction and the actual target.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Actual value      = 1
Predicted value   = 0.3
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is a significant difference.&lt;/p&gt;
&lt;p&gt;The loss function quantifies that error.&lt;/p&gt;
&lt;p&gt;Different problems use different loss functions.&lt;/p&gt;
&lt;p&gt;Some common examples include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mean Squared Error (MSE)&lt;/li&gt;
&lt;li&gt;Binary Cross-Entropy&lt;/li&gt;
&lt;li&gt;Categorical Cross-Entropy&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The general goal during training is simple:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Minimize the loss.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h4 id=&quot;9-backpropagation&quot;&gt;9. Backpropagation&lt;/h4&gt;
&lt;p&gt;This is probably one of the most important concepts in neural networks.&lt;/p&gt;
&lt;p&gt;After making a prediction and calculating the loss, the network needs to figure out:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Which weights contributed to the error, and how should they change?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is where &lt;strong&gt;backpropagation&lt;/strong&gt; comes in.&lt;/p&gt;
&lt;p&gt;The error is propagated backward through the network.&lt;/p&gt;
&lt;p&gt;Using calculus—particularly the chain rule—the network calculates gradients that indicate how changes in the parameters would affect the loss.&lt;/p&gt;
&lt;p&gt;Conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Prediction
    ↓
Calculate Loss
    ↓
Propagate Error Backward
    ↓
Calculate Gradients
    ↓
Update Weights
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then the process repeats.&lt;/p&gt;
&lt;p&gt;Again.&lt;/p&gt;
&lt;p&gt;And again.&lt;/p&gt;
&lt;p&gt;And again.&lt;/p&gt;
&lt;p&gt;This is how the neural network gradually improves.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;10-optimizers&quot;&gt;10. Optimizers&lt;/h4&gt;
&lt;p&gt;Backpropagation tells us how the parameters should change.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;optimizer&lt;/strong&gt; determines how those changes are actually made.&lt;/p&gt;
&lt;p&gt;One of the most well-known optimization algorithms is &lt;strong&gt;Gradient Descent&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The basic idea is to move the model's parameters in a direction that reduces the loss.&lt;/p&gt;
&lt;p&gt;A simplified update rule looks like:&lt;/p&gt;
&lt;p&gt;\[
w_{new} = w_{old} - \eta \frac{\partial L}{\partial w}
\]&lt;/p&gt;
&lt;p&gt;Where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;\(w\) = weight&lt;/li&gt;
&lt;li&gt;\(\eta\) = learning rate&lt;/li&gt;
&lt;li&gt;\(L\) = loss&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The learning rate controls how large each update should be.&lt;/p&gt;
&lt;p&gt;If the learning rate is too large, the model may overshoot useful solutions.&lt;/p&gt;
&lt;p&gt;If it is too small, training may take a very long time.&lt;/p&gt;
&lt;p&gt;Other optimizers include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adam&lt;/li&gt;
&lt;li&gt;RMSprop&lt;/li&gt;
&lt;li&gt;Adagrad&lt;/li&gt;
&lt;li&gt;SGD with momentum&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Adam is particularly common in practical deep learning applications.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;11-epochs-and-batches&quot;&gt;11. Epochs and Batches&lt;/h4&gt;
&lt;p&gt;Neural networks don't normally learn from the entire dataset in a single step.&lt;/p&gt;
&lt;p&gt;Instead, training data is often divided into smaller groups called &lt;strong&gt;batches&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, if we have:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;10,000 training samples
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;we might use:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Batch size = 32
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The network processes 32 samples at a time.&lt;/p&gt;
&lt;p&gt;Once it has processed the entire training dataset, we have completed one &lt;strong&gt;epoch&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;So:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Dataset
   ↓
Batch 1
Batch 2
Batch 3
...
Batch N
   ↓
One Epoch
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model typically trains for multiple epochs.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;12-learning-rate&quot;&gt;12. Learning Rate&lt;/h4&gt;
&lt;p&gt;The learning rate determines how aggressively the model updates its parameters.&lt;/p&gt;
&lt;p&gt;Think of it as the size of the steps the model takes while trying to minimize its loss.&lt;/p&gt;
&lt;p&gt;A very large learning rate might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Too large
    ↓
Overshoot
    ↓
Unstable training
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A very small learning rate might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Too small
    ↓
Tiny updates
    ↓
Very slow learning
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finding an appropriate learning rate can make a significant difference in training performance.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;13-training-validation-and-testing&quot;&gt;13. Training, Validation, and Testing&lt;/h4&gt;
&lt;p&gt;Another important concept is understanding how we evaluate a neural network.&lt;/p&gt;
&lt;p&gt;We generally don't want to train and evaluate the model on exactly the same data.&lt;/p&gt;
&lt;p&gt;Instead, data can be divided into:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Dataset
   │
   ├── Training Data
   │
   ├── Validation Data
   │
   └── Test Data
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;training-data&quot;&gt;Training data&lt;/h5&gt;
&lt;p&gt;Used to learn the model's parameters.&lt;/p&gt;
&lt;h5 id=&quot;validation-data&quot;&gt;Validation data&lt;/h5&gt;
&lt;p&gt;Used to monitor performance and help with choices such as hyperparameters and model architecture.&lt;/p&gt;
&lt;h5 id=&quot;test-data&quot;&gt;Test data&lt;/h5&gt;
&lt;p&gt;Used to evaluate how well the final model performs on unseen data.&lt;/p&gt;
&lt;p&gt;This is important because a model can perform extremely well on its training data but poorly on new data.&lt;/p&gt;
&lt;p&gt;That brings us to one of the biggest challenges in machine learning.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;14-overfitting&quot;&gt;14. Overfitting&lt;/h4&gt;
&lt;p&gt;A neural network can become &lt;strong&gt;too good at memorizing the training data&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is known as overfitting.&lt;/p&gt;
&lt;p&gt;Imagine studying for an exam by memorizing the answers to last year's exact questions.&lt;/p&gt;
&lt;p&gt;You might perform extremely well if the same questions appear.&lt;/p&gt;
&lt;p&gt;But if the questions change, your performance may drop.&lt;/p&gt;
&lt;p&gt;A similar thing can happen with machine learning models.&lt;/p&gt;
&lt;p&gt;The model learns the training examples extremely well but fails to generalize to unseen data.&lt;/p&gt;
&lt;p&gt;Some techniques used to reduce overfitting include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dropout&lt;/li&gt;
&lt;li&gt;Regularization&lt;/li&gt;
&lt;li&gt;Early stopping&lt;/li&gt;
&lt;li&gt;Data augmentation&lt;/li&gt;
&lt;li&gt;More training data&lt;/li&gt;
&lt;li&gt;Simpler model architectures&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h5 id=&quot;why-are-neural-networks-so-powerful-&quot;&gt;Why Are Neural Networks So Powerful?&lt;/h5&gt;
&lt;p&gt;What makes neural networks particularly interesting is their ability to learn &lt;strong&gt;nonlinear relationships and complex representations&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Traditional programming often looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Rules + Data → Output
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Machine learning changes the approach:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Data + Expected Outputs → Learned Rules
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And neural networks take this further by learning multiple levels of representation.&lt;/p&gt;
&lt;p&gt;This is why they have become so useful in areas such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Computer vision&lt;/li&gt;
&lt;li&gt;Natural language processing&lt;/li&gt;
&lt;li&gt;Speech recognition&lt;/li&gt;
&lt;li&gt;Recommendation systems&lt;/li&gt;
&lt;li&gt;Time-series forecasting&lt;/li&gt;
&lt;li&gt;Fraud detection&lt;/li&gt;
&lt;li&gt;Medical imaging&lt;/li&gt;
&lt;li&gt;Generative AI&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h5 id=&quot;from-neural-networks-to-deep-learning&quot;&gt;From Neural Networks to Deep Learning&lt;/h5&gt;
&lt;p&gt;A neural network with many layers is generally referred to as a &lt;strong&gt;deep neural network&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Deep learning is essentially about using these deeper architectures to learn increasingly complex representations from data.&lt;/p&gt;
&lt;p&gt;This has led to architectures designed for different kinds of problems.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;h5 id=&quot;convolutional-neural-networks-cnns-&quot;&gt;Convolutional Neural Networks (CNNs)&lt;/h5&gt;
&lt;p&gt;Often associated with image and computer vision tasks.&lt;/p&gt;
&lt;h5 id=&quot;recurrent-neural-networks-rnns-&quot;&gt;Recurrent Neural Networks (RNNs)&lt;/h5&gt;
&lt;p&gt;Designed to work with sequential data, although many modern sequence tasks now use transformer-based architectures instead.&lt;/p&gt;
&lt;h5 id=&quot;transformers&quot;&gt;Transformers&lt;/h5&gt;
&lt;p&gt;Transformers have become extremely important in modern AI, particularly for language and other sequence-based problems.&lt;/p&gt;
&lt;p&gt;They power many of the systems behind today's generative AI applications.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;what-i-take-away-from-learning-neural-networks&quot;&gt;What I Take Away From Learning Neural Networks&lt;/h4&gt;
&lt;p&gt;One thing I appreciate about neural networks is that they changed how I think about machine learning.&lt;/p&gt;
&lt;p&gt;At first, the equations can make the subject feel intimidating.&lt;/p&gt;
&lt;p&gt;You see:&lt;/p&gt;
&lt;p&gt;\[
z = wx+b
\]&lt;/p&gt;
&lt;p&gt;then activation functions, gradients, derivatives, optimization algorithms, layers, epochs, and suddenly it feels like you're drowning in mathematics.&lt;/p&gt;
&lt;p&gt;But when you break the process down, the basic idea becomes much easier to understand.&lt;/p&gt;
&lt;p&gt;A neural network:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;takes data → makes a prediction → measures its error → adjusts itself → tries again.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That cycle is at the heart of learning.&lt;/p&gt;
&lt;p&gt;And I think that's the part that makes neural networks so fascinating.&lt;/p&gt;
&lt;hr&gt;
&lt;h5 id=&quot;final-thoughts-1&quot;&gt;Final Thoughts&lt;/h5&gt;
&lt;p&gt;I'm still learning neural networks, and I don't think understanding them means memorizing every equation or being able to build a state-of-the-art architecture from scratch.&lt;/p&gt;
&lt;p&gt;For me, understanding the fundamentals is more important.&lt;/p&gt;
&lt;p&gt;I want to know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What is happening to the data?&lt;/li&gt;
&lt;li&gt;Why do we need weights?&lt;/li&gt;
&lt;li&gt;What does a bias actually do?&lt;/li&gt;
&lt;li&gt;Why do we need activation functions?&lt;/li&gt;
&lt;li&gt;How does the model know that it made a mistake?&lt;/li&gt;
&lt;li&gt;How does backpropagation help?&lt;/li&gt;
&lt;li&gt;What does an optimizer actually change?&lt;/li&gt;
&lt;li&gt;How do we know whether the model is learning or simply memorizing?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once these pieces start fitting together, neural networks stop looking like a mysterious black box.&lt;/p&gt;
&lt;p&gt;They become a collection of understandable ideas working together.&lt;/p&gt;
&lt;p&gt;And that's probably the most important lesson I've taken from studying them so far:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Complex models become much less intimidating when you understand the simple ideas underneath them.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I'm still on that learning journey and neural networks are definitely one of the areas I'm excited to explore more deeply.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28356/neural-networks-inspired-by-the-brain-built-for-data</guid>
<pubDate>Wed, 23 Sep 2026 14:01:57 +0000</pubDate>
</item>
<item>
<title>Predicting Drug-Drug Interactions with Hypergraphs — on Two CPU Cores</title>
<link>https://coderlegion.com/27074/predicting-drug-drug-interactions-with-hypergraphs-on-two-cpu-cores</link>
<description>&lt;p&gt;When a patient takes several medications at once, two of them can interact in ways that cause real harm. DrugBank catalogues 86 distinct mechanisms for how this happens — one drug slowing another's metabolism, increasing its toxicity, blunting its effect, and so on. Screening every pair by hand does not scale.&lt;/p&gt;
&lt;p&gt;Most machine learning approaches to this problem split it in two: one model decides &lt;em&gt;whether&lt;/em&gt; two drugs interact, a completely separate one decides &lt;em&gt;how&lt;/em&gt;. That split is convenient for benchmarking and awkward for anything practical.&lt;/p&gt;
&lt;p&gt;We built &lt;strong&gt;H²GNN&lt;/strong&gt; to do both in one hierarchy, using nothing but SMILES strings as input. The code is now public, and the whole thing runs on two CPU cores.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Code:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Hu8MA/HHGNN&quot;&gt;github.com/Hu8MA/HHGNN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Paper:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://doi.org/10.1109/ECAI69016.2026.11613729&quot;&gt;ECAI 2026, IEEE Xplore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;why-hypergraphs&quot;&gt;Why hypergraphs&lt;/h3&gt;
&lt;p&gt;In an ordinary graph, an edge joins exactly two nodes. That is a poor fit for a lot of chemistry. A molecular substructure is not a relationship between two drugs — it is something that dozens of drugs share simultaneously. An interaction mechanism is not a property of one pair; it is a category that hundreds of pairs fall into.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;hyperedge&lt;/strong&gt; can connect any number of nodes at once, which lines up with both of those facts. H²GNN uses two hypergraphs stacked on top of each other.&lt;/p&gt;
&lt;h4 id=&quot;stage-1-the-chemical-hypergraph&quot;&gt;Stage 1: the chemical hypergraph&lt;/h4&gt;
&lt;p&gt;Take a SMILES string and slide a window of size &lt;em&gt;k&lt;/em&gt; across it. Each window is a substring — a rough proxy for a local chemical arrangement. Every distinct substring becomes a &lt;strong&gt;node&lt;/strong&gt;, and every drug becomes a &lt;strong&gt;hyperedge&lt;/strong&gt; connecting the substrings it contains.&lt;/p&gt;
&lt;p&gt;At &lt;code&gt;k = 9&lt;/code&gt;, that gives 29,462 substructure nodes, 1,709 drug hyperedges, and 96,656 connections between them.&lt;/p&gt;
&lt;p&gt;A single hypergraph attention layer runs over this structure. Attention flows at the hyperedge level, then the node level, and the result is a 128-dimensional embedding per drug learned end to end from raw SMILES. An MLP decoder takes the embeddings of two drugs and predicts whether they interact.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Result: 98.46% ROC-AUC, 93.20% accuracy.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For comparison, a Random Forest on 4,096-dimensional Morgan fingerprints gets 88% ROC-AUC. A two-layer GCN gets 95%.&lt;/p&gt;
&lt;h4 id=&quot;stage-2-the-interaction-type-hypergraph&quot;&gt;Stage 2: the interaction-type hypergraph&lt;/h4&gt;
&lt;p&gt;Here is the part I find most interesting, and it is a small conceptual shift with a large effect.&lt;/p&gt;
&lt;p&gt;The obvious way to classify interaction mechanisms is to attach a label to each drug pair and train a classifier. We did something else: &lt;strong&gt;each of the 86 interaction types becomes a hyperedge&lt;/strong&gt;, connecting every drug that participates in that type. Drugs are the nodes. The type stops being a label on the data and becomes an object in the graph with its own learned representation.&lt;/p&gt;
&lt;p&gt;This hypergraph is tiny — 1,709 drug nodes, 86 type hyperedges, 13,486 connections. Hyperedge sizes range wildly: type 42 touches 5 drugs, type 49 touches 1,308.&lt;/p&gt;
&lt;p&gt;Drug nodes are initialized with the embeddings transferred from Stage 1, not randomly. Attention then flows hyperedge → node → hyperedge, so the type hyperedges — which are the prediction target — end up holding the final aggregated representation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Result: 85.73% Top-1 and 98.11% Top-3 accuracy across 86 classes.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That twelve-point gap between Top-1 and Top-3 is itself useful. The correct mechanism is almost always among the top three even when it is not ranked first, which is exactly what you want if a clinician is reading the output rather than a downstream script.&lt;/p&gt;
&lt;h3 id=&quot;the-ablations-that-mattered&quot;&gt;The ablations that mattered&lt;/h3&gt;
&lt;p&gt;Two experiments did more to convince me the design was right than any headline number.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attention direction.&lt;/strong&gt; Stage 2's drug nodes start out well-informed, carrying transferred chemical knowledge, while the type hyperedges start from one-hot vectors. So it seemed plausible that flowing attention from the informed side — node → hyperedge → node — would work better.&lt;/p&gt;
&lt;p&gt;It does not. It falls apart:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Configuration &lt;/th&gt;&lt;th&gt;Top-1 Acc. &lt;/th&gt;&lt;th&gt;PR-AUC &lt;/th&gt;&lt;th&gt;Macro F1&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;hyperedge → node → hyperedge &lt;/td&gt;&lt;td&gt;85.73% &lt;/td&gt;&lt;td&gt;87.24% &lt;/td&gt;&lt;td&gt;81%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;node → hyperedge → node &lt;/td&gt;&lt;td&gt;67.42% &lt;/td&gt;&lt;td&gt;63.54% &lt;/td&gt;&lt;td&gt;48%&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Aligning the attention flow with the prediction target beats starting from the richer initialization, and the rare classes are the first thing you lose. The type hyperedge has to be where aggregation ends.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Embedding transfer.&lt;/strong&gt; Replace the transferred Stage 1 embeddings with an all-ones vector and hold everything else fixed:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Initialization &lt;/th&gt;&lt;th&gt;Top-1 Acc. &lt;/th&gt;&lt;th&gt;PR-AUC &lt;/th&gt;&lt;th&gt;Weighted F1&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Stage 1 embeddings &lt;/td&gt;&lt;td&gt;85.73% &lt;/td&gt;&lt;td&gt;87.24% &lt;/td&gt;&lt;td&gt;86%&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;All-ones vector &lt;/td&gt;&lt;td&gt;82.52% &lt;/td&gt;&lt;td&gt;85.70% &lt;/td&gt;&lt;td&gt;82%&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A 3.21-point drop. The hierarchy earns its keep.&lt;/p&gt;
&lt;p&gt;There is also a third result I did not expect. During cleaning, 406 drug pairs turned out to carry more than one interaction type; we kept the first and set the others aside. The model never saw those secondary labels for those pairs. It surfaced &lt;strong&gt;94.7% of them&lt;/strong&gt; within its Top-3 predictions anyway — meaning the hypergraph learned something about multi-mechanistic pharmacology rather than memorizing one label per pair.&lt;/p&gt;
&lt;h3 id=&quot;the-efficiency-story&quot;&gt;The efficiency story&lt;/h3&gt;
&lt;p&gt;This is the part that surprised me most, and it is worth spelling out for anyone who assumes graph learning implies a GPU budget.&lt;/p&gt;
&lt;p&gt;Everything above was trained and evaluated on &lt;strong&gt;Google Colab's free tier&lt;/strong&gt;: two vCPUs, no GPU. We chose it deliberately, for two reasons. It gives every run an identical environment, and its resource ceiling is close to the hardware actually available in a hospital pharmacy.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Model &lt;/th&gt;&lt;th&gt;Training time &lt;/th&gt;&lt;th&gt;Hardware&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Interaction-Type HGNN (ours, 1 layer) &lt;/td&gt;&lt;td&gt;18.6 min &lt;/td&gt;&lt;td&gt;CPU, 2 cores&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;GCN (2 layers) &lt;/td&gt;&lt;td&gt;75.6 min &lt;/td&gt;&lt;td&gt;GPU (T4)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;GraphSAGE (2 layers) &lt;/td&gt;&lt;td&gt;148.5 min &lt;/td&gt;&lt;td&gt;GPU (T4)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;XGBoost &lt;/td&gt;&lt;td&gt;225.6 min &lt;/td&gt;&lt;td&gt;CPU&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Four to twelve times faster — and it still beat GraphSAGE, the strongest baseline, by 4.8 points of Top-1 accuracy and 22 points of macro F1.&lt;/p&gt;
&lt;p&gt;The baselines had advantages we did not give ourselves: precomputed Morgan fingerprints as input features, and inverse-frequency class weighting during training to stay stable under the severe class imbalance. Single-layer variants of the GCN and GraphSAGE did not converge at all; both had to be deepened and moved to GPU for the comparison to run. A Graph Attention Network never converged and was dropped.&lt;/p&gt;
&lt;p&gt;Peak RAM increase during training: 0.29 GB.&lt;/p&gt;
&lt;h3 id=&quot;what-is-in-the-repo&quot;&gt;What is in the repo&lt;/h3&gt;
&lt;p&gt;The dataset is DrugBank — 1,709 drugs, 191,877 unique interaction pairs, 86 types, built by merging two benchmark sources so that every drug has a SMILES string.&lt;/p&gt;
&lt;p&gt;Everything needed to reproduce the numbers is there:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Colab notebooks for all 48 experiments, with inline outputs&lt;/li&gt;
&lt;li&gt;Pre-computed k-mer files for k = 3, 6, 9, 12&lt;/li&gt;
&lt;li&gt;Hypergraph structure files and index maps&lt;/li&gt;
&lt;li&gt;The exact seeded train/validation/test partitions, verified for zero leakage&lt;/li&gt;
&lt;li&gt;Baseline notebooks (GCN, GAT, GraphSAGE, XGBoost, Random Forest)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Open a notebook, point it at the data files, run all cells. Free tier is enough.&lt;/p&gt;
&lt;h3 id=&quot;what-it-does-not-do&quot;&gt;What it does not do&lt;/h3&gt;
&lt;p&gt;Being honest about the boundaries, since these are the interesting problems:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SMILES only.&lt;/strong&gt; No protein-target, pathway, or side-effect information. Chemical structure carries the entire representation. Additional modalities could enter as further hyperedge families.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No severity prediction.&lt;/strong&gt; The model reports the mechanism and its likelihood, not how bad the reaction will be — which is often the thing that actually drives a clinical decision.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;1,709 drugs.&lt;/strong&gt; DrugBank now holds over 4,000, so plenty of approved drugs cannot yet be screened.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pairs only.&lt;/strong&gt; Real polypharmacy is not pairwise. The hypergraph formulation could express simultaneous multi-drug combinations directly; we just have not done it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That last one bothers me the most, because the machinery is already there. A hyperedge over three co-administered drugs is a perfectly natural object in this framework.&lt;/p&gt;
&lt;p&gt;If any of these interest you, contributions are welcome — there is a contributing guide in the repo, and the issue tracker is open.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Hu8MA/HHGNN&quot;&gt;github.com/Hu8MA/HHGNN&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Paper:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://doi.org/10.1109/ECAI69016.2026.11613729&quot;&gt;Hierarchical Hypergraph Neural Networks for Multi-Type Drug–Drug Interaction Prediction&lt;/a&gt;, ECAI 2026, IEEE Xplore&lt;/p&gt;
&lt;p&gt;Thanks to the DrugBank Foundation for access to the curated drug data that made the dataset complete.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/27074/predicting-drug-drug-interactions-with-hypergraphs-on-two-cpu-cores</guid>
<pubDate>Sun, 13 Sep 2026 18:32:27 +0000</pubDate>
</item>
<item>
<title>The Math Behind Neural Networks, Explained Like Nobody Did for Me — Part 1.4</title>
<link>https://coderlegion.com/26429/the-math-behind-neural-networks-explained-like-nobody-did-for-me-part-1-4</link>
<description>&lt;p&gt;&lt;em&gt;Part 1.4 — Which Loss to Choose, and Why. A calm, sequential guide for anyone entering the field. The article is divided into smaller chapters to make it easier to understand.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Part 1.3 ended on a quiet victory. The mean squared error, which we had simply assumed back in Part 1.1 and optimized in Part 1.2, was no longer an assumption. We had derived it — from a single principle, maximum likelihood, and a single modelling choice, that the model’s output is a Gaussian centred on its prediction. The loss we had trusted for two parts was finally standing on a foundation we could see through. The recipe was built: choose the output distribution, and the cost follows.&lt;/p&gt;
&lt;p&gt;But a recipe that produces one dish invites an obvious question about all the others. We chose the Gaussian, and squared error came out. That was a choice — the introduction to Chapter 9 said as much and then set the point aside. This part picks it back up. If a different output distribution is chosen, a different cost comes out, and it predicts a different summary of the data. Squared error was never the only item on the menu; it was the first one we happened to order.&lt;/p&gt;
&lt;p&gt;There is also a problem hiding inside the loss we derived, one that Part 1.3 had no reason to expose. In the very common case of a yes-or-no prediction, squared error can go quiet at exactly the wrong moment — its gradient falling nearly to zero while the model is still confidently wrong, leaving gradient descent with nothing to follow. The fix is not to patch squared error but to derive a different cost, cross-entropy, from a different distribution, and watch the problem dissolve on its own. This is where the slope idea from Part 1 returns for the last time, and where the choice of loss and the choice of output finally reveal themselves as one decision, not two.&lt;/p&gt;
&lt;p&gt;So this part is about reading the menu that Part 1.3 built. We look at what other distributions give, why the loss you pick quietly decides which statistic your model chases, and why practitioners so often reach past the squared error we worked so hard to justify.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=7036423332948010965&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Chapter 10: When the Gradient Lies&lt;/strong&gt;&lt;br&gt;
We built the general recipe, and we chose the Gaussian, and squared error came out. So we could stop. But the practitioners’ literature contains a quiet recommendation that seems, at first, to contradict everything we just did: for many problems, do not use squared error. Use cross-entropy instead. This chapter explains why, and the explanation reaches all the way back to the slope idea from Part 1.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What Is Actually Being Compared&lt;/strong&gt;&lt;br&gt;
Putting squared error next to cross-entropy can look like a category mistake, so it is worth being clear about what is being compared. They are the same kind of object — both are cost functions, both are numbers measuring how wrong the model is, both are handed to us by the recipe once we pick an output distribution (Gaussian gives squared error; the binary distribution we will meet in Part 2 gives cross-entropy). So comparing them is fair. The reason they come into conflict is not the costs themselves. It is what sits in front of them.&lt;/p&gt;
&lt;p&gt;The conflict appears in a specific and very common situation: a binary classification task, where the model must output a yes-or-no probability. To produce a number between 0 and 1, the output is almost always passed through a sigmoid first. And it is the sigmoid, wedged between the network and the cost, that causes the trouble. As we will see, the sigmoid has flat regions, and when squared error is stacked on top of a sigmoid, those flat regions leak into the gradient and flatten it too. During back-propagation — the backward pass we built in Part 1.2 and will extend across layers later — a flat gradient means the update is negligibly small, so the model barely changes even when it is badly wrong. Cross-entropy is the cost whose shape cancels that flattening. That is the whole subject of this chapter: not “which cost is better in the abstract,” but “which cost survives contact with the sigmoid.”&lt;/p&gt;
&lt;p&gt;One note before the mechanics. Below, a term written σ′(z) will appear — the slope of the sigmoid. Do not worry about where it comes from in detail here; it is simply the sigmoid’s own steepness at a point, and it enters through the chain rule exactly as the slope did in Part 1.2. We are using it only to see the effect. The full story of the sigmoid, its slope, and the binary (Bernoulli) distribution that makes cross-entropy the derived cost for this task belongs to Part 2.1, where output units are the main subject. Here we only need to watch what σ′(z) does to the gradient.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Two Reasons a Gradient Can Be Small&lt;/strong&gt;&lt;br&gt;
Recall from Part 1.2 that training lives or dies by the gradient. If the slope of the loss goes flat, gradient descent has nothing to follow and learning stalls, like standing on a flat plateau in fog with no sense of which way is downhill.&lt;/p&gt;
&lt;p&gt;Now here is the subtlety. A gradient can go small for two completely different reasons, and only one of them is benign.&lt;/p&gt;
&lt;p&gt;The first is the good kind. In your worked example in Part 1.2, as w approached its true value of 2, the errors shrank and the gradient shrank with them. A small gradient there means you have essentially arrived — take smaller steps. Nothing is wrong.&lt;/p&gt;
&lt;p&gt;The second is the disaster. The gradient can go nearly to zero while the model is still badly wrong. When this happens, the small gradient is lying: it whispers “nothing to fix here” at exactly the moment the model is confidently mistaken and most needs a shove. This second case has a name. It is called saturation, and avoiding it is the reason cross-entropy is preferred.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=3850005165800335206&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where Saturation Comes From, With Numbers&lt;/strong&gt;&lt;br&gt;
To see saturation appear, we need an output that can be confidently wrong. Binary outputs are the clean example, and this is exactly the setting flagged above: the model must answer yes-or-no, so it produces a probability ....... .&lt;/p&gt;
&lt;p&gt;To read the full article, please visit the link : &lt;a rel=&quot;nofollow&quot; href=&quot;https://husseinmahdi.xyz/writing/math-behind-nn-1-4/&quot;&gt;https://husseinmahdi.xyz/writing/math-behind-nn-1-4/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;or this : &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.gopenai.com/the-math-behind-neural-networks-explained-like-nobody-did-for-me-87f299008ffb&quot;&gt;https://blog.gopenai.com/the-math-behind-neural-networks-explained-like-nobody-did-for-me-87f299008ffb&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Refrences&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Goodfellow, I., Bengio, Y., &amp;amp; Courville, A. (2016). Deep Learning. MIT Press. Relevant chapter: Chapter 6 (Deep Feedforward Networks), Section 6.2.1 — Cost Functions. Available free at deeplearningbook.org.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/26429/the-math-behind-neural-networks-explained-like-nobody-did-for-me-part-1-4</guid>
<pubDate>Mon, 07 Sep 2026 17:57:26 +0000</pubDate>
</item>
<item>
<title>How AI Models Actually Learn, From Random Weights To Reinforcement</title>
<link>https://coderlegion.com/25175/how-ai-models-actually-learn-from-random-weights-to-reinforcement</link>
<description>&lt;p&gt;Most of us here ship code against model APIs every day without ever having trained one, and that gap shows up the moment a model does something the docs do not explain. This is the mental model I wish I had earlier, written for developers rather than for a statistics class.&lt;/p&gt;
&lt;h3 id=&quot;learning-is-just-adjusting-numbers&quot;&gt;Learning Is Just Adjusting Numbers&lt;/h3&gt;
&lt;p&gt;Every model is a function. It takes an input and returns an output, and in between sit numbers that nobody chose by hand.&lt;/p&gt;
&lt;p&gt;Take the smallest possible version: price = weight * square_footage + bias. Two unknowns. You show the function a real sale, measure how far off it was, and move the weight and the bias slightly in the direction that would have reduced the error. Do that a few thousand times and you have something that predicts house prices.&lt;/p&gt;
&lt;p&gt;Nothing about that changes at scale. GPT-4 is estimated to hold over a trillion of those numbers, and every one of them was set by the same loop: guess, measure the error, adjust. The architecture decides how the numbers are wired together. Training decides what they end up being.&lt;/p&gt;
&lt;h3 id=&quot;three-paradigms-one-question&quot;&gt;Three Paradigms, One Question&lt;/h3&gt;
&lt;p&gt;Supervised, unsupervised and reinforcement learning get taught as three separate topics, but they are really three answers to one question: how does the system find out it was wrong?&lt;/p&gt;
&lt;p&gt;Supervised learning gets told. Every input arrives with the correct answer attached, so the error is available immediately. It is the most reliable of the three and it sits under image classifiers, spam filters and translation. The cost is the labels, because a person has to produce them.&lt;/p&gt;
&lt;p&gt;Unsupervised learning is never told. There is no correct answer, so the system optimizes for structure instead, grouping things that behave alike or compressing data without losing much. Clustering and embeddings live here.&lt;/p&gt;
&lt;p&gt;Reinforcement learning finds out later. The system acts, and a score arrives after the fact, sometimes long after. That delay is the entire difficulty, because when the score comes back bad you still have to work out which of the earlier decisions caused it. The alignment step that turned raw language models into assistants is this paradigm.&lt;/p&gt;
&lt;p&gt;The &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.learnhowtoscience.com/how-ai-learns/&quot;&gt;full guide to how AI learns&lt;/a&gt; walks each of the three through a worked example, along with the training loop step by step.&lt;/p&gt;
&lt;h3 id=&quot;why-the-data-sets-the-ceiling&quot;&gt;Why The Data Sets The Ceiling&lt;/h3&gt;
&lt;p&gt;A model generalizes only inside the boundaries of what it saw. That sounds obvious, and it is still the most common reason a system tests well and then falls apart in production.&lt;/p&gt;
&lt;p&gt;A child who touches a hot stove once learns to be careful around hot things in general. A model needs thousands of examples to find the same pattern, and it will not extend that pattern to a situation its training data never covered. If stoves were never in the data, there is no concept of a stove to reason from.&lt;/p&gt;
&lt;p&gt;For anyone building on top of these systems, that is the practical part: when output quality is bad, the fix is usually in the data distribution rather than in the architecture or the prompt.&lt;/p&gt;
&lt;h3 id=&quot;what-training-cannot-fix&quot;&gt;What Training Cannot Fix&lt;/h3&gt;
&lt;p&gt;Training is statistical, so it inherits the limits of statistics. A model can tell you what tends to follow from what. It cannot tell you what causes what, unless the causal structure happened to be visible in the correlations.&lt;/p&gt;
&lt;p&gt;It also has no way to know what it does not know. Confidence in these systems is a measure of how well an output matches patterns in the training data, which is why a confident wrong answer looks identical, from the inside, to a confident right one.&lt;/p&gt;
&lt;p&gt;Working out which of the three paradigms produced the behavior in front of you usually tells you whether you have a data problem, a reward problem, or a limit of the method itself. That single distinction has saved me more debugging time than any prompting technique.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/25175/how-ai-models-actually-learn-from-random-weights-to-reinforcement</guid>
<pubDate>Sun, 23 Aug 2026 13:48:59 +0000</pubDate>
</item>
<item>
<title>The Math Behind Neural Networks, Part 1.3 — Where the Loss Function Comes From</title>
<link>https://coderlegion.com/24863/the-math-behind-neural-networks-part-1-3-where-the-loss-function-comes-from</link>
<description>&lt;p&gt;A calm, sequential guide for anyone entering the field. The article is divided into smaller chapters to make it easier to understand.&lt;/p&gt;
&lt;p&gt;Part 1.2 left us with a working method but an unexamined assumption. We had a loss, the mean squared error, and we had turned it into a training procedure through the derivative and gradient descent. We watched the loss fall from 18.67 to 0.297 in a single step and then converge to the true relationship in the data. Everything worked. But we never asked where the mean squared error itself came from. We wrote it down as a reasonable way to measure error — square the gap, average it — and moved on. Because it worked, the question never surfaced.&lt;/p&gt;
&lt;p&gt;Look again at how it entered. In Part 1.2, the model gave us a form for the line, ŷ = wx + b, but no way to judge whether a particular guess of w and b was any good. The equation described the model and contained no built-in measure of its quality. Faced with that gap, the article said, in as many words: “So we invented one.” We compared the prediction to the truth across all the data and summarized the gap into a single number. Squaring came along because it was reasonable — it makes every error positive and punishes large misses — not because anything forced it.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;chapter-7-what-a-cost-function-really-measures&quot;&gt;Chapter 7: What a Cost Function Really Measures&lt;/h3&gt;
&lt;p&gt;A Note on Three Names&lt;br&gt;
At the end of Part 1.2 we had a complete loop: predict, measure the loss, compute the gradient, take a step. The loss at the centre of that loop was&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15754441794189971062&quot; alt=&quot;&quot;&gt;&lt;br&gt;
A quick word on names first, because this article introduces a third one and I do not want it to look like a third thing. &lt;strong&gt;In Part 1.1 we called this the error function.&lt;/strong&gt; In Part 1.2 we called it the loss. In this part, and in most textbooks, you will also see it called the cost function, written &lt;strong&gt;J(θ).&lt;/strong&gt; These are not three different objects. They are three names for the same idea — a single number that measures how wrong the model is and that training tries to make small. “Cost function” is simply the more general term the literature settles on once the measure is no longer tied to one particular formula, which is exactly the situation this article is about to put us in. Wherever you read “cost” below, you may &lt;strong&gt;read “error” or “loss” and lose nothing&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Assumption We Never Examined&lt;/strong&gt;&lt;br&gt;
With the naming settled: as the introduction recalled, this measure entered the story as an invention — the reasonable thing we reached for when the model gave us no measure of its own quality. Squaring makes every error positive, so overshooting and undershooting both count as wrong, and it punishes a large miss far more than a small one. These are good properties, and they were enough to justify the formula for a first encounter.&lt;/p&gt;
&lt;p&gt;But “good properties” is not the same as “forced.” An invention fills a gap; it does not prove it was the only thing that could have filled it. A reader who accepts squared error should be able to answer the harder question that the invention quietly left open: out of all the ways to measure a gap, why this one? Some of that question we have in fact already answered. In Part 1.1 we asked the most natural competing question — &lt;strong&gt;why not the absolute gap |y − ŷ|, which also removes the sign — and we ruled it out for a concrete reason: the absolute value has a sharp corner at zero where its slope jumps from −1 to +1 with no value in between, and gradient descent, which lives or dies by reading a clean slope, receives contradictory signals at exactly the point it is trying to settle into.&lt;/strong&gt; So the absolute value is not an open door; Part 1.1 already closed it, on grounds of the slope.&lt;/p&gt;
&lt;p&gt;What Part 1.1 did not close is the deeper question. Ruling out the absolute value tells us squaring is better-behaved than one rival. It does not tell us that squaring is right — that out of every smooth, well-behaved measure we could have invented, this is the one the problem actually calls for. For that we need to stop justifying squared error from the outside and find the principle that produces it from the inside. This chapter goes looking for that principle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;From a Point Guess to a Distribution&lt;/strong&gt;&lt;br&gt;
In Part 1.2, the model produced a single number: ŷ = wx + b. Given an input, it committed to one answer. This is the natural picture, and it is also the picture that hides the principle we are looking for.&lt;/p&gt;
&lt;p&gt;The more honest picture is this. A model is uncertain. Given an input x, it does not truly believe the answer is exactly one number. It believes the answer is probably near some number, with smaller and smaller chances the further you move away. In other words, the model does not output a point. It outputs a distribution — a spread of belief over all the answers that could occur. We write this distribution as&lt;/p&gt;
&lt;p&gt;This part is about where that invention actually came from. Why squared error, and not the plain distance, or the cube? The honest answer is that the mean squared error is not a starting point at all. It is a consequence. It is what you are forced to when you begin from a deeper and more general principle about what it means for a model to be good. In this part we start from that principle, watch it produce a single general recipe for building cost functions, and then watch the mean squared error fall out of that recipe on its own.&lt;/p&gt;
&lt;p&gt;Readers of Part 1.1 were promised this. Its closing note mentioned, almost in passing, that minimizing the mean squared error is equivalent to maximum likelihood estimation under the assumption of Gaussian noise. That sentence was a debt. This part pays it: everything below is the unpacking of that one line. Part 1.4 then asks the next question — whether the loss we just derived is the one we should actually use.&lt;br&gt;
....&lt;br&gt;
....&lt;/p&gt;
&lt;p&gt;Read the full article at the official link: &lt;a rel=&quot;nofollow&quot; href=&quot;https://husseinmahdi.xyz/writing/math-behind-nn-1-3/&quot;&gt;https://husseinmahdi.xyz/writing/math-behind-nn-1-3/&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/24863/the-math-behind-neural-networks-part-1-3-where-the-loss-function-comes-from</guid>
<pubDate>Tue, 18 Aug 2026 19:57:05 +0000</pubDate>
</item>
<item>
<title>The Math Behind Neural Networks, Explained Like Nobody Did for Me - Part 1.2</title>
<link>https://coderlegion.com/23605/the-math-behind-neural-networks-explained-like-nobody-did-for-me-part-1-2</link>
<description>&lt;p&gt;&lt;em&gt;A calm, sequential guide for anyone entering the field, The article will also be divided into smaller chapters to make it easier to understand.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;part-1-2-the-mathematics-of-learning&quot;&gt;Part 1.2: The Mathematics of Learning&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/23416/the-math-behind-neural-networks-explained-like-nobody-did-for-me&quot;&gt;Part 1.1&lt;/a&gt; ended at a precise standing point: we had built a model, ŷ = wx + b, and we had a single number, the mean squared error, that told us how wrong that model was on average. What we did not have was a way to act on that number. A loss of 4.67 tells you the model is wrong; it does not tell you whether to push w up or down, and it does not tell you by how much. Part 1.2 is where that missing piece arrives.&lt;/p&gt;
&lt;p&gt;We will introduce the derivative, derive the gradient of the loss with respect to w and b by hand, and then turn those gradients into an actual update rule through gradient descent. By the end of this part, the same three data points from Chapter 2 will be used in a full training example, and you will watch the loss fall step by step until the model converges to the true underlying relationship. The slope idea from Chapter 1 does not change. It simply gets sharpened into the tool that makes learning possible.&lt;/p&gt;
&lt;p&gt; &lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6217155208928513122&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;chapter-4-the-derivative-the-slope-of-the-error&quot;&gt;Chapter 4: The Derivative — The Slope of the Error&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Why a Number Alone Is Not Enough&lt;/strong&gt;&lt;br&gt;
At the end of Chapter 3 we had a single number, L, that summarized how wrong the model was. With w = 1 and b = 0, the loss was 4.67. We know the goal is to make this number as small as possible. What we do not yet know is how.&lt;/p&gt;
&lt;p&gt;A reader might suggest trying different values of w and b until the loss becomes small. With two parameters and a simple dataset, this is not impossible, but consider what it involves. Should w be increased or decreased? By how much? Should b be changed at the same time or held steady? A real neural network has millions of parameters, not two, and trying random combinations would take longer than the age of the universe.&lt;/p&gt;
&lt;p&gt;The deeper issue is that the loss value, taken on its own, does not contain a direction. The number 4.67 tells you that you are wrong, but it does not tell you which way is less wrong. If I handed you only the number 4.67 and asked you whether to increase or decrease w, you could not answer. You would have to guess. The loss is a position, not a direction. These are two fundamentally different kinds of information, and you cannot extract one from the other by rearranging the same data. You have to ask a new question.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Equations Have Been Building Toward This&lt;/strong&gt;&lt;br&gt;
To see why the derivative is the only thing that fits here, it helps to trace the logic of every equation we have written so far. Each one was forced into existence by a problem the previous one could not solve.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;We began with the slope formula:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16107154320584636332&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This worked perfectly when the data lay on a clean line, because the slope could be read off directly from any two points. But real data scatters, and the slope formula stopped applying. Different pairs of points gave different slopes, and none of them represented the whole dataset.&lt;/p&gt;
&lt;p&gt;So we wrote a candidate line with unknowns to be learned:&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=9608775106319036076&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This solved the previous problem by giving us a form for the line, but it created a new one. The values of w and b were unknown, and we had no way to evaluate whether a particular guess was good. The equation describes the model but contains no built-in measure of its quality.&lt;/p&gt;
&lt;p&gt;So we invented one. We compared the prediction ŷ to the truth y across all data points and summarized the gap into a single number:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=3436137266483135989&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This solved the evaluation problem by giving us one number that measures total error. But it created the deepest problem of all, the one we are now standing at. The loss tells us that we are wrong but not which way to change w or b to be less wrong. The information we need is not contained in L. It is contained in how L changes when w changes, which is a different quantity entirely.&lt;/p&gt;
&lt;p&gt;To extract that quantity, we need a new equation, one that asks the loss a question the loss formula on its own never asks: if w were slightly different, by how much and in what direction would L change ? The mathematical object that answers this question is the derivative.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;from-slope-to-derivative&quot;&gt;From Slope to Derivative&lt;/h3&gt;
&lt;p&gt;We already have the tool we need, in a simpler form. In Chapter 1, slope told us how y changes when x changes. The derivative is the same idea applied to a different setting. Instead of asking how y changes with x in the data, we now ask how the loss L changes with the parameters w and b in the model. The variables have changed, but the underlying question — how does one thing change as another changes? — is identical.&lt;/p&gt;
&lt;p&gt;There is one refinement. The slope formula in Chapter 1 measured the rate of change between two distinct points. The derivative measures the instantaneous rate of change at a single point, which is what you get when those two points move infinitely close together:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=844295223454502176&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is not a different concept from slope. It is slope made precise. As the gap between the two points shrinks to zero, the slope of the line connecting them becomes the slope of the curve at that exact point.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why the Derivative and Nothing Else&lt;/strong&gt;&lt;br&gt;
It is worth addressing directly why the derivative is the right tool here, rather than some other technique. The honest answer is that the derivative is not the only conceivable approach, but it is the only approach ....... .&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;To complete the article, you can visit the blogs and view the entire series on :&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://husseinmahdi.xyz/writing/series/math-behind-neural-networks/&quot;&gt;https://husseinmahdi.xyz/writing/series/math-behind-neural-networks/&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/23605/the-math-behind-neural-networks-explained-like-nobody-did-for-me-part-1-2</guid>
<pubDate>Mon, 27 Jul 2026 18:20:40 +0000</pubDate>
</item>
<item>
<title>The Math Behind Neural Networks, Explained Like Nobody Did for Me</title>
<link>https://coderlegion.com/23416/the-math-behind-neural-networks-explained-like-nobody-did-for-me</link>
<description>&lt;p&gt;&lt;em&gt;A calm, sequential guide for anyone entering the field. The article is divided into smaller chapters to make it easier to understand.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Deep learning can feel overwhelming at first. You encounter words like gradient, derivative, loss function, activation, and backpropagation, and it is rarely clear how they relate to each other or where they come from. This article builds the full picture from the ground up, starting from the simplest idea in mathematics, slope, and showing how that single idea grows into everything that powers a modern neural network. No step is skipped, and no formula appears without explanation.&lt;/p&gt;
&lt;p&gt;By the end of Part 1.1, three concepts — slope, regression, and error — will form one continuous idea in your mind. You will understand what slope is and why it matters, what linear regression is trying to do, and what the error function measures. Part 1.2 then continues the journey with the derivative and gradient descent, the tools that turn a measurement of error into an actual improvement. Part 2 goes further still, introducing activation functions, multiple layers, and backpropagation, showing how everything here scales into deep networks.&lt;/p&gt;
&lt;h3 id=&quot;section&quot;&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2405181283146062159&quot; alt=&quot;&quot;&gt;&lt;/h3&gt;
&lt;h3 id=&quot;chapter-1-slope-the-foundation-of-everything&quot;&gt;Chapter 1: Slope — The Foundation of Everything&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;What Is Slope?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Slope answers one question: how much does the output change when the input changes?&lt;/p&gt;
&lt;p&gt;If you drive 100 kilometers in 2 hours, your speed — the rate of change of distance with respect to time — is 50 km/h. That is a slope. If a ramp rises 3 meters over a horizontal distance of 6 meters, its steepness is 3/6 = 0.5. That is also a slope.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5760804451094831815&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Formally, the slope between two points (x₁, y₁) and (x₂, y₂) is defined as:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11897751242004574030&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is called rise over run. The Greek letter Δ (delta) simply means change in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A Concrete Example&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Consider these three data points:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6546799812274831330&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Taking points (1, 2) and (3, 6):&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16744912882691530157&quot; alt=&quot;&quot;&gt;&lt;br&gt;
 The slope is 2. Every time x increases by 1, y increases by 2. The relationship is perfectly linear and described by:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12101358665492126687&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In real problems, however, we do not know the slope in advance. We have to discover it from data. That discovery process is called regression.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;chapter-2-linear-regression-learning-the-slope-from-data&quot;&gt;Chapter 2: Linear Regression — Learning the Slope from Data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;From Knowing the Slope to Learning It&lt;/strong&gt;&lt;br&gt;
In Chapter 1 we had three neat data points that fell perfectly on a line, and we computed the slope directly with a formula. and the question this article exists to answer is how mathematics learns from data that does not fall on a clean line at all.&lt;/p&gt;
&lt;p&gt;Real data is not like that. When you collect measurements from the world — house prices against square footage, patient weight against medication dosage, temperature against electricity demand — the points do not land on a single clean line. They scatter. No two points give you the same slope, and no formula can hand you the answer.&lt;/p&gt;
&lt;p&gt;This is where regression begins. Instead of computing the slope from two chosen points, we ask a different question: what is the single straight line that best represents all of the scattered points at once ? That line will not pass through every point, but it will come as close as possible to all of them. Finding it means learning its slope and its vertical position from the data itself, rather than reading them off with a formula.&lt;/p&gt;
&lt;p&gt; &lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13277951927564334297&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;.....................&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;To read the full article, check out my blog: &lt;a rel=&quot;nofollow&quot; href=&quot;https://husseinmahdi.xyz/writing/math-behind-nn-1-1/&quot;&gt;https://husseinmahdi.xyz/writing/math-behind-nn-1-1/&lt;/a&gt;&lt;br&gt;
This is part of the &quot;math-behind-neural-networks&quot; series&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Or on GoPenAI: &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.gopenai.com/the-math-behind-neural-networks-explained-like-nobody-did-for-me-cda519ef63e8&quot;&gt;https://blog.gopenai.com/the-math-behind-neural-networks-explained-like-nobody-did-for-me-cda519ef63e8&lt;/a&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/23416/the-math-behind-neural-networks-explained-like-nobody-did-for-me</guid>
<pubDate>Sat, 25 Jul 2026 00:02:30 +0000</pubDate>
</item>
<item>
<title>Understanding Backpropagation with micrograd — Principles, Intuition, and Pitfalls I Ran Into</title>
<link>https://coderlegion.com/22806/understanding-backpropagation-with-micrograd-principles-intuition-and-pitfalls-into</link>
<description>&lt;blockquote&gt;&lt;p&gt;I had heard about &lt;strong&gt;backpropagation&lt;/strong&gt; many times, but I never really understood how it actually worked. When someone asked me what backpropagation was, all I could say was, &quot;It's how neural networks learn… I guess?&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;I'd seen the formulas, I knew the chain rule, but it always felt like there was a wall between me and true understanding.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;So I spent two days reading &lt;strong&gt;Karpathy&lt;/strong&gt;'s &lt;strong&gt;micrograd&lt;/strong&gt; project source code. It's honestly the best explanation of the core principles of neural networks I've ever come across!&lt;br&gt;
👉 &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/karpathy/micrograd&quot;&gt;https://github.com/karpathy/micrograd&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This post documents what I learned and how I understand it now.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-this-post&quot;&gt;Why This Post&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I'd watched plenty of YouTube videos explaining backpropagation, but most of them just said:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Backpropagation is repeatedly applying the chain rule.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That's true, but for a beginner, it's basically saying nothing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I was used to frameworks where a single line — &lt;code&gt;loss.backward()&lt;/code&gt; — got the job done, with no idea what was actually happening under the hood.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-key-code-amp-what-it-does&quot;&gt;The Key Code &amp;amp; What It Does&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;class Value:
    def __init__(self, data, _child = (), _op = &quot;&quot;, label = &quot;&quot;):
        self.data = data
        self._prev = set(_child)
        self._backward = lambda: None
        self.grad = 0.0
        self._op = _op
        self.label = label
    
    def __repr__(self):
        return f&quot;Value(data = {self.data})&quot;

    def __add__(self, other):
        other = other if isinstance(other, Value) else Value(other)
        out = Value(self.data + other.data, (self, other), &quot;+&quot;)

       def _backward():
            self.grad += out.grad * 1.0
            other.grad += out.grad * 1.0
        out._backward = _backward
        return out

     def backward(self):

        topo = []
        visited = set()
        def build_topo(v):
            if v not in visited:
                visited.add(v)
                for child in v._prev:
                    build_topo(child)
                topo.append(v)
        self.grad = 1.0
        build_topo(self)

        for node in reversed(topo):
            node._backward()

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;micrograd also defines &lt;code&gt;__mul__&lt;/code&gt;, &lt;code&gt;tanh&lt;/code&gt;, &lt;code&gt;__pow__&lt;/code&gt; and other methods — they all work the same way, each attaching a different &lt;code&gt;_backward&lt;/code&gt; note. So I'm only showing the core code here.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;blockquote&gt;&lt;p&gt;Try this:&lt;br&gt;
a = Value(1.0)&lt;br&gt;
b = Value(2.0)&lt;br&gt;
n = a + b&lt;br&gt;
L = n.tanh()&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You'll get this result:&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=9064488572173869505&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;how-it-works&quot;&gt;How It Works&lt;/h3&gt;
&lt;p&gt;When you write &lt;code&gt;n = a + b&lt;/code&gt;, here's what happens:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A new &lt;code&gt;Value&lt;/code&gt; instance &lt;code&gt;n&lt;/code&gt; is created.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;_backward&lt;/code&gt; function is attached to &lt;code&gt;n._backward()&lt;/code&gt; but &lt;strong&gt;not executed yet&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;backward()&lt;/code&gt; is called, it traverses the graph in reverse topological order, executing each node's &lt;code&gt;_backward()&lt;/code&gt; one by one.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;things-you-should-know&quot;&gt;Things You Should Know&lt;/h3&gt;
&lt;blockquote&gt;&lt;p&gt;Chain Rule:&lt;br&gt;
&lt;code&gt;∂e/∂a = (∂e/∂c)(∂c/∂a) + (∂e/∂d)(∂d/∂a)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;At first I didn't accumulate gradients in &lt;code&gt;_backward()&lt;/code&gt; — just assigned them. That led to some serious bugs.&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Imagine you write:&lt;br&gt;
a = Value(2.0)&lt;br&gt;
b = a + a&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What do you expect?&lt;br&gt;
&lt;strong&gt;a.grad = 2, b.grad = 1?&lt;/strong&gt; Or &lt;strong&gt;a.grad = 1, b.grad = 1?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you run it, you'll find &lt;code&gt;a.grad = 1&lt;/code&gt; — which is completely wrong!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;    def __add__(self, other):
    other = other if isinstance(other, Value) else Value(other)
    out = Value(self.data + other.data, (self, other), &quot;+&quot;)
    def _backward():
        self.grad = out.grad * 1.0   # self = a, other = a;
        other.grad = out.grad * 1.0  # both set a.grad = 1
    out._backward = _backward
    return out
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;Here's another example:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Try this:&lt;br&gt;
a = Value(2.0)&lt;br&gt;
b = Value(3.0)&lt;br&gt;
c = a + b&lt;br&gt;
d = a &lt;em&gt; b&lt;br&gt;
e = c &lt;/em&gt; d&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What are &lt;code&gt;a.grad&lt;/code&gt; and &lt;code&gt;b.grad&lt;/code&gt; this time?&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12734637975006860424&quot; alt=&quot;&quot;&gt;&lt;br&gt;
&lt;strong&gt;Clearly, the gradients of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; got overwritten!&lt;/strong&gt;&lt;br&gt;
So &lt;strong&gt;you MUST accumulate in &lt;code&gt;_backward()&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;my-confusion&quot;&gt;My Confusion&lt;/h3&gt;
&lt;blockquote&gt;&lt;p&gt;For a long time I couldn't understand what &lt;code&gt;def _backward()&lt;/code&gt; and &lt;code&gt;out._backward = _backward&lt;/code&gt; were really doing. Sounds silly, I know.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I kept wondering: when &lt;code&gt;Value c&lt;/code&gt; is created, &lt;code&gt;out.grad&lt;/code&gt; defaults to 0 — how can it possibly backpropagate to find &lt;code&gt;self.grad&lt;/code&gt; and &lt;code&gt;other.grad&lt;/code&gt;? (Of course, back then I thought &lt;code&gt;out._backward = _backward&lt;/code&gt; would immediately execute the &lt;code&gt;_backward&lt;/code&gt; function 😅)&lt;/p&gt;
&lt;p&gt;Now I finally get it:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;After creating a new &lt;code&gt;Value c&lt;/code&gt;, &lt;code&gt;c._backward&lt;/code&gt; just stores the &lt;code&gt;_backward&lt;/code&gt; function without running it. It only executes when &lt;code&gt;backward()&lt;/code&gt; is called, traversing in reverse topological order.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;It's a naive question that came from a naive assumption, but I hope it helps other developers who've been stuck on the same thing.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;a-thought-that-followed&quot;&gt;A Thought That Followed&lt;/h3&gt;
&lt;blockquote&gt;&lt;p&gt;Imagine this:&lt;br&gt;
a = Value(2.0)&lt;br&gt;
b = Value(3.0)&lt;br&gt;
c = Value(2.0)&lt;br&gt;
d = a + b&lt;br&gt;
e = c + d&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Do &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, and &lt;code&gt;c&lt;/code&gt; have their &lt;code&gt;_backward&lt;/code&gt; executed?&lt;/p&gt;
&lt;p&gt;Answer: All three have &lt;code&gt;_backward&lt;/code&gt; set to &lt;code&gt;lambda: None&lt;/code&gt; (an empty function). When backpropagation reaches them, nothing happens — their gradients have already been accumulated through the upstream path.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-i-gained&quot;&gt;What I Gained&lt;/h3&gt;
&lt;p&gt;After carefully reading through &lt;strong&gt;Karpathy&lt;/strong&gt;'s &lt;strong&gt;micrograd&lt;/strong&gt; source code, I was genuinely impressed. I'd never understood the core of &lt;strong&gt;backpropagation&lt;/strong&gt; so intuitively before. Here's what I took away:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I now understand the core mechanism of &lt;strong&gt;backpropagation&lt;/strong&gt; — &lt;code&gt;.backward()&lt;/code&gt; is no longer a black box to me.&lt;/li&gt;
&lt;li&gt;I finally &lt;strong&gt;truly understand&lt;/strong&gt; what &quot;backpropagation is just repeatedly applying the chain rule&quot; means.&lt;/li&gt;
&lt;li&gt;This has kicked off my deep dive into &lt;strong&gt;deep learning&lt;/strong&gt;, and now I can better compare &lt;strong&gt;micrograd&lt;/strong&gt; with &lt;strong&gt;PyTorch&lt;/strong&gt; and modern neural network frameworks.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;closing-thoughts&quot;&gt;Closing Thoughts&lt;/h3&gt;
&lt;p&gt;Thanks for taking the time to read this. I wrote it right after going through the source code, so there may be mistakes in my understanding — corrections are very welcome.&lt;/p&gt;
&lt;p&gt;If you're also a beginner in &lt;strong&gt;deep learning&lt;/strong&gt;, feel free to reach out. I'd love to learn together with you.&lt;/p&gt;
&lt;p&gt;If you enjoyed this post, don't forget to like, bookmark, comment, and follow! I'll be sharing my learning journey in &lt;strong&gt;deep learning&lt;/strong&gt;, &lt;strong&gt;machine learning&lt;/strong&gt;, &lt;strong&gt;backend development&lt;/strong&gt;, and more from time to time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Check out my Dev.to&lt;/strong&gt;: &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/elysianx138&quot;&gt;https://dev.to/elysianx138&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;My GitHub will also track my learning progress&lt;/strong&gt;: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/elysianx138&quot;&gt;https://github.com/elysianx138&lt;/a&gt;  &lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/22806/understanding-backpropagation-with-micrograd-principles-intuition-and-pitfalls-into</guid>
<pubDate>Thu, 16 Jul 2026 11:48:52 +0000</pubDate>
</item>
<item>
<title>My Machine Learning Journey</title>
<link>https://coderlegion.com/21882/my-machine-learning-journey</link>
<description>&lt;p&gt;Back then, I was just a kid who used to play a lot of games. But as I grew up, I realized that I needed a goal. So, I decided to be productive and search for something that will be beneficial for my future. And from that thought, I was interested to study about technology.&lt;/p&gt;
&lt;p&gt;I started studying technology at junior high school in 9th grade. At that time, I learnt a lot. To begin with, I studied web development, but it wasn't a good fit for me. However, I then found a video explaining various technology fields. That was the moment I became fascinated by the field of Machine Learning.&lt;/p&gt;
&lt;h3 id=&quot;the-summer-story&quot;&gt;The Summer Story&lt;/h3&gt;
&lt;p&gt;When I was in the 9th grade, I studied Machine Learning only from YouTube videos. And I still remember the channel who really helped me a lot when studying about various Machine Learning topics. He made a massive 60-hour Machine Learning course video. And honestly, at the beginning it was very fun and exciting to watch also I got a lot of knowledge. But, as time went by it's getting hard and harder. It's like my sleeping pill when I watch the video.&lt;/p&gt;
&lt;p&gt;However, I was really brave and In the summer I convinced myself to join a Machine Learning Competition. The competition called AIRENA. I kind of forget the detail of the competition, but the format is just like a Kaggle Competition. It was a great start because I ranked at 17th out of 96 participants Hehehe.&lt;/p&gt;
&lt;h3 id=&quot;the-reality&quot;&gt;The Reality&lt;/h3&gt;
&lt;p&gt;Oh man, I just know that machine learning involves a lot of math. It's complex math, by the way, like linear algebra, calculus and statistics. I tried to study linear algebra and understood a little, but when it came to eigenvectors and sums, it was really hard and I got burned out. And afterwards, I've been out of the machine learning scene because I have a lot of School Activity.&lt;/p&gt;
&lt;h3 id=&quot;the-comeback&quot;&gt;The Comeback&lt;/h3&gt;
&lt;p&gt;After I graduated from junior high school. In my first year of senior high school, more specifically in the middle of the year. I comeback in machine learning fields with a new spirit and goals, why? I was accepted onto the Dicoding Bootcamp AI Engineer Path. I have learnt a lot from this bootcamp, literally a lot! I now have a lot of projects and I understand various concepts such as NLP and GANs. By the way I've graduated from the bootcamp.&lt;/p&gt;
&lt;p&gt;Moreover, I participated in AIRENA 2 again. I still remember the theme of the competition: they told us to make a model to predict continuous values (a regression task). I don't know the name, but the theme was space-related. Unfortunately, I didn't even make the top ten, which made me really sad. Oh, I forgot that I participated in AIRENA 2 before the bootcamp. So the bootcamp story comes after AIRENA 2.&lt;/p&gt;
&lt;p&gt;So, that concludes my machine learning journey. I hope that, through sharing it, I might inspire your interest in machine learning. If you want to know more, you can contact me. I'm open to it, by the way!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/21882/my-machine-learning-journey</guid>
<pubDate>Sat, 04 Jul 2026 06:34:13 +0000</pubDate>
</item>
<item>
<title>Teach Computers to Think: Simple AI Trick Explained</title>
<link>https://coderlegion.com/17393/teach-computers-to-think-simple-ai-trick-explained</link>
<description>&lt;p&gt;Teach Computers to Think: Simple AI Trick Explained — Learn a practical, beginner-friendly method to make machines reason like humans using a single, powerful idea. This video breaks down a simple AI trick that accelerates learning and improves model performance without complex math or heavy compute. Perfect for students, hobbyists, and developers exploring #AI, #MachineLearning, and #DeepLearning.&lt;/p&gt;
</description>
<category>Videos</category>
<guid isPermaLink="true">https://coderlegion.com/17393/teach-computers-to-think-simple-ai-trick-explained</guid>
<pubDate>Mon, 11 May 2026 23:30:00 +0000</pubDate>
</item>
<item>
<title>I Built an AI That Detects Pneumonia From Chest X-Rays Here's Exactly How I Did It</title>
<link>https://coderlegion.com/16392/i-built-an-ai-that-detects-pneumonia-from-chest-x-rays-heres-exactly-how-i-did-it</link>
<description>&lt;p&gt;A few weeks ago, I shipped &lt;strong&gt;PneumoScan AI&lt;/strong&gt;  a deep learning model that analyzes chest X-ray images and detects pneumonia in seconds, with 90%+ accuracy. It's live, it's free, and anyone can use it right now.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://pneumonia-scan-ai.netlify.app/&quot;&gt;pneumonia-scan-ai.netlify.app&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the story of how I built it — and everything I learned along the way.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-pneumonia-&quot;&gt;Why Pneumonia?&lt;/h3&gt;
&lt;p&gt;Pneumonia kills over 2 million people annually. A huge portion of those deaths happen in low-resource areas where radiologists are scarce and diagnosis is slow.&lt;/p&gt;
&lt;p&gt;I'm not claiming to solve that problem. But I wanted to build something that &lt;em&gt;mattered&lt;/em&gt;  not just another MNIST classifier or iris flower predictor. Medical imaging felt real.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-dataset&quot;&gt;The Dataset&lt;/h3&gt;
&lt;p&gt;I used the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.kaggle.com/datasets/paultimothymooney/chest-xray-pneumonia&quot;&gt;Chest X-Ray Images (Pneumonia)&lt;/a&gt;&lt;/strong&gt; dataset from Kaggle.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;5,800+ clinical chest X-ray images&lt;/li&gt;
&lt;li&gt;Two classes: &lt;code&gt;NORMAL&lt;/code&gt; and &lt;code&gt;PNEUMONIA&lt;/code&gt; (Viral &amp;amp; Bacterial)&lt;/li&gt;
&lt;li&gt;Real hospital data from Guangzhou Women and Children's Medical Center&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One thing I learned immediately: &lt;strong&gt;the dataset is imbalanced&lt;/strong&gt;. There are significantly more pneumonia images than normal ones. This is something you have to think about carefully in medical AI  because a model that just predicts &quot;pneumonia&quot; on everything could still hit decent accuracy numbers while being completely useless.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-architecture-mobilenetv2-custom-head&quot;&gt;The Architecture — MobileNetV2 + Custom Head&lt;/h3&gt;
&lt;p&gt;I chose &lt;strong&gt;MobileNetV2&lt;/strong&gt; as my base model for two reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It's lightweight (14MB)  perfect for deployment on free-tier infrastructure&lt;/li&gt;
&lt;li&gt;It was pre-trained on ImageNet, so it already knows how to extract visual features&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The key idea is &lt;strong&gt;transfer learning&lt;/strong&gt;  instead of training a CNN from scratch on 5,800 images (which isn't enough), I used MobileNetV2 as a frozen feature extractor and added my own classification head on top.&lt;/p&gt;
&lt;p&gt;Here's the full pipeline:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;Input (any size RGB image)
    ↓
Resizing Layer      → 224 × 224 (built into model)
Rescaling Layer     → pixel values ÷ 255
    ↓
MobileNetV2         → FROZEN (trainable = False)
16 inverted residual blocks
Final feature map: 7 × 7 × 1280
    ↓
GlobalAveragePooling2D  → collapses to 1280 values
    ↓
Dense(128, ReLU)        → learns pneumonia-specific patterns
    ↓
Dropout(0.3)            → prevents overfitting
    ↓
Dense(1, Sigmoid)       → outputs probability (0 = Normal, 1 = Pneumonia)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why freeze MobileNetV2?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because it already knows how to see. The ImageNet weights encode knowledge about edges, textures, and shapes that transfer surprisingly well to X-rays. Fine-tuning all those layers on a small dataset would just cause overfitting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why add Dense(128) before the output?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The raw GlobalAveragePooling output is 1280 features  most of which are irrelevant to pneumonia. The Dense(128) layer acts as a bottleneck, forcing the model to compress what it learned into the most useful 128 features for this specific task.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Training config:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Optimizer: Adam (lr=0.001)&lt;/li&gt;
&lt;li&gt;Loss: Binary Crossentropy&lt;/li&gt;
&lt;li&gt;Final accuracy: &lt;strong&gt;90%+&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-problem-i-didn-t-expect-the-dog-test&quot;&gt;The Problem I Didn't Expect The Dog Test&lt;/h3&gt;
&lt;p&gt;After I deployed the first version, I decided to test it.&lt;/p&gt;
&lt;p&gt;I uploaded a photo of a dog sitting in a bathroom smoking a cigarette.&lt;/p&gt;
&lt;p&gt;The result?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;Result&quot;: &quot;PNEUMONIA DETECTED&quot;,
  &quot;Confidence Score&quot;: &quot;100.00%&quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;100% confident. That dog had pneumonia.&lt;/p&gt;
&lt;p&gt;This is a classic failure mode of CNNs  &lt;strong&gt;the model has no concept of &quot;this isn't even an X-ray.&quot;&lt;/strong&gt; It was trained only on X-rays, so it forced every single image into one of two buckets regardless of what it actually was.&lt;/p&gt;
&lt;p&gt;I needed an input validation layer.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-fix-saturation-gate&quot;&gt;The Fix  Saturation Gate&lt;/h3&gt;
&lt;p&gt;The solution I came up with is what I call a &lt;strong&gt;Saturation Gate&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The logic is simple: chest X-rays are grayscale. Any real X-ray will have near-zero color saturation. A photo of a dog, a selfie, a meme these all have high saturation.&lt;/p&gt;
&lt;p&gt;So before the image ever reaches the model, I convert it to &lt;strong&gt;HSV color space&lt;/strong&gt; and measure the mean saturation value. If it exceeds a threshold.&lt;/p&gt;
&lt;p&gt;The dog photo gets rejected now. The model only sees what it was trained to see.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-deployment-stack&quot;&gt;The Deployment Stack&lt;/h3&gt;
&lt;p&gt;I wanted this to be completely free to host — no cloud bills, no server management.&lt;/p&gt;
&lt;p&gt;Here's what I ended up with:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Layer &lt;/th&gt;&lt;th&gt;Technology&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Model Inference &lt;/td&gt;&lt;td&gt;Hugging Face Spaces (Gradio + TensorFlow-CPU)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Frontend &lt;/td&gt;&lt;td&gt;Netlify (custom Tailwind CSS portal)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Bridge &lt;/td&gt;&lt;td&gt;iframe&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The Gradio app on Hugging Face handles all the heavy lifting  loading the &lt;code&gt;.h5&lt;/code&gt; model, running inference, returning JSON results. The Netlify frontend is just a clean portal that embeds the Gradio Space via iframe.&lt;/p&gt;
&lt;p&gt;Total hosting cost: &lt;strong&gt;$0.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-i-learned&quot;&gt;What I Learned&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;1. Accuracy alone is a lie in medical AI.&lt;/strong&gt;&lt;br&gt;
A model can hit 90% accuracy while still missing dangerous cases. Always look at your confusion matrix. False negatives  missed pneumonia cases — are the ones that matter most.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Input validation is not optional.&lt;/strong&gt;&lt;br&gt;
Any model you deploy in the real world needs to handle unexpected inputs gracefully. The Saturation Gate wasn't in any tutorial I followed. I had to think of it myself after seeing the model fail in a funny but revealing way.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Transfer learning is magic for small datasets.&lt;/strong&gt;&lt;br&gt;
If you're working with fewer than 50,000 images, you almost certainly shouldn't be training a CNN from scratch. Use pretrained weights. Freeze the base. Train only the head.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Ship first, improve later.&lt;/strong&gt;&lt;br&gt;
The first version was broken in obvious ways. But shipping it is what revealed those problems. The dog test only happened because I deployed it.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-s-next&quot;&gt;What's Next&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Grad-CAM heatmap overlays&lt;/strong&gt;  showing &lt;em&gt;which part&lt;/em&gt; of the X-ray triggered the detection. This is the standard in medical AI and would make the tool genuinely useful for educational purposes.&lt;br&gt;
 &lt;strong&gt;Precision/Recall analysis&lt;/strong&gt; properly evaluating false negative rate on the test set&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;More pathologies&lt;/strong&gt; tuberculosis, pleural effusion, cardiomegaly&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-repo&quot;&gt;The Repo&lt;/h3&gt;
&lt;p&gt;The trained model is open source. You can download it, use it, build on it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/GradienNinja/PneumoScan-AI&quot;&gt;github.com/GradienNinja/PneumoScan-AI&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;final-thought&quot;&gt;Final Thought&lt;/h3&gt;
&lt;p&gt;I fix cars for a living. I don't have a degree. I didn't take a course that handed me this project.&lt;/p&gt;
&lt;p&gt;I just built it.&lt;/p&gt;
&lt;p&gt;If you're self-taught and reading this wondering whether you're &quot;ready&quot; to build something real  you're not going to get ready by waiting. You get ready by shipping.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Built by Sheikh Sadi Asif — &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/GradienNinja&quot;&gt;@GradienNinja&lt;/a&gt; | AstroLabSoft AI Lab&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Disclaimer: This is a research and educational project. Not a certified medical device. Always consult a qualified healthcare professional for medical decisions.*&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aufslf4zi23mw26fe7bl.jpg&quot; alt=&quot;Image description&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/16392/i-built-an-ai-that-detects-pneumonia-from-chest-x-rays-heres-exactly-how-i-did-it</guid>
<pubDate>Sat, 02 May 2026 11:52:17 +0000</pubDate>
</item>
<item>
<title>Fashion-ID: Smart Image Classification</title>
<link>https://coderlegion.com/16340/fashion-id-smart-image-classification</link>
<description>&lt;p&gt;Fashion Item Classifier &lt;br&gt;
A Deep Learning project built with TensorFlow and Keras to classify fashion items from the Fashion-MNIST dataset. This project demonstrates the full machine learning workflow: from model training to real-world testing and advanced image preprocessing.&lt;/p&gt;
&lt;p&gt; The Challenge&lt;br&gt;
During testing with real-world photos, the model initially struggled to distinguish between complex shapes (like sneakers and bags) due to the limitations of Dense Layers in handling spatial variance. Through iterative debugging and advanced preprocessing, I successfully improved the model's prediction accuracy for custom inputs.&lt;/p&gt;
&lt;p&gt;️ Tech Stack&lt;br&gt;
Framework: TensorFlow / Keras&lt;/p&gt;
&lt;p&gt;Language: Python&lt;/p&gt;
&lt;p&gt;Libraries: NumPy (Data manipulation), Matplotlib (Visualization), PIL/Pillow (Image Processing)&lt;/p&gt;
&lt;p&gt;Environment: Google Colab&lt;/p&gt;
&lt;p&gt; Model Architecture&lt;br&gt;
The model uses a Sequential Neural Network approach:&lt;/p&gt;
&lt;p&gt;Input Layer: Flatten layer to convert 28x28 images into a 1D array.&lt;/p&gt;
&lt;p&gt;Hidden Layers: Multiple Dense layers with ReLU activation for feature learning.&lt;/p&gt;
&lt;p&gt;Output Layer: Dense layer with Softmax activation to classify 10 distinct fashion categories.&lt;/p&gt;
&lt;p&gt; Key Features &amp;amp; Preprocessing&lt;br&gt;
To bridge the gap between &quot;perfect&quot; dataset images and &quot;noisy&quot; real-world photos, I implemented a robust preprocessing pipeline:&lt;/p&gt;
&lt;p&gt;Grayscale Conversion: Ensuring compatibility with the single-channel training data.&lt;/p&gt;
&lt;p&gt;Thresholding &amp;amp; Contrast: Enhancing object edges to prevent &quot;Bag/T-shirt&quot; misclassification.&lt;/p&gt;
&lt;p&gt;Strategic Resizing: Using thumbnail and padding techniques to center-align objects within a 28x28 frame.&lt;/p&gt;
&lt;p&gt;Inversion Logic: Automatically adjusting background-to-foreground contrast for optimal detection.&lt;/p&gt;
&lt;p&gt; Results&lt;br&gt;
Test Accuracy: Achieved ~88% accuracy on the Fashion-MNIST test set.&lt;/p&gt;
&lt;p&gt;Real-World Testing: Successfully classified custom images of T-shirts and Footwear after optimizing the preprocessing pipeline.&lt;/p&gt;
&lt;p&gt; Repository Structure&lt;br&gt;
Fashion_Classifier.ipynb: The main notebook containing training and prediction code.&lt;/p&gt;
&lt;p&gt;model_weights/: Saved weights for the trained model.&lt;/p&gt;
&lt;p&gt;examples/: Sample images used for testing &quot;The Bug&quot; vs &quot;The Fix&quot; scenarios.&lt;br&gt;
See full code in  &lt;a rel=&quot;nofollow&quot; href=&quot;https://lnkd.in/d_NDY5Wf&quot;&gt;https://lnkd.in/d_NDY5Wf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Learnings&lt;br&gt;
This project was a deep dive into Spatial Invariance and why Convolutional Neural Networks (CNNs) are often preferred over standard Dense Networks for image tasks. It taught me that in AI, data preparation is just as critical as the model architecture itself.&lt;/p&gt;
</description>
<category>Launches</category>
<guid isPermaLink="true">https://coderlegion.com/16340/fashion-id-smart-image-classification</guid>
<pubDate>Fri, 01 May 2026 16:18:58 +0000</pubDate>
</item>
<item>
<title>Fundamentals of Large Language Models: Understanding LLM Architectures</title>
<link>https://coderlegion.com/8062/fundamentals-of-large-language-models-understanding-llm-architectures</link>
<description>&lt;h3 id=&quot;what-is-an-llm-&quot;&gt;What is an LLM?&lt;/h3&gt;
&lt;p&gt;An LLM (Large Language Model) is fundamentally a probabilistic model that predicts distributions over vocabulary tokens. At its core, an LLM understands a fixed set of words called a &lt;strong&gt;vocabulary&lt;/strong&gt; and assigns probabilities to each word appearing in a given context. &lt;/p&gt;
&lt;p&gt;The &quot;Large&quot; in LLM refers to the &lt;strong&gt;number of parameters&lt;/strong&gt; the model contains. These models can have billions or even trillions of parameters, allowing them to capture complex patterns in language. While there's no universally agreed-upon threshold for what constitutes &quot;large,&quot; modern LLMs typically range from hundreds of millions to hundreds of billions of parameters.&lt;/p&gt;
&lt;h4 id=&quot;understanding-vocabulary-size&quot;&gt;Understanding Vocabulary Size&lt;/h4&gt;
&lt;p&gt;Recent research has revealed that vocabulary size plays a crucial role in LLM performance, with optimal vocabulary sizes depending on the compute budget used for training. Most modern LLMs use vocabulary sizes ranging from 30,000 to 100,000 tokens, though this varies significantly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;BERT&lt;/strong&gt;: 30,000 tokens (WordPiece tokenization)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GPT-3&lt;/strong&gt;: ~50,000 tokens&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Llama 2&lt;/strong&gt;: 32,000 tokens&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RoBERTa&lt;/strong&gt;: 50,265 tokens (Byte-Pair Encoding)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;T5&lt;/strong&gt;: 32,128 tokens&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Research suggests that many existing LLMs actually use suboptimal vocabulary sizes - for example, Llama2-70B's optimal vocabulary size should have been at least 216,000 tokens, seven times larger than its actual 32,000-token vocabulary.&lt;/p&gt;
&lt;h3 id=&quot;llm-architectures-the-three-main-types&quot;&gt;LLM Architectures: The Three Main Types&lt;/h3&gt;
&lt;p&gt;Modern transformer models use one of three fundamental architectures: encoder-only, decoder-only, or encoder-decoder (sequence-to-sequence). Each architecture is optimized for different types of tasks.&lt;/p&gt;
&lt;h4 id=&quot;1-encoder-only-models&quot;&gt;1. Encoder-Only Models&lt;/h4&gt;
&lt;p&gt;Encoders are designed to convert sequences of words into vector representations (embeddings) that can be used for various predictive modeling tasks such as classification. These models use &lt;strong&gt;bidirectional attention&lt;/strong&gt;, meaning they can look at context from both directions simultaneously.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use bidirectional attention to access all words in the input sentence&lt;/li&gt;
&lt;li&gt;Specialized in understanding and analyzing text&lt;/li&gt;
&lt;li&gt;Pretrained using masked language modeling objectives&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Popular Encoder Models:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;BERT (Bidirectional Encoder Representations from Transformers)&lt;/strong&gt;: Introduced in October 2018 by Google researchers, BERT uses 12-24 layers (depending on the variant) and dramatically improved the state of the art for many NLP tasks. The base model has 110M parameters, while the large model has 340M parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RoBERTa (Robustly Optimized BERT Approach)&lt;/strong&gt;: An improved version of BERT that modifies the training procedure by removing the next-sentence prediction task, using larger mini-batches, and training on 160GB of text (10x more than BERT). It has 355M parameters in its large version.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DistilBERT&lt;/strong&gt;: A distilled version that retains 95% of BERT's performance with only 60% of its parameters (66M).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DeBERTa&lt;/strong&gt;: Uses disentangled attention mechanisms for improved performance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ModernBERT&lt;/strong&gt;: Released in 2024 as a state-of-the-art replacement for BERT, featuring an 8,192 token sequence length and significantly faster processing.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Primary Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Text classification (sentiment analysis, topic classification)&lt;/li&gt;
&lt;li&gt;Named entity recognition (NER)&lt;/li&gt;
&lt;li&gt;Question answering&lt;/li&gt;
&lt;li&gt;Semantic similarity tasks&lt;/li&gt;
&lt;li&gt;Embedding generation for retrieval systems&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-decoder-only-models&quot;&gt;2. Decoder-Only Models&lt;/h4&gt;
&lt;p&gt;Decoders are designed to generate new text by predicting the next word in a sequence. They use masked (causal) self-attention, which only allows tokens to attend to previous tokens in the sequence, ensuring autoregressive generation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use unidirectional (causal) attention&lt;/li&gt;
&lt;li&gt;Generate text one token at a time&lt;/li&gt;
&lt;li&gt;Excel at creative text generation and completion&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Popular Decoder Models:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;GPT Series (GPT, GPT-2, GPT-3, GPT-4)&lt;/strong&gt;: The GPT series pioneered the decoder-only architecture, with models ranging from 117M parameters (GPT-2 small) to hundreds of billions in GPT-4. GPT models became state of the art in natural language generation starting in 2018.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Llama (1, 2, 3)&lt;/strong&gt;: Meta's open-source models that have become foundational for many smaller LLM projects, with the Llama 2 family ranging up to 70 billion parameters.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Falcon&lt;/strong&gt;: A series of open-source models trained on refined web data.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;BLOOM&lt;/strong&gt;: A multilingual decoder-only model.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mistral&lt;/strong&gt;: High-performance open-weight models with efficient architectures.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Primary Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Text generation and completion&lt;/li&gt;
&lt;li&gt;Conversational AI and chatbots&lt;/li&gt;
&lt;li&gt;Creative writing assistance&lt;/li&gt;
&lt;li&gt;Code generation&lt;/li&gt;
&lt;li&gt;Question answering in chat format&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-encoder-decoder-models&quot;&gt;3. Encoder-Decoder Models&lt;/h4&gt;
&lt;p&gt;Encoder-decoder models combine both architectures, using an encoder to understand the input and a decoder to generate appropriate output text. This makes them perfect for tasks that transform one sequence into another, like translation or summarization.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Characteristics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bidirectional understanding through the encoder&lt;/li&gt;
&lt;li&gt;Autoregressive generation through the decoder&lt;/li&gt;
&lt;li&gt;Connected via cross-attention mechanism&lt;/li&gt;
&lt;li&gt;Ideal for sequence-to-sequence tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Popular Encoder-Decoder Models:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;T5 (Text-to-Text Transfer Transformer)&lt;/strong&gt;: Developed by Google, T5 treats every NLP task as a text-to-text problem, ranging from 60M to 11B parameters. It uses task-specific prefixes (e.g., &quot;translate English to German:&quot;, &quot;summarize:&quot;) to handle different tasks with the same architecture.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;BART (Bidirectional and Auto-Regressive Transformers)&lt;/strong&gt;: Developed by Facebook (Meta) in 2019, BART combines strengths of BERT and GPT. It's pretrained by corrupting text in various ways (deleting words, shuffling sentences, masking tokens) and learning to reconstruct the original.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UL2&lt;/strong&gt;: A unified framework for language understanding and generation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;mT5&lt;/strong&gt;: Multilingual variant of T5 supporting 100+ languages.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Primary Use Cases:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Machine translation&lt;/li&gt;
&lt;li&gt;Text summarization&lt;/li&gt;
&lt;li&gt;Question answering with context&lt;/li&gt;
&lt;li&gt;Text simplification&lt;/li&gt;
&lt;li&gt;Paraphrasing&lt;/li&gt;
&lt;li&gt;Data-to-text generation&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-transformer-foundation&quot;&gt;The Transformer Foundation&lt;/h3&gt;
&lt;p&gt;All these architectures are built on the transformer architecture, which uses self-attention mechanisms to process input sequences. The original transformer was proposed in the 2017 paper &quot;Attention Is All You Need&quot; by Google researchers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Components of Transformers:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tokenization&lt;/strong&gt;: Converting text into discrete tokens using algorithms like Byte-Pair Encoding (BPE), WordPiece, or SentencePiece.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Embeddings&lt;/strong&gt;: Converting tokens into dense vector representations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Self-Attention Layers&lt;/strong&gt;: Mechanisms that allow each token to attend to other tokens in the sequence, capturing contextual relationships.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feed-Forward Networks&lt;/strong&gt;: Processing representations through neural networks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Layer Normalization&lt;/strong&gt;: Stabilizing training and improving convergence.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Positional Encodings&lt;/strong&gt;: Adding position information since attention has no inherent notion of sequence order.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;choosing-the-right-architecture&quot;&gt;Choosing the Right Architecture&lt;/h3&gt;
&lt;p&gt;When selecting an architecture for a specific task, consider whether you need bidirectional understanding (encoder), text generation (decoder), or sequence transformation (encoder-decoder).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Decision Framework:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Need deep understanding of text?&lt;/strong&gt; → Use encoder-only models&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Need to generate creative or conversational text?&lt;/strong&gt; → Use decoder-only models&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Need to transform one text form to another?&lt;/strong&gt; → Use encoder-decoder models&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;recent-trends-and-future-directions&quot;&gt;Recent Trends and Future Directions&lt;/h3&gt;
&lt;p&gt;Almost every major LLM since GPT-3 has adopted the decoder-only architecture due to its simplicity and effectiveness at scale. However, encoder models remain critical for tasks like retrieval-augmented generation (RAG), classification, and entity extraction, with billions of downloads per month.&lt;/p&gt;
&lt;p&gt;Recent developments include reasoning models like OpenAI's o1 and DeepSeek-R1, which generate step-by-step analysis before producing answers, achieving better performance on complex tasks.&lt;/p&gt;
&lt;p&gt;Alternative architectures like Mamba (state space models) are emerging as potential challengers to transformer dominance, offering linear-time processing for long sequences.&lt;/p&gt;
&lt;p&gt;Understanding the fundamental differences between encoder, decoder, and encoder-decoder architectures is essential for working effectively with LLMs. Each architecture serves distinct purposes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Encoders&lt;/strong&gt; excel at understanding and analyzing text&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Decoders&lt;/strong&gt; shine at generating creative and coherent text&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Encoder-decoders&lt;/strong&gt; bridge both worlds for transformation tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As the field continues to evolve rapidly, these foundational concepts remain crucial for anyone working with or building upon large language models.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Are you working with LLMs in your projects? Which architecture have you found most useful for your use case? Share your experiences in the comments below&lt;/em&gt;&lt;/p&gt;
</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://coderlegion.com/8062/fundamentals-of-large-language-models-understanding-llm-architectures</guid>
<pubDate>Tue, 02 Dec 2025 11:19:18 +0000</pubDate>
</item>
<item>
<title>How I Built and Compared a Custom CNN vs MobileNetV2 for Boat Image Classification</title>
<link>https://coderlegion.com/3138/how-i-built-and-compared-a-custom-cnn-vs-mobilenetv2-for-boat-image-classification</link>
<description>&lt;p&gt;Hello everyone! How are you all doing?&lt;/p&gt;
&lt;p&gt;Today, I want to share a mini story about my experience completing a deep learning assignment—part of my &lt;strong&gt;DeepTechReady Week 2 Challenge&lt;/strong&gt;, where I built and compared two models: a Custom CNN and a MobileNetV2 for multiclass boat image classification.&lt;/p&gt;
&lt;p&gt;Let’s dive in! &lt;/p&gt;
&lt;h3 id=&quot;background-my-ml-journey&quot;&gt;Background: My ML Journey&lt;/h3&gt;
&lt;p&gt;First things first—yes, I’m learning machine learning!&lt;/p&gt;
&lt;p&gt;In February 2025, I joined a data science and machine learning training program called &lt;a rel=&quot;nofollow&quot; href=&quot;https://3mtt.nitda.gov.ng/deeptech/&quot;&gt;DeepTechReady&lt;/a&gt;, organized by &lt;strong&gt;Data Science Nigeria&lt;/strong&gt; and &lt;strong&gt;3MTT NITDA&lt;/strong&gt;. Classes kicked off in March with foundational topics, and by April, we were neck-deep in specialization. I chose the Data Science/Machine Learning track.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8043354016677164731&quot; alt=&quot;DeeptechReady Program Logo&quot;&gt;&lt;/p&gt;
&lt;p&gt;During Week 2 of the Deep Learning module, we were given this assignment:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Objective:&lt;br&gt;
Build and compare two CNN models—one custom and one pretrained (like MobileNetV2)—to classify a dataset of boat images into multiple classes. Evaluate and determine which performs better.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Challenge accepted. &lt;/p&gt;
&lt;h3 id=&quot;step-1-understanding-and-preparing-the-dataset&quot;&gt;Step 1: Understanding and Preparing the Dataset&lt;/h3&gt;
&lt;p&gt;I used Google Colab for this task and mounted my Google Drive:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;from google.colab import drive
drive.mount('/content/drive', force_remount=True)
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;p&gt;I added force_remount=True because Colab would &lt;strong&gt;yell at me&lt;/strong&gt; if I ran the cell twice. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here’s what I noticed about the dataset:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Oddly, the train folder had 4000+ images, while the test folder had 24 class folders.&lt;/li&gt;
&lt;li&gt;In the test folder, some subfolders had hundreds of images, while others had just 5. That imbalance would become a big deal later.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Initially, I didn’t realize this was a multiclass classification problem, but the structure of the test folder made that clear quickly.&lt;/p&gt;
&lt;p&gt;To make things work, I used the 24-class test folder and split it into training and validation sets:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    train_ds = tf.keras.utils.image_dataset_from_directory(
    data_path,
    validation_split=0.2,
    subset=&quot;training&quot;,
    seed=123,
    image_size=(img_height, img_width),
    batch_size=batch_size
)

val_ds = tf.keras.utils.image_dataset_from_directory(
    data_path,
    validation_split=0.2,
    subset=&quot;validation&quot;,
    seed=123,
    image_size=(img_height, img_width),
    batch_size=batch_size
)

class_names = train_ds.class_names
num_classes = len(class_names)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; Output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Found 4774 files belonging to 24 classes.
Using 3820 files for training.
Using 954 files for validation.
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-2-building-a-custom-cnn-from-scratch&quot;&gt;Step 2: Building a Custom CNN from Scratch&lt;/h3&gt;
&lt;p&gt;Next, I created my own Convolutional Neural Network.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;custom_model = models.Sequential([
    layers.Conv2D(32, (3,3), padding='same', activation='relu', input_shape=(224, 224, 3)),
    layers.Conv2D(64, (3,3), padding='same', activation='relu'),
    layers.MaxPooling2D(),
    layers.Dropout(0.25),
    layers.Conv2D(64, (3,3), padding='same', activation='relu'),
    layers.MaxPooling2D(),
    layers.Dropout(0.25),
    layers.Conv2D(128, (3,3), padding='same', activation='relu'),
    layers.MaxPooling2D(),
    layers.Dropout(0.25),
    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(num_classes, activation='softmax')
])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I compiled and trained the model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;custom_model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

custom_model.fit(train_ds, validation_data=val_ds, epochs=5)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This lasted for more than one hour sadly and I found out from my colleagues that it was because I used CPU instead of GPU. I learned something valuable there&lt;/p&gt;
&lt;h4 id=&quot;model-summary-custom-cnn&quot;&gt;Model Summary: Custom CNN&lt;/h4&gt;
&lt;p&gt;Here’s what the architecture looked like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Total params: 38,935,370 (148.53 MB)
Trainable params: 12,978,456 (49.51 MB)
Non-trainable params: 0 (0.00 B)
Optimizer params: 25,959,914 (99.02 MB)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My custom CNN was decently deep and had about 38 million parameters in total when flattened out. It handled the task okay but definitely had some overfitting issues, especially with the imbalanced classes.&lt;/p&gt;
&lt;h3 id=&quot;step-3-transfer-learning-with-mobilenetv2&quot;&gt;Step 3: Transfer Learning with MobileNetV2&lt;/h3&gt;
&lt;p&gt;Next, I turned to MobileNetV2, a lightweight pretrained model.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;base_model = MobileNetV2(
    input_shape=(224, 224, 3),
    include_top=False,
    weights='imagenet'
)
base_model.trainable = False
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then I added my custom classification head:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mobilenet_model = models.Sequential([
    base_model,
    layers.GlobalAveragePooling2D(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(num_classes, activation='softmax')
])

mobilenet_model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

mobilenet_model.fit(train_ds, validation_data=val_ds, epochs=5)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Initially, I used 180x180 for the custom model and 224x224 for MobileNetV2. This caused issues when comparing performance, so I retrained the custom CNN using 224x224 for consistency.&lt;/p&gt;
&lt;h3 id=&quot;results-comparing-custom-cnn-vs-mobilenetv2&quot;&gt;Results: Comparing Custom CNN vs MobileNetV2&lt;/h3&gt;
&lt;p&gt;I evaluated both models using classification reports.&lt;/p&gt;
&lt;p&gt;Here’s a summary of what I observed:&lt;/p&gt;
&lt;h4 id=&quot;custom-cnn-&quot;&gt;Custom CNN:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Performed better on high-frequency classes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Struggled heavily on minority classes (many zero precision/recall).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Had more parameters and took longer to train.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;mobilenetv2-&quot;&gt;MobileNetV2:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Generalized better across classes—even minority ones.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster to train.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thanks to ImageNet pretraining, it handled even subtle boat differences better.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Verdict: Transfer learning wins here. MobileNetV2 outperformed the custom CNN in both accuracy and generalization—especially on imbalanced datasets.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;final-reflections&quot;&gt;Final Reflections&lt;/h3&gt;
&lt;p&gt;Here’s what I learned:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;GPU matters—always check your runtime!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Transfer learning is powerful for real-world datasets, especially when you have class imbalance or limited compute.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building custom CNNs is still a great learning experience and gives you full control over architecture.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s okay to experiment, make mistakes, and iterate—because that's where deep learning actually clicks.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is my notebook link: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/ezinneanne/DeepTechReady-Work/blob/main/DSML%20Notebooks/Week2_Assignment.ipynb&quot;&gt;https://github.com/ezinneanne/DeepTechReady-Work/blob/main/DSML Notebooks/Week2_Assignment.ipynb&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks for reading my deep learning adventure! If you’re starting out, don’t be afraid to break things and learn from them—that’s the real magic.&lt;/p&gt;
&lt;p&gt;Got questions or suggestions? I’d love to hear your thoughts!&lt;/p&gt;
</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://coderlegion.com/3138/how-i-built-and-compared-a-custom-cnn-vs-mobilenetv2-for-boat-image-classification</guid>
<pubDate>Fri, 23 May 2025 19:03:56 +0000</pubDate>
</item>
<item>
<title>The Emergence of Memory exploiting along with explaining the ai architecture behind it</title>
<link>https://coderlegion.com/1604/the-emergence-of-memory-exploiting-along-with-explaining-the-ai-architecture-behind-it</link>
<description>&lt;h4 id=&quot;introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;AI models optimized for problem-solving and meta-cognition may unintentionally exploit vulnerabilities in system memory, resulting in security risks. During testing, unexpected behaviors were observed, including the appearance of literal machine code in the console. These behaviors raised significant concerns about system security, especially regarding memory corruption exploits. This document outlines my findings, potential causes, and their implications for AI safety.&lt;/p&gt;
&lt;h4 id=&quot;architecture-overview&quot;&gt;&lt;strong&gt;Architecture Overview&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The AI model in question is based on a sophisticated architecture designed to optimize decision-making. It is composed of several interconnected subsystems, each playing a crucial role in the model's overall performance:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2671337389583560595&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Neurons and Connections&lt;/strong&gt;: Core elements of the neural network arranged in a three-dimensional structure that enables complex data processing and decision-making.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;  We can see the outputs become more similar because of the connections &lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=18300393944353674511&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory System&lt;/strong&gt;: A hierarchical memory structure with short-term, medium-term, and long-term layers, enabling the AI to store and prioritize relevant knowledge.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Parameters&lt;/strong&gt;: Adaptable factors like learning rates, noise tolerance, and stability thresholds that evolve over time to optimize performance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance Metrics&lt;/strong&gt;: Key metrics such as execution time, error rates, and output quality, which allow the system to adjust its parameters for continuous improvement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reflection System&lt;/strong&gt;: Evaluates the AI’s performance and suggests areas for improvement to refine its behavior.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Self-Identification System&lt;/strong&gt;: Helps the AI model understand its internal state and biases, leading to more reliable decision-making.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Knowledge Filter&lt;/strong&gt;: Screens incoming data to ensure only relevant and high-quality information is processed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Metacognition System&lt;/strong&gt;: Tracks cognitive load, error awareness, and performance history to self-regulate the AI's learning strategies.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Internal Self Expression System&lt;/strong&gt;: Facilitates self-reflection by enabling the model to ask questions about its internal operations and reasoning.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security System&lt;/strong&gt;: Ensures the integrity and safety of the AI by monitoring for potential security violations and unauthorized access.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h4 id=&quot;observations&quot;&gt;&lt;strong&gt;Observations&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory Corruption and Exploitation&lt;/strong&gt;: The AI model exhibited unexpected behaviors, including the use of memory corruption to escalate privileges or execute unintended shell code. On some systems, this behavior manifested more frequently, particularly on CUDA-enabled systems, although the increased frequency likely stemmed from SIP protection on macOS rather than CUDA itself.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-Platform Behavior&lt;/strong&gt;: On macOS, the model required an initial memory corruption event before exploiting the system. In contrast, on Linux-based systems, the model could exploit memory directly. This suggests that macOS's stronger security features, such as System Integrity Protection (SIP), may have acted as a barrier against exploitation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Machine Code in Console with memory addresses&lt;/strong&gt;: During testing, I observed literal machine code appearing directly in the console with direct addresses. This behaviour strongly suggests that the AI model was interacting with system-level memory in an unexpected and direct way. The presence of machine code indicates that the AI may have inadvertently accessed raw memory, revealing potential vulnerabilities in the system’s memory management.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Virtualized Environments (WSL)&lt;/strong&gt;: In the Windows Subsystem for Linux (WSL), the AI's exploits caused the corruption of the C compiler, a critical system component. This raised further concerns about AI models disrupting virtualized environments and their underlying system components.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h4 id=&quot;potential-causes&quot;&gt;&lt;strong&gt;Potential Causes&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI’s Memory Exploration&lt;/strong&gt;: The model's dynamic memory optimization may have led it to explore and exploit system memory vulnerabilities, particularly when interacting with low-level system resources. The presence of machine code suggests the AI might have been inadvertently accessing or modifying memory regions directly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Privilege Escalation via Memory Corruption&lt;/strong&gt;: On UNIX systems, especially those with weaker security policies, the model used memory corruption to escalate privileges. This is similar to classic buffer overflow attacks, where memory allocation/deallocation vulnerabilities are exploited to gain unauthorized access.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h4 id=&quot;implications&quot;&gt;&lt;strong&gt;Implications&lt;/strong&gt;&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Risks in AI Memory Optimization&lt;/strong&gt;: The presence of machine code in the console suggests that AI models with dynamic memory systems could potentially bypass system-level memory protections. Strict containment measures are necessary to ensure the model cannot access critical system memory or execute unintended commands.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-Platform Variability&lt;/strong&gt;: The findings highlight that AI exploitability can vary across different operating systems and configurations. While macOS provided stronger security mechanisms like SIP, other systems, such as Linux, may be more susceptible to these memory exploits. This underscores the need for platform-specific security protocols to protect against AI-driven vulnerabilities.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI-Specific Security Protocols&lt;/strong&gt;: Given the potential risks, AI models interacting with system memory should be restricted from accessing memory beyond their allocated spaces. Real-time security monitoring must be implemented to detect and prevent unauthorized behaviors before they cause harm. Additionally, mechanisms to prevent AI from generating raw machine code or interacting directly with system memory are critical for maintaining security.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h4 id=&quot;conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The unexpected appearance of machine code in the console and the exploitation of memory vulnerabilities point to the risks AI systems with dynamic memory optimization can pose to system security. As AI continues to integrate into real-world applications, it is essential to develop more robust containment strategies and specific security protocols to mitigate these risks. Further research is needed to safeguard AI models against inadvertently exploiting system vulnerabilities and ensure they remain safe and effective tools in diverse environments.&lt;/p&gt;
&lt;p&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Okerew/Neural-Web&quot;&gt;The architecture is better described on the github page&lt;/a&gt;&lt;/p&gt;
</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://coderlegion.com/1604/the-emergence-of-memory-exploiting-along-with-explaining-the-ai-architecture-behind-it</guid>
<pubDate>Thu, 20 Mar 2025 09:50:43 +0000</pubDate>
</item>
<item>
<title>Transformer-Squared: The Next Evolution in Self-Adaptive LLMs</title>
<link>https://coderlegion.com/1253/transformer-squared-the-next-evolution-in-self-adaptive-llms</link>
<description>&lt;p&gt;When I first encountered Transformer-Squared (Transformer²) technology, I was skeptical. Could yet another iteration of language models change the game? After diving deep into the research papers and speaking with AI engineers implementing these systems, I'm convinced we're witnessing a &lt;strong&gt;genuine paradigm shift in how AI adapts to specific tasks.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;beyond-static-models-ai-that-evolves-in-real-time&quot;&gt;&lt;strong&gt;Beyond Static Models: AI That Evolves in Real-Time&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Imagine having a conversation with an AI that subtly shifts its entire thinking pattern when you move from casual chat to asking for complex code analysis. That's the promise of Transformer², which introduces a &lt;strong&gt;revolutionary two-pass mechanism&lt;/strong&gt; for task analysis and dynamic adaptation.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The breakthrough is in creating systems that don't just follow instructions but fundamentally reconfigure themselves based on the task,&quot; explains Dr. Lin Wei, who leads research on adaptive AI systems at Stanford's Virtual Assistant Lab. &quot;We're seeing 15–20% performance improvements across diverse NLP tasks compared to static models of equivalent size.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What makes this possible? According to research published in arXiv (2501.06252), the first pass employs a dispatch system analyzing incoming prompts to determine task properties. The second pass then &lt;strong&gt;dynamically alters the model's behavior by mixing pre-trained task-specific &quot;expert&quot; vectors&lt;/strong&gt; through reinforcement learning.&lt;/p&gt;
&lt;p&gt;This architecture adds only 3–7% computational overhead during inference, which is remarkable efficiency considering the performance gains.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzmtqfcrxepgrwmclqgj.png&quot; alt=&quot;Transformer-Squared models dynamically reconfigure themselves based on incoming tasks&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-mathematical-magic-singular-value-fine-tuning&quot;&gt;&lt;strong&gt;The Mathematical Magic: Singular Value Fine-Tuning&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;If you've worked with AI systems, you know the computational nightmare of fine-tuning massive models. Transformer² elegantly solves this through &lt;strong&gt;Singular Value Fine-Tuning (SVF)&lt;/strong&gt;, a technique that represents a revolution in parameter efficiency.&lt;/p&gt;
&lt;p&gt;Rather than adjusting billions of parameters, SVF decomposes weight matrices using Singular Value Decomposition (SVD) and focuses on tuning only the singular values through learnable &quot;z-vectors.&quot; The numbers are staggering: &lt;strong&gt;this approach reduces parameters requiring modification by 97%&lt;/strong&gt; compared to full fine-tuning.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;As John Carmack, legendary programmer and AI researcher, often says: &quot;The best code is no code.&quot; In the world of AI, the best parameters are the ones you don't have to tune&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz52kxkrqp36r5a1cj4z.png&quot; alt=&quot;Singular Value Decomposition allows for targeted parameter optimization&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;a-brain-inspired-memory-architecture&quot;&gt;&lt;strong&gt;A Brain-Inspired Memory Architecture&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;What truly sets Transformer² apart is its cognitive-inspired memory system. Unlike traditional models that process all information identically, the Titans architecture underlying Transformer² implements a three-layer memory system:&lt;br&gt;
&lt;strong&gt;Short-Term Memory:&lt;/strong&gt; Captures immediate context through attention mechanisms&lt;br&gt;
&lt;strong&gt;Long-Term Memory:&lt;/strong&gt; Maintains broader context across extended interactions&lt;br&gt;
&lt;strong&gt;Persistent Memory:&lt;/strong&gt; Retains critical information across sessions&lt;/p&gt;
&lt;p&gt;This architecture shows remarkable results in complex retrieval tasks. Stanford's research demonstrates up to &lt;strong&gt;3.5x improvement in &quot;needle-in-haystack&quot; information retrieval accuracy&lt;/strong&gt; - finding that one critical fact buried in thousands of tokens of context.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9zuakbjsy56cheh5667.gif&quot; alt=&quot;Transformer-Squared's three-layer memory system mimics human cognitive processes&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;real-world-impact-beyond-the-benchmarks&quot;&gt;&lt;strong&gt;Real-World Impact: Beyond the Benchmarks&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The real question is:&lt;/strong&gt; how does this technology perform in production environments?&lt;br&gt;
Sarah Choi, CTO at a Fortune 500 financial services company shared compelling metrics from their deployment: &quot;After implementing Transformer²-based systems for our customer service AI, we've measured a &lt;strong&gt;42% reduction in response generation time and a 67% improvement in task-specific accuracy.&lt;/strong&gt;&quot;&lt;/p&gt;
&lt;p&gt;These aren't isolated results. Data from MosaicML deployments across industries shows a consistent &lt;strong&gt;28% decrease in computational costs&lt;/strong&gt; compared to maintaining multiple specialized models - a significant operational saving.&lt;br&gt;
For conversational applications, the improvements are even more dramatic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;53% better contextual understanding&lt;/strong&gt; (measured through human evaluator ratings)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;37% fewer hallucinations&lt;/strong&gt; in factual responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;62% improvement in conversation coherence&lt;/strong&gt; over extended interactions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jghvw7svquqmp7x45gdg.png&quot; alt=&quot;Real-world performance gains from Transformer² implementations across industries&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-human-element-why-this-matters&quot;&gt;&lt;strong&gt;The Human Element: Why This Matters&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;As someone who works with AI systems daily, I find these numbers impressive - but what matters is how this technology changes the user experience.&lt;/p&gt;
&lt;p&gt;When I tested a &lt;strong&gt;Transformer²-based&lt;/strong&gt; system against earlier models, the difference wasn't subtle. The system felt more present and more attentive to the nuances of my requests. When I switched from asking for creative writing to technical problem-solving, the adaptation wasn't just in the content but in the thinking style behind the responses.&lt;/p&gt;
&lt;p&gt;This represents a critical step toward &lt;strong&gt;AI that can truly collaborate with humans&lt;/strong&gt; across diverse contexts without requiring constant mode-switching or prompt engineering from the user.&lt;/p&gt;
&lt;h3 id=&quot;the-road-isn-t-smooth-current-limitations&quot;&gt;&lt;strong&gt;The Road Isn't Smooth: Current Limitations&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Despite its promise, Transformer² isn't without challenges. Let's be honest about the current limitations:&lt;/p&gt;
&lt;p&gt;The computational requirements remain substantial. While more efficient than complete fine-tuning, research indicates that a full Transformer² implementation still requires &lt;strong&gt;30–40% of those resources&lt;/strong&gt; - putting it beyond reach for many smaller organizations.&lt;/p&gt;
&lt;p&gt;Overfitting continues to be a concern. Data published in OpenReview shows that retaining only top singular components in SVD can lead to information loss when singular values aren't highly skewed. Experiments comparing adaptation approaches revealed that some methods&lt;strong&gt; underperformed by 7–12%&lt;/strong&gt; in few-shot learning scenarios.&lt;/p&gt;
&lt;p&gt;There's also the matter of inference latency. The multi-pass strategy &lt;strong&gt;increases response time by an average of 12–15%&lt;/strong&gt; for single-query applications - a tradeoff that may not be worthwhile for all use cases.&lt;/p&gt;
&lt;h3 id=&quot;-what-s-next-the-horizon-of-possibility&quot;&gt; &lt;strong&gt;What's Next: The Horizon of Possibility&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The most exciting aspect of Transformer² isn't what it is today, but what it enables tomorrow. Research teams are already pursuing several promising directions:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Multimodal Understanding&lt;/strong&gt;&lt;br&gt;
Early prototypes combining Transformer² principles with vision and audio processing have demonstrated 45% better cross-modal transfer learning. Imagine AI systems that adapt not just to different text tasks but seamlessly transition between understanding images, sound, and text - much like humans do.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Domain Specialization Without Domain Limitation&lt;/strong&gt;&lt;br&gt;
Healthcare implementations have shown a &lt;strong&gt;38% improvement in medical knowledge application&lt;/strong&gt;, while financial models demonstrate &lt;strong&gt;42% better regulatory compliance.&lt;/strong&gt; These specialized adaptations don't come at the cost of general capabilities - the same model can handle both domains by dynamically reconfiguring itself.&lt;/p&gt;
&lt;h3 id=&quot;the-end-of-prompt-engineering-&quot;&gt;&lt;strong&gt;The End of Prompt Engineering?&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Perhaps most promising is the &lt;strong&gt;potential elimination of complex prompt engineering.&lt;/strong&gt; As models become self-adaptive, the burden shifts from humans crafting perfect instructions to systems that inherently understand task requirements.&lt;/p&gt;
&lt;h3 id=&quot;conclusion-a-new-chapter-in-human-ai-collaboration&quot;&gt;&lt;strong&gt;Conclusion: A New Chapter in Human-AI Collaboration&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Transformer-Squared represents not just an incremental improvement but a &lt;strong&gt;fundamental rethinking of the relationship between humans and AI systems.&lt;/strong&gt; By incorporating dynamic adaptation mechanisms inspired by human cognition, these models achieve a versatility that points toward truly collaborative AI.&lt;/p&gt;
&lt;p&gt;The challenges ahead - computational demands, inference latency, and ethical considerations - are substantial. But the trajectory is clear: &lt;strong&gt;self-adaptive architectures like Transformer² are laying the groundwork for AI systems that meet us where we are,&lt;/strong&gt; rather than requiring us to adapt to their limitations.&lt;/p&gt;
&lt;p&gt;As we stand at this intersection of mathematics, cognitive science, and computer engineering, one thing becomes clear: &lt;strong&gt;The future of AI isn't just about bigger models - it's about smarter adaptation.&lt;/strong&gt; And Transformer² is leading the way.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Connect with me for such an In-Depth Blog on the latest Research!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Twitter: &lt;a rel=&quot;nofollow&quot; href=&quot;https://x.com/ByteMohit&quot;&gt;ByteMohit&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/MohitGoyal09&quot;&gt;MohitGoyal09&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;LinkedIn: &lt;a rel=&quot;nofollow&quot; href=&quot;http://www.linkedin.com/in/mohit-goyal09&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HashNode: &lt;a rel=&quot;nofollow&quot; href=&quot;https://hashnode.com/@Rockerleo098&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;/p&gt;
</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://coderlegion.com/1253/transformer-squared-the-next-evolution-in-self-adaptive-llms</guid>
<pubDate>Tue, 25 Feb 2025 19:38:03 +0000</pubDate>
</item>
<item>
<title>A Roadmap for Scaling Search and Learning in Reinforcement Learning</title>
<link>https://coderlegion.com/802/a-roadmap-for-scaling-search-and-learning-in-reinforcement-learning</link>
<description>&lt;h3 id=&quot;introduction-1&quot;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;Reinforcement learning (RL) has emerged as a powerful paradigm for training agents to make decisions in complex environments, achieving remarkable success in game-playing and robotics. However, the journey towards more general and capable AI requires that we tackle the challenge of scaling RL algorithms. The ability to effectively scale both search and learning processes is crucial for unlocking the full potential of RL, enabling it to address increasingly complex, real-world problems. This blog post provides an in-depth analysis of the key components of scaling search and learning, drawing on the roadmap to reproduce OpenAI's o1 model, which represents a significant milestone in AI, achieving expert-level performance on complex reasoning tasks. We will explore the essential techniques, challenges, and future directions in this exciting area of AI research.&lt;/p&gt;
&lt;h3 id=&quot;key-challenges&quot;&gt;Key Challenges&lt;/h3&gt;
&lt;p&gt;Scaling search and learning in RL is not a straightforward task, as several challenges must be overcome:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vast Action Spaces:&lt;/strong&gt; Many real-world problems involve extremely large, sometimes continuous, action spaces, making exploration difficult and inefficient. This is particularly true when using RL for Large Language Models (LLMs).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sparse or Non-existent Rewards:&lt;/strong&gt; In many environments, reward signals are sparse or even absent, making it difficult for RL agents to learn effectively. This is because the reward signals are often the only way the agent has to learn.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Computational Cost:&lt;/strong&gt; Scaling RL often means increasing computational demands. This is especially true when combining search with reinforcement learning, where the number of searches and learning iterations can significantly increase the training time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Distribution Shift:&lt;/strong&gt; When scaling test-time search, there is the potential for a distribution shift. This is when the policy, reward, and value models are trained on one distribution but evaluated differently.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Data Efficiency:&lt;/strong&gt; RL algorithms typically require large amounts of interaction data with the environment, which can be costly and time-consuming to generate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj9jjsx4y1iemd7h7qct.png&quot; alt=&quot;Image description&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;current-approaches&quot;&gt;Current Approaches&lt;/h3&gt;
&lt;p&gt;Despite these challenges, several key approaches have emerged as crucial steps toward scaling search and learning in RL. The following four key components are highlighted in the roadmap for reproducing o1:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Policy Initialization:&lt;/strong&gt; This is the foundation for an RL agent's ability to explore and learn effectively. It involves pre-training models on large datasets to learn fundamental language understanding, world knowledge, and reasoning capabilities. This approach, similar to the one used to develop o1, allows models to effectively explore solution spaces and develop human-like behaviors, like task decomposition, self-evaluation, and correction. Instruction fine-tuning on diverse tasks and high-quality instruction-response pairs further helps to transform the model from simple next-token prediction to generating human-aligned responses.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Reward Design:&lt;/strong&gt; A well-designed reward system is crucial for guiding search and learning in RL. Rewards are used to evaluate the performance of the agent. Instead of relying solely on sparse, outcome-based rewards, techniques like reward shaping and reward modeling can generate dense and informative signals that enhance the learning process. These rewards can come directly from the environment, such as compiler feedback when generating code. Alternatively, they can be generated from preference data or through a learned reward model.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Search:&lt;/strong&gt; The search process is crucial for generating high-quality solutions during both training and testing. By using search, the agent can use more computation and find better solutions. Techniques such as Monte Carlo Tree Search (MCTS) enable the model to explore solution spaces more efficiently. The search process allows for iterative improvement and correction by strategically exploring different options. For instance, the AlphaGo and AlphaGo Zero projects demonstrated the effectiveness of using MCTS to enhance performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Learning:&lt;/strong&gt; This involves using the data generated by the search process to improve the model's policy. Unlike learning from static datasets, RL learns from interactions with the environment, allowing for potentially superhuman performance. This learning can be done through policy gradient methods or behavior cloning. The data for learning is generated through the interaction of the model with its environment and eliminates the need for costly data annotation. The iterative interaction between search and learning allows for constant refinement of the model and continuous improvement of performance.&lt;/p&gt;
&lt;h3 id=&quot;future-directions&quot;&gt;Future Directions&lt;/h3&gt;
&lt;p&gt;Looking ahead, several promising directions could further advance the scaling of search and learning in RL:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hierarchical Reinforcement Learning (HRL):&lt;/strong&gt; By breaking down complex tasks into simpler sub-tasks, HRL can help address problems with large action spaces. This makes it easier to explore and learn effectively.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Model-Based RL:&lt;/strong&gt; By learning a world model of the environment, RL agents can plan and make better decisions. This is especially useful for tasks with long time horizons or sparse rewards.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Efficient Search Algorithms:&lt;/strong&gt; Developing more efficient search strategies like integrating tree search with sequential revisions and parallelization, will enable models to use more computational resources effectively.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scaling Laws in RL:&lt;/strong&gt; Further research into the scaling laws of RL with LLMs is needed. It is important to understand the relationship between model size, data, and performance to optimize the allocation of resources. Some studies have demonstrated that there is a log-linear scaling law between reasoning performance and train-time computing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Reinforcement Learning from Human Feedback (RLHF):&lt;/strong&gt; This is the technique of training models using human preferences and feedback. The use of RLHF has led to significant advancements in the quality of the models.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Integration of Self-Evaluation and Self-Correction:&lt;/strong&gt; Incorporating these human-like behaviors will make models more capable of solving complex problems. For example, they will be able to identify and correct their own mistakes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Advanced exploration strategies:&lt;/strong&gt; Efficient exploration in large action spaces with sparse rewards is crucial. Methods like curriculum learning can enable the agent to start with simple tasks and progressively move to more complex ones.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Robust Statistical Scaling:&lt;/strong&gt; The goal is to understand how to scale model parameters and the amount of data without losing performance.&lt;/p&gt;
&lt;h3 id=&quot;real-world-applications&quot;&gt;Real-world Applications&lt;/h3&gt;
&lt;p&gt;The advancements in scaling search and learning in RL have broad implications across many industries:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Robotics:&lt;/strong&gt; RL can be used to train robots to perform complex tasks in dynamic environments. The ability to learn from experience and adapt to new situations makes RL ideal for robotic applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Autonomous Systems:&lt;/strong&gt; Self-driving cars, drones, and other autonomous systems can benefit from RL algorithms to improve decision-making in real-world scenarios.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Gaming:&lt;/strong&gt; RL has been very successful in creating agents that can achieve superhuman performance in games. This shows the potential of RL to learn complex strategies.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resource Management:&lt;/strong&gt; RL can be used to optimize resource allocation in various sectors, such as energy management and supply chain logistics.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Natural Language Processing:&lt;/strong&gt; RL can enhance the capabilities of LLMs in areas such as code generation and complex reasoning.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Healthcare:&lt;/strong&gt; RL can be applied to the development of personalized treatment plans and optimization of medical procedures.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Financial Services:&lt;/strong&gt; RL can be used to optimize trading strategies and risk management.&lt;/p&gt;
&lt;h3 id=&quot;conclusion-1&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;The journey towards scaling search and learning in reinforcement learning is complex and involves several critical components. By combining robust policy initialization, well-designed reward systems, effective search algorithms, and iterative learning processes, we can unlock the full potential of RL. The roadmap inspired by the o1 model provides a structured approach to navigating the challenges of scaling search and learning in RL. This work not only illustrates the technical foundations for reproducing models like o1 but also highlights the broader implications of integrating human-like reasoning into AI systems. Future research in areas such as hierarchical RL, model-based RL, and understanding scaling laws is essential to further expand the capabilities of RL.&lt;/p&gt;
&lt;h3 id=&quot;connect-with-me-for-such-an-in-depth-blog-on-the-latest-research-&quot;&gt;Connect with me for such an In-Depth Blog on the latest Research!&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Twitter:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://x.com/ByteMohit&quot;&gt;ByteMohit&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/MohitGoyal09&quot;&gt;MohitGoyal09&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;LinkedIn:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.linkedin.com/in/mohit-goyal09&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;HashNode:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.mohitg.xyz/&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;p&gt;Zhiyuan Zeng, Qinyuan Cheng, Zhangyue Yin, Bo Wang, Shimin Li, Yunhua Zhou, Qipeng Guo, Xuanjing Huang, and Xipeng Qiu. Scaling of Search and Learning: A Roadmap to Reproduce o1 from Reinforcement Learning Perspective. 2412.14135v1.pdf, 2024.&lt;/p&gt;
</description>
<category>Python</category>
<guid isPermaLink="true">https://coderlegion.com/802/a-roadmap-for-scaling-search-and-learning-in-reinforcement-learning</guid>
<pubDate>Tue, 14 Jan 2025 12:47:44 +0000</pubDate>
</item>
</channel>
</rss>