<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Taha Hussein Two on Medium]]></title>
        <description><![CDATA[Stories by Taha Hussein Two on Medium]]></description>
        <link>https://medium.com/@taha.hussein.two?source=rss-4041ca87d01d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rpkYiUfid-Oyac93Ckwhrg.jpeg</url>
            <title>Stories by Taha Hussein Two on Medium</title>
            <link>https://medium.com/@taha.hussein.two?source=rss-4041ca87d01d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:48:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taha.hussein.two/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fine-Tuning, LoRA, QLoRA, and KD-LoRA: A Beginner-Friendly Guide to AI Model Customization]]></title>
            <link>https://medium.com/@taha.hussein.two/fine-tuning-lora-qlora-and-kd-lora-a-beginner-friendly-guide-to-ai-model-customization-432efaff88cf?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/432efaff88cf</guid>
            <category><![CDATA[fine-tuning]]></category>
            <category><![CDATA[kd-lora]]></category>
            <category><![CDATA[lora]]></category>
            <category><![CDATA[qlora-fine-tuning]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Tue, 20 Oct 2026 09:08:15 GMT</pubDate>
            <atom:updated>2026-10-20T09:08:15.348Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBPiNnL8Jpi28zj0wMS5OA.jpeg" /></figure><p><strong>How do we turn a general-purpose AI model into a model that performs better on a specific task?</strong></p><p>Large language models (LLMs) can answer questions, summarize documents, generate code, and understand natural language. But what if you need a model that follows a particular writing style, understands specialized terminology, or performs consistently on a specific task?</p><p>Training a model from scratch is usually expensive and requires substantial computing resources. Fortunately, there are techniques that allow us to adapt existing models more efficiently.</p><p>In this article, we will explore four important concepts: <strong>Fine-Tuning, LoRA, QLoRA, and KD-LoRA</strong>.</p><h3>1. What Is Fine-Tuning?</h3><p>Most modern language models are pretrained on large datasets. During pretraining, they learn patterns in language, information representations, and general-purpose capabilities.</p><p>However, a pretrained model may not perform well enough on every specialized task.</p><p>Fine-tuning continues the training process using a more targeted dataset.</p><p>For example, imagine you want a model to answer customer support questions in a consistent format. You could prepare examples of customer questions and high-quality responses, then fine-tune a suitable pretrained model on those examples.</p><p>The goal is to adapt the model’s behavior to the task.</p><p>There are different approaches to fine-tuning. Full fine-tuning updates the model’s trainable base parameters, while parameter-efficient methods update a much smaller set of additional parameters.</p><p>That brings us to LoRA.</p><h3>2. What Is LoRA?</h3><p>LoRA stands for <strong>Low-Rank Adaptation</strong>.</p><p>Instead of updating all the original model weights, LoRA introduces small trainable components into selected parts of the model. The original weights are typically frozen while these additional parameters are trained.</p><p>Why is this useful?</p><ul><li>Fewer parameters need to be trained.</li><li>Training can require less memory and computational work.</li><li>Adaptations can be stored in relatively small adapter files.</li><li>Multiple task-specific adapters can be used with a compatible base model.</li></ul><p>Think of a pretrained model as a powerful foundation. LoRA lets you adapt that foundation for a particular task without having to retrain every parameter.</p><p>LoRA does not eliminate the need for suitable data, a compatible model, or proper evaluation. Its efficiency depends on the model, configuration, task, and training setup.</p><h3>3. What Is QLoRA?</h3><p>QLoRA combines <strong>quantization</strong> with LoRA-based fine-tuning.</p><p>Quantization represents model weights using lower-precision numerical formats. In common QLoRA setups, the frozen base model is loaded in 4-bit form, while LoRA adapters are trained.</p><p>This can substantially reduce the memory required to fine-tune a large model.</p><p>QLoRA is particularly useful when working with limited GPU memory. However, it still requires sufficient memory for activations, gradients, optimizer states, and other training components.</p><p>The key idea is simple:</p><p><strong>LoRA reduces the number of trainable parameters, while QLoRA also reduces the memory footprint of the frozen base model.</strong></p><p>This makes some fine-tuning workflows possible on hardware that would struggle with conventional full fine-tuning.</p><h3>4. What About KD-LoRA?</h3><p>Knowledge distillation is a technique in which a student model learns from a teacher model. The teacher can provide predictions, probability distributions, or other learning signals that help guide the student.</p><p>LoRA, meanwhile, is a parameter-efficient adaptation technique.</p><p>The term <strong>KD-LoRA</strong> may refer to approaches that combine knowledge distillation with LoRA, but its exact meaning depends on the specific paper or implementation.</p><p>Conceptually, such an approach can combine two ideas:</p><ul><li>Knowledge distillation helps transfer useful behavior or knowledge from a teacher to a student.</li><li>LoRA can make adapting a model more parameter-efficient.</li></ul><p>These are related but distinct ideas. Knowledge distillation does not automatically require LoRA, and LoRA does not automatically involve a teacher model.</p><p>When studying a particular KD-LoRA method, check its original paper or implementation to understand exactly how the two techniques are combined.</p><h3>5. Fine-Tuning vs. LoRA vs. QLoRA</h3><p>Here is a quick comparison.</p><p>TechniqueMain ideaPotential advantageFull Fine-TuningUpdate the base model’s trainable weightsBroad adaptation flexibilityLoRATrain small adapter parametersFewer trainable parametersQLoRAQuantize the base model and train LoRA adaptersLower base-model memory usageKD with LoRACombine teacher–student learning with LoRA-based adaptationPotentially efficient knowledge transfer</p><p>These approaches are not always direct alternatives. Fine-tuning describes the broader adaptation process, LoRA and QLoRA are parameter-efficient training approaches, and knowledge distillation describes a way to transfer knowledge.</p><h3>6. Which Technique Should You Learn First?</h3><p>If you are starting with language-model customization, a sensible learning path is:</p><ol><li>Understand pretrained models and supervised fine-tuning.</li><li>Learn LoRA and how adapters work.</li><li>Explore QLoRA and quantization.</li><li>Study knowledge distillation and specific methods that combine it with LoRA.</li></ol><p>Once you understand these foundations, you can start experimenting with real datasets and evaluate whether your adapted model actually improves on your target task.</p><h3>Final Thoughts</h3><p>AI model customization is not simply about making a model bigger. It is about choosing an appropriate training strategy for a specific goal, dataset, and hardware budget.</p><p>Fine-tuning gives us the broader framework. LoRA helps reduce the number of trainable parameters. QLoRA reduces memory requirements further, while knowledge distillation provides another way to transfer capabilities between models.</p><p>Understanding the differences helps you make better decisions when building AI applications.</p><h3>Watch the Video</h3><p>I also explain these concepts in Arabic in this video:</p><p><strong>Fine-Tuning, LoRA, QLoRA, and KD-LoRA</strong></p><p>youtube: <a href="https://www.youtube.com/watch?v=7lZgG9dWBA0">https://www.youtube.com/watch?v=7lZgG9dWBA0</a></p><p>LinkedIn: <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">https://www.linkedin.com/in/taha-hussein-b0a583425/</a></p><p>Github: <a href="https://github.com/Taha2hussein">https://github.com/Taha2hussein</a></p><p>If you are learning AI model customization, which topic would you like to explore next: LoRA implementation, QLoRA training, or knowledge distillation?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432efaff88cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG Evaluation Explained: How to Know If Your AI Application Is Actually Good]]></title>
            <link>https://medium.com/@taha.hussein.two/rag-evaluation-explained-how-to-know-if-your-ai-application-is-actually-good-1a43dec48f86?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a43dec48f86</guid>
            <category><![CDATA[rag-evaluation-explained]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 09:52:24 GMT</pubDate>
            <atom:updated>2026-10-13T09:52:24.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GgY_zq83rpXdFH-ZxEwrFQ.png" /></figure><p>Building a RAG (Retrieval-Augmented Generation) application is relatively straightforward.</p><p>You load documents, generate embeddings, retrieve relevant chunks, and pass them to an LLM.</p><p>But here is the important question:</p><p><strong>How do you know whether your RAG system is actually producing reliable answers?</strong></p><p>Testing a few questions manually is not enough. A system may perform well on simple queries while failing on ambiguous questions, missing information, or complex multi-document queries.</p><p>This is where RAG evaluation becomes essential.</p><h3>1. RAG Evaluation Has Two Major Parts</h3><p>A RAG pipeline combines retrieval and generation. Each stage can fail independently.</p><h3>Retrieval Evaluation</h3><p>Retrieval evaluation measures whether the system finds the right information.</p><p>Important metrics include:</p><ul><li><strong>Recall@K:</strong> Does the retrieved top-K contain the relevant documents?</li><li><strong>Precision@K:</strong> How many retrieved documents are actually relevant?</li><li><strong>MRR (Mean Reciprocal Rank):</strong> How highly ranked is the first relevant result?</li><li><strong>NDCG:</strong> Does the ranking place the most relevant documents near the top?</li></ul><p>For example, if the correct document is never retrieved, even a powerful LLM may generate an incorrect answer.</p><h3>Generation Evaluation</h3><p>Generation evaluation measures the quality of the final answer.</p><p>Key dimensions include:</p><ul><li><strong>Faithfulness:</strong> Are the answer’s claims supported by the retrieved context?</li><li><strong>Answer Relevance:</strong> Does the answer address the user’s question?</li><li><strong>Correctness:</strong> Does the answer match verified ground truth?</li><li><strong>Context Relevance:</strong> Does the retrieved context contain useful information for answering the question?</li></ul><p>These dimensions are related, but they are not interchangeable.</p><p>An answer can be relevant to a question while containing unsupported claims.</p><h3>2. Why Evaluating Only the Final Answer Is a Mistake</h3><p>Imagine a chatbot answering questions about company policies.</p><p>A user asks:</p><p>“What is the refund period?”</p><p>The correct policy says 30 days, but the retriever returns an outdated document stating 14 days.</p><p>The LLM confidently responds with 14 days.</p><p>Where did the failure happen?</p><p>The generation model may have followed the supplied context correctly, but the retrieval system provided outdated information.</p><p>Without evaluating retrieval independently, it is easy to spend time changing prompts when the real problem is the data or retrieval pipeline.</p><h3>3. Build an Evaluation Dataset</h3><p>Before optimizing your system, create a dataset of representative questions.</p><p>Each test case can contain:</p><ul><li>A question</li><li>Expected answer</li><li>Relevant document IDs</li><li>Retrieved contexts</li><li>Generated answer</li></ul><p>Include straightforward questions, ambiguous questions, questions requiring multiple documents, and questions that cannot be answered using your knowledge base.</p><p>The last category is particularly important because reliable systems must recognize when evidence is insufficient.</p><h3>4. Introduce Automated Evaluation</h3><p>You can begin with Python scripts for retrieval metrics and deterministic checks.</p><p>For semantic evaluation, frameworks such as RAGAS can help assess dimensions such as faithfulness and answer relevance.</p><p>However, automated scores should not be treated as absolute truth. LLM-based evaluators can make mistakes, so validate their judgments against human-reviewed examples.</p><h3>5. Evaluate the Entire System</h3><p>A production-oriented evaluation strategy should consider more than answer quality.</p><p>Track:</p><ul><li>Retrieval quality</li><li>Answer correctness and faithfulness</li><li>Latency</li><li>Token consumption and cost</li><li>Error rates</li><li>Performance on questions with missing information</li></ul><p>A reliable RAG application is not simply one that generates convincing answers. It is one whose behavior can be measured, tested, and improved.</p><h3>Final Thoughts</h3><p>RAG evaluation helps you identify whether a failure comes from retrieval, context quality, generation, or the underlying data.</p><p>My recommended starting point is simple:</p><ol><li>Create a representative evaluation dataset.</li><li>Measure retrieval quality independently.</li><li>Evaluate generated answers against verified references.</li><li>Investigate failures instead of relying on a single overall score.</li><li>Repeat the evaluation whenever the system changes</li></ol><p><strong>The real goal is not to make an AI application look intelligent. It is to make its reliability measurable.</strong></p><p>What evaluation metrics do you use in your RAG projects?</p><p><strong>Connect with me</strong></p><ul><li>YouTube: <a href="https://www.youtube.com/@Tahahussein-Ai">YouTube Channel</a></li><li>LinkedIn: <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">LinkedIn Profile</a></li><li>GitHub: <a href="https://github.com/Taha2hussein">https://github.com/Taha2hussein</a></li></ul><p>#GenerativeAI #RAG #LLMEvaluation #ArtificialIntelligence #Python</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a43dec48f86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built TokenSaver to Reduce Unnecessary AI Image Data]]></title>
            <link>https://medium.com/@taha.hussein.two/i-built-tokensaver-to-reduce-unnecessary-ai-image-data-a7516fe5e35e?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7516fe5e35e</guid>
            <category><![CDATA[saver-token]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Wed, 07 Oct 2026 22:08:32 GMT</pubDate>
            <atom:updated>2026-10-07T22:08:32.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZA0HwGsXhcOWaMRASdhUUg.jpeg" /></figure><p>If you use ChatGPT, Claude, or other AI tools regularly, you probably upload screenshots without thinking much about their size.</p><p>A screenshot might be several thousand pixels wide, even when the actual information you need from it is much smaller.</p><p>That made me wonder:</p><p><strong>How much of that image is actually necessary for the AI to understand what I’m asking?</strong></p><p>So I built <strong>TokenSaver</strong>, a Firefox extension that optimizes images before you send them to AI tools.</p><h3>What is TokenSaver?</h3><p><strong>TokenSaver is a free Firefox extension that optimizes screenshots and images before they are uploaded to AI tools.</strong></p><p>It can work with images you:</p><ul><li>Select from your computer</li><li>Drag and drop</li><li>Paste directly from your clipboard</li></ul><p>The extension analyzes the image and reduces unnecessary dimensions while keeping the useful content.</p><p>It also shows an estimated token count before and after optimization.</p><h3>Try TokenSaver</h3><p><a href="https://addons.mozilla.org/en-US/firefox/addon/tokensaver-image-optimizer/"><strong>TokenSaver — Image Optimizer for Firefox</strong></a></p><h3>Why did I build it?</h3><p>I spend a lot of time working with AI coding tools.</p><p>Screenshots are useful for things like:</p><ul><li>Debugging UI problems</li><li>Sharing error messages</li><li>Explaining code</li><li>Sending screenshots from IDEs</li><li>Analyzing dashboards</li><li>Asking AI to read text from an image</li></ul><p>But screenshots can also contain a lot of pixels that don’t add useful information.</p><p>For example, you might take a screenshot of an entire 4K monitor when the AI only needs to understand a small error message in the middle.</p><p>The idea behind TokenSaver is simple:</p><p><strong>Don’t send more image data than the AI actually needs.</strong></p><h3>How does it work?</h3><p>TokenSaver processes the image locally in the browser.</p><p>Depending on the target AI platform and the selected optimization mode, it can:</p><ul><li>Crop unnecessary margins</li><li>Resize oversized images</li><li>Optimize the image dimensions</li><li>Estimate the image token usage</li><li>Show the difference before and after optimization</li></ul><p>There are different optimization modes depending on whether you want to prioritize image quality or saving.</p><p>The important part is that the optimization happens before the image is uploaded.</p><h3>Privacy was important to me</h3><p>Screenshots aren’t always harmless.</p><p>They can contain:</p><ul><li>Source code</li><li>Customer information</li><li>Internal dashboards</li><li>Error logs</li><li>Personal information</li><li>Private conversations</li></ul><p>That’s why I didn’t want TokenSaver to require a server just to process an image.</p><p>The extension processes images locally in the browser.</p><p><strong>Your image doesn’t need to be uploaded to a TokenSaver server.</strong></p><p>There is also no tracking built into the extension.</p><h3>What I learned building it</h3><p>The interesting part wasn’t simply resizing an image.</p><p>The real challenge was understanding how AI platforms treat image inputs.</p><p>Different platforms can use different approaches when processing images, so simply saying:</p><blockquote><em>“Resize everything to 50%”</em></blockquote><p>isn’t a very useful strategy.</p><p>TokenSaver instead tries to optimize around the requirements of the target platform.</p><p>That makes the problem much more interesting than a normal image compressor.</p><h3>What’s next?</h3><p>TokenSaver is currently Firefox-only.</p><p>I’d like to eventually support more browsers and explore additional ways of reducing unnecessary input when working with AI.</p><p>For now, I wanted to keep the project simple:</p><p><strong>A small tool that solves a problem I personally experienced.</strong></p><p>If you regularly send screenshots to AI tools, I’d love for you to try it.</p><h3>Get TokenSaver</h3><p><a href="https://addons.mozilla.org/en-US/firefox/addon/tokensaver-image-optimizer/"><strong>Install TokenSaver for Firefox</strong></a></p><p>If you try it, I’d especially like to hear where the optimization works well and where it doesn’t.</p><h3>About me</h3><p>I’m <strong>Taha Hussein</strong>, an engineer working across iOS development and AI.</p><p><strong>LinkedIn:</strong> <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">https://www.linkedin.com/in/taha-hussein-b0a583425/</a></p><p><strong>YouTube:</strong> <a href="https://www.youtube.com/@Tahahussein-Ai">https://www.youtube.com/@Tahahussein-Ai</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7516fe5e35e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embeddings, Cosine Similarity, and Semantic Search: Understanding How AI Searches by Meaning]]></title>
            <link>https://medium.com/@taha.hussein.two/embeddings-cosine-similarity-and-semantic-search-understanding-how-ai-searches-by-meaning-8a4df88b8f6d?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a4df88b8f6d</guid>
            <category><![CDATA[semantic-search]]></category>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[cosine-similarity]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Mon, 21 Sep 2026 08:53:26 GMT</pubDate>
            <atom:updated>2026-09-21T08:53:26.250Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*vU2MIKyt9NO4cSbZJZUPQw.jpeg" /></figure><p>When we search for something, we usually expect the search engine to find pages containing the same words we typed.</p><p>But what if we could search by <strong>meaning</strong>, even when the exact words are completely different?</p><p>For example, imagine searching for:</p><blockquote><em>“I want to learn coding”</em></blockquote><p>and finding a document that says:</p><blockquote><em>“Python is a programming language.”</em></blockquote><p>There is no exact match between the two sentences, but their meanings are related.</p><p>This is where <strong>Embeddings, Cosine Similarity, and Semantic Search</strong> become important.</p><h3>1. What is an Embedding?</h3><p>An embedding is simply a way of converting text into numbers.</p><p>For example:</p><pre>&quot;I love programming&quot;</pre><p>can be converted into a numerical representation such as:</p><pre>[0.021, -0.143, 0.087, 0.312, ...]</pre><p>The actual embedding contains many numbers. In our example, the model we will use produces 384 numbers for each sentence.</p><p>The important idea is:</p><pre>Text<br> ↓<br>Embedding Model<br> ↓<br>Numbers</pre><p>Why do we need numbers?</p><p>Because computers are very good at comparing numbers.</p><p>Once two sentences have been converted into embeddings, we can compare their representations and estimate how similar their meanings are.</p><h3>2. Let’s Create Our First Embeddings</h3><p>We can use the sentence-transformers library.</p><p>Install it with:</p><pre>pip install sentence-transformers scikit-learn</pre><p>Then:</p><pre>from sentence_transformers import SentenceTransformer</pre><pre>model = SentenceTransformer(&quot;all-MiniLM-L6-v2&quot;)</pre><pre>sentences = [<br>    &quot;I love programming&quot;,<br>    &quot;I enjoy coding&quot;,<br>    &quot;The weather is very hot&quot;<br>]</pre><pre>embeddings = model.encode(sentences)</pre><pre>print(embeddings.shape)</pre><p>You should get something similar to:</p><pre>(3, 384)</pre><p>This means:</p><ul><li>We have 3 sentences.</li><li>Each sentence was converted into 384 numbers.</li></ul><p>So:</p><pre>&quot;I love programming&quot;</pre><p>became a vector of numbers.</p><p>The same happened with the other two sentences.</p><h3>3. But How Do We Compare Them?</h3><p>Now we have three embeddings.</p><p>We need a way to answer:</p><blockquote><em>How similar are these two sentences?</em></blockquote><p>One common method is <strong>Cosine Similarity</strong>.</p><p>Don’t worry about the mathematical formula for now.</p><p>Think of Cosine Similarity simply as:</p><blockquote><em>A number that tells us how similar two pieces of text are based on their embeddings.</em></blockquote><p>Let’s calculate it.</p><pre>from sklearn.metrics.pairwise import cosine_similarity</pre><pre>similarity = cosine_similarity(embeddings)</pre><pre>print(similarity)</pre><p>You may get something like:</p><pre>[<br> [1.00, 0.63, 0.12],<br> [0.63, 1.00, 0.22],<br> [0.12, 0.22, 1.00]<br>]</pre><p>Let’s understand it.</p><p>Our sentences are:</p><pre>0 → I love programming<br>1 → I enjoy coding<br>2 → The weather is very hot</pre><p>The value:</p><pre>0.63</pre><p>means that:</p><pre>&quot;I love programming&quot;</pre><p>and:</p><pre>&quot;I enjoy coding&quot;</pre><p>are relatively similar in meaning.</p><p>While:</p><pre>0.12</pre><p>shows that:</p><pre>&quot;I love programming&quot;</pre><p>and:</p><pre>&quot;The weather is very hot&quot;</pre><p>are much less related.</p><p>The exact numbers can vary depending on the embedding model.</p><h3>4. Why Is This Interesting?</h3><p>Notice something important.</p><p>The first sentence contains:</p><pre>programming</pre><p>while the second contains:</p><pre>coding</pre><p>They don’t use exactly the same word.</p><p>Yet the embedding model can recognize that the concepts are related.</p><p>This is the main difference between traditional keyword search and semantic search.</p><h3>5. What Is Semantic Search?</h3><p>Semantic Search means searching based on <strong>meaning</strong>, rather than simply looking for the exact words.</p><p>Imagine we have these documents:</p><pre>Document 1:<br>Python is a programming language.</pre><pre>Document 2:<br>Machine learning is a branch of artificial intelligence.</pre><pre>Document 3:<br>The weather is very hot today.</pre><pre>Document 4:<br>Football is a popular sport.</pre><p>Now our user searches:</p><pre>&quot;I want to learn coding&quot;</pre><p>A traditional keyword search may struggle because the documents don’t necessarily contain the exact words from the query.</p><p>Semantic search works differently.</p><p>First, we create an embedding for every document:</p><pre>Document<br>   ↓<br>Embedding Model<br>   ↓<br>Vector</pre><p>Then we create an embedding for the user’s query:</p><pre>&quot;I want to learn coding&quot;<br>          ↓<br>    Embedding Model<br>          ↓<br>        Vector</pre><p>Now we compare the query embedding with every document embedding.</p><p>Conceptually:</p><pre>Query<br>  ↓<br>Embedding<br>  ↓<br>Compare with documents<br>  ↓<br>Similarity scores<br>  ↓<br>Sort results<br>  ↓<br>Return the most similar documents</pre><p>The Python document may receive the highest similarity because its meaning is closely related to programming and coding.</p><h3>6. A Small Semantic Search Example</h3><p>Let’s implement the basic idea.</p><pre>from sentence_transformers import SentenceTransformer<br>from sklearn.metrics.pairwise import cosine_similarity</pre><pre>model = SentenceTransformer(&quot;all-MiniLM-L6-v2&quot;)</pre><pre>documents = [<br>    &quot;Python is a programming language.&quot;,<br>    &quot;Machine learning is a branch of artificial intelligence.&quot;,<br>    &quot;The weather is very hot today.&quot;,<br>    &quot;Football is a popular sport.&quot;<br>]</pre><pre>query = &quot;I want to learn coding&quot;</pre><pre>document_embeddings = model.encode(documents)<br>query_embedding = model.encode([query])</pre><pre>scores = cosine_similarity(<br>    query_embedding,<br>    document_embeddings<br>)[0]</pre><pre>for document, score in zip(documents, scores):<br>    print(f&quot;{score:.3f} - {document}&quot;)</pre><p>The output might look similar to:</p><pre>0.70 - Python is a programming language.<br>0.55 - Machine learning is a branch of artificial intelligence.<br>0.12 - The weather is very hot today.<br>0.08 - Football is a popular sport.</pre><p>The exact scores depend on the model.</p><p>But the important thing is that we can now rank the documents according to their semantic similarity to the query.</p><h3>7. The Whole Idea in One Picture</h3><p>The entire process can be simplified to:</p><pre>&quot;I want to learn coding&quot;<br>                           │<br>                           ▼<br>                    Embedding Model<br>                           │<br>                           ▼<br>                    Query Embedding<br>                           │<br>              ┌────────────┼────────────┐<br>              ▼            ▼            ▼<br>          Document 1   Document 2   Document 3<br>              │            │            │<br>              ▼            ▼            ▼<br>          Embedding    Embedding    Embedding<br>              │            │            │<br>              └────────────┼────────────┘<br>                           ▼<br>                  Cosine Similarity<br>                           │<br>                           ▼<br>                    Similarity Scores<br>                           │<br>                           ▼<br>                    Ranked Results</pre><p>This simple pipeline is behind many modern AI search systems.</p><h3>8. Embeddings vs Semantic Search</h3><p>These terms are related, but they are not the same thing.</p><h3>Embedding</h3><p>Converts text into numbers:</p><pre>Text → Numbers</pre><h3>Cosine Similarity</h3><p>Compares two embeddings:</p><pre>Embedding A + Embedding B<br>             ↓<br>       Similarity Score</pre><h3>Semantic Search</h3><p>Uses embeddings and similarity to search by meaning:</p><pre>Query<br> ↓<br>Embedding<br> ↓<br>Compare<br> ↓<br>Rank<br> ↓<br>Results</pre><h3>9. Why Are Embeddings Important in AI?</h3><p>Embeddings are not limited to simple search.</p><p>They are used in many modern AI applications, including:</p><ul><li>Semantic search</li><li>Recommendation systems</li><li>Document retrieval</li><li>Question answering</li><li>RAG systems</li><li>Similarity detection</li><li>Clustering</li><li>Text classification</li><li>Retrieval systems</li></ul><p>Once you understand embeddings, many AI systems become easier to understand because you start seeing the common pattern:</p><pre>Convert information into numbers<br>        ↓<br>Compare or retrieve<br>        ↓<br>Use the result</pre><h3>10. The Most Important Idea</h3><p>Don’t get stuck on the mathematics at this stage.</p><p>The core idea is extremely simple:</p><blockquote><strong><em>Embedding converts meaning into numbers.</em></strong></blockquote><p>Then:</p><blockquote><strong><em>Cosine Similarity compares those numerical representations.</em></strong></blockquote><p>And finally:</p><blockquote><strong><em>Semantic Search uses this comparison to find information that is similar in meaning.</em></strong></blockquote><p>That’s the foundation.</p><p>Once these three concepts become clear, you can move toward more advanced systems such as vector databases and RAG without feeling like they appeared out of nowhere.</p><h3>Final Takeaway</h3><p>The pipeline is:</p><pre>Text<br> ↓<br>Embedding<br> ↓<br>Numerical Representation<br> ↓<br>Cosine Similarity<br> ↓<br>Similarity Score<br> ↓<br>Semantic Search<br> ↓<br>Relevant Results</pre><p>You don’t need to memorize complicated formulas to understand the idea.</p><p>First understand what the system is doing.</p><p>Then learn the mathematics and implementation details when you need them.</p><p>LinkedIn: <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">https://www.linkedin.com/in/taha-hussein-b0a583425/</a></p><p>YouTube: <a href="https://www.youtube.com/@Tahahussein-Ai">https://www.youtube.com/@Tahahussein-Ai</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a4df88b8f6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Finally Understood Transformers: A Practical Explanation of Attention, Q, K, and V]]></title>
            <link>https://medium.com/@taha.hussein.two/i-finally-understood-transformers-a-practical-explanation-of-attention-q-k-and-v-a56a1cf4a3ca?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a56a1cf4a3ca</guid>
            <category><![CDATA[i-understood-transformer]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 09:01:30 GMT</pubDate>
            <atom:updated>2026-09-18T09:01:30.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBYYqRAKJL1aGhu4Mtn2Zw.jpeg" /></figure><p>If you are learning Large Language Models, sooner or later you will hear the same words again and again:</p><p><strong>Transformer. Attention. Query. Key. Value. Embeddings.</strong></p><p>At first, they can feel like a collection of complicated mathematical terms.</p><p>But once you understand what attention is actually doing, the Transformer architecture becomes much easier to reason about.</p><p>In this article, I will explain Transformers from an engineering perspective rather than treating them as a black box.</p><h3>1. Why Did We Need Transformers?</h3><p>Before Transformers became dominant, sequence modeling often relied on architectures such as RNNs and LSTMs.</p><p>The problem is that processing a sequence step by step makes it harder to efficiently capture relationships between distant tokens and limits parallelization during training.</p><p>Transformers introduced a different idea:</p><blockquote><em>Instead of processing tokens strictly one after another, allow tokens to directly interact with each other through attention.</em></blockquote><p>This became the foundation for many modern language models.</p><h3>2. Start With Tokens</h3><p>Consider this sentence:</p><pre>The cat sat on the mat</pre><p>A language model does not directly receive the sentence as English words.</p><p>The text is first tokenized.</p><p>Conceptually:</p><pre>&quot;The cat sat on the mat&quot;</pre><pre>        ↓</pre><pre>[&quot;The&quot;, &quot;cat&quot;, &quot;sat&quot;, &quot;on&quot;, &quot;the&quot;, &quot;mat&quot;]</pre><pre>        ↓</pre><pre>[12, 531, 827, 44, 12, 901]</pre><p>The exact tokens and IDs depend on the tokenizer.</p><p>These IDs are then converted into vectors called <strong>embeddings</strong>.</p><p>For example:</p><pre>cat → [0.21, -0.73, 0.14, 0.91]</pre><p>The vector is not a human-readable definition of “cat.”</p><p>It is a learned numerical representation.</p><h3>3. The Problem: Understanding Context</h3><p>Consider:</p><pre>The bank approved my loan.</pre><p>and:</p><pre>I sat beside the river bank.</pre><p>The word bank appears in both sentences, but its meaning depends on context.</p><p>This is where attention becomes extremely important.</p><p>Instead of treating every token independently, the model can ask:</p><blockquote><em>Which other tokens are relevant to understanding this token?</em></blockquote><p>For bank, words such as:</p><pre>loan<br>approved<br>river<br>sat</pre><p>can have very different importance depending on the sentence.</p><h3>4. Attention</h3><p>The basic idea behind self-attention is surprisingly intuitive.</p><p>For each token, the model creates three representations:</p><ul><li>Query (Q)</li><li>Key (K)</li><li>Value (V)</li></ul><p>Think of them conceptually as:</p><p><strong>Query:</strong><br>“What information am I looking for?”</p><p><strong>Key:</strong><br>“What kind of information do I contain?”</p><p><strong>Value:</strong><br>“What information should I provide?”</p><p>This is not literally how the neural network “thinks”, but it is a useful mental model.</p><h3>5. Computing Attention</h3><p>The core equation is:</p><pre>Attention(Q, K, V)<br>=<br>softmax(QKᵀ / √dₖ)V</pre><p>Let’s break it down.</p><p>First:</p><pre>QKᵀ</pre><p>calculates how compatible each query is with each key.</p><p>Then we divide by:</p><pre>√dₖ</pre><p>to stabilize the values.</p><p>Then:</p><pre>softmax(...)</pre><p>converts the scores into weights.</p><p>Finally, those weights are multiplied by:</p><pre>V</pre><p>to produce the new representation.</p><p>PyTorch provides optimized implementations of scaled dot-product attention, including torch.nn.functional.scaled_dot_product_attention.</p><h3>6. A Small Example</h3><p>Imagine we have three tokens:</p><pre>I love AI</pre><p>Suppose each token has an embedding dimension of 4.</p><p>Our input matrix might look conceptually like:</p><pre>X =<br>[<br>  [0.2, 0.1, 0.7, 0.3],   # I<br>  [0.8, 0.4, 0.1, 0.6],   # love<br>  [0.5, 0.9, 0.3, 0.2]    # AI<br>]</pre><p>The Transformer learns projection matrices:</p><pre>WQ<br>WK<br>WV</pre><p>and calculates:</p><pre>Q = XWQ</pre><pre>K = XWK</pre><pre>V = XWV</pre><p>Now every token has its own Query, Key, and Value.</p><p>The attention mechanism can calculate relationships between them.</p><h3>7. Why Is This Powerful?</h3><p>Suppose we process:</p><pre>The developer opened the repository because it contained the bug.</pre><p>When representing:</p><pre>it</pre><p>the model can attend strongly to:</p><pre>repository</pre><p>rather than treating it as an isolated token.</p><p>This ability to dynamically combine information from other tokens is one of the central ideas behind Transformers.</p><h3>8. Multi-Head Attention</h3><p>One attention mechanism may learn one type of relationship.</p><p>But language contains many relationships.</p><p>For example:</p><pre>The developer fixed the bug because it was blocking the release.</pre><p>Different attention heads can learn different patterns.</p><p>Conceptually:</p><pre>Transformer<br>                      │<br>          ┌───────────┼───────────┐<br>          ↓           ↓           ↓<br>       Head 1       Head 2      Head 3<br>          │           │           │<br>      syntax       context     relationships</pre><p>The outputs are combined and projected again.</p><p>This is called <strong>Multi-Head Attention</strong>.</p><h3>9. Attention Is Not the Entire Transformer</h3><p>A common beginner mistake is thinking:</p><pre>Transformer = Attention</pre><p>Not exactly.</p><p>A Transformer block contains multiple components.</p><p>A simplified GPT-style block looks like:</p><pre>Input<br>  │<br>  ▼<br>Self-Attention<br>  │<br>  ▼<br>Add &amp; Normalize<br>  │<br>  ▼<br>Feed Forward Network<br>  │<br>  ▼<br>Add &amp; Normalize<br>  │<br>  ▼<br>Output</pre><p>Modern architectures may modify the exact ordering, normalization, positional encoding, and other details.</p><p>PyTorch’s Transformer tooling exposes these building blocks, while lower-level APIs such as scaled dot-product attention allow more customized implementations.</p><h3>10. What Does GPT Actually Do?</h3><p>GPT-style models are autoregressive language models.</p><p>Given:</p><pre>The weather is</pre><p>the model predicts a probability distribution for the next token.</p><p>For example:</p><pre>great     0.31<br>beautiful 0.18<br>cold      0.12<br>...</pre><p>The model then selects or samples a token and continues.</p><p>Conceptually:</p><pre>The weather is<br>       ↓<br>The weather is great<br>       ↓<br>The weather is great today<br>       ↓<br>...</pre><p>This simple next-token prediction objective becomes incredibly powerful when the model has enough parameters, data, and compute.</p><h3>11. Why Transformers Matter for AI Engineers</h3><p>If you are building modern AI systems, you don’t necessarily need to implement every Transformer layer from scratch.</p><p>But you should understand what happens underneath the abstractions.</p><p>For example, Hugging Face Transformers provides a unified interface for loading, using, training, and saving Transformer models.</p><p>That means you can write something as simple as:</p><pre>from transformers import pipeline</pre><pre>generator = pipeline(<br>    &quot;text-generation&quot;,<br>    model=&quot;...&quot;<br>)</pre><pre>result = generator(<br>    &quot;Artificial intelligence is&quot;,<br>    max_new_tokens=50<br>)</pre><p>But the abstraction is much more useful when you understand what is happening underneath it.</p><h3>12. What I Recommend Learning Next</h3><p>Once you understand the Transformer architecture, the next logical steps are:</p><pre>Transformers<br>     ↓<br>Tokenizers<br>     ↓<br>Pretrained Models<br>     ↓<br>Fine-Tuning<br>     ↓<br>LoRA / PEFT<br>     ↓<br>RAG<br>     ↓<br>Tool Calling<br>     ↓<br>AI Agents</pre><p>The Hugging Face LLM Course follows a similar progression from Transformer fundamentals to using pretrained models and then fine-tuning.</p><h3>Final Thoughts</h3><p>The most important lesson is not memorizing:</p><pre>QKᵀ / √dₖ</pre><p>The important thing is understanding the idea behind it:</p><blockquote><strong><em>Attention allows a token representation to dynamically incorporate information from other tokens.</em></strong></blockquote><p>Once that clicks, concepts such as Multi-Head Attention, GPT, BERT, encoder/decoder architectures, and modern LLMs become much easier to understand.</p><p>And that is the point where you stop treating LLMs as magic and start treating them as engineering systems.</p><h3>Connect With Me</h3><p>YouTube: <a href="https://www.youtube.com/@Tahahussein-Ai">https://www.youtube.com/@Tahahussein-Ai</a></p><p>GitHub: <a href="https://github.com/Taha2hussein">https://github.com/Taha2hussein</a></p><p>LinkedIn: <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">https://www.linkedin.com/in/taha-hussein-b0a583425/</a></p><p>I share my journey through <strong>Python, Machine Learning, Deep Learning, LLMs, and AI Engineering</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a56a1cf4a3ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why PyTorch Is One of the Most Important Tools to Learn for Deep Learning]]></title>
            <link>https://medium.com/@taha.hussein.two/why-pytorch-is-one-of-the-most-important-tools-to-learn-for-deep-learning-ec63ea165f3b?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec63ea165f3b</guid>
            <category><![CDATA[pytorch-tutorial-beginner]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Tue, 15 Sep 2026 09:05:26 GMT</pubDate>
            <atom:updated>2026-09-15T09:05:26.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQTeHJffdyv2XPZjV9AIRQ.jpeg" /></figure><p>If you want to learn modern Artificial Intelligence, learning Python is only the beginning.</p><p>Sooner or later, you’ll encounter <strong>PyTorch</strong>.</p><p>PyTorch is a machine learning framework that makes it possible to build and train neural networks using Python. It has become an important tool for Deep Learning research, education, Computer Vision, Natural Language Processing, and Generative AI.</p><p>But why should you learn it?</p><h3>PyTorch Makes Deep Learning Feel Like Python</h3><p>One of the biggest advantages of PyTorch is its programming experience.</p><p>You can define tensors, neural networks, loss functions, and training loops using familiar Python code.</p><p>For example:</p><pre>import torch</pre><pre>x = torch.tensor([1, 2, 3])</pre><pre>print(x)</pre><p>This simple tensor is the building block for much more complicated neural networks.</p><h3>Tensors Are Everywhere</h3><p>Neural networks work with numbers.</p><p>Images, text representations, audio, and other types of data eventually need to be represented numerically.</p><p>PyTorch uses tensors to represent these values.</p><p>For example:</p><pre>x = torch.rand(32, 128)</pre><p>This could represent a batch of 32 examples, each containing 128 numerical features.</p><p>Once you understand tensors, many PyTorch concepts become easier.</p><h3>The Magic of Automatic Differentiation</h3><p>Training a neural network requires gradients.</p><p>Calculating these gradients manually for a large neural network would be extremely difficult.</p><p>PyTorch provides automatic differentiation.</p><pre>x = torch.tensor(3.0, requires_grad=True)</pre><pre>y = x ** 2</pre><pre>y.backward()</pre><pre>print(x.grad)</pre><p>PyTorch calculates the derivative automatically.</p><p>This is one of the fundamental mechanisms behind neural network training.</p><h3>Building Models</h3><p>PyTorch provides torch.nn for creating neural networks.</p><p>For example:</p><pre>import torch.nn as nn</pre><pre>model = nn.Sequential(<br>    nn.Linear(10, 32),<br>    nn.ReLU(),<br>    nn.Linear(32, 1)<br>)</pre><p>Even a relatively small amount of code can define a complete neural network.</p><h3>The Training Loop</h3><p>At the heart of Deep Learning is the training loop.</p><p>The general process looks like this:</p><pre>Data<br> ↓<br>Model<br> ↓<br>Prediction<br> ↓<br>Loss<br> ↓<br>Gradient<br> ↓<br>Optimizer<br> ↓<br>Updated Model</pre><p>In PyTorch:</p><pre>optimizer.zero_grad()</pre><pre>prediction = model(x)</pre><pre>loss = criterion(prediction, y)</pre><pre>loss.backward()</pre><pre>optimizer.step()</pre><p>Understanding these lines is much more important than memorizing them.</p><p>Once you understand what each step does, you can start building increasingly complex models.</p><h3>What Can You Do With PyTorch?</h3><p>You can use PyTorch for:</p><ul><li>Computer Vision</li><li>Natural Language Processing</li><li>Deep Learning</li><li>Transformers</li><li>Generative AI</li><li>Large Language Models</li><li>Research</li></ul><p>And this is where PyTorch becomes especially interesting.</p><p>After learning the fundamentals, you can move from simple neural networks to <strong>Attention and Transformer architectures</strong>.</p><h3>Your PyTorch Learning Path</h3><p>A practical learning path could look like:</p><p><strong>Python → PyTorch → Neural Networks → CNNs → Attention → Transformers → LLMs → Fine-tuning → RAG</strong></p><p>Don’t try to learn everything at once.</p><p>Build small projects.</p><p>Understand the mathematics behind the models.</p><p>Then implement the ideas yourself.</p><p>That’s how PyTorch becomes a real skill rather than just another library you installed.</p><h3>Final Thoughts</h3><p>If you’re planning to work in Deep Learning or modern AI, PyTorch is a framework worth learning deeply.</p><p>The goal shouldn’t be to memorize the PyTorch API.</p><p>The goal is to understand what’s happening underneath the code.</p><p>That’s when you can move from using existing models to actually understanding and building them.</p><p>I publish tutorials covering <strong>PyTorch, Transformers, Machine Learning, and modern AI</strong>, with a focus on understanding the concepts and implementing them in Python.</p><p><strong>YouTube:</strong> <a href="https://www.youtube.com/@Tahahussein-Ai">https://www.youtube.com/@Tahahussein-Ai</a></p><p><strong>GitHub:</strong> <a href="https://github.com/Taha2hussein">https://github.com/Taha2hussein</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec63ea165f3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built a Leakage-Safe AutoML Framework from Scratch — Here’s Why It Matters]]></title>
            <link>https://medium.com/@taha.hussein.two/i-built-a-leakage-safe-automl-framework-from-scratch-heres-why-it-matters-61d10d979a20?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/61d10d979a20</guid>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Thu, 27 Aug 2026 12:23:33 GMT</pubDate>
            <atom:updated>2026-08-27T12:23:33.438Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong><em>بسم الله الرحمن الرحيم</em></strong></h3><h3>Most AutoML tools quietly leak information from your test set into your training pipeline. I set out to fix that.</h3><p>A few months ago, I was running a classic ML experiment on a tabular dataset. I used a popular AutoML library, got a great cross-validation score, and confidently reported the results to my team. Then I tried the model on a real holdout set. The performance dropped by 18%.</p><p>After days of debugging, I found the culprit: data leakage in the preprocessing step. The imputation statistics, scaling parameters, and even some feature engineering had been computed on the <em>entire</em> dataset <em>before</em> the train/test split. The model had already “seen” the test set during preprocessing.</p><p>This is not a rare bug. It is a systemic flaw in how many ML pipelines are structured. And most practitioners don’t even know it’s happening.</p><p>So I decided to build something different: a lightweight, leakage-safe, production-oriented ML experimentation framework built on scikit-learn. One that makes every decision transparent, every step auditable, and every metric trustworthy.</p><p>Here is what I learned along the way.</p><h3>The Problem: Leakage Is Everywhere</h3><p>Data leakage in ML preprocessing usually happens in one of three ways:</p><ol><li>Pre-fit leakage: Computing mean imputation, standard scaling, or target encoding on the full dataset before splitting.</li><li>Feature engineering leakage: Creating interaction terms or ratios using global statistics that include the test set.</li><li>Model selection leakage: Using the test set to pick hyperparameters or models, then reporting that same test score as “final performance.”</li></ol><p>Most AutoML frameworks — even well-known ones — handle the <em>model training</em> inside cross-validation, but leave the <em>preprocessing</em> outside. The result? Your “unseen” test set is not unseen at all.</p><p>I wanted a framework where the train/test split is the very first thing that happens, and where every preprocessing step lives inside the CV loop.</p><h3>The Solution: A Decision Engine That Thinks Before It Trains</h3><p>I didn’t want to build yet another wrapper around sklearn.pipeline.Pipeline. I wanted a system that reasons about the data before deciding what to do with it.</p><p>The core of the framework is the Decision Engine. It inspects the dataset — size, feature types, class balance, target skew — and produces an explicit, auditable strategy.</p><p>Every decision is logged with four fields:</p><ul><li>What was chosen</li><li>Why it was chosen</li><li>What action it triggers</li><li>Confidence level (high / medium / low)</li></ul><p>Here is what it looks like in practice:</p><p>Python</p><pre>from src.detection.decision_engine import build_strategy</pre><pre>strategy = build_strategy(<br>    problem_type=&quot;binary_classification&quot;,<br>    n_samples=1200,<br>    n_features=45,<br>    n_numeric=30,<br>    n_categorical=15,<br>    high_cardinality_cats=3,<br>    imbalance_ratio=4.2,<br>    target_skew=None,<br>    config={...}<br>)</pre><p>The engine then decides:</p><ul><li>CV Strategy: StratifiedKFold because it&#39;s classification with imbalance.</li><li>Primary Metric: average_precision (PR-AUC) instead of roc_auc — because ROC-AUC is misleading when the positive class is rare.</li><li>Class Weight: balanced because the imbalance ratio is 4.2.</li><li>Target Transform: None (this is classification).</li><li>Model Candidates: LogisticRegression, RandomForestClassifier, HistGradientBoostingClassifier — but <em>not</em> SVC, because with 1,200 samples and 45 features, the quadratic complexity of SVM isn&#39;t worth the marginal gain.</li></ul><p>Notice the last point: the framework does not brute-force every model. It selects a <em>sensible</em> subset based on dataset characteristics. This makes experiments faster, cheaper, and more reproducible.</p><h3>Architecture: Leakage Prevention by Design</h3><p>The framework is structured as a modular pipeline where every stage is isolated and testable:</p><p>plain</p><pre>ml_framework/<br>├── src/<br>│   ├── data/           # Load, validate, profile, split<br>│   ├── detection/      # Problem type, feature types, Decision Engine<br>│   ├── preprocessing/  # ColumnTransformer pipelines (inside CV!)<br>│   ├── features/       # Engineering hooks (also inside CV)<br>│   ├── models/         # Extensible registry<br>│   ├── training/       # Baseline → CV → tuning → final train<br>│   ├── evaluation/     # Metrics, error analysis, plots<br>│   ├── explainability/ # Permutation importance + optional SHAP<br>│   └── experiments/    # Runner + reporter</pre><h3>The Golden Rule</h3><blockquote><em>The train/test split happens before any </em><em>fit().</em></blockquote><blockquote><em>All imputation, scaling, and encoding live inside an </em><em>sklearn.Pipeline + </em><em>ColumnTransformer.</em></blockquote><blockquote><em>Cross-validation and hyperparameter tuning operate on the full pipeline (preprocess + model), never on raw data.</em></blockquote><blockquote><em>Final metrics are computed once on the untouched test set.</em></blockquote><p>This is not a configuration option. It is hard-coded into the architecture.</p><h3>A Real Example: House Prices Regression</h3><p>Here is how you run an experiment:</p><p>bash</p><pre>pip install ml-experiment-framework</pre><pre>ml-experiment   --data train.csv   --target SalePrice   --problem-type regression</pre><p>The framework auto-detects the problem type if you omit --problem-type. It profiles the data, builds the preprocessing pipeline, runs staged model selection, tunes the top candidates, and produces a full report.</p><h3>Terminal Output</h3><p>plain</p><pre>============================================================<br>ML EXPERIMENT COMPLETE<br>============================================================</pre><pre>Problem: Regression<br>Dataset: 1460 rows × 81 columns<br>Train: 1168 rows<br>Test: 292 rows<br>Primary Metric: RMSE<br>Baseline: -0.42<br>Best Model: HistGradientBoostingRegressor<br>CV: -0.251 ± 0.009<br>Test rmse: 0.237<br>Test mae: 0.164<br>Test r2: 0.891<br>Model saved: artifacts/models/best_model.joblib<br>Report: artifacts/reports/final_report.html<br>============================================================</pre><p>Notice the separation:</p><ul><li>CV score is used for model selection and tuning.</li><li>Test score is reported once, at the very end, as the honest estimate of generalization.</li></ul><p>No peeking. No leakage. No inflated numbers.</p><h3>The Decision Engine in Detail</h3><p>Let me show you why this is not just a wrapper. Here is a simplified excerpt from the model selection logic:</p><p>Python</p><pre>def _select_candidates(problem_type, n_samples, n_features, ...):<br>    is_clf = &quot;classification&quot; in problem_type<br>    candidates = []</pre><pre>    if is_clf:<br>        candidates = [<br>            &quot;LogisticRegression&quot;,<br>            &quot;RandomForestClassifier&quot;,<br>            &quot;HistGradientBoostingClassifier&quot;<br>        ]<br>        if n_samples &lt; 5000 and n_features &lt; 100:<br>            candidates.append(&quot;ExtraTreesClassifier&quot;)<br>        if n_samples &lt; 1500 and n_features &lt; 40:<br>            candidates.append(&quot;SVC&quot;)  # O(n²) — only on small data<br>    else:<br>        candidates = [<br>            &quot;Ridge&quot;,<br>            &quot;RandomForestRegressor&quot;,<br>            &quot;HistGradientBoostingRegressor&quot;<br>        ]<br>        if n_samples &lt; 5000:<br>            candidates.append(&quot;ExtraTreesRegressor&quot;)<br>        if n_samples &lt; 1500 and n_features &lt; 40:<br>            candidates.append(&quot;SVR&quot;)</pre><pre>    return candidates</pre><p>This is domain knowledge encoded into software:</p><ul><li>SVM is quadratic in sample size. On 100K rows, it is infeasible. On 1K rows, it is competitive.</li><li>ExtraTrees is robust but slower. We only add it when the dataset is small enough to justify the cost.</li><li>Tree-based models (Random Forest, HistGradientBoosting) are always included because they are strong defaults with minimal tuning.</li></ul><p>The same reasoning applies to metrics:</p><ul><li>Balanced binary classification → roc_auc</li><li>Imbalanced binary classification (ratio &gt; 3) → average_precision (PR-AUC)</li><li>Multiclass → f1_weighted</li><li>Regression with skewed target → log1p transform + RMSLE</li></ul><p>These are not arbitrary defaults. They are statistically informed choices.</p><h3>Extensibility: Your Models, Your Rules</h3><p>The framework is designed to be extended without forking the codebase.</p><h3>Add a custom model:</h3><p>Python</p><pre>from src.models.registry import register_model<br>from sklearn.ensemble import AdaBoostClassifier</pre><pre>register_model(<br>    &quot;AdaBoostClassifier&quot;,<br>    AdaBoostClassifier,<br>    problem_types=[&quot;binary_classification&quot;, &quot;multiclass_classification&quot;],<br>    default_params={&quot;random_state&quot;: 42},<br>    search_space={&quot;n_estimators&quot;: [50, 100, 200]},<br>)</pre><h3>Add a custom data loader:</h3><p>Python</p><pre>from src.data.loader import register_loader</pre><pre>@register_loader(&quot;feather&quot;)<br>def load_feather(path):<br>    import pandas as pd<br>    return pd.read_feather(path)</pre><h3>Add a custom metric:</h3><p>Pass --metric my_scorer if registered with sklearn, or set evaluation.primary_metric in the YAML config.</p><h3>What I Learned</h3><p>Building this framework taught me three things that no course or tutorial could:</p><h3>1. Leakage is subtle and expensive</h3><p>You can have perfect cross-validation scores and still ship a broken model. The only defense is architectural: enforce the split before any transformation, and never let the test set influence training in any way.</p><h3>2. “Auto” does not mean “brute force”</h3><p>The best AutoML is not the one that tries every model. It is the one that knows which models to skip. A Decision Engine that understands dataset characteristics is more valuable than a registry of 50 models.</p><h3>3. Transparency beats black boxes</h3><p>Every choice in this framework is logged with a reason. When a stakeholder asks, “Why did you use PR-AUC instead of accuracy?” — you don’t have to guess. You point to the Decision Engine log.</p><h3>Try It Yourself</h3><p>bash</p><pre># Install from PyPI<br>pip install ml-experiment-framework</pre><pre># Run an experiment<br>ml-experiment --data your_data.csv --target your_target</pre><pre># Or use a config file<br>ml-experiment --config configs/default.yaml --data train.csv --target y</pre><pre># Predict on new data<br>ml-experiment predict   --model artifacts/models/best_model.joblib   --data new_data.csv   --output predictions.csv</pre><p>📦 PyPI: <a href="https://pypi.org/project/ml-experiment-framework">pypi.org/project/ml-experiment-framework</a><br>💻 GitHub: <a href="https://github.com/Taha2hussein/ml-experiment-framework">https://github.com/Taha2hussein/ml-experiment-framework</a><br>📊 Kaggle Notebook: <a href="https://www.kaggle.com/code/tahahussein2020/house-prices-advanced-regression">https://www.kaggle.com/code/tahahussein2020/house-prices-advanced-regression</a></p><h3>What’s Next</h3><p>I am actively working on:</p><ul><li>Bayesian optimization via Optuna (optional dependency)</li><li>SHAP explainability integration</li><li>Time-series split support for temporal data</li><li>Model comparison reports with statistical significance testing</li></ul><p>If you find this useful, give it a ⭐ on GitHub or open an issue. I would love to hear how you use it.</p><p><em>Thanks for reading. If you are building ML systems, I hope this reminds you that the most dangerous bugs are the ones you cannot see — and that good architecture is the only real defense.</em></p><p>About the author: ML Engineer focused on building correct, reproducible, and explainable machine learning systems. Open source contributor. You can find me on <a href="https://www.linkedin.com/in/taha-hussein-b0a583425/">LinkedIn</a> and <a href="https://github.com/Taha2hussein">GitHub</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61d10d979a20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Race Condition in Email Verification Leading to Email Bombing]]></title>
            <link>https://medium.com/@taha.hussein.two/race-condition-in-email-verification-leading-to-email-bombing-46d3e058e148?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/46d3e058e148</guid>
            <category><![CDATA[race-condition]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Mon, 18 May 2026 14:21:56 GMT</pubDate>
            <atom:updated>2026-05-18T14:21:56.067Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Exploiting Race Condition in Email Verification to Trigger Mass Emails</strong></p><h3>Introduction</h3><p>While testing an email verification flow in a production web application, I identified a race condition vulnerability caused by missing server-side rate limiting and lack of atomic request handling.</p><p>This issue allowed multiple verification emails to be triggered simultaneously to the same target email address.</p><h3>Vulnerability Overview</h3><p><strong>Type:</strong> Race Condition / Business Logic Flaw / Rate Limit Bypass</p><p><strong>Affected Functionality:</strong> Email Verification Endpoint</p><p>The application exposed an endpoint responsible for sending verification emails:</p><p>POST /<a href="/service/mailto:custard/pubcustard/secure/verification/sendVerificationEmail?email=target@email.com">custard/pubcustard/secure/verification/sendVerificationEmail?email=target@email.com</a></p><p>The frontend attempted to prevent abuse by showing a loading spinner and temporarily blocking repeated clicks.</p><p>However, this protection existed only on the client side.</p><p>The backend processed every request independently without checking whether a verification email had already been sent recently.</p><h3>Root Cause</h3><p>The server lacked:</p><ul><li>Server-side rate limiting</li><li>Atomic locking per email/session</li><li>Cooldown period between requests</li></ul><p>Because of this, concurrent requests arriving at nearly the same moment were all accepted.</p><h3>Proof of Concept</h3><p>Using Python multithreading, I sent 50 simultaneous requests:</p><pre>import requests<br>import concurrent.futures<br><br>def send_request():<br>    requests.post(target_url)<br><br>with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:<br>    for _ in range(50):<br>        executor.submit(send_request)</pre><h3>Result</h3><p>All requests returned:</p><pre>204 No Content</pre><p>The target inbox received 50 identical verification emails almost instantly.</p><h3>Impact</h3><h3>1. Email Bombing</h3><p>Attackers can flood inboxes with verification emails.</p><h3>2. User Harassment</h3><p>Victims may be overwhelmed with repeated messages.</p><h3>3. Security Smokescreen</h3><p>Important security emails may be hidden among spam.</p><h3>4. SMTP Reputation Damage</h3><p>High-volume abuse may cause domain blacklisting.</p><h3>5. Resource Exhaustion</h3><p>Mass email generation consumes infrastructure resources.</p><h3>Recommended Fixes</h3><h3>Implement Server-Side Rate Limiting</h3><p>Example:</p><ul><li>1 email per 60 seconds per user/email</li></ul><h3>Add Atomic Locking</h3><p>Use Redis or database locks.</p><h3>Return Proper Error</h3><h3>Conclusion</h3><p>Client-side protections should never be trusted as the primary abuse prevention mechanism.</p><p>Without backend enforcement, race conditions can easily bypass intended restrictions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46d3e058e148" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication Rate Limit Bypass via X-Forwarded-For Header Spoofing]]></title>
            <link>https://medium.com/@taha.hussein.two/authentication-rate-limit-bypass-via-x-forwarded-for-header-spoofing-ac0d0ba1cd96?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac0d0ba1cd96</guid>
            <category><![CDATA[rate-limiting]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Mon, 18 May 2026 14:18:12 GMT</pubDate>
            <atom:updated>2026-05-18T14:18:12.649Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Bypassing Authentication Rate Limits Using X-Forwarded-For Header Spoofing</strong></h3><h3>Introduction</h3><p>During authentication security testing, I discovered a rate limiting bypass caused by trusting a user-controlled HTTP header.</p><p>The application enforced brute-force protection based on IP address, but relied directly on the X-Forwarded-For header.</p><h3>Vulnerability Overview</h3><p><strong>Type:</strong> Rate Limit Bypass / Header Trust Misconfiguration</p><p><strong>Affected Endpoint:</strong></p><p>POST /api/authentication/login</p><p>Normal failed login attempts eventually triggered:</p><pre>429 Too Many Requests</pre><p>However, modifying the X-Forwarded-For header bypassed this restriction.</p><h3>Root Cause</h3><p>The backend trusted:</p><p>X-Forwarded-For: attacker-controlled-ip</p><p>Instead of validating proxy headers from trusted infrastructure.</p><p>As a result, attackers could spoof a new IP on every request.</p><h3>Proof of Concept</h3><p>Initial request:</p><p>POST /api/authentication/login<br><a href="/service/mailto:username=victim@example.com">username=victim@example.com</a>&amp;password=wrong</p><p>Response</p><p>429 Too Many Requests</p><p>Bypass request:</p><pre>POST /api/authentication/login<br>X-Forwarded-For: 11.22.33.44</pre><p>Response:</p><pre>401 Unauthorized</pre><p>No rate limiting triggered.</p><h3>Automation</h3><p>A simple loop was enough:</p><p>for i in {1..50}; do<br>curl -X POST <a href="https://target.com/api/authentication/login">https://target.com/api/authentication/login</a> \<br>-H “X-Forwarded-For: $RANDOM.$RANDOM.$RANDOM.$RANDOM”<br>done</p><h3>Result</h3><ul><li>50 requests sent</li><li>50 responses returned 401</li><li>0 responses returned 429</li></ul><p>Rate limiting fully bypassed.</p><h3>Security Impact</h3><h3>Unlimited Brute Force</h3><p>Attackers can perform unrestricted password guessing.</p><h3>Account Takeover Risk</h3><p>Weak passwords become vulnerable.</p><h3>Credential Stuffing</h3><p>Large-scale automated login attempts become possible.</p><h3>Security Control Failure</h3><p>Rate limiting becomes ineffective.</p><h3>Conclusion</h3><p>Authentication defenses are only as strong as the metadata they trust.</p><p>Improper proxy handling can silently disable brute-force protections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac0d0ba1cd96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host Header Injection : How I Poisoned Asset URLs]]></title>
            <link>https://medium.com/@taha.hussein.two/host-header-injection-how-i-poisoned-asset-urls-70a920097f2c?source=rss-4041ca87d01d------2</link>
            <guid isPermaLink="false">https://medium.com/p/70a920097f2c</guid>
            <dc:creator><![CDATA[Taha Hussein Two]]></dc:creator>
            <pubDate>Thu, 14 May 2026 16:52:16 GMT</pubDate>
            <atom:updated>2026-05-14T16:52:16.605Z</atom:updated>
            <content:encoded><![CDATA[<p>I discovered a Host Header Injection vulnerability that allowed an unauthenticated attacker to poison asset URLs returned by a public API — enabling phishing, brand impersonation, and content injection inside trusted LMS platforms . The vulnerability was responsibly disclosed via YesWeHack and rewarded</p><h3>Background</h3><p>This program is a widely-used open-source web conferencing platform integrated into Learning Management Systems (LMS) such as Moodle, Canvas, and Schoology. The Greenlight frontend manages rooms, users, and sessions — serving millions of students and instructors worldwide.</p><p>During a security assessment of the platform’s public API, I noticed that the application was reflecting values from the Host HTTP header into sensitive response fields — without any validation or sanitization.</p><h3>Root cause analysis</h3><p>The vulnerability originates inside PublicRoomSerializer, which uses a helper called user_avatar from the Avatarable module to generate the owner_avatar URL.</p><pre>class PublicRoomSerializer &lt; ApplicationSerializer<br>  include Avatarable<br><br>  def owner_avatar<br>    user_avatar(object.user)<br>  end<br>end</pre><p>Internally, this helper builds an absolute URL using request.base_url — which derives its value directly from the client-supplied Host header. Since no validation exists, an attacker can inject any arbitrary host value and have it reflected back in the API response.</p><h3>Proof of concept</h3><pre>GET /api/v1/rooms/{friendly_id}/public.json<br>Host: demo.example.org</pre><h3>Malicious request</h3><pre>curl -s https://demo.example.org/api/v1/rooms/{friendly_id}/public.json \<br>  -H &quot;Host: demo.example.org@attacker-domain.com&quot;</pre><h3>Poisoned response</h3><pre>{<br>  &quot;owner_avatar&quot;: &quot;https://demo.example.org@attacker-domain.com/assets/default-avatar.png&quot;,<br>  &quot;owner_name&quot;: &quot;Room Owner&quot;,<br>  &quot;friendly_id&quot;: &quot;mjk-oan-apg-ra8&quot;<br>}</pre><h3>Security impact</h3><p>Because program is embedded inside trusted LMS environments, this vulnerability creates a wide attack surface:</p><ul><li>Phishing attacks targeting students and instructors through trusted LMS link previews</li><li>Attacker-controlled images injected into chat previews, emails, and LMS announcements</li><li>Abuse of Open Graph consumers and social platform link previews</li><li>No authentication required — the endpoint is fully public</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70a920097f2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>