<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://yhy258.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://yhy258.github.io/" rel="alternate" type="text/html" /><updated>2026-11-13T15:40:10+09:00</updated><id>https://yhy258.github.io/feed.xml</id><title type="html">Joonhyuk Seo</title><subtitle>Applying visual generative models to solve real-world problems.</subtitle><author><name>Joonhyuk Seo</name><email>joonhyuk.seow@gmail.com</email></author><entry><title type="html">A Diffusion Model You Can Run in This Page</title><link href="https://yhy258.github.io/blog/diffusion-playground/" rel="alternate" type="text/html" title="A Diffusion Model You Can Run in This Page" /><published>2026-11-13T00:00:00+09:00</published><updated>2026-11-13T00:00:00+09:00</updated><id>https://yhy258.github.io/blog/diffusion-playground</id><content type="html" xml:base="https://yhy258.github.io/blog/diffusion-playground/"><![CDATA[<p class="note">This is a sample post. It shows what a post on this blog can contain: math, code, footnotes, notes, and
interactive figures. Edit it or delete it; it lives in <code class="language-plaintext highlighter-rouge">_posts/2026-11-13-diffusion-playground.md</code>.</p>

<h2 id="the-demo">The demo</h2>

<p>Drag the slider to add noise to the data. Then press <strong>Generate from noise</strong> to run the process backwards,
from pure noise to samples.</p>

<figure class="widget" data-demo="diffusion">
  <figcaption><b>Figure 1.</b> 700 points under a variance-preserving diffusion. The slider runs the forward
  process in closed form. The button integrates the reverse process from \(t = 1\) to \(t = 0\) with the exact
  score of the data distribution.</figcaption>
</figure>

<h2 id="what-is-being-computed">What is being computed</h2>

<h3 id="the-forward-process">The forward process</h3>

<p>The forward process mixes a clean sample \(x_0\) with Gaussian noise<sup id="fnref:ddpm" role="doc-noteref"><a href="#fn:ddpm" class="footnote" rel="footnote">1</a></sup>:</p>

\[x_t = \sqrt{\bar\alpha_t}\, x_0 + \sqrt{1 - \bar\alpha_t}\, \epsilon,
\qquad \epsilon \sim \mathcal{N}(0, I).\]

<p>Here \(\bar\alpha_t = \exp\!\big(-\!\int_0^t \beta(s)\, ds\big)\), with a linear schedule
\(\beta(t)\) from 0.1 to 20. The slider’s readout shows the two coefficients as “signal” and “noise”.</p>

<h3 id="the-reverse-process">The reverse process</h3>

<p>Sampling runs time backwards. Both samplers in the figure need only the score
\(\nabla_x \log p_t(x)\)<sup id="fnref:sde" role="doc-noteref"><a href="#fn:sde" class="footnote" rel="footnote">2</a></sup>:</p>

\[\begin{aligned}
\text{SDE:}\quad dx &amp;= \big[-\tfrac{1}{2}\beta(t)\, x - \beta(t)\, \nabla_x \log p_t(x)\big]\, dt + \sqrt{\beta(t)}\, d\bar{w}, \\
\text{ODE:}\quad dx &amp;= -\tfrac{1}{2}\beta(t)\, \big[x + \nabla_x \log p_t(x)\big]\, dt.
\end{aligned}\]

<p>A real diffusion model learns the score with a neural network. Here the data is a mixture of Gaussians with
means \(\mu_k\) and standard deviation \(s\), so \(p_t\) is again a mixture of Gaussians and its score has a
closed form:</p>

\[\nabla_x \log p_t(x) = \sum_k r_k(x)\, \frac{\sqrt{\bar\alpha_t}\,\mu_k - x}{v_t},
\qquad v_t = \bar\alpha_t s^2 + 1 - \bar\alpha_t,\]

<p>where \(r_k(x)\) is the posterior probability that \(x\) came from component \(k\). Tick <strong>Show score field</strong>
to see this vector field change with \(t\).</p>

<h2 id="code">Code</h2>

<p>Code blocks are highlighted and have a copy button. One reverse step of the SDE sampler:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">reverse_step</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">dt</span><span class="p">,</span> <span class="n">score</span><span class="p">):</span>
    <span class="s">"""One Euler-Maruyama step of the reverse SDE, from t to t - dt."""</span>
    <span class="n">b</span> <span class="o">=</span> <span class="n">beta</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
    <span class="n">drift</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">b</span> <span class="o">*</span> <span class="n">x</span> <span class="o">+</span> <span class="n">b</span> <span class="o">*</span> <span class="n">score</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="n">drift</span> <span class="o">*</span> <span class="n">dt</span> <span class="o">+</span> <span class="p">(</span><span class="n">b</span> <span class="o">*</span> <span class="n">dt</span><span class="p">)</span> <span class="o">**</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">torch</span><span class="p">.</span><span class="n">randn_like</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
</code></pre></div></div>

<details>
  <summary>How to add an interactive figure to a post</summary>

  <ol>
    <li>Write the figure as a script in <code class="language-plaintext highlighter-rouge">assets/js/demos/</code>. It finds its own element in the page and fills it.</li>
    <li>Put the element in the post: <code class="language-plaintext highlighter-rouge">&lt;figure class="widget" data-demo="..."&gt;&lt;/figure&gt;</code>.</li>
    <li>List the script in the post’s front matter under <code class="language-plaintext highlighter-rouge">scripts:</code>.</li>
  </ol>

</details>

<h2 id="writing-a-post">Writing a post</h2>

<table>
  <thead>
    <tr>
      <th>To write</th>
      <th>Type</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Inline or display math</td>
      <td><code class="language-plaintext highlighter-rouge">$$ ... $$</code> (within a line, or as its own paragraph)</td>
    </tr>
    <tr>
      <td>A footnote</td>
      <td><code class="language-plaintext highlighter-rouge">[^name]</code> in the text, <code class="language-plaintext highlighter-rouge">[^name]: ...</code> at the end</td>
    </tr>
    <tr>
      <td>A note box</td>
      <td>a paragraph followed by <code class="language-plaintext highlighter-rouge">{: .note}</code></td>
    </tr>
    <tr>
      <td>A figure</td>
      <td><code class="language-plaintext highlighter-rouge">&lt;figure&gt; &lt;img src="..."&gt; &lt;figcaption&gt;...&lt;/figcaption&gt; &lt;/figure&gt;</code></td>
    </tr>
  </tbody>
</table>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:ddpm" role="doc-endnote">
      <p>Ho, Jain, and Abbeel. <a href="https://arxiv.org/abs/2006.11239">Denoising Diffusion Probabilistic Models</a>. NeurIPS 2020. <a href="#fnref:ddpm" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:sde" role="doc-endnote">
      <p>Song et al. <a href="https://arxiv.org/abs/2011.13456">Score-Based Generative Modeling through Stochastic Differential Equations</a>. ICLR 2021. <a href="#fnref:sde" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Joonhyuk Seo</name><email>joonhyuk.seow@gmail.com</email></author><category term="diffusion" /><category term="generative-models" /><summary type="html"><![CDATA[A toy diffusion model on 2D points, with an exact score function instead of a neural network. Also a tour of what a post on this blog can contain.]]></summary></entry></feed>