<?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 Muhammad Fahad on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Fahad on Medium]]></description>
        <link>https://medium.com/@f223442?source=rss-67953226201c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MaHd3JIZorECJl-L</url>
            <title>Stories by Muhammad Fahad on Medium</title>
            <link>https://medium.com/@f223442?source=rss-67953226201c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:49:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@f223442/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[I Built a RAG System That Detects Its Own Hallucinations]]></title>
            <link>https://medium.com/@f223442/i-built-a-rag-system-that-detects-its-own-hallucinations-9570f36d1d5f?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9570f36d1d5f</guid>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 23:15:05 GMT</pubDate>
            <atom:updated>2026-06-25T23:15:05.995Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCv__WhVVPs3Y0lhSLRJOg.png" /></figure><p>Most RAG pipelines generate an answer and ship it. This one generates, critiques, rewrites, and tries again — until it’s confident or honest enough to say “I don’t know.”</p><p>The problem with standard RAG</p><p>Every RAG pipeline has the same blind spot: it generates an answer and assumes it’s correct.</p><p>You retrieve chunks, stuff them into a prompt, get text back — and that text goes directly to the user. If the model hallucinates, confidently mixing retrieved facts with invented ones, there’s no safety net. The pipeline never checks its own work.</p><p>I wanted to fix that. The result is a self-healing RAG system built on LangGraph that retrieves, generates, critiques its own answer, rewrites the query on hallucination, and refuses to answer when the context is genuinely insufficient.</p><p>The architecture: a cyclic graph, not a pipeline</p><p>The key insight is to replace the linear chain with a stateful, cyclic graph. Here’s what the loop looks like:</p><p>Retrieve → Rerank → Generate → Critique → ↺ (rewrite or return)</p><p>Five nodes, one conditional edge that makes the whole thing self-healing:</p><p>1. Retrieve — Dense vector search over Qdrant. The query is embedded with all-MiniLM-L6-v2 (384 dimensions, fully local — no OpenAI embedding API needed).</p><p>2. Rerank — The top-k candidates go through Cohere Rerank, a cross-encoder that re-scores each chunk against the actual query. This is the single biggest precision lever: a BM25 or ANN search returns plausible chunks; a cross-encoder returns relevant ones.</p><p>3. Generate — The reranked context feeds a Groq-hosted Llama 3.3 70B. Fast, free-tier, and surprisingly good at instruction-following.</p><p>4. Critique (LLM-as-judge) — A second LLM call grades the answer against the retrieved context. It returns a JSON verdict: grounded, hallucinated, or insufficient. I strip markdown fences and handle malformed JSON before parsing, because LLMs are surprisingly bad at following their own format instructions.</p><p>5. Route — The conditional edge reads the verdict:</p><p>• Grounded → return the answer</p><p>• Hallucinated → rewrite the query and retry (up to 3 times)</p><p>• Insufficient → return an honest “I don’t have enough context”</p><p>The graph is compiled once, cached with <a href="http://twitter.com/lru_cache">@lru_cache</a>, and reused across requests. LangGraph handles the state dict and loop termination.</p><p>The hardest parts</p><p>Qdrant’s API changed. The .search() method was removed in newer client versions in favor of .query_points(). I wrote a dual-path helper that detects which API is available at runtime so the code works across versions.</p><p>Cohere’s trial key is rate-limited. 10 requests per minute. Running 25-question evaluations means hitting the cap constantly. I added exponential backoff with a 6-second base delay and up to 6 retries — enough to pace the eval within the limit without crashing.</p><p>ragas 0.4.x is broken on langchain v1. It unconditionally imports langchain_community.chat_models.vertexai, which langchain v1 removed. The fix: inject a lightweight stub module into sys.modules before importing ragas. It’s a two-line shim that avoids a 200-line dependency downgrade.</p><p>Streamlit secrets don’t reach config at import time. My Settings dataclass reads from os.environ at import — but Streamlit loads st.secrets after the module tree is already initialized. The fix is a bridge at the top of the app that copies every string secret into os.environ (with .strip() to catch whitespace from pasted API keys) before any pipeline import runs.</p><p>Evaluation with RAGAS</p><p>I scored the system on a 25-question golden dataset using four RAGAS metrics:</p><p>• Faithfulness — are the claims in the answer supported by the retrieved context?</p><p>• Answer relevancy — does the answer address the question?</p><p>• Context recall — did retrieval surface the chunks needed to answer correctly?</p><p>• Context precision — are the retrieved chunks actually relevant (low noise)?</p><p>The entire eval pipeline runs on Groq + local sentence-transformers. No OpenAI key required.</p><p>The stack</p><p>• LangGraph — stateful cyclic graph execution</p><p>• Qdrant — vector store (cloud or local)</p><p>• Cohere Rerank — cross-encoder precision boost</p><p>• Groq + Llama 3.3 70B — LLM (swappable via LLM_PROVIDER env var)</p><p>• sentence-transformers — local embeddings, no API cost</p><p>• RAGAS — evaluation framework</p><p>• FastAPI — REST API</p><p>• Streamlit — demo UI</p><p>What I’d change</p><p>The self-healing loop adds latency two LLM calls per hop instead of one. For a production system, I’d add streaming so the UI shows progress rather than a spinner, and I’d move the critic to a cheaper/faster model since it just needs to parse JSON and check grounding.</p><p>I’d also replace the fixed golden dataset with continuous online evaluation: sample a percentage of live queries, grade them asynchronously, and feed low-scoring ones back into a fine-tuning pipeline.</p><p>The live demo is at self-healing-rags.streamlit.app and the full source is on GitHub at fahadcs321/self-healing-rag. The CI pipeline runs lint and 52 unit tests on every push; the RAGAS evaluation job is gated behind a repo variable so it only runs when I explicitly want to spend the API quota.</p><p>If you’re building RAG systems and not checking your own answers, you’re shipping hallucinations you’ll never see.</p><p>Github: <a href="https://github.com/fahadcs321/self-healing-rag">https://github.com/fahadcs321/self-healing-rag</a><br>Linkedin: <a href="https://www.linkedin.com/in/fahad-muhammad-cs/">https://www.linkedin.com/in/fahad-muhammad-cs/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9570f36d1d5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fine-Tuning a Vision-Language Model on a Free Kaggle GPU: QLoRA Meets Document AI]]></title>
            <link>https://medium.com/@f223442/fine-tuning-a-vision-language-model-on-a-free-kaggle-gpu-qlora-meets-document-ai-7baa6469db15?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7baa6469db15</guid>
            <category><![CDATA[vlm]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Tue, 12 May 2026 06:09:06 GMT</pubDate>
            <atom:updated>2026-05-12T06:09:06.936Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How I taught Qwen2-VL to convert academic paper scans into clean Markdown — in 3 epochs, on a T4.</em></p><h3>The Problem Worth Solving</h3><p>Every research lab, archive, and publishing house has the same headache: thousands of scanned document pages locked in image format — unreadable to search engines, inaccessible to language models, impossible to edit programmatically. Tools like Meta’s Nougat exist for this, but deploying them at scale is compute-heavy and inflexible. What if we could fine-tune a small, open-source vision-language model to do the same job — trained on free hardware, in an afternoon?</p><p>That’s the question I set out to answer for Assignment 5 of my Generative AI course at FAST-NUCES. The result: a fine-tuned Qwen2-VL model that converts academic paper page images into structured Markdown — with over 2× the ROUGE score of the zero-shot baseline.</p><h3>The Stack</h3><ul><li><strong>Model:</strong> Qwen2-VL-2B-Instruct — a 2B-parameter vision-language model from Alibaba’s Qwen team, strong on OCR and document layout understanding</li><li><strong>Fine-tuning:</strong> QLoRA (4-bit NF4 quantization + LoRA adapters via PEFT)</li><li><strong>Dataset:</strong> Nougat — arXiv paper page images paired with .mmd Markdown files</li><li><strong>Platform:</strong> Kaggle free tier (2× NVIDIA T4 GPUs, 16 GB VRAM each)</li><li><strong>Evaluation:</strong> ROUGE-1 and ROUGE-L F1 scores</li><li><strong>Deployment:</strong> Gradio app with a public share link</li></ul><h3>The Dataset</h3><p>The Nougat dataset pairs scientific paper page images with their Markdown transcriptions — equations in LaTeX, section headings, figure captions, tables, and all. I sampled 3,000 pairs and applied an 80/20 train/validation split.</p><p>Image preprocessing uses letterbox resizing: scale the longest side to 256 pixels, then pad with white pixels to reach a 256×256 square. This preserves the original layout proportions without distorting text lines or equation symbols — a detail that matters more than it sounds when your model needs to distinguish a minus sign from an em dash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oFddPLYvdoiKlSagKwf1Rg.png" /></figure><h3>QLoRA: Making 2B Parameters Trainable on a T4</h3><p>Full fine-tuning a 2B-parameter model in FP32 requires ~16 GB of VRAM for weights alone — before gradients, optimizer states, or activations. QLoRA collapses this through two compounding techniques.</p><p><strong>4-bit NF4 quantization</strong> stores the frozen base model weights in NormalFloat-4 format — theoretically optimal for the near-Gaussian weight distributions of pretrained transformers. Memory usage drops ~75% vs FP32, and the base weights are never updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9hCGd3n4PAiit8Si1kE8g.png" /></figure><p><strong>LoRA adapters</strong> inject small trainable rank-decomposition matrices at each attention and MLP layer. The weight update is W’ = W + B×A, where B ∈ ℝ^(d×r) and A ∈ ℝ^(r×d), with rank r=16. Only ~28M adapter parameters — roughly 1.4% of total — receive gradient updates. Double quantization further saves ~0.4 bits/parameter by quantizing the quantization constants themselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRp1--hPJT1id1vwALRScQ.png" /></figure><h3>The Training Pipeline</h3><p>Qwen2-VL expects inputs in ChatML format — a structured conversation with typed content blocks per role:</p><pre>System:    &quot;You are an expert document parser. Convert...&quot;<br>User:      [image token] + &quot;Convert this image to Markdown...&quot;<br>Assistant: [ground truth markdown — loss computed here only]</pre><p>The critical detail is <strong>label masking</strong>: system and user tokens are set to -100 so the cross-entropy loss is computed only on the assistant’s markdown output. Without this, the model wastes capacity learning to predict the prompt it already sees — a subtle bug with a large performance cost.</p><p>Training configuration: AdamW at lr=2e-4 with cosine decay and 10% linear warmup, gradient accumulation over 4 steps (effective batch size 8), gradient norm clipping at 1.0, and checkpoint selection by validation loss across 3 epochs.</p><h3>Results</h3><p>After 3 epochs on 2,400 training pairs, the fine-tuned model achieved:</p><ul><li><strong>ROUGE-1: 0.41</strong>–40%+ unigram overlap with ground-truth Markdown</li><li><strong>ROUGE-L: 0.37</strong>–37%+ longest common subsequence match</li><li>Validation loss converged smoothly; no signs of overfitting</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*cLu0oMp_CW944jd5ZOmOIg.png" /></figure><p>The zero-shot base model (no fine-tuning) scored ~0.18 on ROUGE-1. Fine-tuning more than doubled the score. Qualitatively, the gap is even wider: the base model often outputs unstructured prose or abandons LaTeX notation entirely. The fine-tuned model produces properly headed documents with equations, bullet lists, and tables intact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0j11NqoV--IUNSx6FeW5mQ.png" /></figure><p>Three bonus experiments added further insight. Zero-shot vs fine-tuned comparisons showed the adapter’s contribution clearly. A prompt-style comparison (minimal vs detailed vs step-by-step) revealed that more structured instructions consistently outperform brief ones. And epoch-count analysis confirmed that 3 epochs hit the sweet spot: 2 epochs underfit, 5 epochs risk overfitting on a 3,000-sample dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QUz6u5xLnyz6ieTB5O3kEg.png" /></figure><h3>The Gradio Demo</h3><p>Deployment took one cell. demo.launch(share=True) creates a public ngrok URL — no server, no port-forwarding. The interface offers two tabs: a rendered Markdown preview and a raw text view for copy-pasting, with example images pre-loaded from the validation set so evaluators can test immediately.</p><h3>Three Things That Surprised Me</h3><p><strong>Label masking matters more than you’d expect.</strong> Skipping it doesn’t crash training — it silently degrades it. The model learns to predict the instruction string rather than generate content. A small implementation detail with an outsized effect on output quality.</p><p><strong>Image resolution is a real tradeoff.</strong> Larger images preserve more text detail but expand the visual token count dramatically, inflating context length and slowing training. The 256×256 letterbox was the pragmatic sweet spot between fidelity and speed.</p><p><strong>Greedy decoding outperforms sampling here.</strong> do_sample=False with repetition_penalty=1.1 consistently produced cleaner, more structured Markdown than temperature-based sampling. For structured prediction tasks, determinism is often the right call.</p><h3>Final Thoughts</h3><p>Fine-tuning a vision-language model for document parsing is now genuinely within reach — no research lab budget, no custom hardware, no multi-day runs. Three epochs on Kaggle free compute, 3,000 document pairs, and a QLoRA recipe that fits in a single readable notebook.</p><p>If you’re working on document digitization, academic paper processing, or any task that requires reading structured content from images, the Qwen2-VL + QLoRA stack is one worth adding to your toolkit. The code is clean, the results are real, and the demo takes about 30 seconds to spin up.</p><p>Full notebook in the references below. Questions welcome in the comments.</p><p><a href="https://github.com/fahadcs321/VLM-s/tree/main">https://github.com/fahadcs321/VLM-s/tree/main</a></p><p><em>Tags: Machine Learning · NLP · Computer Vision · Deep Learning · Open Source · Tutorial</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7baa6469db15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Teaching a Neural Network to Sketch — Without Ever Showing It a Pair]]></title>
            <link>https://medium.com/@f223442/teaching-a-neural-network-to-sketch-without-ever-showing-it-a-pair-f0cab75bc172?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0cab75bc172</guid>
            <category><![CDATA[cyclegan]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Sun, 19 Apr 2026 16:35:05 GMT</pubDate>
            <atom:updated>2026-04-19T16:35:05.940Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I built a CycleGAN from scratch to translate between two sketch domains, and what I learned about unpaired image translation along the way.</h3><p>Imagine asking a student to learn French by handing them a pile of English books and a pile of French books — separately, with no translations between them. That is essentially what <strong>CycleGAN</strong> does with images.</p><p>In this project, I built a CycleGAN from scratch in PyTorch to learn a bidirectional mapping between two sketch domains — detailed art-school sketches from <strong>TU-Berlin</strong> and 20-second mobile doodles from <strong>Google QuickDraw</strong> — without ever showing the model a paired example. The whole thing ran on Kaggle’s free dual-T4 GPU tier in under two hours.</p><p>By the end of this post, you will understand:</p><ul><li>Why unpaired image-to-image translation is fundamentally different from supervised translation</li><li>How cycle consistency replaces paired supervision</li><li>The practical tricks that separate “GAN technically runs” from “GAN actually converges”</li><li>How the model did on SSIM, PSNR, and visual inspection</li></ul><p>If you just want the code, the full notebook and deployed Gradio app are linked at the bottom.</p><h3>The Problem: Translation Without Parallel Text</h3><p>Most image translation models are trained on pairs. If you want to colourise a black-and-white photo, you feed the network thousands of (grayscale, colour) pairs and let supervised learning do its thing.</p><p>But what if you do not have pairs? What if you have a stack of real-world horse photos and a stack of zebra photos from completely different contexts and cannot possibly match them one-to-one? This is the setting CycleGAN was designed for.</p><p>The original CycleGAN paper (Zhu et al., 2017) proposed a wonderfully elegant idea: if you learn <strong>two</strong> generators — one for each direction — you can use the composition of both as a proxy for supervision.</p><blockquote><em>Translate an image to the other domain, then back. The reconstruction should match the original.</em></blockquote><p>This “cycle consistency” constraint replaces paired data.</p><h3>The Datasets: Two Flavours of Sketch</h3><p>I deliberately picked two sketch sources rather than sketch-versus-photo, to make the mapping learnable but not trivial.</p><p><strong>TU-Berlin Sketch Dataset</strong> — 20,000 carefully drawn sketches across 250 object categories (flying saucer, ashtray, scissors, bench…). Each is 1111×1111 pixels, drawn by humans over tens of seconds with detail like internal contours and hatching. I pulled this straight from Hugging Face with load_dataset(&quot;sdiaeyu6n/tu-berlin&quot;).</p><p><strong>Google QuickDraw</strong> — 50 million stroke-based doodles, each drawn in 20 seconds on a mobile screen by Quick, Draw! players. The dataset ships as JSON stroke arrays which I rasterised to 256×256 PNGs.</p><p>I sampled 2,000 TU-Berlin sketches (Domain A) and 1,700 QuickDraw doodles (Domain B).</p><p><strong>TU-Berlin — deliberate, detailed human drawings:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_LKpCXLxHORibElnmhqAg.png" /></figure><p><strong>QuickDraw — fast, loose 20-second mobile doodles:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgoWCyQfPVzhhfURJh0DSQ.png" /></figure><p>The aesthetic difference is immediate: TU-Berlin sketches are deliberate and detailed, QuickDraw doodles are fast and loose.</p><h3>Is there actually a domain gap to learn?</h3><p>This is the question to ask before training any translation model. If your two domains are statistically identical, CycleGAN has nothing meaningful to translate.</p><p>I looked at two diagnostics:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7vmvc6vq8j_YBLFVjmK6HQ.png" /></figure><p>On the left, a log-scale pixel intensity histogram. Both domains are pure line art (huge mass at 0 and 255), but the ink tone and distribution differ subtly.</p><p>On the right is the more telling signal — <strong>ink density</strong>, the fraction of dark pixels per image. TU-Berlin sits at a mean of 1.8% dark pixels with tight variance. QuickDraw has a mean of 4.2% with a much wider spread. That makes intuitive sense: detailed art-school sketches use controlled, sparse lines; QuickDraw has messier strokes because people are drawing under a 20-second timer.</p><p>Those distributions do not overlap much. CycleGAN has room to learn.</p><h3>What the DataLoader Actually Produces</h3><p>CycleGAN uses <em>unpaired</em> data — meaning the DataLoader returns one random sketch and one independently sampled doodle per step. There is no correspondence between them, and the model never learns one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytQs34LYJFoWSLUNzl6J7Q.png" /></figure><p>This is the crucial mental model: at training time, the network literally does not know which doodle “goes with” which sketch, because nothing does.</p><h3>The Architecture</h3><p>CycleGAN uses four networks, trained jointly:</p><p>NetworkRoleG_ABGenerator: Sketch → DoodleG_BAGenerator: Doodle → SketchD_ADiscriminator: real sketch vs fake sketchD_BDiscriminator: real doodle vs fake doodle</p><h3>Generator — ResNet-6</h3><p>I followed the original recipe but reduced ResNet blocks from 9 to 6 to fit the Kaggle T4 memory budget:</p><pre>c7s1-64 → d128 → d256 → 6 × ResBlock(256) → u128 → u64 → c7s1-3</pre><p>Every convolution uses <strong>reflection padding</strong> (avoids edge artifacts) and <strong>instance normalization</strong> (per-sample, rather than per-batch — critical for style transfer). The output is passed through tanh so it lands in [-1, 1], matching the normalised inputs.</p><p>7.84M parameters per generator. Two generators plus two discriminators means roughly 20M trainable parameters total.</p><h3>Discriminator — 70×70 PatchGAN</h3><p>Instead of asking “is this whole image real or fake?”, a PatchGAN asks the question over overlapping 70×70 patches and outputs a grid of real/fake scores. At 128×128 input resolution, this gives a 14×14 patch map.</p><p>Why? Because <strong>textures are local</strong>. A full-image discriminator often ignores local artifacts to focus on global composition. PatchGAN forces it to scrutinise every region, which sharpens the generator’s output.</p><pre>class PatchDiscriminator(nn.Module):<br>    def __init__(self, in_ch=3, ndf=64, n_layers=3):<br>        super().__init__()<br>        layers = [nn.Conv2d(in_ch, ndf, 4, 2, 1), nn.LeakyReLU(0.2, True)]<br>        nf, nf_prev = ndf, ndf<br>        for i in range(1, n_layers):<br>            nf_prev, nf = nf, min(nf * 2, 512)<br>            layers += [<br>                nn.Conv2d(nf_prev, nf, 4, 2, 1),<br>                nn.InstanceNorm2d(nf), nn.LeakyReLU(0.2, True),<br>            ]<br>        ...</pre><h3>The Losses: Three Signals, One Objective</h3><p>CycleGAN’s total generator loss has three components:</p><p><strong>1. Adversarial loss (LSGAN variant)</strong> — fool the discriminators. I used MSE on patch outputs rather than binary cross-entropy, because LSGAN is visibly more stable and does not saturate.</p><p><strong>2. Cycle-consistency loss</strong> — the core idea. For every image x in Domain A, the round-trip G_BA(G_AB(x)) should match x. Mirrored for Domain B. I weighted this with <strong>λ = 10</strong>, the paper&#39;s default. This is by far the dominant signal early in training.</p><p><strong>3. Identity loss</strong> — feed a Domain-B image into the G_AB generator (which was trained to map A→B). It should come out unchanged, because it is already in the target domain. Weighted <strong>λ = 5</strong>. This stops the generators from inventing spurious colour shifts or tone changes.</p><p>Combined: <strong>L_G = L_GAN + 10 · L_cycle + 5 · L_identity</strong></p><h3>Training: Where GANs Actually Get Tricky</h3><p>Getting a GAN to converge is a different sport from training a normal supervised model. Three ingredients made the difference:</p><h3>1. Replay buffer</h3><p>The discriminator gets updated on a mix of real images and a rolling buffer of <em>past</em> fake images — not just whatever the generator produced this step. Without this, D oscillates badly: it becomes great at detecting whatever G output last minute, then G shifts its style and D has to relearn. With the buffer, D sees a stable distribution of fakes and settles.</p><pre>class ReplayBuffer:<br>    def __init__(self, max_size=50):<br>        self.data = []<br>    def push_and_pop(self, images):<br>        out = []<br>        for img in images.detach():<br>            if len(self.data) &lt; self.max_size:<br>                self.data.append(img); out.append(img)<br>            else:<br>                if random.random() &lt; 0.5:<br>                    i = random.randint(0, self.max_size - 1)<br>                    out.append(self.data[i].clone()); self.data[i] = img<br>                else:<br>                    out.append(img)<br>        return torch.cat(out, 0)</pre><h3>2. Mixed precision on dual GPUs</h3><p>Kaggle gives you two T4 GPUs for free. Using torch.cuda.amp for FP16 forward passes, I wrapped every model in nn.DataParallel to split each batch across both cards. This brought epoch time from ~6 minutes to under 3.5.</p><h3>3. Linear LR decay after warmup</h3><p>Run at the full 2e-4 learning rate for 15 epochs, then linearly decay to zero over the remaining 15. Adam with β = (0.5, 0.999) — the lower momentum β₁ is a standard GAN trick to prevent overshoot.</p><h3>Resumable checkpoints</h3><p>Kaggle sessions time out. I wrote the full state (models + optimisers + schedulers + AMP scalers + loss history) to disk every epoch so training picks up exactly where it left off on the next session. This turned out to be essential — I hit a Kaggle timeout at epoch 28 and resumed seamlessly.</p><h3>Results</h3><h3>Training Curves</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ME6pTaInSjqTiSoMb0DkeA.png" /></figure><p>Three plots tell the story:</p><ul><li><strong>Generator loss</strong> stabilises around 2.0 after the first epoch’s wild swings. The generator is not winning outright (loss should not go to zero) but holds its own against the discriminator.</li><li><strong>Discriminator loss</strong> drops from 0.63 to ~0.1 — D is confident, but not perfectly so, which is exactly the equilibrium you want.</li><li><strong>Cycle-consistency loss</strong> drops from 1.24 to 0.28 — a <strong>4.4× reduction</strong>. This is the actual supervision signal, and it is still trending downward at epoch 30. More epochs would help further.</li></ul><h3>Quantitative Evaluation</h3><p>Because this is <em>unpaired</em> translation, there is no ground-truth target for a translated image — you cannot ask “how close is G_AB(x) to the true x-in-domain-B&quot; because no such truth exists.</p><p>The right metric is the <strong>cycle reconstruction</strong>: given the round-trip G_BA(G_AB(x)), how close is the reconstruction to the original? This directly measures what cycle consistency optimises.</p><p>MetricDomain A (sketch ↺)Domain B (doodle ↺)<strong>SSIM</strong>0.9396<strong>0.9920PSNR</strong>27.60 dB<strong>29.44 dB</strong></p><p>A cycle SSIM above 0.94 on unpaired data is strong. The reason Domain B scores higher (0.99) is that QuickDraw doodles are sparser and structurally simpler — there is less for the generator to “lose” in the round-trip.</p><h3>Qualitative Results</h3><p>The numbers are fine, but what actually comes out?</p><p><strong>Sketch → Doodle → Sketch</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*KG-bh4UtNygHD6AXzw3S2g.png" /></figure><p>Column 1 is the original TU-Berlin sketch, column 2 is the QuickDraw-style translation, column 3 is the reconstruction. Notice how the translated middle column has <strong>thicker, bolder strokes</strong> — that is the QuickDraw style the generator learned. The reconstructions in column 3 recover the original fine detail remarkably well.</p><p><strong>Doodle → Sketch → Doodle</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*Xlodgc-gbYmcK9XlGLHCJA.png" /></figure><p>This direction is harder — the generator has to <em>add</em> detail to a minimal doodle. You can see it attempting to lighten strokes and soften the harsh QuickDraw marks. The reconstructions are near-perfect because the round-trip passes through a detailed intermediate state.</p><h3>Deployment: A Live Gradio App</h3><p>A CycleGAN that only runs in a notebook is not very useful. I exported the two generator checkpoints (31 MB each) and wrapped them in a Gradio interface:</p><pre>def translate(img, direction):<br>    x = pre(img.convert(&quot;RGB&quot;)).unsqueeze(0).to(DEVICE)<br>    with torch.no_grad():<br>        y = (G_AB if direction == &quot;Sketch → Photo&quot; else G_BA)(x)<br>    return T.ToPILImage()((y.clamp(-1, 1).squeeze(0).cpu() + 1) / 2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OA6OIQiermeEU3HxyKwSuQ.png" /></figure><p>Upload any sketch, pick a direction, and the translation comes back inline. The whole app is ~80 lines and deploys to a free Hugging Face Space in about 3 minutes.</p><h3>What I Would Do Differently</h3><p><strong>More epochs.</strong> The cycle loss was still dropping at epoch 30. I bet 50 would give visibly sharper translations.</p><p><strong>Wider ResNet.</strong> I stuck to 6 blocks to fit memory, but 9 blocks at 256×256 resolution (the original paper’s config) would capture more detail. A single T4 cannot fit it, but you could use gradient accumulation.</p><p><strong>Actual sketch ↔ photo, not sketch ↔ doodle.</strong> Swapping QuickDraw for a real photo dataset (CelebA faces, Oxford Flowers) would make this a genuine sketch-to-photo task — much harder, but also visually more impressive.</p><p><strong>Feature-matching loss.</strong> Adding a VGG-based perceptual loss on top of the L1 cycle loss often sharpens textures at the cost of slightly lower SSIM. Worth experimenting.</p><h3>Takeaways</h3><ol><li><strong>Cycle consistency is a remarkable trick.</strong> Replacing paired data with “round-trip should match” expands the set of problems you can solve. Any two domains you can collect data from become candidates.</li><li><strong>GAN stabilisation tricks matter more than architecture tweaks.</strong> Reflection padding, replay buffers, LSGAN, and linear LR decay each contribute. Skip any one and training gets noticeably worse.</li><li><strong>The “right metric” depends on the supervision.</strong> In paired settings, SSIM against the target makes sense. In unpaired settings, SSIM against the cycle reconstruction is the honest metric — it measures what the loss actually enforces.</li><li><strong>Kaggle’s free tier is remarkably capable.</strong> Two T4s + AMP + DataParallel got me a full 30-epoch training run in about 90 minutes. For a personal project, that is unreasonably good.</li></ol><h3>Resources</h3><ul><li><strong>Full Kaggle notebook</strong> (training + evaluation + Gradio): <a href="https://www.kaggle.com/code/fahad386/notebooke5b45484d4/edit#5.-Training-Loop">https://www.kaggle.com/code/fahad386/notebooke5b45484d4/edit#5.-Training-Loop</a></li><li><strong>Live Gradio app</strong> on Hugging Face Spaces: <a href="https://huggingface.co/spaces/fahad386/cyclegan-sketch-photo">https://huggingface.co/spaces/fahad386/cyclegan-sketch-photo</a></li><li><strong>Source code</strong>: <a href="https://github.com/fahadcs321/CycleGan">https://github.com/fahadcs321/CycleGan</a></li></ul><p>Original paper: Zhu, J.-Y., Park, T., Isola, P., &amp; Efros, A. A. (2017). <em>Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks.</em></p><p><em>If you found this useful, a clap or a follow would mean a lot. Questions welcome in the responses.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0cab75bc172" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Storyteller: Teaching Machines to Describe What They See]]></title>
            <link>https://medium.com/@f223442/neural-storyteller-teaching-machines-to-describe-what-they-see-d3812c406f2b?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3812c406f2b</guid>
            <category><![CDATA[image-captioning]]></category>
            <category><![CDATA[seq2seq-model]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 18:18:27 GMT</pubDate>
            <atom:updated>2026-02-18T18:18:27.305Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Building an image captioning model from scratch using Seq2Seq, Bahdanau Attention, and the Flickr30k dataset.</em></p><p>Can a machine look at a photograph and tell you what’s happening in it — in plain English? That’s the question we set out to answer in our Generative AI course project at FAST-NUCES. The result is <strong>Neural Storyteller</strong>, an end-to-end image captioning pipeline that takes a raw image as input and produces a natural language description as output.</p><p>In this post, we walk through the full journey — from extracting visual features to generating captions word-by-word — and share the key design decisions, training process, and results.</p><h3>The Problem: Bridging Vision and Language</h3><p>Image captioning sits at the intersection of computer vision and natural language processing. The model needs to understand <em>what’s in</em> an image (objects, actions, scenes) and then express that understanding as a coherent sentence. This makes it a truly multimodal challenge, and a classic testbed for sequence-to-sequence learning.</p><p>We used the <strong>Flickr30k</strong> dataset, which contains approximately 31,000 images, each annotated with five human-written captions — giving us over 150,000 image-caption pairs to learn from.</p><h3>Step 1: Seeing the World Through ResNet’s Eyes</h3><p>Training a CNN alongside an RNN from scratch is computationally expensive and often unnecessary. Instead, we used a <strong>pre-trained ResNet50</strong> as a fixed feature extractor. By removing the final classification layer, each image is converted into a <strong>2048-dimensional feature vector</strong> — a compact numerical summary of its visual content.</p><p>We pre-computed and cached these features for all 31,000+ images into a single pickle file. This decouples the visual pipeline from the language pipeline and makes training significantly faster.</p><h3>Step 2: Preparing the Text</h3><p>Raw captions need cleaning before they can be fed to a model. Our preprocessing pipeline handles contraction expansion (e.g., “can’t” becomes “cannot”), punctuation and URL removal, lowercasing, and wrapping every caption with &lt;start&gt; and &lt;end&gt; tokens.</p><p>We then built a vocabulary by keeping only words that appear at least 5 times across the dataset, and mapped every word to an integer index. Special tokens like &lt;pad&gt;, &lt;start&gt;, &lt;end&gt;, and &lt;unk&gt; handle padding, sequence boundaries, and out-of-vocabulary words respectively.</p><h3>Step 3: The Architecture — Encoder-Decoder with Attention</h3><p>Our model follows a classic Seq2Seq design with one critical enhancement: <strong>Bahdanau (additive) attention</strong>.</p><h3>Encoder</h3><p>The encoder is a simple feedforward network: a Linear layer projects the 2048-dim ResNet feature into a 512-dim hidden representation, followed by Layer Normalization, ReLU activation, and Dropout for regularization.</p><h3>Decoder</h3><p>The decoder is a <strong>2-layer LSTM</strong> that generates captions one word at a time. At each time step, it receives the embedding of the previous word concatenated with an attention-weighted context vector from the encoder. This context vector is further modulated by a <strong>gating mechanism</strong> — a sigmoid gate that lets the model control how much visual information flows into each decoding step.</p><p>The output at each step passes through a linear layer that maps back to vocabulary size, producing logits over the entire word space.</p><h3>Why Attention Matters</h3><p>Without attention, the decoder would receive a single, static summary of the entire image. With Bahdanau attention, the decoder can dynamically focus on different aspects of the encoded representation at each word generation step — attending more to action-related features when generating verbs, and object-related features when generating nouns.</p><h3>Step 4: Training</h3><p>We trained for up to 20 epochs with the following configuration:</p><p>HyperparameterValueBatch Size128Learning Rate3e-4 (Adam)Weight Decay1e-4Label Smoothing0.1Gradient Clippingmax_norm = 5.0LR SchedulingReduceLROnPlateau (factor=0.5, patience=2)Early Stoppingpatience = 5 epochs</p><p>The loss function is <strong>CrossEntropyLoss</strong> with ignore_index=0 to skip padding tokens. During training, we use <strong>teacher forcing</strong> — feeding the ground truth token at each step rather than the model&#39;s own prediction, which stabilizes learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LvgZROzwQlewXm41ETiFA.png" /></figure><h3>Step 5: Generating Captions at Inference</h3><p>We implemented two decoding strategies:</p><p><strong>Greedy Search</strong> picks the highest-probability word at every step. It’s fast but can get stuck in suboptimal paths since it never backtracks.</p><p><strong>Beam Search</strong> (with beam width = 5) maintains multiple candidate sequences at each step, keeping the top-k most probable partial captions. Final sequences are scored using length-normalized log probabilities, which prevents the model from favoring shorter, less informative captions.</p><h3>Results</h3><p>We evaluated on a test subset of 500 images using standard metrics:</p><p>MetricScoreBLEU-1Computed on test setBLEU-2Computed on test setBLEU-3Computed on test setBLEU-4Computed on test setPrecisionToken-levelRecallToken-levelF1-ScoreToken-level</p><p>Qualitatively, the model generates reasonable descriptions for many images — correctly identifying people, actions, and settings. Beam search generally produces more fluent and complete captions compared to greedy decoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-qboI-ERFd4bQX1sJ5hJg.png" /></figure><h3>Deployment: A Gradio Demo</h3><p>To make the model interactive, we built a <strong>Gradio</strong> web app. Users can upload any image, choose between Greedy and Beam Search decoding, adjust the beam width, and instantly receive a generated caption. Under the hood, the app runs ResNet50 feature extraction followed by our trained encoder-decoder — all in real time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NbRtnVzKMr_CvBJjWYNMMw.png" /></figure><h3>Key Takeaways</h3><ol><li><strong>Feature caching is essential.</strong> Pre-extracting CNN features saved us enormous training time and let us iterate quickly on the language model.</li><li><strong>Attention makes a real difference.</strong> Even with a simple single-vector encoder (no spatial regions), the gated attention mechanism improved caption quality noticeably.</li><li><strong>Beam search vs. greedy is a meaningful trade-off.</strong> Beam search produces better captions at the cost of slower inference. For a demo, greedy is snappy; for evaluation, beam search wins.</li><li><strong>Label smoothing and gradient clipping matter.</strong> These small training tricks prevented overfitting and training instability, especially with a 2-layer LSTM.</li></ol><h3>What’s Next?</h3><p>There’s plenty of room to push this further: using spatial features from ResNet (a grid of regions instead of a single vector), switching to Transformer-based decoders, experimenting with CIDEr-optimized training via self-critical sequence training (SCST), or fine-tuning on domain-specific datasets.</p><p>For now, though, Neural Storyteller demonstrates that a well-designed Seq2Seq model with attention can learn to describe images in surprisingly coherent and descriptive language — and that’s a pretty compelling result from a few hours of GPU time.</p><p><em>This project was completed as Assignment 1 for the Generative AI (AI4009) course at FAST-NUCES, Spring 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3812c406f2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Zero to Cloud Hero: Your Complete Guide to Setting Up AWS EC2 with Remote Desktop]]></title>
            <link>https://medium.com/@f223442/from-zero-to-cloud-hero-your-complete-guide-to-setting-up-aws-ec2-with-remote-desktop-976d03136cc5?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/976d03136cc5</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 17:01:51 GMT</pubDate>
            <atom:updated>2026-02-08T17:01:51.679Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how to get your own cloud server up and running with a full graphical interface? Whether you’re a student diving into cloud computing or a developer looking to host applications, this guide will walk you through the entire process of setting up an AWS EC2 instance with remote desktop access and file hosting capabilities.</p><h3>Why AWS EC2?</h3><p>Amazon’s Elastic Compute Cloud (EC2) is one of the most popular cloud computing platforms, offering scalable virtual servers that you can configure to your exact needs. The best part? You can access it from anywhere in the world, and you only pay for what you use.</p><p>In this tutorial, I’ll share my journey of creating an Ubuntu EC2 instance, setting up a graphical desktop environment, and hosting files via HTTP — all skills that are essential for modern cloud development.</p><h3>Phase 1: Creating Your EC2 Instance</h3><p>The first step is getting your virtual machine up and running on AWS.</p><h3>Launching the Instance</h3><p>I started by logging into the AWS Management Console at console.aws.amazon.com and navigating to the EC2 service. After clicking “Launch Instance,” I was presented with several configuration options that would define my virtual machine’s characteristics.</p><h3>Key Configuration Steps</h3><p><strong>Naming Your Instance</strong>: I named mine “F223431VM” to keep track of it easily. Good naming conventions are crucial when you’re managing multiple cloud resources.</p><p><strong>Choosing an AMI (Amazon Machine Image)</strong>: The AMI determines what operating system and pre-installed software your instance will have. I selected an Ubuntu Server image, which is perfect for development work and comes with all the essential tools.</p><p><strong>Instance Type</strong>: This determines your virtual machine’s computing power. For learning purposes and light workloads, a t2.micro or similar instance type works perfectly and often falls within AWS’s free tier.</p><p><strong>Security: The Key Pair</strong>: Here’s something critical — I created a key pair named “f223431NU” using RSA encryption with a .pem file format. This key pair is your ticket to securely accessing your instance. Think of it as a digital key to your virtual server. Download it immediately and store it safely — you can’t retrieve it again!</p><p><strong>Network Settings</strong>: I configured the security group to control traffic to my instance. This is your virtual firewall, and getting it right is crucial for both security and functionality.</p><p><strong>Storage Configuration</strong>: I allocated sufficient storage for my needs. EC2 gives you flexibility here, and you can always expand later if needed.</p><h3>Phase 2: Connecting via SSH</h3><p>Once my instance was running (I verified this in the EC2 dashboard where the instance state showed “running”), it was time to connect.</p><h3>The SSH Connection</h3><p>Using Windows PowerShell, I connected to my instance using the .pem key file I downloaded earlier. The command looked something like this:</p><pre>ssh -i /path/to/your-key.pem ubuntu@your-instance-public-ip</pre><p>That first successful SSH connection is always exciting! You’re now commanding a computer that exists somewhere in Amazon’s data centers, possibly thousands of miles away.</p><h3>Phase 3: Configuring Security Rules</h3><p>Before diving into the desktop setup, I needed to configure proper network access. I edited the EC2 instance’s Security Group to allow:</p><ul><li><strong>SSH (port 22)</strong>: For secure command-line access</li><li><strong>RDP (port 3389)</strong>: For Remote Desktop connections</li><li><strong>TCP port 8000</strong>: For hosting web applications</li></ul><p>These inbound rules act as gatekeepers, determining what traffic can reach your instance. Setting them correctly ensures you can access your services while maintaining security.</p><h3>Phase 4: Installing the Desktop Environment</h3><p>Here’s where things get really interesting. By default, Ubuntu Server doesn’t come with a graphical interface — it’s all command line. But we can change that!</p><h3>System Updates First</h3><p>I started by updating the system packages:</p><pre>sudo apt update</pre><p>This ensures all package information is current and prevents installation issues.</p><h3>Installing XFCE Desktop</h3><p>I chose XFCE as my desktop environment because it’s lightweight and works beautifully with remote connections:</p><pre>sudo apt install -y xfce4 xfce4-goodies</pre><p>XFCE strikes a perfect balance between functionality and performance, making it ideal for remote desktop use.</p><h3>Setting Up XRDP</h3><p>XRDP is the magic ingredient that allows Windows Remote Desktop to connect to Linux systems:</p><pre>sudo apt install -y xrdp</pre><p>After installation, I configured XRDP to use XFCE:</p><pre>echo &quot;xfce4-session&quot; | sudo tee /home/ubuntu/.xsession</pre><h3>Security: Setting a Password</h3><p>Since we’ll be connecting via Remote Desktop, the Ubuntu user needs a password:</p><pre>sudo passwd ubuntu</pre><h3>Final Firewall Configuration</h3><p>I opened port 3389 in Ubuntu’s firewall to allow RDP traffic:</p><pre>sudo ufw allow 3389/tcp</pre><p>Then verified that XRDP was running properly:</p><pre>sudo systemctl status xrdp</pre><p>Seeing that “Active: active (running)” status was a great feeling!</p><h3>Phase 5: Connecting via Remote Desktop</h3><p>Now for the moment of truth. I opened Windows Remote Desktop Connection (Win+R, then type “mstsc”), entered my EC2 instance’s public IP address, and clicked connect.</p><p>After entering the Ubuntu username and password I set earlier, I was greeted by a beautiful XFCE desktop environment. The characteristic blue mouse wallpaper confirmed I was in! I could see the familiar desktop icons — Trash, File System, Home folder — all accessible through a GUI instead of just the command line.</p><p>This is when it really hits you: you’re using a graphical desktop interface on a computer in the cloud. It’s responsive, functional, and ready for work.</p><h3>Phase 6: Hosting Files via HTTP Server</h3><p>The final piece of the puzzle was setting up a simple HTTP server to share files.</p><h3>Creating Your File Directory</h3><p>I created a directory to store the files I wanted to host and added some content to it. Python makes it incredibly easy to spin up a quick HTTP server:</p><pre>python3 -m http.server 8000</pre><p>This single command turns your directory into a web-accessible file server running on port 8000.</p><h3>Accessing Your Files</h3><p>With the server running and port 8000 open in my security group, I could access my files from any browser by navigating to:</p><pre>http://your-instance-public-ip:8000</pre><p>And there they were — my files, hosted in the cloud, accessible from anywhere in the world!</p><h3>Key Takeaways</h3><p>Setting up an EC2 instance with full remote desktop capabilities might seem daunting at first, but breaking it down into steps makes it manageable:</p><ol><li><strong>Security First</strong>: Always configure security groups carefully and use key pairs for SSH access</li><li><strong>Update Before Installing</strong>: Keep your system current before adding new software</li><li><strong>Choose Lightweight Tools</strong>: XFCE and XRDP provide excellent performance for remote desktop work</li><li><strong>Test Each Step</strong>: Verify services are running (like checking XRDP status) before moving forward</li><li><strong>Document Your Process</strong>: Take notes on configurations — you’ll thank yourself later</li></ol><h3>What’s Next?</h3><p>Now that you have a fully functional cloud server with GUI access and file hosting capabilities, the possibilities are endless:</p><ul><li>Deploy web applications</li><li>Set up development environments</li><li>Create automated workflows</li><li>Experiment with cloud-native tools</li><li>Build and test software in a clean environment</li></ul><p>The cloud is no longer just for large enterprises. With services like AWS EC2, anyone can harness the power of cloud computing for learning, development, or production workloads.</p><h3>Final Thoughts</h3><p>My first time setting up an EC2 instance with remote desktop was a learning experience filled with small victories — the first successful SSH connection, seeing the desktop environment load for the first time, and watching my HTTP server spring to life. Each step taught me something valuable about cloud infrastructure and system administration.</p><p>Whether you’re working on a class assignment, building a personal project, or exploring cloud technologies, this setup gives you a solid foundation. The combination of command-line access via SSH and graphical access via RDP provides the flexibility to work however you’re most comfortable.</p><p>Remember, cloud computing is all about experimentation and learning. Don’t be afraid to try things, make mistakes, and rebuild. That’s how you develop real expertise.</p><p>Happy cloud computing! ☁️</p><p><em>Have questions about AWS EC2 or cloud computing? Drop them in the comments below! If you found this guide helpful, give it a clap and follow for more cloud tutorials and technical guides.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=976d03136cc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloud Computing: A Decade-Long Journey From Vision to Reality]]></title>
            <link>https://medium.com/@f223442/cloud-computing-a-decade-long-journey-from-vision-to-reality-08301fd07f98?source=rss-67953226201c------2</link>
            <guid isPermaLink="false">https://medium.com/p/08301fd07f98</guid>
            <category><![CDATA[history]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Muhammad Fahad]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 13:04:29 GMT</pubDate>
            <atom:updated>2026-01-31T13:04:29.666Z</atom:updated>
            <content:encoded><![CDATA[<p><em>An in-depth analysis of two foundational research papers that predicted the cloud revolution</em></p><p>In 2009 and 2010, two research teams — one from UC Berkeley and another from the University of Waterloo — published comprehensive analyses of cloud computing that would prove remarkably prescient. Today, as we live in a world where cloud services power everything from Netflix to modern AI systems, it’s fascinating to look back at these foundational papers and see how accurately they predicted both the opportunities and challenges of this transformative technology.</p><p>This blog post provides a comprehensive analysis of both papers, exploring their key insights, comparing their perspectives, and examining how their predictions have held up over time.</p><h3><strong>The Two Foundational Papers</strong></h3><p><strong>Paper 1: </strong>“Above the Clouds: A Berkeley View of Cloud Computing” by Michael Armbrust, Armando Fox, and colleagues from UC Berkeley’s RAD Lab (February 2009)</p><p><strong>Paper 2: </strong>“Cloud Computing: State-of-the-Art and Research Challenges” by Qi Zhang, Lu Cheng, and Raouf Boutaba from the University of Waterloo (April 2010)</p><p>While the Berkeley paper takes a more visionary and economic approach, the Waterloo paper provides a comprehensive technical survey. Together, they offer complementary perspectives on cloud computing at a pivotal moment in its development.</p><h3><strong>What is Cloud Computing? Defining the Paradigm</strong></h3><p>Both papers grapple with defining cloud computing, acknowledging the confusion surrounding the term. The Waterloo team adopts NIST’s definition: <em>“a model for enabling convenient, on-demand network access to a shared pool of configurable computing resources that can be rapidly provisioned and released with minimal management effort.”</em></p><p>The Berkeley researchers are more philosophical, viewing cloud computing as the sum of Software as a Service (SaaS) and Utility Computing. They distinguish between:</p><ul><li><strong>Public Clouds: </strong>Available on a pay-as-you-go basis to the general public</li><li><strong>Private Clouds: </strong>Internal datacenters not available to the public</li><li><strong>Hybrid Clouds: </strong>Combinations of public and private clouds</li></ul><p>Importantly, both papers identify <strong>three revolutionary characteristics</strong> that distinguish cloud computing from previous paradigms:</p><p><strong>1. The Illusion of Infinite Resources</strong></p><p>Cloud computing eliminates the need to plan far ahead for provisioning. Resources appear infinite and available on demand, fundamentally changing how organizations think about capacity planning.</p><p><strong>2. No Upfront Commitment</strong></p><p>Companies can start small and scale only when needed. This was revolutionary in 2009, when building even a modest datacenter required significant capital investment. The barrier to entry for new services dropped dramatically.</p><p><strong>3. Pay-for-Use Pricing</strong></p><p>Resources could be acquired on a short-term basis (processors by the hour, storage by the day) and released when no longer needed. This aligned costs directly with actual usage, rewarding conservation.</p><p><strong>The Economics: Why Cloud Computing Makes Financial Sense</strong></p><p>The Berkeley paper shines in its economic analysis. The researchers argue that the key enabler wasn’t just technology — it was <strong>massive economies of scale</strong> achieved by very large datacenters.</p><p><strong>The 5–7x Cost Advantage</strong></p><p>According to James Hamilton’s estimates cited in the Berkeley paper, very large datacenters (50,000+ servers) could purchase resources at 1/5 to 1/7 the cost of medium-sized datacenters (1,000 servers). Specific advantages included:</p><ul><li><strong>Network bandwidth: </strong>7.1x cheaper ($13 vs $95 per Mbit/sec/month)</li><li><strong>Storage: </strong>5.7x cheaper ($0.40 vs $2.20 per GB/month)</li><li><strong>Administration: </strong>7.1x better efficiency (1000+ vs 140 servers per administrator)</li></ul><p>These cost advantages meant cloud providers could offer services well below what medium-sized companies could achieve on their own while still making substantial profits.</p><h3><strong>Elasticity: The Real Value Proposition</strong></h3><p>The Berkeley researchers introduce a crucial concept: <strong>elasticity isn’t just about cost optimization — it’s about risk transfer.</strong></p><p>Traditional datacenter provisioning faced two deadly risks:</p><ul><li><strong>Over-provisioning: </strong>Buying too much capacity leads to wasted resources. If you provision for peak load but average utilization is only 20%, you’re paying for 80% idle capacity.</li><li><strong>Under-provisioning: </strong>Buying too little capacity means turning away customers during spikes, losing both immediate revenue and potentially permanent customers due to poor service.</li></ul><p>The paper provides a simple but powerful equation for deciding whether to move to the cloud:</p><p><strong><em>UserHours_cloud × (revenue — Cost_cloud) ≥ UserHours_datacenter × (revenue — Cost_datacenter / Utilization)</em></strong></p><p>This equation reveals that datacenter costs must be divided by utilization, which typically maxes out at 60–80% to maintain acceptable performance. Cloud computing eliminates this overhead.</p><h3><strong>Real-World Example: Animoto’s Explosive Growth</strong></h3><p>The Berkeley paper cites Animoto, which scaled from 50 servers to 3,500 servers in just three days when their Facebook app went viral. No traditional datacenter provisioning model could have handled this growth rate. This wasn’t just cost optimization — it was operational survival.</p><h3><strong>Cloud Architecture: From Hardware to Applications</strong></h3><p>The Waterloo paper excels in its architectural analysis, proposing a clear four-layer model:</p><p><strong>Layer 1: Hardware/Datacenter Layer</strong></p><p>Physical resources including servers, routers, switches, power, and cooling. The researchers emphasize that datacenter network design must achieve:</p><ul><li>Uniform high capacity between any two servers</li><li>Support for free VM migration</li><li>Fault tolerance and resiliency</li><li>Scalability to handle tens of thousands of servers</li></ul><p><strong>Layer 2: Infrastructure Layer (Virtualization)</strong></p><p>Creates pools of storage and computing resources through virtualization technologies like Xen, KVM, and VMware. This layer is essential for dynamic resource assignment and statistical multiplexing.</p><p><strong>Layer 3: Platform Layer</strong></p><p>Operating systems and application frameworks that minimize the burden of deploying applications. Examples include Google App Engine’s API support for web applications.</p><p><strong>Layer 4: Application Layer</strong></p><p>Actual cloud applications that can leverage automatic scaling for better performance and lower costs.</p><h3><strong>Three Service Models: IaaS, PaaS, and SaaS</strong></h3><p>Both papers identify three distinct service models, each offering different trade-offs between control and convenience:</p><p><strong>Infrastructure as a Service (IaaS)</strong></p><p><strong>Example: Amazon EC2</strong></p><p>Provides raw computing resources — virtual machines that look like physical hardware. Users control nearly the entire software stack from the kernel upwards. This offers maximum flexibility but makes it difficult for providers to offer automatic scaling since they don’t understand the application semantics.</p><p><strong>Platform as a Service (PaaS)</strong></p><p><strong>Examples: Microsoft Azure, Google App Engine</strong></p><p>Provides operating systems, development frameworks, and APIs. Azure is intermediate — offering .NET libraries and managed runtime. App Engine is highly constrained but offers impressive automatic scaling by enforcing a stateless computation tier separated from a stateful storage tier.</p><p><strong>Software as a Service (SaaS)</strong></p><p><strong>Examples: Salesforce, Google Apps</strong></p><p>Complete applications delivered over the internet. Users access the service without managing any infrastructure.</p><p><strong>Key Technologies Enabling the Cloud</strong></p><p>The Waterloo paper provides an excellent survey of the technologies that made cloud computing possible:</p><p><strong>Distributed File Systems</strong></p><p><strong>Google File System (GFS): </strong>Designed for very large files across commodity servers, dividing files into 64MB chunks with replication for reliability.</p><p><strong>Hadoop Distributed File System (HDFS): </strong>Open-source implementation inspired by GFS, storing data across geo-diverse nodes with automatic replication.</p><p><strong>MapReduce Framework</strong></p><p>Google’s MapReduce — and its open-source counterpart Hadoop MapReduce — enabled distributed computing on massive datasets. The Berkeley paper highlights how this democratized large-scale data processing: using 1,000 servers for one hour costs the same as one server for 1,000 hours, but completes the job 1,000 times faster.</p><p><strong>Virtualization</strong></p><p>Technologies like Xen and VMware enabled resource pooling and dynamic allocation. Virtual machines could be migrated between physical servers for load balancing, maintenance, or energy optimization.</p><h3><strong>Top 10 Obstacles and Research Challenges</strong></h3><p>Both papers identify critical challenges that needed to be addressed. The Berkeley paper frames each obstacle with a corresponding opportunity:</p><p><strong>1. Service Availability</strong></p><p><strong>Challenge: </strong>Cloud outages could take services offline. The Berkeley paper documented several 2008 outages of Amazon S3 and Google AppEngine.</p><p><strong>Opportunity: </strong>Use multiple cloud providers for business continuity. Use elasticity to defend against DDoS attacks by rapidly scaling to absorb malicious traffic.</p><p><strong>2. Data Lock-In</strong></p><p><strong>Challenge: </strong>Proprietary APIs make it difficult to move data and applications between providers.</p><p><strong>Opportunity: </strong>Standardize APIs to enable ‘surge computing’ — using public clouds to handle overflow from private datacenters.</p><p><strong>3. Data Confidentiality and Security</strong></p><p><strong>Challenge: </strong>Concerns about data security, auditability, and compliance with regulations like HIPAA and Sarbanes-Oxley.</p><p><strong>Opportunity: </strong>Deploy encryption, VLANs, firewalls, and offer geographical data storage to comply with national laws.</p><p><strong>4. Data Transfer Bottlenecks</strong></p><p><strong>Challenge: </strong>Network bandwidth costs are high. At $100–150 per terabyte, transferring large datasets is expensive.</p><p><strong>Opportunity: </strong>Physical shipping! Jim Gray calculated that FedExing disks is often cheaper and faster than network transfer. The Berkeley paper suggests ‘Netflix for Cloud Computing’ where providers ship disk arrays.</p><p><strong>5. Performance Unpredictability</strong></p><p><strong>Challenge: </strong>Virtual machines sharing physical resources can experience I/O interference. The Berkeley team’s experiments showed disk performance varying by 16%.</p><p><strong>Opportunity: </strong>Improved VM support, flash memory to reduce I/O contention, and gang scheduling for HPC applications.</p><p><strong>6. Scalable Storage</strong></p><p>Creating storage systems that scale arbitrarily while meeting performance, durability, and availability requirements remained an open research problem. The variety of incompatible storage solutions (S3, SimpleDB, BigTable) showed no clear winner.</p><p><strong>7–10. Additional Challenges</strong></p><ul><li><strong>Debugging large distributed systems: </strong>Bugs that only appear at scale are hard to reproduce</li><li><strong>Scaling quickly: </strong>Auto-scaling using machine learning to predict resource needs</li><li><strong>Reputation fate sharing: </strong>One customer’s spam can get everyone’s IPs blacklisted</li><li><strong>Software licensing: </strong>Traditional per-server licenses don’t fit pay-as-you-go models</li></ul><h3><strong>Additional Research Frontiers (Waterloo Paper)</strong></h3><p>The Waterloo team identified several technical challenges that complemented Berkeley’s list:</p><p><strong>Automated Service Provisioning</strong></p><p>Mapping high-level service level objectives (like ‘99.9% uptime’ or ‘response time under 200ms’) to low-level resource requirements (CPU cores, memory, bandwidth) requires sophisticated performance modeling using queuing theory, control theory, or machine learning.</p><p><strong>Server Consolidation and Energy Management</strong></p><p>In 2006, datacenters consumed 1.5% of total US energy with 18% annual growth. Optimally consolidating VMs onto fewer physical servers (a variant of the NP-hard bin-packing problem) while avoiding resource congestion was crucial for both cost and environmental reasons.</p><p><strong>Virtual Machine Migration</strong></p><p>Live migration with minimal downtime (tens of milliseconds) enabled dynamic load balancing. However, detecting hotspots and deciding when to migrate remained challenging, especially given varying VM resource footprints over time.</p><p><strong>What These Papers Got Right</strong></p><p>Looking back from 2025, it’s remarkable how prescient both papers were:</p><p><strong>The Economics Were Spot-On</strong></p><p>The 5–7x cost advantage of massive datacenters has held true. Today’s hyperscale cloud providers (AWS, Azure, Google Cloud) operate at unprecedented scales, and cloud computing has indeed become cheaper for most workloads than building your own datacenter.</p><p><strong>Elasticity is King</strong></p><p>The Berkeley team’s emphasis on elasticity and risk transfer was absolutely correct. Modern applications routinely auto-scale based on demand, and the ability to handle traffic spikes without over-provisioning has become table stakes.</p><p><strong>Multiple Service Models Coexist</strong></p><p>The prediction that different applications would demand different levels of abstraction proved accurate. Today we have thriving IaaS (AWS EC2), PaaS (Heroku, Google App Engine), and SaaS (Salesforce, Office 365) ecosystems.</p><p><strong>Research Challenges Were Real</strong></p><p>Many identified challenges — energy efficiency, auto-scaling, security, debugging distributed systems — remain active research areas today, though significant progress has been made on all fronts.</p><p><strong>What They Couldn’t Foresee</strong></p><p>Despite their prescience, some developments surprised even these forward-thinking researchers:</p><p><strong>Serverless/Functions-as-a-Service</strong></p><p>AWS Lambda (2014) and serverless computing took abstraction further than anyone predicted. Developers now write functions without thinking about servers at all, paying only for execution time measured in milliseconds.</p><p><strong>Containers and Kubernetes</strong></p><p>Docker (2013) and Kubernetes (2014) created an intermediate layer between VMs and applications that neither paper anticipated. Containers became the dominant way to package and deploy cloud applications.</p><p><strong>Machine Learning and AI Workloads</strong></p><p>While both papers discussed batch processing and MapReduce, neither foresaw how cloud computing would become essential infrastructure for training massive AI models. GPU instances and specialized AI chips have become major cloud offerings.</p><p><strong>Edge Computing</strong></p><p>The rise of IoT and latency-sensitive applications drove computing back toward the edge, creating hybrid models where processing happens both in centralized clouds and distributed edge locations.</p><h3><strong>Key Insights and Takeaways</strong></h3><p><strong>1. Cloud Computing is About Economics, Not Just Technology</strong></p><p>The Berkeley paper’s greatest contribution is showing that cloud computing succeeded because of business model innovation as much as technical innovation. The pay-as-you-go model, combined with economies of scale, fundamentally changed the economics of IT.</p><p><strong>2. Different Workloads Need Different Solutions</strong></p><p>There’s no one-size-fits-all cloud solution. Some applications need raw infrastructure control (IaaS), others benefit from managed platforms (PaaS), and some want complete solutions (SaaS). This diversity is a strength, not a weakness.</p><p><strong>3. Architectural Modularity Enables Innovation</strong></p><p>The Waterloo paper’s four-layer architecture shows how loose coupling between layers allows each to evolve independently. This modularity enabled rapid innovation at every level.</p><p><strong>4. Challenges Drive Innovation</strong></p><p>Many of the obstacles identified in 2009–2010 became opportunities for startups and research projects. Data lock-in concerns led to containerization and infrastructure-as-code. Performance unpredictability drove improvements in VM technology. Energy concerns spurred green computing initiatives.</p><p><strong>Why These Papers Still Matter in 2025</strong></p><p>These papers aren’t just historical documents — they offer lessons relevant to today’s technology landscape:</p><p><strong>Understanding Fundamentals</strong></p><p>The core principles — elasticity, pay-as-you-go pricing, economies of scale — still drive cloud economics. Understanding these fundamentals helps make better architectural decisions.</p><p><strong>Evaluating New Paradigms</strong></p><p>The framework for analyzing cloud computing (economic benefits, technical architecture, challenges and opportunities) provides a template for evaluating emerging paradigms like edge computing, quantum computing, or whatever comes next.</p><p><strong>Recognizing Patterns</strong></p><p>Many ‘new’ challenges in modern distributed systems — latency, consistency, failure handling, resource optimization — are variations of problems identified in these papers. Understanding the historical context helps avoid reinventing wheels.</p><h3><strong>Conclusion: The Long Arc from Vision to Reality</strong></h3><p>Reading these papers in 2025 is like reading a map of the future written in the past. The Berkeley and Waterloo researchers saw clearly how cloud computing would transform IT infrastructure, even while the technology was in its infancy.</p><p>Their predictions were remarkable:</p><ul><li>Cloud computing would become the dominant paradigm for deploying applications ✓</li><li>Economies of scale would make centralized clouds more economical than private datacenters ✓</li><li>Multiple service models (IaaS, PaaS, SaaS) would coexist ✓</li><li>Elasticity and pay-as-you-go pricing would be transformative ✓</li><li>Security, performance, and standardization would remain ongoing challenges ✓</li></ul><p>But perhaps more important than what they got right is the framework they provided for thinking about cloud computing — not just as a technology, but as an economic and architectural transformation.</p><p>For anyone building modern applications, these papers offer invaluable perspective. They remind us that:</p><ul><li><strong>Technology succeeds when it solves real economic problems</strong></li><li><strong>Different problems require different levels of abstraction</strong></li><li><strong>Today’s obstacles are tomorrow’s opportunities</strong></li><li><strong>Foundational principles remain relevant even as specific technologies evolve</strong></li></ul><p>As we stand in 2025, with cloud computing now the default rather than the exception, these papers serve as both historical record and timeless guide. They show us not just where cloud computing came from, but how to think about where it — and computing in general — might go next.</p><p><strong>References</strong></p><p><strong>1. </strong>Armbrust, M., Fox, A., Griffith, R., Joseph, A. D., Katz, R., Konwinski, A., … &amp; Zaharia, M. (2010). A view of cloud computing. <em>Communications of the ACM, 53</em>(4), 50–58.</p><p><strong>2. </strong>Zhang, Q., Cheng, L., &amp; Boutaba, R. (2010). Cloud computing: state-of-the-art and research challenges. <em>Journal of Internet Services and Applications, 1</em>(1), 7–18.</p><p><strong>3. </strong>Original Berkeley Technical Report: Armbrust, M., et al. (2009). Above the Clouds: A Berkeley View of Cloud Computing. Technical Report No. UCB/EECS-2009–28, University of California at Berkeley.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08301fd07f98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>