<?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"><channel><title><![CDATA[Simply ML - Machine Learning Made Clear]]></title><description><![CDATA[Simply ML breaks down machine learning concepts, research ideas, and papers into clear, intuitive explanations for learners and practitioners.]]></description><link>https://blogs.sagnikdas.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1753941961461/2e67d869-9d94-4a3d-b8d7-73908453eae2.png</url><title>Simply ML - Machine Learning Made Clear</title><link>https://blogs.sagnikdas.com</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 04:58:26 GMT</lastBuildDate><atom:link href="https://blogs.sagnikdas.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Inside GPT-OSS: Open-Weight Reasoning Models Built for Agentic AI]]></title><description><![CDATA[GPT-OSS refers to a pair of open-weight reasoning models, released under the Apache 2.0 license. Accessible here: gpt-oss-20b; gpt-oss-120b. Unlike proprietary ChatGPT, GPT-OSS is designed to be run, modified, and fine-tuned by developers. The models...]]></description><link>https://blogs.sagnikdas.com/inside-gpt-oss-open-weight-reasoning-models-built-for-agentic-ai</link><guid isPermaLink="true">https://blogs.sagnikdas.com/inside-gpt-oss-open-weight-reasoning-models-built-for-agentic-ai</guid><category><![CDATA[AI]]></category><category><![CDATA[gpt-oss]]></category><category><![CDATA[chatgpt]]></category><dc:creator><![CDATA[Sagnik Das]]></dc:creator><pubDate>Thu, 22 Jan 2026 07:00:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769040051321/5683e731-2764-4689-b6ac-7a0cc538faa9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>GPT-OSS refers to a pair of open-weight reasoning models, released under the Apache 2.0 license. Accessible here: <a target="_blank" href="https://huggingface.co/openai/gpt-oss-20b">gpt-oss-20b</a>; <a target="_blank" href="https://huggingface.co/openai/gpt-oss-120b">gpt-oss-120b</a>. Unlike proprietary ChatGPT, GPT-OSS is designed to be <em>run, modified, and fine-tuned</em> by developers. The models are optimized for agentic workflows, long-form reasoning, tool use, and structured outputs.</p>
<p>This article provides a practical overview and insight into GPT-OSS, its architecture, training pipeline, reasoning abilities, and how it fits in today’s context.</p>
<h2 id="heading-gpt-oss-is-much-more-flexible-than-chatgpt">GPT-OSS is much more flexible than ChatGPT</h2>
<ul>
<li><p>Open-weight and flexible, allowing for tweaking and experimentation.</p>
</li>
<li><p>Designed for agentic workflows (Python and web search)</p>
</li>
<li><p>Capable of long CoT (chain of thought)</p>
</li>
<li><p>Customizable by developers</p>
</li>
</ul>
<p>As of today, OpenAI operates ChatGPT, one of the most widely used and influential public conversational AI models. The company releasing an open-source model available to the public gains a lot of attention in both academia and industry. However, it is clear that GPT-OSS has a very different safety profile than OpenAI’s flagship product and API endpoints. This difference is not due to weaker training, but rather because open-weight models cannot rely on centralized, system-level safeguards once they are released. GPT-OSS-20B model is meant to be used on regular consumer hardware with a minimum of 16GB main memory, whereas GPT-OSS-120B is meant to be used on servers. While one can use ChatGPT out-of-the-box, GPT-OSS requires some basic coding to get it running. I personally find that writing a small script in Python does the job quickly and efficiently. Otherwise, to get a feel for how the model responds, HuggingFace provides an inference option on the model landing page. However, this is a freemium option and may be discontinued in the future.</p>
<h2 id="heading-architecture-overview">Architecture Overview</h2>
<p>GPT-OSS models are autoregressive <strong>Mixture-of-Experts (MoE)</strong> transformers built on architectural ideas from GPT-2 and GPT-3.</p>
<h4 id="heading-model-sizes">Model Sizes</h4>
<ul>
<li><p><strong>GPT-OSS-120B:</strong> 116.8B total parameters, 36 layers, 5.1B active parameters per token.</p>
</li>
<li><p><strong>GPT-OSS-20B:</strong> 20.9B total parameters, 24 layers, 3.6B active parameters per token.</p>
</li>
</ul>
<p>For enabling efficient inference, only a subset of experts is active per token, even though the total number of parameter count are large.</p>
<h2 id="heading-quantization-and-hardware-efficiency">Quantization and Hardware Efficiency</h2>
<p>GPT-OSS applies post-training quantization to MoE weights using the <strong>MXFP4</strong> format (4.25 bits per parameter). This helps reduce the memory footprint, and users do not need to have access to a large server farm to infer on the model. Thus, this enables:</p>
<ul>
<li><p>GPT-OSS-120B to be able to run on an 80GB GPU</p>
</li>
<li><p>GPT-OSS-20B to be able to run with only 16GB of memory</p>
</li>
</ul>
<p>Apparently, even with lower computing resources, users can infer models locally. Also, potentially secure network use-cases like handling payslips, banking documents, and medical information can be summarized using the local model without risk of any data leakage over the internet. Without quantization, individual researchers, small companies, and even regular users wouldn’t have been able to communicate with models with good features and chat abilities locally.</p>
<h2 id="heading-tokenizer">Tokenizer</h2>
<p>TikToken is a library available on GitHub, maintained by OpenAI. It contains <strong>o200k_harmony</strong> tokenizer, which is a Byte Pair Encoding (BPE) tokenizer extended with special tokens for role-based and channel-based chat formatting. Byte Pair Encoding (BPE) is a method that breaks text into small, reusable pieces so a language model can efficiently understand and generate words, even ones it has never seen before.</p>
<h2 id="heading-pretraining">Pretraining</h2>
<h4 id="heading-data">Data</h4>
<p>GPT-OSS models are trained on a text-only dataset containing trillions of tokens with special emphasis on:</p>
<ul>
<li><p>STEM and mathematics</p>
</li>
<li><p>Programming and code</p>
</li>
<li><p>General knowledge</p>
</li>
</ul>
<p>Harmful content, like biosecurity, was filtered using CBRN pretraining filters developed initially for GPT-4o.</p>
<h4 id="heading-training-infrastructure">Training Infrastructure</h4>
<p>Training was conducted on NVIDIA H100 GPUs using PyTorch with expert-optimized Triton kernels and FlashAttention:</p>
<ul>
<li><p><strong>GPT-OSS-120B:</strong> approximately 2.1M H100 GPU-hours</p>
</li>
<li><p><strong>GPT-OSS-20B:</strong> approximately 10x fewer GPU-hours</p>
</li>
</ul>
<h2 id="heading-post-training-and-reasoning">Post-Training and Reasoning</h2>
<p>After pretraining, models were post-trained using CoT (chain of thought) reinforcement learning techniques, in a similar way to how OpenAI’s o3 models were trained. Models are taught:</p>
<ul>
<li><p>How to reason step by step?</p>
</li>
<li><p>How to solve complex math and coding problems?</p>
</li>
<li><p>How to use tools such as Python execution and web browsing?</p>
</li>
</ul>
<h4 id="heading-harmony-chat-format">Harmony Chat Format</h4>
<p>GPT-OSS uses the harmony chat format, which is a role-based messaging structure with explicit message boundaries like System, Developer, User, and Assistant. Imagine you instruct another person to help you prepare for final exams, just act as an agent who only asks you questions, whereas you are the agent who will just answer. GPT-OSS is trained using a similar system to follow the User-Assistant setting to chat with an human-user.</p>
<p>The format also introduces <strong>channels:</strong></p>
<ul>
<li><p><strong>analysis:</strong> internal chain-of-thought</p>
</li>
<li><p><strong>commentary:</strong> tool calls</p>
</li>
<li><p><strong>final:</strong> user-visible output</p>
</li>
</ul>
<p>This structure enables advanced agentic behaviors but requires careful handling, especially in multi-turn conversations. One has to keep in mind, user-AI agent role mustn’t be reversed, otherwise the application wouldn’t serve its purpose.</p>
<h4 id="heading-variable-reasoning-effort">Variable Reasoning Effort</h4>
<p>In ChatGPT, one can choose various options like Auto, Instant, Thinking, Pro, and Deep-Research. This helps ChatGPT determine how long the user is willing to wait for a response and how long CoT should apply to get the desired output. Similarly, in GPT-OSS, we have 3 different effort levels:</p>
<ul>
<li><p>low</p>
</li>
<li><p>medium</p>
</li>
<li><p>high</p>
</li>
</ul>
<p>These are set via system prompt keywords (e.g., <strong>Reasoning: high</strong>). Higher levels result in longer chain-of-thought and improved accuracy, at the cost of latency and compute.</p>
<h4 id="heading-agentic-tool-use">Agentic Tool Use</h4>
<p>A large language model that is trained on fewer parameters is prone to hallucinations; it is to the benefit of users that the model has the capability to interact with tools. GPT-OSS models are trained to interact with:</p>
<ul>
<li><p>Web browsing via <strong>search</strong> and <strong>open</strong></p>
</li>
<li><p>Python code execution in a stateful Jupyter environment</p>
</li>
<li><p>Arbitrary developer-defined functions with schemas.</p>
</li>
</ul>
<p>Tool use can be toggled to be enabled/disabled through the system prompt.</p>
<h2 id="heading-evaluation-results">Evaluation Results</h2>
<h4 id="heading-reasoning-and-coding">Reasoning and Coding</h4>
<p>While it is debatable who performs the best in solving complex problems amongst Gemini, Claude AI, ChatGPT, and other public chat models, GPT-OSS, among the offline models, is particularly strong in mathematics and reasoning-heavy tasks. For example, GPT-OSS-20B uses over 20k chain-of-thought tokens per AIME problem on average. Both models perform strongly on coding and tool-use benchmarks, with GPT-OSS-120B approaching the performance of OpenAI’s o4-mini.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769036445897/d6189b25-4c5c-4655-92e0-d1d6664eb265.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-health-performance">Health Performance</h4>
<p>GPT-OSS models perform competitively on HealthBench evaluations.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769035826187/175341f9-ffc8-4790-9ca4-2e7b7ba1b172.png" alt class="image--center mx-auto" /></p>
<p>Notably, GPT-OSS-120B approaches OpenAI o3 performance and outperforms several frontier closed models. However, it is important to note that the advice from a large language model is not intended to replace medical professionals.</p>
<h4 id="heading-multilingual-performance">Multilingual Performance</h4>
<p>On MMMLU benchmarks across 14 languages, GPT-OSS-120B at a high reasoning effort setting comes close to o4-mini-high performance.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769036019896/24ef00ce-5fad-4245-8f96-cf51a87f9bf7.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-safety-and-limitations">Safety and Limitations</h2>
<p>Even the best of systems have limitations, and so do GPT-OSS models. As it is an open-weight light model, it doesn’t have the same safety standards as OpenAI’s proprietary counterparts and also has other limitations.</p>
<h4 id="heading-preparedness-framework">Preparedness Framework</h4>
<p>GPT-OSS-120B does not reach OpenAI’s “High capability” thresholds under the Preparedness Framework, even after adversarial fine-tuning.</p>
<ul>
<li><p>Biological and chemical capability</p>
</li>
<li><p>Cyber capability</p>
</li>
<li><p>AI self-improvement</p>
</li>
</ul>
<h4 id="heading-disallowed-content-and-jailbreaks">Disallowed Content and Jailbreaks</h4>
<p>On standard disallowed content evaluations, both models perform on par with OpenAI o4-mini. GPT-OSS-20B slightly underperforms on illicit/violent categories but still exceeds GPT-4o. Robustness to jailbreaks using the StrongReject benchmark is comparable to o4-mini.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769036374502/35b6ebd3-c7fe-4964-82fd-ca56b4d9f3a3.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-instruction-hierarchy">Instruction Hierarchy</h4>
<p>All public chat LLM models should/must follow the instruction hierarchy to behave like a chatbot; otherwise, they would fail to do the bare-minimum itself, chat. GPT-OSS follows system and developer message priorities; it generally underperforms o4-mini on instruction hierarchy tests such as system prompt extraction and prompt injection hijacking.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769036661898/20ceb3df-a6e5-4b42-90e2-688c4892ccfd.png" alt class="image--center mx-auto" /></p>
<h4 id="heading-chain-of-thought-and-hallucinations">Chain-of-Thought and Hallucinations</h4>
<p>GPT-OSS chains of thought are intentionally unrestricted, thus:</p>
<ul>
<li><p>CoT may contain hallucinations</p>
</li>
<li><p>CoT may include unsafe or unfiltered language</p>
</li>
</ul>
<p>Researchers found that when models are explicitly discouraged from expressing certain thoughts, they can instead learn to conceal their reasoning while continuing to behave incorrectly. Developers are advised not to expose raw chain-of-thought to end users, as it may contain hallucinated or unfiltered language that is inappropriate for direct display.</p>
<h4 id="heading-fairness-and-bias">Fairness and Bias</h4>
<p>On the BBQ fairness benchmarks, GPT-OSS models perform at roughly the same level as OpenAI o4-mini.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769037084369/f89d26fc-827b-4b39-94f4-33332b19be27.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>GPT-OSS represents a significant step forward for open-weight reasoning models. It combines long CoT reasoning, agentic tool use, and strong math and coding performance in a form developers can fully control. Training an LLM from scratch is technically infeasible for the majority of individuals because of the massive compute requirement, unless one owns a supercomputer at home or is spending a fortune on cloud infrastructure. Technical freedom and openess shifts the burden of responsibility. OpenAI’s model card and license clearly list GPT-OSS’s shortcomings and where it may fail. Like any other thing in the world, for example, a car can be used both as a transportation medium and a lethal machine when in the hands of a criminal. An LLM has to be used responsibly, especially when the restrictions are lifted. Safety, deployment, and monitoring are no longer handled by a centralized API, but by the system builder. However, for teams building agentic systems, this is not a drop-in replacement for ChatGPT, but a powerful foundation.</p>
<h2 id="heading-references">References</h2>
<p>[1] OpenAI <em>et al.</em>, “gpt-oss-120b &amp; gpt-oss-20b Model Card,” Aug. 08, 2025, <em>arXiv</em>: arXiv:2508.10925. doi: <a target="_blank" href="https://doi.org/10.48550/arXiv.2508.10925">10.48550/arXiv.2508.10925</a>.</p>
<details><summary>Disclaimer</summary><div data-type="detailsContent">All images and tables are reproduced from [1]. Cover Image is obtained from <a target="_self" href="https://raw.githubusercontent.com/openai/gpt-oss/main/docs/gpt-oss-120b.svg">HuggingFace</a>. This article is an independent technical summary and interpretation of the OpenAI GPT-OSS model card. The author is not affiliated with OpenAI, and any opinions or interpretations are solely those of the author.</div></details>]]></content:encoded></item><item><title><![CDATA[Why Variational Autoencoders Are the Secret Sauce of the GenAI Revolution]]></title><description><![CDATA[Introduction: The GenAI Age — Creating Instead of Curating
Generative AI (GenAI) is transforming the landscape of technology, powering applications which can generate audio, art, or photorealistic images. We have seen a recent trend of Ghibli images ...]]></description><link>https://blogs.sagnikdas.com/variational-autoencoders-secret-sauce-genai</link><guid isPermaLink="true">https://blogs.sagnikdas.com/variational-autoencoders-secret-sauce-genai</guid><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Sagnik Das]]></dc:creator><pubDate>Thu, 31 Jul 2025 10:11:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753956573930/d24d050d-f737-4d17-ba58-dcbed75e2d0f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction-the-genai-age-creating-instead-of-curating">Introduction: The GenAI Age — Creating Instead of Curating</h1>
<p>Generative AI (GenAI) is transforming the landscape of technology, powering applications which can generate audio, art, or photorealistic images. We have seen a recent trend of Ghibli images being famous throughout the world, as millions of users use ChatGPT DALL-E to generate cartoon-like images by uploading their original images. Although the advanced image generation models use Diffusion techniques instead of Variational Autoencoders, it is interesting to understand how it all started. Generation of any new article, music, or drawing is particularly challenging for humans, as the human mind works best for classification (e.g. distinguishing between two or more objects). The same is the challenge for machines, while classification tasks are comparatively easy for computational engines, generation requires more intricate techniques and, of course, lots of computational power. Images are high-dimensional representations of the real world scene, and the generation of new images would not be possible if the machine doesn’t understand how to deal with the same. Variational Autoencoders, a foundational model, are thus introduced to solve this problem.</p>
<h1 id="heading-what-is-a-variational-auto-encoder-vae">What is a Variational Auto Encoder (VAE)?</h1>
<p>A VAE learns to encode real-world data (e.g. images, text, speech) into a compressed latent space before reconstructing or generating new data points from this space.</p>
<h2 id="heading-how-does-it-work">How does it work?</h2>
<ul>
<li><p><strong>Encoder:</strong> Projects input x into a lower-dimensional latent variable z, which represents the original input.</p>
</li>
<li><p><strong>Latent Space:</strong> Latent space is a lower-dimensional, structured representation learned, where complex data, such as images or sounds, are encoded as abstract, meaningful features that capture the underlying variations in the data.</p>
</li>
<li><p><strong>Decoder:</strong> Regenerates data from sampled latent representations, which means the network can create new similar data, not just reconstruct the input.</p>
</li>
</ul>
<p>$$\text{Dimension of Input Variable:} \quad x \in \mathbb{R}^D$$</p><p>$$\text{Dimension of Latent Variable:} \quad z \in \mathbb{R}^K$$</p><p>$$\text{where} \quad K &lt;<p><img src="https://upload.wikimedia.org/wikipedia/commons/4/4a/VAE_Basic.png" alt="Auto Encoder Image" class="image--center mx-auto" /></p>
<p><em>Image by EugenioTL - Own work, CC BY-SA 4.0,</em> <a target="_blank" href="https://commons.wikimedia.org/w/index.php?curid=107231101"><em>https://commons.wikimedia.org/w/index.php?curid=107231101</em></a></p>
<h2 id="heading-math-behind-the-magic">Math Behind the Magic</h2>
<p>The core of Variational Autoencoders (VAEs) is the optimisation of the Evidence Lower Bound (ELBO), which balances two goals:</p>
<ul>
<li><p>Accurately reconstructing data from the latent space.</p>
</li>
<li><p>Ensuring the latent encodings follow a standard, well-behaved distribution (typically Gaussian).</p>
</li>
</ul>
<p>$$\mathcal{L}(x_n, z_n, \psi, \theta^x) = -\log p(x_n | z_n, \theta^x) + D_{KL}\big( q(z_n|x_n, \psi) \;\|\; p(z_n) \big)$$</p><p>where:</p>
<p>$$p(x_n | z_n, \theta^x) \; \text{is the likelihood term for reconstructing the data}$$</p><p>$$q(z_n|x_n, \psi) \; \text{is the approximate posterior from the encoder}$$</p><p>$$p(z_n) \; \text{is the prior over latent variables (usually a standard normal).}$$</p><p>$$D_{KL}\big( q(z_n|x_n, \psi) \;\|\; p(z_n) \big) \; \text{is the Kullback-Leibler (KL) divergence, regularizing the latent space.}$$</p><p>The <strong>reparameterization trick</strong> allows gradients to flow through stochastic nodes, making training possible (crucial for GenAI scalability).</p>
<h2 id="heading-core-intuition">Core Intuition</h2>
<p>So far, we have defined the loss function of the Variational Autoencoder for training the model to reconstruct (or generate) new data samples. Minimising the loss would lead to the output of the decoder being close to the actual image input. Using techniques such as Backpropagation and Stochastic Gradient Descent, we compute the gradient of the loss function with respect to all network parameters by applying the chain rule backwards through the network layers — from the decoder output, through the latent space, back to the encoder input. Then, we update network parameters to minimise the loss function.</p>
<p>Complete ELBO Loss is a combination of two parts:</p>
<ul>
<li><p><strong>Reconstruction Loss:</strong> Measures how well the decoder can recreate the original input from the latent representation, typically using mean squared error or binary cross-entropy.</p>
</li>
<li><p><strong>KL Divergence Loss:</strong> Regularises the encoder’s latent distribution to stay close to a standard normal distribution, ensuring the latent space remains well-structured and enabling smooth generation.</p>
</li>
</ul>
<h2 id="heading-inference-phase-from-latent-code-to-new-data">Inference Phase: From Latent Code to New Data</h2>
<p>After training is completed, we remove the encoder block from the scenario and now rely on the decoder block to generate new data samples (e.g. images). Unlike training (which encodes real data into latent space), inference starts from the latent space and generates entirely new outputs.</p>
<p>VAE inference follows a straightforward three-step process:</p>
<ul>
<li><strong>Sample from the prior</strong>: Draw a random latent code from the learned prior distribution (typically standard normal).</li>
</ul>
<p>$$z’ \sim p(z|\theta^z)$$</p><ul>
<li><strong>Compute decoder parameters</strong>: Use the decoder network to map the latent code to output distribution parameters.</li>
</ul>
<p>$$\hat{\theta}^x = f(z’; \theta^x)$$</p><ul>
<li><strong>Generate the output</strong>: Sample the final output from the parameterised distribution.</li>
</ul>
<p>$$x \sim p(x|\hat{\theta}_x)$$</p><h2 id="heading-the-elbo-reparameterization-making-vae-training-possible">The ELBO Reparameterization: Making VAE Training Possible</h2>
<p>While the ELBO objective we discussed earlier provides the conceptual framework for VAE training, there’s a critical mathematical challenge: <em>how do you backpropagate through random sampling</em>? The answer lies in an elegant mathematical trick called the <strong>reparameterization trick</strong>.</p>
<p>$$z_n = h(x_n; \psi)\mu + \epsilon_n h(x_n; \psi)\sigma$$</p><p>Instead of sampling z directly from the encoder’s output distribution, we express it as above.</p>
<p>where:</p>
<p>$$h(x_n; \psi)\mu \; \text{and} \; h(x_n; \psi)\sigma \; \text{are the mean and standard deviation output by the encoder}$$</p><p>$$\epsilon_n \sim \mathcal{N}(0,1) \; \text{is noise sampled from a standard normal distribution}$$</p><h3 id="heading-this-reparameterization-transforms-the-optimisation-problem-into">This reparameterization transforms the optimisation problem into</h3>
<p>$$\arg\min_{\psi,\theta^x} \mathbb{E}{x_n,\epsilon_n} \;\mathcal{N}(x_n|f(z_n; \theta^x)\mu, f(z_n; \theta^x)\sigma) + D{KL}(q(z_n|x_n, \psi), \mathcal{N}(z_n|0,1))$$</p><p>The brilliant insight is that gradients can now flow through the <strong>deterministic functions</strong></p>
<p>$$h(x_n; \psi)\mu \; \text{and} \; h(x_n; \psi)\sigma$$</p><p>$$\text{while the randomness is isolated in} \; \epsilon_n$$</p><p><img src="https://www.researchgate.net/publication/374693185/figure/fig1/AS:11431281198179610@1697206307688/Simplified-schematic-of-the-VAE-variational-autoencoder-VAE-models-Fig-1-are.png" alt="Simplified schematic of the VAE variational autoencoder VAE models... |  Download Scientific Diagram" /></p>
<p><em>Source: Puchalski, Andrzej &amp; Komorska, Iwona. (2023). Generative modelling of vibration signals in machine maintenance. Eksploatacja i Niezawodnosc - Maintenance and Reliability. 25. 10.17531/ein/173488.</em></p>
<h2 id="heading-closed-form-kl-divergence">Closed Form KL Divergence</h2>
<p>KL divergence can be computed analytically when dealing with Gaussian distributions:</p>
<p>$$D_{KL}(q(z_n|x_n, \psi), \mathcal{N}(0,1)) \propto -\log h(x_n; \psi)\sigma + \frac{1}{2}h(x_n; \psi)\sigma^2 + \frac{1}{2}h(x_n; \psi)_\mu^2$$</p><p>Without the reparameterization trick, VAE training would be impossible. It’s the mathematical bridge that allows us to:</p>
<ul>
<li><p>Maintain the probabilistic nature of the latent space</p>
</li>
<li><p>Enable gradient-based optimisation</p>
</li>
<li><p>Scale VAE training to complex, high-dimensional data</p>
</li>
</ul>
<h2 id="heading-simplified-loss">Simplified Loss</h2>
<p>While the full VAE formulation with probabilistic outputs is mathematically elegant, <strong>practitioners often use a simplified version</strong> that’s easier to implement and train while maintaining most of the benefits.</p>
<p>Instead of the full probabilistic framework where we sample from the decoder output distribution, we can directly use the mean as our reconstruction.</p>
<p>$$\hat{x} = f(z_n; \theta^x)_\mu$$</p><p>This omits the variance term, transforming our complex probabilistic generation into a straightforward deterministic reconstruction.</p>
<h3 id="heading-simplified-loss-function">Simplified Loss Function</h3>
<p>$$\arg\min_{\psi,\theta^x} \mathbb{E}{x_n,z_n} \sum{d=1}^{D} (x_{n,d} - f(z_n; \theta^x)d)^2 + \sum_{k=1}^{K} \left[-\log h(x_n; \psi){\sigma_k} + \frac{1}{2}h(x_n; \psi){\sigma_k}^2 + \frac{1}{2}h(x_n; \psi)_{\mu_k}^2\right]$$</p><p>where:</p>
<ul>
<li><p>The first term is a simple mean squared error (MSE) between the input and the reconstruction.</p>
</li>
<li><p>The second term is the analytical KL divergence regularising the latent space.</p>
</li>
</ul>
<h3 id="heading-why-this-works-in-practice">Why this works in practice</h3>
<p>This simplified approach offers several advantages:</p>
<ul>
<li><p><strong>Computational Efficiency</strong>: No need to sample from the decoder distribution during training, reducing computational overhead.</p>
</li>
<li><p><strong>Implementation Simplicity</strong>: The loss becomes a straightforward combination of reconstruction error and KL regularisation, much easier to code and debug.</p>
</li>
<li><p><strong>Stable Training</strong>: Removing the stochastic sampling from the decoder output often leads to more stable gradients and faster convergence.</p>
</li>
<li><p><strong>Retained Generative Power</strong>: The latent space still maintains its probabilistic structure through the encoder, preserving the model’s ability to generate diverse samples</p>
</li>
</ul>
<h1 id="heading-vae-algorithm">VAE Algorithm</h1>
<p>We have covered the most important mathematical aspects in the past sections; now, let’s explore how we can implement this programatically.</p>
<pre><code class="lang-plaintext">Data:
    •    D: Dataset
    •    q_φ(z|x): Inference model
    •    p_θ(x, z): Generative model
Result:
    •    θ, φ: Learned parameters
Algorithm:
(θ, φ) ← Initialize parameters
while SGD not converged do
    M ~ D (Random minibatch of data) 
    ε ~ p(ε) (Random noise for every datapoint in M)
    Compute L_θ,φ(M, ε) and its gradients ∇_θ,φ L_θ,φ(M, ε)
    Update θ and φ using SGD optimizer
end
</code></pre>
<p><em>Source: D. P. Kingma and M. Welling, “An Introduction to Variational Autoencoders,” FNT in Machine Learning, vol. 12, no. 4, pp. 307–392, 2019, doi:</em> <a target="_blank" href="https://doi.org/10.1561/2200000056"><em>10.1561/2200000056</em></a><em>.</em></p>
<h1 id="heading-conclusionhttpsdoiorg1015612200000056">Con<a target="_blank" href="https://doi.org/10.1561/2200000056">clusion</a></h1>
<p><a target="_blank" href="https://doi.org/10.1561/2200000056">Variational Au</a>toencoders represent far more than just another neural network architecture—they embody a <strong>fundamental shift in how machines understand and create</strong>. By learning to compress the essence of data into structured latent spaces and probabilistically generate new samples, VAEs laid the mathematical groundwork for the entire GenAI revolution we’re witnessing today. While modern systems like ChatGPT, DALL-E, and Stable Diffusion have moved toward diffusion models and transformers for their impressive results, <strong>they all build upon the core insights pioneered by VAEs</strong>: the power of latent space representations, the importance of probabilistic generation, and the elegant mathematics of variational inference.</p>
<h2 id="heading-key-takeaways">Key Takeaways</h2>
<ul>
<li><p><strong>VAEs solved the fundamental challenge</strong> of teaching machines to generate rather than just classify.</p>
</li>
<li><p><strong>The ELBO objective and reparameterization trick</strong> remain essential concepts in modern generative modelling.</p>
</li>
<li><p><strong>Probabilistic latent spaces</strong> enable the diversity and creativity we see in today’s GenAI applications.</p>
</li>
<li><p><strong>The mathematical principles behind VAEs</strong> continue to influence cutting-edge research in generative AI.</p>
</li>
</ul>
<h2 id="heading-the-road-ahead">The Road Ahead</h2>
<p>As we stand at the forefront of the GenAI era, understanding VAEs isn’t just about historical appreciation—it’s about grasping the mathematical DNA of machine creativity. Whether you’re a researcher pushing the boundaries of generative modelling, a developer implementing creative AI solutions, or simply someone fascinated by how machines learn to imagine, the principles embedded in VAEs will continue to guide the future of artificial creativity.</p>
<p>The next time you marvel at an AI-generated image or piece of music, remember: <em>it all started with the elegant mathematics of variational autoencoders—<strong><strong>teaching machines not just to think, but to dream</strong></strong>.</em></p>
</p>]]></content:encoded></item><item><title><![CDATA[Your 92% Accurate AI Model Might Be Dangerous (Here's Why)]]></title><description><![CDATA[The Problem We're Not Talking About
Your deep learning model can detect cancer from MRI scans with 92% accuracy. Impressive, right? But here's the uncomfortable question: Should doctors actually trust it?
As AI engineers, we often celebrate high accu...]]></description><link>https://blogs.sagnikdas.com/your-92-accurate-ai-model-might-be-dangerous-heres-why</link><guid isPermaLink="true">https://blogs.sagnikdas.com/your-92-accurate-ai-model-might-be-dangerous-heres-why</guid><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[Deep Learning]]></category><dc:creator><![CDATA[Sagnik Das]]></dc:creator><pubDate>Wed, 16 Jul 2025 22:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753728063255/a79d39fc-6882-4b8d-904a-9e840a79722d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-the-problem-were-not-talking-about">The Problem We're Not Talking About</h2>
<p>Your deep learning model can detect cancer from MRI scans with 92% accuracy. Impressive, right? But here's the uncomfortable question: <strong>Should doctors actually trust it?</strong></p>
<p>As AI engineers, we often celebrate high accuracy scores as the ultimate win. But when I dug deeper into the epistemology (fancy word for "how we know what we know") of AI in medicine, I realized we might be solving the wrong problem entirely.</p>
<h2 id="heading-the-black-box-dilemma">The Black Box Dilemma</h2>
<p>Let's be honest about what we've built. Modern neural networks are essentially:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Oversimplified, but you get the idea</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">diagnose_cancer</span>(<span class="hljs-params">mri_scan</span>):</span>
    <span class="hljs-comment"># 50+ layers of transformations</span>
    <span class="hljs-comment"># Billions of parameters</span>
    <span class="hljs-comment"># Gradient descent magic</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">"cancer_probability: 0.92"</span>
</code></pre>
<p>The problem? Even we don't really understand how this function works internally. Sure, we can trace the math, but can you explain to a doctor <em>why</em> the model flagged this specific scan?</p>
<p>This isn't just a UX problem—it's an <strong>epistemic crisis</strong>. In medicine, being right isn't enough. You need to be right <em>for the right reasons</em>.</p>
<h2 id="heading-why-trust-me-it-works-isnt-enough">Why "Trust Me, It Works" Isn't Enough</h2>
<p>Imagine you're a doctor. An AI system tells you a patient has cancer, but you can't explain why. The patient asks: "How do you know?"</p>
<p>Your options:</p>
<ol>
<li><p>"The computer said so, and it's usually right"</p>
</li>
<li><p>"I can see suspicious tissue patterns in regions X and Y that typically indicate..."</p>
</li>
</ol>
<p>Option 1 might work for recommending movies, but it's ethically and epistemologically bankrupt in medicine.</p>
<h3 id="heading-the-reliability-trap">The Reliability Trap</h3>
<p>Some argue for <strong>computational reliabilism</strong>—basically, "if it works consistently, we should trust it." This sounds reasonable until you consider:</p>
<ul>
<li><p><strong>Edge cases</strong>: What happens when the model encounters something outside its training distribution?</p>
</li>
<li><p><strong>Bias amplification</strong>: High accuracy on your test set might hide systematic biases</p>
</li>
<li><p><strong>Accountability</strong>: When the model fails, who's responsible?</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># This is what we often do</span>
<span class="hljs-keyword">if</span> model_accuracy &gt; <span class="hljs-number">0.9</span>:
    deploy_to_production()

<span class="hljs-comment"># This is what we should consider</span>
<span class="hljs-keyword">if</span> model_accuracy &gt; <span class="hljs-number">0.9</span> <span class="hljs-keyword">and</span> model_is_interpretable() <span class="hljs-keyword">and</span> bias_tested():
    deploy_to_production()
</code></pre>
<h2 id="heading-what-this-means-for-ai-engineers">What This Means for AI Engineers</h2>
<p>If you're building AI systems for healthcare (or any high-stakes domain), here's what to consider:</p>
<h3 id="heading-1-build-in-explainability-from-day-one">1. Build in Explainability from Day One</h3>
<p>Don't treat interpretability as an afterthought.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Example with SHAP</span>
<span class="hljs-keyword">import</span> shap

explainer = shap.Explainer(model)
shap_values = explainer(X_test)

<span class="hljs-comment"># Now you can show which features drove the decision</span>
shap.plots.waterfall(shap_values[<span class="hljs-number">0</span>])
</code></pre>
<h3 id="heading-2-design-for-epistemic-transparency">2. Design for Epistemic Transparency</h3>
<p>Create systems where:</p>
<ul>
<li><p><strong>Confidence intervals</strong> are meaningful and well-calibrated</p>
</li>
<li><p><strong>Feature importance</strong> is interpretable to domain experts</p>
</li>
<li><p><strong>Decision boundaries</strong> can be explained in domain terms</p>
</li>
<li><p><strong>Uncertainty quantification</strong> is built-in, not bolted-on</p>
</li>
</ul>
<h3 id="heading-3-collaborate-with-domain-experts">3. Collaborate with Domain Experts</h3>
<p>Your model might be mathematically sound, but does it make medical sense? Partner with doctors to:</p>
<ul>
<li><p>Validate that important features align with medical knowledge</p>
</li>
<li><p>Identify potential failure modes</p>
</li>
<li><p>Ensure explanations are clinically meaningful</p>
</li>
</ul>
<h2 id="heading-the-bigger-picture">The Bigger Picture</h2>
<p>This isn't just about medical AI—it's about <strong>responsible AI development</strong>. As we build increasingly powerful systems, we need to ask:</p>
<ul>
<li><p>Are we optimizing for the right metrics?</p>
</li>
<li><p>Can we explain our models' decisions to stakeholders?</p>
</li>
<li><p>Are we building trust or just demanding it?</p>
</li>
</ul>
<h2 id="heading-practical-takeaways">Practical Takeaways</h2>
<ol>
<li><p><strong>Accuracy is necessary but not sufficient</strong> for high-stakes AI</p>
</li>
<li><p><strong>Interpretability should be a first-class requirement</strong>, not a nice-to-have</p>
</li>
<li><p><strong>Domain expertise is irreplaceable</strong>—collaborate, don't replace</p>
</li>
<li><p><strong>Epistemic humility</strong> is crucial—know what your model doesn't know</p>
</li>
</ol>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>The next time you see that 92% accuracy score, ask yourself: "Would I trust this system to make decisions about my health?" If the answer is no, you've got more work to do.</p>
<p>Building AI that's not just accurate but genuinely trustworthy is one of the most important challenges in tech today. It's not just about better algorithms—it's about building systems that deserve the trust we're asking for.</p>
<hr />
<p><em>What are your thoughts on explainable AI? Have you worked on interpretability in high-stakes domains?</em></p>
]]></content:encoded></item></channel></rss>