<?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 Emon ML Engineer on Medium]]></title>
        <description><![CDATA[Stories by Emon ML Engineer on Medium]]></description>
        <link>https://medium.com/@emon.mlengineer?source=rss-b16daa9ff5c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*scZAVVQKcZ-E3hCN</url>
            <title>Stories by Emon ML Engineer on Medium</title>
            <link>https://medium.com/@emon.mlengineer?source=rss-b16daa9ff5c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:05:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emon.mlengineer/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 RoBERTa on LIAR: Everything That Happens After trainer.train()]]></title>
            <link>https://medium.com/@emon.mlengineer/fine-tuning-roberta-on-liar-everything-that-happens-after-trainer-train-cac4b8112bcd?source=rss-b16daa9ff5c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cac4b8112bcd</guid>
            <category><![CDATA[fine-tuning-llm]]></category>
            <category><![CDATA[fine-tuning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[llm-evaluation]]></category>
            <dc:creator><![CDATA[Emon ML Engineer]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 17:26:45 GMT</pubDate>
            <atom:updated>2026-10-13T19:03:30.130Z</atom:updated>
            <content:encoded><![CDATA[<h3>Training this model took 5.5 minutes on a free Colab T4. Everything else took three days, and the three days are what made the model worth publishing.</h3><p>I fine-tuned roberta-base on <strong>LIAR</strong>, a dataset of 12,836 political statements rated by PolitiFact, to classify a claim as real or fake. The final model scores <strong>64.5% accuracy and 0.635 macro-F1</strong> on the held-out split. That accuracy looks mediocre, and this post explains why it is the wrong number to look at, how I nearly trained the task backwards without noticing, and what I found when I stopped trusting the metrics and started reading the model’s mistakes.</p><p>Everything here comes from one run. The <a href="https://huggingface.co/emonHasan01/liar-roberta">model</a> and its full results are public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQ5nv1hTuLM9xx7eIdGpUg.png" /></figure><h3>The labels are not in the order you expect</h3><p>LIAR rates each statement on a six-point truthfulness scale. Hugging Face stores those ratings as integers 0 to 5, which makes them look like a scale. <strong>They are not sorted by truthfulness.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*fRQsl2vwM4n7gYrd9L36Gw.png" /></figure><p>The two <strong>least</strong> truthful classes sit at positions 4 and 5, exactly where a reader expects the truthful end. This is the original TSV&#39;s column order, carried through unchanged.</p><p>My first version mapped label in [4, 5] to REAL. Every label was inverted. The model trained without complaint, the loss went down, and the accuracy landed around 60% — well within the range a working model produces on this dataset. <strong>Nothing in the training output signals the problem.</strong> I only caught it by printing a few statements next to their assigned binary labels and reading them.</p><p>The fix is not to memorise the right indices. It is to never use indices at all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*Q8VqFiFR-qkvgmOqzoD_VA.png" /></figure><p>The order the names come back in no longer matters. When I later switched dataset mirrors and the names arrived alphabetised instead, this code kept working while an index-based version would have silently broken again.</p><p><strong>The general lesson:</strong> any time a dataset encodes a category as an integer, resolve it through the name. The integer is an implementation detail of whoever built the loader, and it can change between versions of the same dataset.</p><h3>Six classes into two, and what it costs</h3><p>Six-way classification on LIAR is a genuinely hard problem that published work struggles with. Binary is more tractable and more useful for a demo, so I collapsed it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*CaN0gmX2IqZFofMV_0ZhvQ.png" /></figure><p>The interesting decision is where half-true goes. PolitiFact uses it for claims that are accurate but omit critical context. I put it on the FAKE side because the claim as stated misleads, which is the thing I wanted the model to catch.</p><p><strong>That choice is defensible, not obvious, and it has consequences.</strong> It pushes the split to 35% REAL and 65% FAKE, and it groups a nuanced category with outright fabrication. Later, when I broke accuracy down by original class, half-true turned out to be where the model performs worst — 53%, barely above chance. The collapse put the hardest category on the majority side, where its errors are easy to miss.</p><p>I kept the original six-class label on every row throughout the pipeline, even though training only used the binary target. That one extra column made the per-class analysis later possible. <strong>If you collapse labels, keep the originals.</strong></p><h3>Imbalance needs two fixes, not one</h3><p>At 35/65, plain cross-entropy drifts toward predicting FAKE for everything, because that is a cheap way to lower the loss. The standard remedy is class weighting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*8yvTXEUUs4tAVPJ0RXOeew.png" /></figure><p>The formula n / (2 × class_count) gives each class the same total influence regardless of how many examples it has. REAL examples count 1.407×, FAKE examples 0.776×.</p><p><strong>Here is the part most tutorials leave out.</strong> Weighting the loss while still selecting the checkpoint by accuracy sets the two against each other. The loss is pushing the model to treat both classes as equally important; the selection metric is rewarding whichever epoch predicted the majority class most often. You can end up weighting the loss correctly and then picking the epoch where the weighting worked <em>least</em> well.</p><p>So the selection metric has to move too:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*KyauEK602KeLq1QoevMpfA.png" /></figure><p><strong>Macro-F1 averages the F1 of each class without regard to class size.</strong> A model that answers FAKE every time scores zero F1 on REAL, which drags its macro-F1 down to 0.391 no matter how good its accuracy looks. Accuracy cannot see that failure. Macro-F1 cannot miss it.</p><h3>Every hyperparameter, and the reason for it</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*UOqLRAJTrvKtL79omc-RHA.png" /></figure><p>Three of these deserve more than a row.</p><p><strong>Learning rate: 2e-5 because this is full fine-tuning.</strong> Every one of the 125M parameters receives an update, so each step moves a lot of the model. Too large a rate and the pretrained representations get destroyed — catastrophic forgetting. The contrast with LoRA is instructive: LoRA trains roughly 0.3M parameters, about 0.2% of the model, so each one has to carry far more of the update. <strong>LoRA typically wants 1e-4 to 5e-4, ten to twenty times higher.</strong> Running LoRA at 2e-5 is one of the most common reasons a PEFT run appears to learn nothing.</p><p><strong>Warmup matters here for a specific reason.</strong> Loading roberta-base into a sequence-classification head prints this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*gzllQGLfzynyzknZtMYOMA.png" /></figure><p>The pretrained language-modelling head is discarded and a fresh classification head is created with random weights. For the first several hundred steps, gradients flowing back from that random head are mostly noise. Without warmup, that noise arrives at full learning rate and damages encoder representations that cost enormous compute to learn. <strong>Warmup lets the head become roughly sensible before the encoder is asked to move much.</strong></p><p><strong>Dynamic padding was the largest speed win.</strong> Padding every sequence to max_length=128 when the median statement is 22 tokens means most of each batch is padding — real compute spent on &lt;pad&gt; tokens. DataCollatorWithPadding pads only to the longest sequence in each batch:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*o4XQ5OUBqjpukrf5GwTtzw.png" /></figure><p>This cut training from roughly 20 minutes to 5.5, with identical results.</p><h3>Measure the baselines before you train anything</h3><p>I ran two baselines before writing a single line of training code. This took under two minutes and it reframed the entire project.</p><p><strong>Baseline 1 — answer FAKE every time.</strong> No model, no learning, one line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*ce-bRDEFWyGdDsAP2eiZug.png" /></figure><p><strong>64.15% accuracy.</strong> That is the number any model has to beat before it has demonstrated anything at all.</p><p><strong>Baseline 2 — TF-IDF plus logistic regression.</strong> Word and bigram counts into a linear classifier. No neural network, no GPU, 1.8 seconds to train:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*zmB4gvuOapX1T2AdgRe-ZA.png" /></figure><p>This one matters more than the first. The majority baseline tells you the floor; <strong>the bag-of-words baseline tells you how much of the task is solvable by surface word statistics alone.</strong> If a transformer barely beats it, the transformer is mostly doing lexical matching too, whatever you hoped it was learning.</p><p>Knowing both numbers before training changed how I read every result afterwards. When the fine-tuned model came back at 64.5% accuracy, I already knew that was 0.4 points above a trivial rule rather than a respectable score. <strong>Without the baselines I would have reported 64.5% as a result. With them, I had to go find the real story.</strong></p><h3>The results, and the two stories they tell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*AbslVt0C9Gy36DvG7bhGyw.png" /></figure><p>The grey bars barely move across all three. The blue bars tell you what actually happened.</p><p>Two honest summaries of the same run:</p><p>“The fine-tuned model reaches 64.5% accuracy, beating a trivial baseline by 0.4 points. Three days of work for a rounding error.”</p><p>“The fine-tuned model reaches 0.635 macro-F1 against 0.391 for the trivial baseline — a gain of 0.244, and it beats a strong bag-of-words baseline by 0.033.”</p><p><strong>Both are true.</strong> Which one you publish is a choice, and it is the choice that separates a model card you can trust from one you cannot.</p><p>The per-class report shows where the asymmetry lives:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*kDq1xAs96cOEQPVv5DNhJw.png" /></figure><p><strong>REAL precision is 0.503.</strong> When this model says a statement is real, it is right about half the time — no better than a coin flip. FAKE precision is 0.775, substantially better. The model is far more useful as a flagging tool than as a clearing tool, and that asymmetry is invisible in the single accuracy figure.</p><p>The ROC AUC of 0.696 is worth noting separately. <strong>AUC is threshold-independent</strong>, so it measures whether the model ranks fake claims above real ones regardless of where you draw the line. At 0.696 it clearly ranks better than chance, which means the ranking is more trustworthy than any individual verdict.</p><h3>Interrogating the model</h3><p>Four checks, none of which take long, all of which told me something the headline metrics hid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*HvG893_N3L6MHrFKQinbiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*vi4vMIlTCcjagkWEJhMb1g.png" /></figure><p><strong>The ends of the scale separate; the middle does not.</strong> pants-fire at 0.750 and true at 0.687 are the model’s best categories. half-true at 0.532 is essentially a coin flip, and its mean P(FAKE) of 0.534 shows the model has almost no opinion about those statements at all.</p><p>This is a sensible result rather than a defect. Distinguishing half-true from mostly-true is an editorial judgement that PolitiFact’s writers make using context, sourcing and intent. <strong>None of that is recoverable from 18 words of text</strong>, and it would be more suspicious if the model claimed otherwise.</p><h3>Threshold sweep</h3><p>The 0.5 cutoff is a convention inherited from argmax, not a finding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*FTCCj5QGRdpI1XWsMRRJMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*Sj0aH9sqpOGA_GIcfUvSRQ.png" /></figure><p><strong>F1 peaks at 0.785 with a 0.25 cutoff — 0.09 above the default.</strong> That gain was sitting there for free, found by a loop over twenty values.</p><p>The right threshold depends on what the model is for. Triaging claims for a human reviewer wants high recall, so 0.25. Auto-flagging with no review wants high precision, so 0.80 and accept that you catch only 14%. <strong>Shipping a single hard-coded 0.5 silently makes that decision for every downstream user.</strong> I exposed P(FAKE) instead.</p><h3>Calibration</h3><p>A confidence score is only useful if it means something. Expected calibration error bins predictions by confidence and compares each bin’s stated confidence to its actual accuracy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*6iBxIIqABoGGB358LoCAFQ.png" /></figure><p><strong>ECE 0.0425</strong> means that across bins, stated confidence is off by about 4 percentage points on average. That is better than I expected — neural classifiers are usually far more overconfident. The class weighting plausibly helped, since it stops the model from driving all probability mass toward the majority class.</p><h3>Reading the mistakes</h3><p>The check that taught me the most. I sorted all 456 errors by confidence and read the top ones:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*UqfwvRkHBP_Pd3KRO2Rf2g.png" /></figure><p><strong>Every one of them is a true statement about a politically charged subject.</strong> The pattern is unmistakable: the model learned that controversial political language predicts a false rating. That is a reasonable correlation in the training data — PolitiFact selects inflammatory claims for fact-checking — but it is emphatically not fact-checking.</p><p>No aggregate metric would have surfaced this. <strong>It took twenty minutes of reading actual rows</strong>, and it is now the first thing in the model card’s limitations section.</p><h3>Shipping it into a browser</h3><p>A model nobody can try is a model nobody believes. My original plan was a Gradio Space, but Hugging Face now requires a paid plan for Gradio and Docker Spaces — <strong>static Spaces remain free for everyone.</strong></p><p>That constraint produced a better result. A static Space can run the model client-side with <a href="https://github.com/huggingface/transformers.js">Transformers.js</a>, which means no server, no cold starts, no sleeping after 48 hours of inactivity, and no per-user cost. It needs two steps.</p><h3>ONNX export</h3><p>PyTorch weights are just numbers; the operations are defined in Python. <strong>ONNX packages the computation graph and the weights into one file</strong>, so a runtime that has never heard of PyTorch can execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*qkZFjrRZnv2l0P-vqAwV4g.png" /></figure><p><strong>dynamic_axes is the line that matters.</strong> Without it the graph is frozen at the dummy input’s exact batch size and sequence length, and the browser could only ever score one sentence of exactly that length.</p><h3>Quantization</h3><p>The fp32 export is 499 MB. Nobody waits for that. Dynamic quantization stores each weight as int8 with a scale factor per tensor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*hOa9Cq5x27rgQnyLtCkAsw.png" /></figure><p><strong>499 MB becomes 125 MB</strong> — the difference between a demo people try and one they abandon. On mobile it is also the difference between working and exhausting the tab’s memory.</p><p>The cost is precision. So I verified before publishing anything, comparing PyTorch, fp32 ONNX and int8 ONNX on the same inputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*55NzF7n_YrdRzXZLQNS84Q.png" /></figure><p>Gaps under 0.002, well inside the 0.05 threshold I set as an assert. <strong>If the check fails, nothing uploads.</strong> A broken model in a public repo is worse than no model.</p><p>The Space itself is one index.html: Transformers.js from a CDN, the model pulled from the Hub, scored locally. Long text is chunked at sentence boundaries and averaged, since the model only reads 128 tokens at a time. The threshold slider from the sweep is exposed directly in the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*GYLiV-D2stsAQDzZqJBefA.png" /></figure><p>The interface deliberately says <em>reads false</em> rather than <em>FAKE</em>. The model measures resemblance to debunked claims, and the wording should not promise more than that.</p><h3>What I would carry to the next fine-tune</h3><p><strong>Resolve categorical labels by name, never by index.</strong> The integer encoding belongs to whoever wrote the loader and can change between dataset versions. Mine was inverted and nothing in the training output complained.</p><p><strong>Measure baselines before training.</strong> Two minutes of work that determines whether every later number means anything. A model that cannot beat TF-IDF is doing lexical matching with extra steps.</p><p><strong>Pick the metric that can see your failure mode.</strong> On imbalanced data, accuracy cannot distinguish a working model from a constant predictor. Weighting the loss while selecting on accuracy sets the two halves of your pipeline against each other.</p><p><strong>Read the mistakes.</strong> Twenty minutes with the highest-confidence errors told me more about what the model learned than every aggregate metric combined. Nothing else surfaced the political-language bias.</p><p><strong>Sweep the threshold.</strong> 0.5 is inherited from argmax, not derived from your data. Mine gave up 0.09 F1 for no reason.</p><p><strong>Verify before publishing.</strong> Export and quantization are lossy steps. An assert comparing against the original costs one cell and prevents shipping something broken.</p><h3>On the number itself</h3><p>0.635 macro-F1 is not impressive, and I am not going to dress it up. <strong>LIAR is hard for a reason</strong>: predicting a fact-checker’s verdict from the wording of a claim, with no access to the facts, has a low ceiling. Published binary results sit broadly in this range.</p><p>What I would push back on is the instinct to hide that. A model card claiming 95% accuracy on LIAR almost always means an inverted label map, a leak, or accuracy quoted against an unstated 64% floor. <strong>The honest number with its baselines attached is more useful than an impressive number with nothing to anchor it.</strong></p><h3>Links</h3><p>• Model, with full charts, per-class results and limitations: <a href="https://huggingface.co/emonHasan01/liar-roberta">emonHasan01/liar-roberta</a></p><p>• Dataset: <a href="https://huggingface.co/datasets/liar">LIAR</a> (Wang, ACL 2017)</p><p>• Base model: <a href="https://huggingface.co/roberta-base">roberta-base</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cac4b8112bcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why a 92% Accuracy Model Still Created a Terrible User Experience]]></title>
            <link>https://medium.com/@emon.mlengineer/why-a-92-accuracy-model-still-created-a-terrible-user-experience-f1d01a42f691?source=rss-b16daa9ff5c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1d01a42f691</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[fine-tuning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm-evaluation]]></category>
            <dc:creator><![CDATA[Emon ML Engineer]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 21:53:36 GMT</pubDate>
            <atom:updated>2026-06-11T21:53:36.469Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*HFIuuY9wilFnLCH7GbJYpg.png" /></figure><p>𝙄 𝙎𝙩𝙤𝙥𝙥𝙚𝙙 𝙏𝙧𝙪𝙨𝙩𝙞𝙣𝙜 𝘼𝙄 𝘽𝙚𝙣𝙘𝙝𝙢𝙖𝙧𝙠𝙨</p><p>My model scored 92% 𝙖𝙘𝙘𝙪𝙧𝙖𝙘𝙮. Real users still hated it.</p><p>At first, I couldn’t understand why. I had spent weeks training and evaluating the model.</p><p>The metrics looked great:</p><p>‣ 92% 𝘼𝙘𝙘𝙪𝙧𝙖𝙘𝙮</p><p>‣ 𝙎𝙩𝙧𝙤𝙣𝙜 𝙋𝙧𝙚𝙘𝙞𝙨𝙞𝙤𝙣 &amp; 𝙍𝙚𝙘𝙖𝙡𝙡</p><p>‣ 𝘾𝙡𝙚𝙖𝙣 𝘾𝙤𝙣𝙛𝙪𝙨𝙞𝙤𝙣 𝙈𝙖𝙩𝙧𝙞𝙭</p><p>‣ 𝙎𝙤𝙡𝙞𝙙 𝙑𝙖𝙡𝙞𝙙𝙖𝙩𝙞𝙤𝙣 𝙍𝙚𝙨𝙪𝙡𝙩𝙨</p><p>From a machine learning perspective, everything seemed successful. Then I let real users try the system. That’s when reality hit.</p><p>Users weren’t asking: “𝙒𝙝𝙖𝙩’𝙨 𝙩𝙝𝙚 𝙢𝙤𝙙𝙚𝙡 𝙖𝙘𝙘𝙪𝙧𝙖𝙘𝙮?”</p><p>They were asking:</p><p>‣ Why is it taking so long to respond?</p><p>‣ Why did it fail on my PDF?</p><p>‣ Why doesn’t it understand my question?</p><p>‣ Why does it sometimes give irrelevant answers?</p><p>‣ Why do I have to retry multiple times?</p><p>The model was performing well. The system wasn’t.</p><p>That experience taught me something important: 𝙐𝙨𝙚𝙧𝙨 𝙙𝙤𝙣’𝙩 𝙚𝙭𝙥𝙚𝙧𝙞𝙚𝙣𝙘𝙚 𝙮𝙤𝙪𝙧 𝙢𝙤𝙙𝙚𝙡. 𝙐𝙨𝙚𝙧𝙨 𝙚𝙭𝙥𝙚𝙧𝙞𝙚𝙣𝙘𝙚 𝙮𝙤𝙪𝙧 𝙚𝙣𝙩𝙞𝙧𝙚 𝙨𝙮𝙨𝙩𝙚𝙢.</p><p>A model can achieve 92% accuracy and still create a poor user experience if:</p><p>‣ Retrieval quality is weak</p><p>‣ Context is incomplete</p><p>‣ Latency is high</p><p>‣ Error handling is missing</p><p>‣ Tool calls fail</p><p>‣ Memory is inconsistent</p><p>‣ Responses are difficult to understand</p><p>Since then, I started measuring different things:</p><p>‣ 𝙏𝙖𝙨𝙠 𝙎𝙪𝙘𝙘𝙚𝙨𝙨 𝙍𝙖𝙩𝙚</p><p>‣ 𝙀𝙣𝙙-𝙩𝙤-𝙀𝙣𝙙 𝙇𝙖𝙩𝙚𝙣𝙘𝙮</p><p>‣ 𝙍𝙚𝙩𝙧𝙞𝙚𝙫𝙖𝙡 𝙍𝙚𝙡𝙚𝙫𝙖𝙣𝙘𝙚</p><p>‣ 𝙐𝙨𝙚𝙧 𝙎𝙖𝙩𝙞𝙨𝙛𝙖𝙘𝙩𝙞𝙤𝙣</p><p>‣ 𝙀𝙧𝙧𝙤𝙧 𝙍𝙚𝙘𝙤𝙫𝙚𝙧𝙮 𝙍𝙖𝙩𝙚</p><p>‣ 𝙋𝙧𝙤𝙙𝙪𝙘𝙩𝙞𝙤𝙣 𝙍𝙚𝙡𝙞𝙖𝙗𝙞𝙡𝙞𝙩𝙮</p><p>These metrics revealed more about the system than accuracy ever did.</p><p>One lesson I keep coming back to: 𝙈𝙖𝙘𝙝𝙞𝙣𝙚 𝙇𝙚𝙖𝙧𝙣𝙞𝙣𝙜 𝙢𝙤𝙙𝙚𝙡𝙨 𝙨𝙤𝙡𝙫𝙚 𝙥𝙧𝙚𝙙𝙞𝙘𝙩𝙞𝙤𝙣𝙨. 𝘼𝙄 𝙨𝙮𝙨𝙩𝙚𝙢𝙨 𝙨𝙤𝙡𝙫𝙚 𝙪𝙨𝙚𝙧 𝙥𝙧𝙤𝙗𝙡𝙚𝙢𝙨.</p><p>And users only care about the second one.</p><p>#AI #MachineLearning #GenerativeAI #AIEngineering #MLOps #LLM #RAG #AgenticAI #LangGraph #SoftwareEngineering</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1d01a42f691" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When LLM Fine-Tuning Fails: A Data-Centric Debugging Story]]></title>
            <link>https://medium.com/@emon.mlengineer/when-llm-fine-tuning-fails-a-data-centric-debugging-story-83ac6f4b7a19?source=rss-b16daa9ff5c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/83ac6f4b7a19</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[generative-ai-use-cases]]></category>
            <category><![CDATA[model-training]]></category>
            <category><![CDATA[lora]]></category>
            <category><![CDATA[data-centric-ai]]></category>
            <dc:creator><![CDATA[Emon ML Engineer]]></dc:creator>
            <pubDate>Tue, 21 Apr 2026 15:57:29 GMT</pubDate>
            <atom:updated>2026-04-21T15:57:29.817Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>When LLM Fine-Tuning Fails: A Data-Centric Debugging Story</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oeIz4Fl6ehcldCSOiIwAPg.jpeg" /></figure><p>Breaking an LLM Fine-Tuning Failure: What Actually Fixed It</p><p>Over the past few weeks, I was working deeply on an LLM fine-tuning pipeline.<br>At first, everything looked correct:</p><ul><li>training loss was decreasing</li><li>metrics were stable</li><li>no obvious signs of overfitting</li></ul><p>But when tested on real-world prompts, the outputs were not usable:</p><ul><li>hallucinations</li><li>poor instruction following</li><li>inconsistent responses</li></ul><p>In short, the model was “training”, but it was not actually “learning”.</p><p>That’s when the real debugging started.</p><p>Initially, I assumed it was a model-related issue.<br>I experimented with hyperparameter tuning, learning rate adjustments, and LoRA configurations multiple times. There was no meaningful improvement.</p><p>So I shifted approach and began auditing the entire pipeline:</p><ul><li>manually inspected the dataset line by line</li><li>analyzed prompt formatting</li><li>evaluated output distributions</li><li>ran repeated real-world sampling tests</li></ul><p>At this point, the root cause became clear:</p><p>The issue was not the model. The issue was the data.</p><p>Specifically:</p><ul><li>inconsistent instruction formats</li><li>weak input-output alignment</li><li>noisy and low-quality samples</li><li>mixed tasks within the same dataset</li></ul><p>The model was not failing — it was confused about what it was supposed to learn.</p><p>I then made a complete shift to a data-centric strategy:</p><ul><li>restructured the dataset into a strict instruction → response schema</li><li>aggressively removed low-quality samples</li><li>added manually curated, high-quality examples</li><li>standardized prompt templates</li><li>created a real-world validation set (not synthetic, actual queries)</li></ul><p>After that, I re-ran LoRA-based SFT.</p><p>The results were significantly different:</p><ul><li>outputs became stable</li><li>hallucinations reduced noticeably</li><li>instruction-following improved</li><li>real-world usability increased substantially</li></ul><p>Key takeaway:</p><p>In LLM engineering, the hardest problem is not the model — it is data design and alignment. If you train a model on poorly structured data, it will learn the wrong patterns very efficiently. Better data is more important than a bigger model.</p><p>Currently exploring deeper work in:</p><ul><li>data-centric LLM training</li><li>alignment (SFT → DPO)</li><li>evaluation pipelines</li><li>agentic AI systems (LangGraph)</li></ul><p>This process was not easy.<br>It involved repeated failure, rethinking, and rebuilding.</p><p>But this is where real engineering happens.</p><p>If you are working with LLMs, what has been your biggest challenge so far?</p><p>#LLM #GenerativeAI #MachineLearning #AIEngineering #AgenticAI #RAG #DeepLearning</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83ac6f4b7a19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a Simple Tool Routing Decision Impacted My AI Chatbot in Production]]></title>
            <link>https://medium.com/@emon.mlengineer/how-a-simple-tool-routing-decision-impacted-my-ai-chatbot-in-production-bba46ce6508c?source=rss-b16daa9ff5c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba46ce6508c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai-tools]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[systems-thinking]]></category>
            <dc:creator><![CDATA[Emon ML Engineer]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 08:13:08 GMT</pubDate>
            <atom:updated>2026-01-29T08:13:08.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*PSoKt9Vnei5_OdaS-EU-eQ.png" /></figure><h3>A Tool Routing Problem I Recently Faced While Building an AI Chatbot</h3><p>A few days ago, while working on a production AI chatbot, I started noticing some unusual behavior:</p><ul><li>Even simple questions were triggering the <strong>wrong tools</strong></li><li><strong>Unnecessary web searches</strong> were being called</li><li>Response time suddenly started increasing</li><li>API costs were slowly but noticeably going up</li></ul><p>At first, I assumed this was a <strong>model or prompt issue</strong>.<br>But after debugging the system more deeply, I realized the real problem was somewhere else.</p><p>Where was the real problem?</p><p>The root cause turned out to be our <strong>tool routing logic</strong>.</p><p>At that time, we were using:</p><ul><li>Keyword-based if/else logic</li><li>Hardcoded tool selection</li><li>Tool calls without any confidence or relevance checks</li></ul><h3>What went wrong because of this?</h3><p>As a result:</p><ul><li>Ambiguous queries were routed to the wrong tools</li><li>Expensive tools were called even when they weren’t needed</li><li>There was no fallback when a tool returned low-quality output</li></ul><p>The system worked in demos, but slowly broke down under real usage.</p><h3>How I solved the problem</h3><p>Instead of treating tool selection as a simple conditional check, I redesigned it as a <strong>decision-making problem</strong>.</p><p>Here’s what I changed:</p><ul><li>Introduced a dedicated <strong>Tool Router Agent</strong></li><li>Started scoring each tool based on:</li><li>Relevance to the query</li><li>Routing confidence</li><li>Cost and latency</li><li>Added explicit fallback paths for low-quality tool responses</li><li>Separated tool execution from the API layer</li></ul><h3>The outcome</h3><ul><li>Correct tool selection</li><li>Significantly lower latency</li><li>Controlled API costs</li><li>A chatbot that became far more <strong>reliable and predictable</strong></li></ul><h3>Key takeaway</h3><p><strong>Tool routing is not a helper function. </strong>It is a <strong>core system design problem</strong>.</p><p>If tool routing is weak, even the best LLM will fail in production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba46ce6508c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>