<?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 Tilak Sharma on Medium]]></title>
        <description><![CDATA[Stories by Tilak Sharma on Medium]]></description>
        <link>https://medium.com/@tilaksharma_33015?source=rss-3b847bc41770------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N6Op_dFLVlh6ba0u2P7NVw.png</url>
            <title>Stories by Tilak Sharma on Medium</title>
            <link>https://medium.com/@tilaksharma_33015?source=rss-3b847bc41770------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:14:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tilaksharma_33015/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[Variational Autoencoders (VAEs) — An Intuitive Understanding.]]></title>
            <link>https://medium.com/@tilaksharma_33015/variational-autoencoders-vaes-an-intuitive-understanding-d7edd68cb846?source=rss-3b847bc41770------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7edd68cb846</guid>
            <category><![CDATA[vae]]></category>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Tilak Sharma]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 17:38:58 GMT</pubDate>
            <atom:updated>2024-09-16T17:35:39.017Z</atom:updated>
            <content:encoded><![CDATA[<h3>Variational Autoencoders (VAEs) — An Intuitive take.</h3><p>Scenario: Let&#39;s say you are running a restaurant and are the head chef. Lately, you’ve been to a food carnival where you got to experience a new cuisine (data x) and were inspired to recreate it and add that dish to your menu. However, you can’t get the exact recipe for it. So you decide to put on your chef hat and analyze the dish to come up with multiple possibilities (latent variables z) that could result in a similar dish, acknowledging uncertainties like ingredient variations or cooking techniques. Below is a brief analogy:</p><ul><li>Data (<em>x</em>): The original dish that the chef is trying to recreate.</li><li>Encoder <em>qϕ​(z∣x) </em>: Acts as the chef analyzing the dish to infer a distribution over possible recipes.</li><li>Latent (<em>z</em>) : The recipe that has essential information/instructions to make the dish.</li><li>Decoder <em>pθ(x∣z) </em>: A cook who uses the recipe to recreate the dish x.</li><li>Prior <em>p(z) </em>: Distribution of all possible standard recipes of the culinary world.</li><li>KL Divergence <em>Dkl </em>: Ensures that the recreated recipes align with standard recipes and don&#39;t diverge too much that it&#39;s no longer the same dish.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*fsQf_6c9NYWFxhWPxvVXyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*gtoP6hetY0h5J5ic-MCvow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*MGWrcyl56KArGq9mZmpQeA.png" /><figcaption>The chef (encoder) encodes the dish (data x) into what the recipe (latent z) could potentially be. The cook (decoder) prepares this dish following a consise recipe to recreate the dish. The encoder, latent representation, and decoder are the components of the VAE.</figcaption></figure><p>VAEs are a class of generative models that model the data distribution p(x) to a probability distribution or the latent representation z. The probabilistic model, helps us generate similar yet non-identical samples by sampling from the latent distribution that is similar to the training data.</p><h4>What&#39;s cooking? Let&#39;s understand <strong>The Reparameterization Trick.</strong></h4><p>The chef infers a probability distribution over possible recipes <em>z</em>, reflecting his uncertainty. The chef upon creating the possibilities of the recipe hands it over to the cook to recreate it. Once the cook recreates the dish, the chef has to taste it again to assess his analysis (encoding) and make any necessary changes. However, if this sampling process is random, it becomes difficult to understand how his changes to the recipes alter the final dish.</p><p>So the chef decides to use a deterministic method to come up with recipes making the process predictable.</p><p><strong>Reparameterization</strong>: The chef expresses the recipe z as a function of inference parameters and some fixed source of randomness.</p><ul><li>Step 1: The chef determines a base recipe μϕ​(x) — his best guess based on the tasted dish.</li><li>Step 2: He acknowledges the uncertainty by considering possible variations σϕ​(x).</li><li>Step 3: He adjusts the base recipe using a standardized variation (ϵ)</li></ul><p>The final recipe or the latent would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/0*w_eR23Rk9UfRb6dm.png" /></figure><p>ϵ is sampled from a standard normal distribution <em>N(0,I)</em></p><p>The chef reparameterizes recipe selection by adjusting his base recipe with controlled variations. Since the chef has a systematic or a standard way of expressing the recipe, changes in ϕ directly influence z making the final dish predictable. The chef can now understand how his inference affects the final dish, allowing for continuous improvement.</p><h3>Training</h3><p><strong>Encoding:</strong></p><ul><li>Input dish <em>x</em> is analyzed by the chef to produce μϕ(x) and σϕ(x).</li></ul><p><strong>Sampling Latent Variable z:</strong></p><ul><li>Sample ϵ∼N(0,I) and compute z=μϕ(x)+σϕ(x)⊙ϵ.</li><li>This represents sampling a specific recipe variation.</li></ul><p><strong>Decoding:</strong></p><ul><li>The cook uses recipe <em>z</em> to prepare a dish <em>x</em>^.</li></ul><p><strong>Computing Loss:</strong></p><ul><li><strong>Reconstruction Loss:</strong> Measures the difference between the original dish <em>x</em> and the recreated dish <em>x^</em>.</li><li><strong>KL Divergence Loss:</strong> Measures how unusual the recipe <em>z</em> is compared to standard recipes p(z).</li></ul><p><strong>Backpropagation:</strong></p><ul><li>Update the encoder and decoder networks to minimize the total loss.</li></ul><h3>Objective Function/ Loss Function</h3><p>The objective function for VAE training is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/0*tjoz5_OVmQCDn4_4.png" /><figcaption>Note: I have skipped the derivation of this loss function for the sake of simplicity since that requires a deep dive into ELBO and some concepts of variational inference.</figcaption></figure><h4><strong>Reconstruction term</strong>:</h4><ol><li>Maximize the likelihood <em>pθ(x|z)</em> that the recreated dish <em>x^</em> matches the original dish <em>x</em>.</li><li>Expectation Over <em>qϕ(z|x) — </em>The chef considers multiple possible recipes due to uncertainty. The average over all these recipes reflects the overall reconstruction quality.</li></ol><h4><strong>Regularization term:</strong></h4><ol><li><strong>KL Divergence:</strong> Measures how much the chef’s inferred recipe distribution <em>qϕ(z|x)</em> deviates from standard culinary practices <em>p(z).</em></li><li>Encourage the chef to infer recipes that are not only good at reconstructing the dish but also plausible and typical within the culinary tradition. If the chef proposes exotic or implausible recipes far from standard practices, the KL divergence increases, penalizing the objective function.</li></ol><h3>Summary</h3><p>Variational Autoencoders (VAEs) are generative models that learn to encode data into a latent space and reconstruct it by balancing two objectives through the Evidence Lower Bound (ELBO). This balance enables VAEs to generate new, coherent data samples by sampling from the learned latent space, effectively capturing the underlying patterns of the original data.</p><blockquote>“Uff.., if only the chef had known the original source — it could have spared him all this trouble!” 😜</blockquote><p>PS: I have simplified most of the concepts and in some cases, it could be an oversimplification. VAEs is a complex topic and I am digesting it in small chunks myself. In my next article, I’ll go over the implementation using a toy example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7edd68cb846" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>