<?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://carl-allen.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://carl-allen.github.io/" rel="alternate" type="text/html" /><updated>2024-12-18T17:26:28+00:00</updated><id>https://carl-allen.github.io/feed.xml</id><title type="html">Carl Allen: Homepage</title><subtitle>ML Postdoc, ENS Paris
</subtitle><entry><title type="html">Disentangling Disentanglement: how VAEs learn Independent Components</title><link href="https://carl-allen.github.io/theory/2024/12/15/disentanglement.html" rel="alternate" type="text/html" title="Disentangling Disentanglement: how VAEs learn Independent Components" /><published>2024-12-15T20:39:00+00:00</published><updated>2024-12-15T20:39:00+00:00</updated><id>https://carl-allen.github.io/theory/2024/12/15/disentanglement</id><content type="html" xml:base="https://carl-allen.github.io/theory/2024/12/15/disentanglement.html"><![CDATA[<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
        inlineMath: [['$','$'], ["\\(","\\)"]],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
      }
    });
  </script>

<p><!--   <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>  -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"></script></p>

<p align="center">
  <img src="/assets/disentanglement/banner.jpg" alt="woooh" width="100%" height="100" style="display: block; margin: 0 auto" />
</p>

<table>
  <tr>
    <th>This post summarises <a href="https://arxiv.org/pdf/2410.22559">Unpicking Data at the Seams: VAEs, Disentanglement and Independent Components (Allen, 2024)</a>, which explains <b>why disentanglement arises in generative latent variable models</b>. </th>
  </tr>
</table>

<p><strong>Disentanglement</strong> is an intriguing phenomenon observed in generative latent variable models, such as <a href="https://arxiv.org/pdf/1312.6114v11"><em>Variational Autoencoders</em> (VAEs)</a> (our focus), <a href="https://arxiv.org/pdf/1406.2661">Generative Adversarial Networks (GANs)</a> and <a href="https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach_High-Resolution_Image_Synthesis_With_Latent_Diffusion_Models_CVPR_2022_paper.pdf">latent Diffusion models</a>. Although disentanglement has not been rigorously defined, it refers to when semantically meaningful factors of the data map to distinct dimensions in latent space. This allows, for example, images to be generated that vary by a particular feature by changing a <em>single</em> latent dimension (Figure 1 (left), or <a href="https://www.youtube.com/watch?v=DbQNKdtoqUw">this video on disentanglement in GANs</a>). It also allows apparent “embedding arithmetic”, e.g. the vector difference between embeddings of two images that vary in style can be added to that of a third image to transform its style (Figure 1, right).</p>

<p>While disentanglement is often associated with particular model families whose popularity may ebb and flow (e.g. VAEs, $\beta$-VAEs, GANs), we show that the phenomenon itself <strong>relates to the latent structure of the data</strong> and is more fundamental than any model that may expose it.</p>

<p><br /></p>
<style>
#left {
   width: 75%;
    float:left;
}

#rightAside {
    width: 25%;
    float:right;
}
</style>

<p align="center">
  <div id="left">
    <img src="/assets/disentanglement/faces2.png" alt="faces" width="490" height="70" />
            <img src="/assets/disentanglement/numbers.png" alt="numbers" width="493" height="70" />
            <img src="/assets/disentanglement/frogs.png" alt="frogs" width="490" height="70" />
  </div>
  <div id="rightAside">
            <img src="/assets/disentanglement/diffusion_church.png" alt="frogs" width="180" height="210" />
  </div>
</p>
<p align="center">
    <small>Figure 1. Illustrating disentanglement: <emph>(left)</emph> Each row of images varies by a single semantic feature, e.g. hair style or orientation. Disentanglement means that (i) such images can be generated by varying a _single_ latent dimension, i.e. by traversing the latent space in "axis-aligned" directions (parallel to standard basis vectors); and (ii) each latent variable affects a distinct semantic feature rather than several or all. <emph>(right)</emph> Changing the style of an image in diffusion models by disentangled features. (Images from <a href="[url](https://arxiv.org/pdf/2002.03754)">Voynov &amp; Babenko (2020)</a> and <a href="[url](https://openaccess.thecvf.com/content/CVPR2023/papers/Wu_Uncovering_the_Disentanglement_Capability_in_Text-to-Image_Diffusion_Models_CVPR_2023_paper.pdf)">Wu et al. (2023))</a></small>
</p>

<p>\(\bullet\) <strong>Motivation</strong>: Disentanglement is particularly intriguing because models such as VAEs are not intentionally designed to achieve it, and it even occurs in settings impossible for other methods (i.e. isotropic Gaussian prior).<sup id="fnref:locatello" role="doc-noteref"><a href="#fn:locatello" class="footnote" rel="footnote">1</a></sup>\(^,\)<sup id="fnref:khemakem" role="doc-noteref"><a href="#fn:khemakem" class="footnote" rel="footnote">2</a></sup> Thus understanding disentanglement may provide new insights into how models learn and what is learnable. More broadly, the ability to separate out independent aspects of the data is relevant to many areas of machine learning, and teasing its generative factors apart may offer fundamental insights into the data itself.</p>

<p>Machine learning has made incredible breakthroughs in recent years but our theoretical understanding lags notably behind, which may have serious implications as models increasingly reach the public sphere. Thus, a fundamental motivation for this work is to unravel some of the mystery of machine learning. We re-emphasise that disentanglement is not a model feature, rather a property of the data that a model may or may not expose and so is of more general interest. That said, autoencoding the data is often the first step in latent diffusion models, so understanding the latent space is relevant to current state of the art models.</p>

<p>\(\bullet\) <strong>Approach</strong>: Recent works suggest that disentanglement arises in VAEs because commonly used diagonal posterior covariance matrices promote column-orthogonality in the decoder’s Jacobian.<sup id="fnref:rolinek" role="doc-noteref"><a href="#fn:rolinek" class="footnote" rel="footnote">3</a></sup>\(^,\)<sup id="fnref:kumarpoole" role="doc-noteref"><a href="#fn:kumarpoole" class="footnote" rel="footnote">4</a></sup> In empirical support, columns of the decoder Jacobian are indeed found to be closer to orthogonal in VAEs with diagonal covariance than those with full covariance or general auto-encoders;<sup id="fnref:rolinek:1" role="doc-noteref"><a href="#fn:rolinek" class="footnote" rel="footnote">3</a></sup> and directly encouraging column-orthogonality with a constraint is shown to induce disentanglement.<sup id="fnref:kumarpoole:1" role="doc-noteref"><a href="#fn:kumarpoole" class="footnote" rel="footnote">4</a></sup></p>

<p>Building on this, <a href="https://arxiv.org/pdf/2410.22559">Allen (2024)</a>: (A) further clarifies the connection between diagonal covariance and Jacobian orthogonality and (B) explains how disentanglement follows, showing that it amounts to <strong>factorising the data distribution into <em>statistically independent components</em></strong>.</p>

<table>
  <tr>
    <th>$$
        \begin{equation}
        \text{diag. posterior covariance} 
            \quad  \overset{A}{\Rightarrow}\quad   \text{column-orthog. Jacobian} 
            \quad \overset{B}{\Rightarrow}\quad    \text{disentanglement}
        \end{equation}
        $$
 </th>
  </tr>
</table>

<p>\(\bullet\) <strong>Problem set-up</strong>: As in a VAE (or GAN), we assume that data \(x\in\mathcal{X} \subseteq\mathbb{R}^n\) are generated by a latent variable model: independent latent variables are sampled \(z\in\mathcal{Z} =\mathbb{R}^m\), \(p(z) = \prod_ip(z_i)\), and <abbr title="A deterministic GAN generator can be thought of the limiting case as Var[x|z] tends to 0.">mapped stochastically to the data space by sampling \(x\sim p(x\mid z)\)</abbr>. The latent prior is commonly assumed to be isotropically Gaussian \(p_\theta(z_i) = \mathcal{N}(z_i,0,1)\). We also assume \(p_\theta(x\mid z)\) is Gaussian.
[Notation: unsubscripted probability distributions denote the ground truth; subscripts indicate modelled distribution.]</p>

<hr />

<p><strong>TL;DR</strong>:</p>
<ol>
  <li>Disentanglement provably occurs in the <em>linear</em> case, \(p_\theta(x\mid z) = \mathcal{N}(x; Dz,\sigma^2I),\ D\in\mathbb{R}^{n\times m}\), corresponding to <a href="https://academic.oup.com/jrsssb/article-abstract/61/3/611/7083217">probabilistic PCA (PPCA)</a>. Of the infinite set of known solutions, a VAE with diagonal posterior covariance finds only those in which latent dimensions \(z_i\) map to independent factors of variation in the data distribution, which defines <em>disentanglement</em>.</li>
  <li>Surprisingly, the rationale for the linear case (described later in this post) extends to non-linear VAEs with diagonal posterior covariance. The latter property encourages columns of the decoder’s Jacobian to be (approximately) orthogonal, which in turn means independent latent variables \(z_i\) pass through the decoder and emerge (in \(\mathcal{X}\)) as statistically independent components that factorise the full push-forward distribution over the decoder-defined manifold.
    <ul>
      <li>i.e. diagonal covariances cause the decoder to map independent factors in the latent space to independent components in the data space.</li>
    </ul>
  </li>
  <li>A VAE’s objective is maximised if the model distribution matches that of the data, hence if the data distribution factorises into independent components then the model distribution must similarly factorise. So independent factors of the data align with independent factors of the model, which (approximately) align with latent variables \(z_i\) (from 2.) and so independent factors of \(p(x)\) map to distinct latent variables of the model, i.e. \(p(x)\) is <em>disentangled</em>.</li>
</ol>

<hr />
<hr />
<p><br /></p>

<table>
  <tr>
    <th>$$
    \begin{equation}
    \text{diag. posterior covariance} 
        \quad  \overset{A}{\Rightarrow}\quad   \text{column-orthog. Jacobian} 
        \color{lightgray}{\quad \overset{B}{\Rightarrow}\quad    \text{disentanglement}}
    \end{equation}
    $$
 </th>
  </tr>
</table>

<h3 id="a-from-diagonal-covariance-to-jacobian-orthogonality">(A) From Diagonal Covariance to Jacobian Orthogonality</h3>

<p>The VAE fits a latent variable model \(p_\theta(x) =\int_z p_\theta(x\mid z)p_\theta(z)\) to  the data distribution \(p(x)\) by maximising the Evidence Lower Bound (ELBO),</p>

\[\ell(\theta, \phi) \quad =\quad \int p(x) \int q_\phi(z\mid x) 
\ \{\ \log p_\theta(x\mid z) \,-\, \beta \log \tfrac{q_\phi(z\mid x)}{p_\theta(z)} \ \}\ dz dx\ ,\]

<p>where the ELBO has \(\beta=1\) and <a href="https://openreview.net/forum?id=Sy2fzU9gl">\(\beta&gt;1\) is found to improve disentanglement</a>. We assume common VAE assumptions:</p>
<ul>
  <li>\(p_\theta(x\mid z) =\mathcal{N}(x;\,d(x),\sigma^2)\quad\) with <em>decoder</em> \(d\in\mathcal{C}^2\) (injective) and fixed variance \(\sigma^2\);</li>
  <li>\(q_\phi(z\mid x)=\mathcal{N}(z;\,e(x),\Sigma_x)\quad\) with <em>encoder</em> \(e\) and learned variance \(\Sigma_x\); and</li>
  <li>\(p_\theta(z)\quad\ \ \ =\mathcal{N}(z;\,0,I)\quad\) where \(z_i\) are <em>independent</em> with \(p_\theta(z_i)=\mathcal{N}(z_i;0,1)\).</li>
</ul>

<blockquote>
  <p><strong>Maximising the ELBO = <em>maximum-likelihood\(^{++}\)</em></strong>: Maximising the likelihood \(\int p(x)\log p_\theta(x)\) minimises the KL divergence between the data and model distributions, but this is often intractable for a latent variable model. Maximising the ELBO minimises the KL divergences between \(p(x)q_\phi(z\mid x)\) <em>and</em> \(p_\theta(x)p_\theta(z\mid x)\doteq p_\theta(x\mid z)p_\theta(z)\), aligning two models of the joint distribution.</p>
</blockquote>

<p>The ELBO is optimised when \(\Sigma_x\) relates to the Hessian of \(\log p_\theta(x\mid z)\) (<a href="http://www0.cs.ucl.ac.uk/staff/c.archambeau/publ/neco_mo09_web.pdf">Opper &amp; Archambeau</a>) hence under certain conditions<sup id="fnref:conditions" role="doc-noteref"><a href="#fn:conditions" class="footnote" rel="footnote">5</a></sup> when:</p>

\[\begin{equation}
  \Sigma_x^{-1} 
    \ \ \overset{O\&amp;A}{=}\ \ I - \mathbb{E}_{q(z\mid x)}[\tfrac{\partial^2\log p_\theta(x\mid z)}{\partial z_i\partial z_j}]
    \ \ \approx\ \ I + \mathbb{E}_{q(z\mid x)}[\tfrac{1}{\beta\sigma^2}J_z^\top J_z]\ ,
  \tag{1}\label{eq:one}
\end{equation}\]

<p>where \(J_z\) is the Jacobian of \(d\) evaluated at \(z\). For this to hold with diagonal \(\Sigma_x\), <strong>columns of \(J_z\) must be (approximately) orthogonal</strong>, \(\forall z\).<sup id="fnref:suggested" role="doc-noteref"><a href="#fn:suggested" class="footnote" rel="footnote">6</a></sup> If \(J_z=U_zS_zV_z^\top\) is the singular value decomposition (SVD), then \(J_z\) is column-orthogonal \(\quad\) <em>iff</em> \(\ \  J_z^\top J_z = V_zS_z^2V_z^\top\) is diagonal \(\quad\)  <em>iff</em> \(\ \ V_z=I\). Hence, by the definition of the Jacobian, diagonal covariances mean that perturbations in latent space in standard basis vectors \(z_i\) (right singular vectors of $J_z$) correspond to perturbations in data space in directions \(\mathbf{u}_i\) (column \(i\) of \(U_z\), left singular vectors of \(J_z\)), with no effect in any other \(\mathbf{u}_{j\ne i}\). Note that this singles out axis-aligned directions in the latent space as “special”, breaking the rotational symmetry implied by the Gaussian prior.</p>

<blockquote>
  <p><strong>Take-away</strong>: the ELBO is maximised as approximate posterior covariances \(\Sigma_x\) tend to optimal posterior covariances defined by derivatives of \(\log p_\theta(x\mid z)\). Diagonal covariances do not necessarily imply column-orthogonality in the decoder Jacobian, but <em>if they exist</em>, the VAE looks for solutions where the Hessian is diagonal hence where columns of the Jacobian are ($\approx$) orthogonal.
<!-- (hinting towards learning independent factors). --></p>
</blockquote>

<hr />
<hr />
<p><br /></p>

<table>
  <tr>
    <th>$$
      \begin{equation}
      {\color{lightgray}{\text{diag. posterior covariance} 
          \quad  \overset{A}{\Rightarrow}}}\quad   \text{column-orthog. Jacobian}
          \quad \overset{B}{\Rightarrow}\quad    \text{disentanglement}
      \end{equation}
      $$
 </th>
  </tr>
</table>

<h3 id="b-from-orthogonality-to-statistical-independence">(B) From Orthogonality to Statistical Independence</h3>

<p>Understanding that diagonal posterior covariance promotes column-orthogonality in the decoder Jacobian, the question then is how does that <em>geometric</em> property leads to the <em>statistical</em> property of disentanglement. For that we consider the <em>push-forward</em> distribution defined by the decoder, supported over a \(m\)-dimensional manifold \(\mathcal{M}_d\subseteq\mathcal{X}\).</p>

<blockquote>
  <p>A <strong>push-forward distribution</strong> describes the probability distribution of the output of a deterministic function given an input distribution. A VAE decoder maps samples of the latent prior \(p_\theta(z)\) to the data space, where it defines a manifold \(\mathcal{M}_d\) and push-forward distribution over it.</p>
</blockquote>

<hr />

<h4 id="linear-case">Linear Case</h4>

<p>For intuition, we first consider the linear case \(x=d(z)=Dz\),  \(D\in\mathbb{R}^{n\times m}\), the model considered in <a href="https://academic.oup.com/jrsssb/article-abstract/61/3/611/7083217">Probabilistic PCA (PPCA)</a>, which has a tractable MLE solution and known optimal posterior</p>

\[\begin{equation}
  p_\theta(z\mid x) = \mathcal{N}(z;\, \tfrac{1}{\sigma^2}M D^\top x,\, M) \quad\quad\quad M = (I + \tfrac{1}{\sigma^2}D^\top D)^{-1}
  \tag{2}\label{eq:two}
\end{equation}\]

<p>Since $D$ is the Jacobian of $d$, the latter expression is in fact a special case of \eqref{eq:one}. Hence if \(D=USV^\top\) is the SVD, the ELBO is maximised when \(\Sigma_x=M,\ \forall x\in\mathcal{X}\) and so, for diagonal \(\Sigma_x\), when \(V=I\).</p>

<p align="center">
  <img src="/assets/disentanglement/linear.png" alt="linear2" width="440" height="190" style="display: block; margin: 0 auto" />
  <small>Figure 2. Illustration of linear decoder $d:\mathcal{X}\to\mathcal{Z}$. The latent Gaussian prior is mapped to a Gaussian distribution in the data space over a linear manifold. </small>
</p>

<p>The aim is to understand how that constraint affects how independent dimensions \(z_i\in\mathcal{Z}\) and the probability density over them pass through the decoder. For a given point \(z^*\in \mathcal{Z}\), let:</p>
<ul>
  <li>\(\mathcal{Z^{(i)}}\subset\mathcal{Z}\) be lines passing through \(z^*\) parallel to each standard basis vector \(e_i\) (blue dashed lines in Fig. 2), and \(\mathcal{M}_d^{(i)}\subset\mathcal{M_d}\)  be their images under \(d\) that follow  \(\mathbf{u}_i\), the left singular vectors of  \(D\) (red dashed lines); and</li>
  <li>\(x^{(U)}=U^\top x=U^\top Dz^*\)  be $x$ in the basis defined by columns of \(U\)<sup id="fnref:notation" role="doc-noteref"><a href="#fn:notation" class="footnote" rel="footnote">7</a></sup></li>
</ul>

<p>Crucially, the Jacobian of the map from \(z\) to \(x^{(U)}\) is the <em>diagonal</em> matrix \(S\), i.e. \(\tfrac{\partial x^{(U)}_i}{\partial z_j} =\{s_i\doteq S_{i,i} \text{ if }i=j; 0 \text{ o/w}\}\). It then follows that independent \(z_i\) map to independent components \(x^{(U)}_i\) since:</p>
<ol>
  <li>each \(x^{(U)}_i\) varies only with a distinct \(z_i\) by considering  \(\tfrac{\partial x^{(U)}_i}{\partial z_j}\) and so are <em>independent</em>;</li>
  <li>the push-forward of \(d\) restricted to \(\mathcal{Z^{(i)}}\) has density \(p(x^{(U)}_i) = \mid\! s_i\!\mid ^{-1}p(z_i)\) over \(\mathcal{M}_d^{(i)}\); and</li>
  <li>the full push-forward distribution is \(p(Dz) = \mid\!D\!\mid ^{-1}p(z) = \prod_i \mid\! s_i\!\mid^{-1}p(z_i) = \prod _ip(x^{(U)}_i)\).</li>
</ol>

<p>This shows that the push-forward distribution defined by the decoder factorises as a product of independent univariate distributions \(p(x^{(U)}_i)\), which each correspond to a distinct latent dimension \(z_i\). Thus, if the data follows that generative process and so factorises (with factors determined by the SVD of ground truth \(D\)), then the ELBO is maximised when independent factors of the model align with those of the data and so p(x) is <strong>disentangled</strong> as a product of <em>independent components</em> that align with latent dimensions.</p>

<p>This may not seem a surprise in the linear case since it is known from the outset that the push-forward distribution is Gaussian and so factorises as a product of univariate Gaussians. However, neither that fact nor the linearity of \(d\) was used at any stage.</p>

<!-- From $$J_z =\tfrac{d x}{d z}=US, \tfrac{d x}{d u} = U$$, we have $$\tfrac{d u}{d z} =S$$, so $$\tfrac{\partial u_i}{\partial z_j} = \{s_i$$ if $$i= j$$, otherwise $$0\}$$ and each $$u_i$$ depends on a distinct independent r.v. so are *independent*.
2. restricting $$D$$ to $$z_i\in \mathcal{Z}^{(i)}$$ and so $$u_i\in\mathcal{M_d^{(i)}}$$, $$p(u_i)= s_i^{-1}p(z_i)$$ (defined over $$\mathcal{M_d^{(i)}}$$)
 -->

<hr />

<h4 id="non-linear-case-with-diagonal-jacobian">Non-linear Case with Diagonal Jacobian</h4>

<p align="center">
  <img src="/assets/disentanglement/non_linear.png" alt="non_linear2" width="420" height="200" style="display: block; margin: 0 auto" />
  <small>Figure 3. Illustration of non-linear decoder $d:\mathcal{X}\to\mathcal{Z}$. The latent Gaussian prior is mapped to a push-forward distribution in the data space over a non-linear manifold. </small>
</p>

<p>We now take an analogous approach for a general VAE (\(x=d(z)\), \(d\in\mathcal{C}^2\)) <em>with column-orthogonal decoder Jacobian</em>. The Jacobian and its factors, \(J_z=U_zS_zV_z^\top\), may now vary with \(z\), however column-orthogonality restricts \(V_z=I,\ \forall z\in \mathcal{Z}\) and \(U_z\), \(S_z\) are continuous w.r.t. \(z\) (from \(d\in\mathcal{C}^2\) and <a href="https://inria.hal.science/inria-00072686/file/RR-3961.pdf">Papadopoulo &amp; Lourakis (2006)</a>).</p>

<p>As in the linear case, for any \(z^*\in \mathcal{Z}\), we can define lines \(\mathcal{Z^{(i)}}\subset\mathcal{Z}\) passing through \(z^*\) parallel to the standard basis (blue dashed lines in Fig. 3), and their images under \(d\), \(\mathcal{M}_d^{(i)}\subset\mathcal{M_d}\), which are potentially curved sub-manifolds following (local) left singular vectors of \(J_{z^*}\) (red dashed lines).</p>

<p>Considering \(x=d(z)\) in the local \(U\)-basis (i.e. columns of \(U_z\)), denoted \(x^{(U)}=U_z^\top x\), the Jacobian of the map from \(z\) to \(U_z^\top x^{(U)}\) is again <em>diagonal</em> \(S_z\). Hence,  as in the linear case, independent \(z_i\in\mathcal{Z}\) map to independent components \(x^{(U)}_i\) and:</p>
<ol>
  <li>\(\{x^{(U)}_i\}_i\) are <em>independent</em> (by consideration of partial derivatives \(\tfrac{\partial x^{(U)}_i}{\partial z_j}\));</li>
  <li>the push-forward of \(d\) restricted to \(\mathcal{Z^{(i)}}\) has density \(p(x^{(U)}_i) = \mid\! s_i\!\mid^{-1}p(z_i)\) over \(\mathcal{M}_d^{(i)}\); and</li>
  <li>the full push-forward satisfies \(p(d(z)) = \mid J_z\mid ^{-1}p(z) = \prod_i \mid\! s_i\!\mid^{-1}p(z_i) = \prod _ip(x^{(U)}_i)\).</li>
</ol>

<p>Thus, by the same argument as in the linear case, the distribution over the decoder manifold factorises as a product of independent univariate push-forward distributions \(p(x^{(U)}_i)\), each corresponding to a distinct latent dimension \(z_i\).</p>

<p>Putting everything together:</p>
<ul>
  <li>The ELBO is maximised if the model distribution fits the data distribution, so assuming that the data distribution has independent factors (by being generated under the considered model or otherwise) the model distribution must factorise similarly.</li>
  <li>From part A, diagonal covariance matrices encourage the decoder’s Jacobian to be (approximately) column-orthogonal and, where so, the push-forward distribution over the model manifold factorises into components aligned with latent dimensions (from part B).</li>
  <li>Thus the ELBO is maximised if independent components of the data distribution align with those of the model and if those of the model align with latent dimensions, thus the VAE <strong>aligns independent components that factorise the data distribution with latent dimensions</strong>, which defines <em>disentanglement</em>.
    <ul>
      <li>(Identifiability depends on uniqueness of independent component distributions, analogous to uniqueness of singular values in the linear case).</li>
    </ul>
  </li>
</ul>

<blockquote>
  <p><strong>Key insight</strong>: the above result hinges on the SVD of the Jacobian \(J_z = U_zS_zV_z^\top\). By differentiability of \(d\), the bases defined by columns of \(U_z\) and \(V_z\) (in \(\mathcal{X}\) and \(\mathcal{Z}\) resp.) are continuous in \(z\) so basis vectors form continuous curves in each domain (these are linear in \(\mathcal{Z}\) when \(V_z=I\)). By definition of the SVD, traversing a submanifold in one domain corresponds to traversing a corresponding submanifold in the other and the mapping between \(x\) considered in the \(U\)-basis and \(z\) considered in the \(V\) basis has diagonal Jacobian given by \(S_z\)  - irrespective of how complex \(d\) may be, whether a single linear layer or a thousand-layer CNN! As such, probability densities over submanifolds in \(\mathcal{Z}\) map separably to their counterpart in \(\mathcal{X}\), which is to say, independent components in \(\mathcal{Z}\) map to independent components in \(\mathcal{X}\).</p>
</blockquote>

<p><strong>Notes</strong>:</p>
<ul>
  <li>While we assume \(d\in\mathcal{C^2}\), i.e. differentiability, the result also holds for continuous \(d\in\mathcal{C^1}\) <em>differentiable almost everywhere</em>, e.g. ReLU networks.</li>
  <li>We recommend reading <a href="https://arxiv.org/pdf/2410.22559">the full paper</a> for further details, such as:
    <ul>
      <li>consideration of whether orthogonality is strictly <em>necessary</em> for disentanglement (the argument above shows it is <em>sufficient</em>);</li>
      <li>further consideration of model <em>identifiability</em>, i.e. up to what symmetries a VAE can identify ground truth generative factors; and</li>
      <li>explanation of the role of $\beta$ in a <a href="https://openreview.net/forum?id=Sy2fzU9gl">$\beta$-VAE</a>, notably:
        <ul>
          <li>if \(p_\theta(x\mid z)\) is of exponential family form then \(\beta\) corresponds to Var\(_\theta[x\mid z]\) (generalising $\sigma^2$ in the Gaussian case); and</li>
          <li>$\beta$ acts a “glue” determining how close data points need to be (in Euclidean norm) for the model to treat them as “similar”, i.e. for their representations to merge.</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

<!-- 
**Interpreting β in β-VAEs**

β-VAEs introduce a hyperparameter β that scales the KL divergence term in the ELBO. Empirical studies have shown that increasing β enhances disentanglement, often at the cost of reconstruction quality. The sources offer a novel interpretation of β, viewing it as a factor scaling the variance of the likelihood distribution.

Increasing β corresponds to increasing the variance of the likelihood, essentially making the model more uncertain about its reconstructions. This increased uncertainty leads to greater overlap between the posterior distributions of nearby data points. As the ELBO encourages Jacobian orthogonality in expectation over the posterior distributions, larger overlap implies that orthogonality constraints apply over a broader region in the latent space, promoting stronger disentanglement.

Conversely, decreasing β reduces the likelihood variance, mitigating the issue of "posterior collapse". This phenomenon occurs when the likelihood becomes overly expressive, directly modeling the data distribution and rendering the latent variables redundant. By reducing the likelihood variance, β < 1 constrains the model's flexibility, preventing it from learning a trivial solution. -->

<hr />
<hr />

<h3 id="final-remarks">Final remarks</h3>

<p>We hope this post provides clearer insight into (i) what disentanglement means and how diagonal covariances, a seemingly innocuous design choice motivated by computational efficiency, leads to it; (ii) how statistically independent components of the data form “seams” running through the data manifold, which a VAE tries to “unpick”; and (iii) how understanding may transfer surprisingly well from linear to non-linear models.</p>

<hr />

<p>This work throws up many interesting questions, e.g.:</p>
<ul>
  <li>if the VAE objective aims to disentangle, why is disentanglement not observed more reliably, e.g. as observed by <a href="https://arxiv.org/pdf/1811.12359">Locatello et al. (2019)</a>?</li>
  <li>how does this relate to VAE extensions that enhance entanglement, such as <a href="https://arxiv.org/abs/1802.05983">FactorVAE</a> and <a href="https://arxiv.org/abs/1802.04942">TC-VAE</a>?</li>
  <li>can this be used to automatically identify independent factors in the latent space of other models, e.g. GANs and latent diffusion models?</li>
  <li>since this result is for continuous data domains, does it translate to discrete data such as text?</li>
  <li>what does this insight into the structure of the data mean for other modelling paradigms, e.g. supervised, semi-supervised, self-supervised and reinforcement learning?</li>
</ul>

<p>If any of these or related questions are of interest and you would like to collaborate, please free to get in touch (by email, twitter or bluesky).</p>

<p>Thanks for reading! We welcome any constructive feedback or discussion on this post on bluesky (I have pinned a link @carl-allen.bsky.social).</p>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:locatello" role="doc-endnote">
      <p><a href="https://arxiv.org/pdf/1811.12359">Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations; Locatello et al. (2019)</a> <a href="#fnref:locatello" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:khemakem" role="doc-endnote">
      <p><a href="https://proceedings.mlr.press/v108/khemakhem20a/khemakhem20a.pdf">Variational Autoencoders and Nonlinear ICA: A Unifying Framework; Khemakhem et al. (2020)</a> <a href="#fnref:khemakem" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:rolinek" role="doc-endnote">
      <p><a href="https://arxiv.org/pdf/1812.06775">Variational Autoencoders Pursue PCA Directions (by Accident); Rolinek et al. (2019)</a> <a href="#fnref:rolinek" class="reversefootnote" role="doc-backlink">&#8617;</a> <a href="#fnref:rolinek:1" class="reversefootnote" role="doc-backlink">&#8617;<sup>2</sup></a></p>
    </li>
    <li id="fn:kumarpoole" role="doc-endnote">
      <p><a href="https://arxiv.org/pdf/2002.00041">On Implicit Regularization in β-VAEs; Kumar \&amp; Poole (2020)</a> <a href="#fnref:kumarpoole" class="reversefootnote" role="doc-backlink">&#8617;</a> <a href="#fnref:kumarpoole:1" class="reversefootnote" role="doc-backlink">&#8617;<sup>2</sup></a></p>
    </li>
    <li id="fn:conditions" role="doc-endnote">
      <p>When second derivatives of the decoder are small almost everywhere, e.g. as in ReLU networks (<a href="https://arxiv.org/pdf/2002.00041">see Abhishek &amp; Kumar, 2020</a>). <a href="#fnref:conditions" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:suggested" role="doc-endnote">
      <p>As previously suggested more additional approximation steps and assumptions.<sup id="fnref:rolinek:2" role="doc-noteref"><a href="#fn:rolinek" class="footnote" rel="footnote">3</a></sup>\(^,\)<sup id="fnref:kumarpoole:2" role="doc-noteref"><a href="#fn:kumarpoole" class="footnote" rel="footnote">4</a></sup> <a href="#fnref:suggested" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:notation" role="doc-endnote">
      <p>Note that we use slightly different notation to the <a href="https://arxiv.org/pdf/2410.22559">original paper</a>. <a href="#fnref:notation" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Carl Allen</name></author><category term="Theory" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">‘Analogies Explained’ … Explained</title><link href="https://carl-allen.github.io/nlp/2019/07/01/explaining-analogies-explained.html" rel="alternate" type="text/html" title="‘Analogies Explained’ … Explained" /><published>2019-07-01T14:44:00+00:00</published><updated>2019-07-01T14:44:00+00:00</updated><id>https://carl-allen.github.io/nlp/2019/07/01/explaining-analogies-explained</id><content type="html" xml:base="https://carl-allen.github.io/nlp/2019/07/01/explaining-analogies-explained.html"><![CDATA[<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
        inlineMath: [['$','$'], ["\\(","\\)"]],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
      }
    });
  </script>

<p><!--   <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>  -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"></script></p>

<blockquote>
  <p>This post aims to present a `less math, more intuition’ overview of <a href="https://arxiv.org/abs/1901.09813">Analogies Explained: Towards Understanding Word Embeddings</a> (ICML, 2019, Best Paper, hon mention), following the <a href="https://icml.cc/media/Slides/icml/2019/104(13-11-00)-13-11-00-4883-analogies_expla.pdf">conference presentation</a>. Target audience: ML, NLP, CL.           <a href="#proving–the-embedding-relationship-of-analogies">[Skip to result]</a></p>
</blockquote>

<hr />
<hr />

<h2 id="background">Background</h2>

<h3 id="word-embeddings">Word Embeddings</h3>

<p><em>Word embeddings</em> $\mathbf{w}=[w^{(1)}, w^{(2)}, … , w^{(d)}]$ are numerical vector representations of words (e.g. $\mathbf{w}_{\text{cat}}=[0.02, 0.29, …, -0.34])$, where each component $w^{(i)}$ can be thought of as capturing a semantic or syntactic feature of the word, and the full vector $\mathbf{w}$ acts as co-ordinates for the word in a high-dimensional “semantic space”.</p>

<p>Word embeddings can be created as a list of word co-occurrence statistics (or their low-rank factorisation); or learned by a <em>neural network</em>, such as <em><a href="https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf">Word2Vec</a></em> (W2V), <em><a href="https://aclanthology.org/D14-1162.pdf">GloVe</a></em> or a large language model. We shall see that these are closely related, and that the latter <em>neural word embeddings</em> learn statistics implied by the training algorithm, rather than them being explicitly defined.</p>

<p>Neural word embeddings (or simply <em>embeddings</em>) are useful across a wide variety of tasks involving natural language, from identifying word similarity or grammatical role, to assessing the sentiment in a customer review. Here, we focus specifically on word embeddings learned by Word2Vec and GloVe as the relative simplicity of their training algorithm and model architevture allows rigorous analysis.</p>

<h3 id="analogies">Analogies</h3>

<p>An intriguing property observed in trained word embeddings is that <em>analogies</em> are often solved simply by adding/subtracting them, e.g.:</p>

<p style="text-align: center">“<strong><em>man</em></strong> is to <strong><em>king</em></strong> as <strong><em>woman</em></strong> is to <strong><em>queen</em></strong>”</p>

<p>can be <em>solved</em> using word embeddings by finding that closest to \(\mathbf{w}_{king}-\mathbf{w}_{man}+\mathbf{w}_{woman}\) (omitting $man$, $woman$ and $king$ themselves), which often turns out to be \(\mathbf{w}_{queen}\).
This suggests that:</p>

\[\begin{equation}
  \mathbf{w}_{king} - \mathbf{w}_{man} + \mathbf{w}_{woman} \approx \mathbf{w}_{queen}\,
  \tag{1}\label{eq:one}
\end{equation}\]

<p>or, in geometric terms, that <strong><em>word embeddings of analogies approximately form parallelograms:</em></strong></p>
<p style="text-align: center"><img src="/assets/analogy/parallelogram2.svg" alt="word embeddings of analogies approximately form a paralellogram" height="170px" />.</p>

<p>While this seems intuitive, the fact that <em>semantic</em> relationships between words appear as <em>geometric</em> relationships between word embeddings is intriguing since word embeddings are not trained to achieve it!
In practice, the parallelograms formed by word embeddings of analogies are not <em>perfect</em>:</p>

<p style="text-align: center"><img src="/assets/analogy/analogy_embeddings.png" alt="word embeddings of analogies not quite a paralellogram" height="250px" /></p>

<p>This shows the (exact) parallelogram formed by \(\mathbf{w}_{king}, \mathbf{w}_{man}, \mathbf{w}_{woman}\) and a fourth vertex (\(\mathbf{w}_{king} {\small-} \mathbf{w}_{man} {\small+} \mathbf{w}_{woman}\))
in the $xy$-plane with several word embeddings plotted relative to it. We see that (i) the embedding of $queen$ is not at the fourth vertex, but is the closest embedding to it; and (ii) that embeddings of 
related words, e.g. \(prince\) and \(lord\), are close relative to random words.</p>

<table class="mbtablestyle">
  <tbody>
    <tr>
      <td>To explain the relationship between word embeddings of analogies \eqref{eq:one}, we describe the gap (marked ‘?’) between \(\mathbf{w}_{queen}\) and \(\mathbf{w}_{king} {\small-} \mathbf{w}_{man} {\small+} \mathbf{w}_{woman}\); and show that it is small, often smallest, for the word that we expect to complete the analogy.</td>
    </tr>
  </tbody>
</table>

<p>We begin by considering what W2V embeddings learn.</p>

<h3 id="word2vec">Word2Vec</h3>

<p><img src="/assets/analogy/neural_network.png" alt="W2V architecture" style="float: right; margin-right: 0px; margin-top: -10px;" height="250px" /></p>

<p>W2V (SkipGram with negative sampling) generates word embeddings by training the weights of a 2-layer “neural network”
to predict <em>context words</em> \(c_j\) (i.e. words that fall within a context window of fixed size \(l\)) around each word  \(w_i\) (the <em>target word</em>) over a text corpus.</p>

<p>To reduce the computational cost of computing \(p(c_j\!\mid\! w_i)\) over all \(c_j\) in a dictionary \(\mathcal{E}\) using a softmax function, sigmoid functions were trained to classify truly occurring context words from words chosen at random (<em>negative samples</em>).</p>

<p><a href="https://papers.nips.cc/paper/5477-neural-word-embedding-as-implicit-matrix-factorization.pdf">Levy &amp; Goldberg (2014)</a> showed that under this regime, matrices \(\mathbf{W}, \mathbf{C}\) (whose columns are word embeddings \(\mathbf{w}_i, \mathbf{c}_j\)) 
approximately factorise a matrix of <em>shifted Pointwise Mutual Information</em> (PMI):</p>

\[\begin{equation}
\mathbf{W}^\top\mathbf{C} \approx \textbf{PMI} - \log k\ ,
\end{equation}\]

<p>where $k$ is the chosen number of negative samples and
\(\begin{equation}
\textbf{PMI}_{i,j} = \text{PMI}(w_i, c_j) = \log\tfrac{p(w_i,\, c_j)}{p(w_i)p(c_j)}
\end{equation}\,.\)</p>

<p>The <em>shift</em> $\log k$ is an arbitary artifact of the algorithm, which we address in the <a href="https://arxiv.org/abs/1901.09813">paper</a> (Sec 5.5, 6.8) but drop here to simplify. The resulting relationship
\(\mathbf{W}^\top\!\mathbf{C} \!\approx\! \textbf{PMI}\)
implies that an embedding \(\mathbf{w}_i\) can be seen as a <em>low-dimensional projection</em> of \(\text{PMI}_i\), the $i^{th}$ row of the PMI matrix, or <em>PMI vector</em>.</p>

<hr />
<hr />
<p id="proof"><br /></p>
<h2 id="proving-the-embedding-relationship-of-analogies">Proving the embedding relationship of analogies</h2>

<p>This suggests observed additive relationships between word embeddings \eqref{eq:one} follow if the projection from PMI vectors to word embeddings induced by the loss function is sufficiently linear and if equivalent relationships exists between PMI vectors, i.e.</p>

\[\begin{equation}
  \text{PMI}_{king} - \text{PMI}_{man} + \text{PMI}_{woman} \approx \text{PMI}_{queen}\ ;
  \tag{2}\label{eq:two}
\end{equation}\]

<p>A least squares loss gives precisely such a linear projection and we conjecture that W2V and Glove are sufficiently linear to preserve the relative spatial arrangement of vectors.</p>

<table class="mbtablestyle">
  <tbody>
    <tr>
      <td>To now prove that relationship \eqref{eq:two} arises between PMI vectors of an analogy, we translate it into a relationship based on <strong>paraphrases</strong> that equate to an analogy.</td>
    </tr>
  </tbody>
</table>

<h3 id="paraphrases">Paraphrases</h3>

<p>Inuitively, when we say a word \(w_*\) <em>paraphrases</em> a set of words \(\mathcal{W}\), we mean that they are <em>semantically interchangeable</em> in the text. For example, wherever \(king\) appears, we might 
instead see both \(man\) <u>and</u>  \(royal\).
Mathematically, we define the best paraphrase \(w^*\) as the word that maximises the likelihood of the context words found around \(\mathcal{W}\), such that the context word distribution around \(w_*\) (denoted \(p(\mathcal{E}\!\mid\!w_*)\)) is most similar to that around \(\mathcal{W}\) (\(p(\mathcal{E}\!\mid\!\mathcal{W})\)), measured by Kullback-Leibler (KL) divergence. Although these distributions are discrete and unordered, we can picture this intuitively as:</p>

<p style="text-align: center"><img src="/assets/analogy/distributions.png" alt="Paraphrase distributions" height="120px" /></p>

<blockquote>
  <p>Definition: \(w_*\) <strong>paraphrases</strong> $\mathcal{W}$ if the <strong>paraphrase error</strong> \({\rho}^{\mathcal{W}, w_*}\!\in\! \mathbb{R}^{n}\)
 is (element-wise) small:</p>

\[\begin{equation}
    {\rho}^{\mathcal{W}, w_*}_j = \log \tfrac{p(c_j|w_*)}{p(c_j|\mathcal{W})}\ ,   \quad c_j\!\in\!\mathcal{E}.
\end{equation}\]
</blockquote>

<p>Paraphase error quantifies the similarity of the context distribution around any two words \(w_1, w_2\) to that of <strong><u>any other word</u></strong> \(w_*\) in terms of their PMI vectors:</p>

<p style="text-align: center"><img src="/assets/analogy/equation_PMI.png" alt="PMI relationship" height="230px" /></p>

<p>The difference comprises the <em>paraphrase error</em>, which is small only when \(w_*\) paraphrases \(\{w_1, w_2\}\), and <em>dependence error</em> terms that <strong><u>do not depend on $w_*$</u></strong>.
We formalise this as:</p>

<blockquote>
  <p>Lemma 1:
For any word \(w_*\!\in\!\mathcal{E}\) and word set \(\mathcal{W}\!\subseteq\!\mathcal{E}\), \(|\mathcal{W}|\!&lt;\!l\), where \(l\) is the context window size:</p>

\[\begin{equation}
    \text{PMI}_*
    \ =\
    \sum_{w_i\in\mathcal{W}} \text{PMI}_{i}
     \,+\, \rho^{\mathcal{W}, w_*}
     \,+\, \sigma^{\mathcal{W}}
     \,-\, \tau^\mathcal{W}\mathbf{1}\ .
\end{equation}\]
</blockquote>

<p>This connects paraphrasing to PMI vector <em>addition</em>, as appears in \eqref{eq:two}, and is readily generalised to quantify the relationship between <em>word sets</em>. We say \(\mathcal{W}\) and \(\mathcal{W}_*\) paraphrase one another if the distributions of context words around them are similar (this reduces to the original definition if \(\mathcal{W}_*\) contains a single word). Lemma 1 naturally extends to:</p>

<blockquote>
  <p>Lemma 2:
For any word sets \(\mathcal{W}, \mathcal{W}_*\!\subseteq\!\mathcal{E}\); \(|\mathcal{W}|, |\mathcal{W}_*|\!&lt;\!l\):</p>

\[\begin{equation}
    \sum_{w_i\in\mathcal{W}_*} \text{PMI}_{i}
    \ =\
    \sum_{w_i\in\mathcal{W}} \text{PMI}_{i}
     \,+\, \rho^{\mathcal{W}, \mathcal{W}_*}
     \,+\, (\sigma^{\mathcal{W}} - \sigma^{\mathcal{W}_*})
     \,-\, (\tau^\mathcal{W} - \tau^{\mathcal{W}_*})\mathbf{1}
\end{equation}\]
</blockquote>

<p>To see how this relates to paraphrases, let \(\mathcal{W} \!=\! \{woman, king\}\) and \(\mathcal{W}_* \!=\!  \{man, queen\}\), whereby</p>

\[\begin{equation}
  \text{PMI}_{king} - \text{PMI}_{man} + \text{PMI}_{woman} \ \approx\ \text{PMI}_{queen}\ ,
\end{equation}\]

<p>if (a) \(\mathcal{W}\) paraphrases \(\mathcal{W}_*\) (i.e. \(\rho^{\mathcal{W}, \mathcal{W}_*}\) is small) and (b) <em>net</em> statistical dependencies are small for words in \(\mathcal{W}\) and 
\(\mathcal{W}_*\) (i.e. \(\sigma^{\mathcal{W}} - \sigma^{\mathcal{W}_*}\) and \(\tau^\mathcal{W} - \tau^{\mathcal{W}_*}\)).</p>

<table class="mbtablestyle">
  <tbody>
    <tr>
      <td>Thus, subject to dependence errors, \eqref{eq:two} holds if \(\{woman, king\}\) paraphrases \(\{man, queen\}\).</td>
    </tr>
  </tbody>
</table>

<p>This establishes that two <em>paraphrases</em> are a sufficient condition for the geometric relationship between word embeddings observed for an <em>analogy</em>.
What remains then, is to show that an analogy “\(w_a\text{ is to }w_{a^*}\text{ as }w_b\text{ is to }w_{b^*}\)” implies that \(\{w_b, w_{a^*}\!\}\) paraphrases \(\{w_a, w_{b^*}\!\}\).
In fact, we show an equivalence by reinterpreting paraphrases as <em>word transformations</em>.</p>

<h3 id="word-transformation">Word Transformation</h3>

<p>The <a href="#paraphrases">paraphrasing</a> of a word set \(\mathcal{W}\) by a word \(w_*\) can be interpreted as a semantic equivalence between \(\mathcal{W}\) and \(w_*\), denoted \(\approx_p\). Alternatively, for a particular word $w$ in $\mathcal{W}$, a paraphrase indicates which words (the remainder of \(\mathcal{W}\), denoted \(\mathcal{W}^+\)) that, when combined with \(w\), make it “more like” – or <em>transform</em> it to – \(w_*\). For example, the paraphrase of \(\{man, royal\}\)  by \(king\) can be viewed as a <em>word transformation</em> from \(man\) to \(king\) by adding \(royal\).
The added words have the effect of <em>narrowing the context</em> or, more precisely, alter the distribution of context words around \(w\) to more closely align with that of \(w_*\). We can illustrate this as:</p>

<p style="text-align: center"><img src="/assets/analogy/word_trans_1.png" alt="word transformation" width="300px" /></p>

<p>where the paraphrase acts as the “glue” in a relationship <em>from</em> \(w\) <em>to</em> \(w_*\).
Thus, for \(w\!\in\!\mathcal{W}\) and \(\mathcal{W}^+ \!=\! \mathcal{W}\!\setminus\!\!\{w\}\), saying “\(w_*\) paraphrases \(\mathcal{W}\)” is equivalent to saying “there exists a word transformation 
from \(w\) to \(w_*\) by adding \(\mathcal{W}^+\)”. Nothing changes other than the perspective.</p>

<p>Extending this to paraphrases between word sets \(\mathcal{W}\), \(\mathcal{W}_*\!\), we can choose \(w \!\in\! \mathcal{W}\), \(w_* \!\in\! \mathcal{W}_*\) and view the paraphrase as 
defining a relationship between \(w\) and \(w_*\) where \(\mathcal{W}^+ \!=\! \mathcal{W}\!\setminus\!\!\{w\}\) is added to \(w\) and \(\mathcal{W}^- \!=\! \mathcal{W_*}\!\!\setminus\!\!\{w_*\}\) 
to \(w_*\):</p>

<p style="text-align: center"><img src="/assets/analogy/word_trans_2.png" alt="word transformation" width="300px" /></p>

<p>This is not (yet) a word transformation, as it lacks the notion of direction <em>from</em> \(w\) <em>to</em> \(w_*\). But, rather than viewing words in \(\mathcal{W}^-\) as <em>added</em> to \(w_*\), we consider them <em>subtracted</em> from \(w\) (hence our naming convention):</p>

<p style="text-align: center"><img src="/assets/analogy/word_trans_3.png" alt="word transformation" width="300px" /></p>

<p>Just as adding words narrows the context, subtracted words can be viewed as <em>broadening</em> the context.</p>

<blockquote>
  <p>Definition: there exists a <strong><em>word transformation</em></strong> from \(w\) to \(w_*\) with <strong><em>transformation parameters</em></strong> \(\mathcal{W}^+\), \(\mathcal{W}^-\subseteq\mathcal{E}\)    <em>iff</em>   \(\ \{w\}\!\cup\!\mathcal{W}^+ \approx_\text{P} \{w_*\}\!\cup\!\mathcal{W}^-\).</p>
</blockquote>

<h4 id="intuition">Intuition</h4>

<p>The intuition behind word transformations mirrors simple algebra: e.g. 5 is <em>transformed</em> to 8 by adding 3, but if 3 were somehow unavailable, then we could add 4 and subtract 1. With paraphrases alone, words can only be <em>added</em> to \(w\) to transform it to \(w_*\), and perhaps no word exists to describe such “semantic difference”. With word transformations, <em>differences between words</em> can also be used offering a far richer toolkit, e.g. the difference between \(man\) and \(king\) might be described crudely by, say, \(royal\) or $crown$, but is perhaps better described by the difference between $woman$ and $queen$. More generally, transformation parameters (\(\mathcal{W}^+, \mathcal{W}^-\)) <em>describe the difference</em> between \(w\) and \(w_*\) or, one might say, how “\(w\) is to \(w_*\)”.</p>

<h3 id="interpreting-analogies">Interpreting Analogies</h3>

<p>We can now mathematically interpret the language of an analogy:</p>

<blockquote>
  <p>Definition (analogy): <em>”\(w_a\) is to \(w_{a^*}\) as \(w_b\) is to \(w_{b^*}\!\)”</em> <em>iff</em> there exist transformation parameters \(\mathcal{W}^+\!, \mathcal{W}^-\!\subseteq\!\mathcal{E}\) that simultaneously
transform both \(w_a\) to \(w_{a^*}\) and \(w_b\) to \(w_{b^*}\).</p>
</blockquote>

<p>Each occurrence of “is to” in the analogy defintion is synonymous to a set of word transformation parameters and “as” implies their equality. Intuitively, this means that the semantic difference within each word pair, as now quantified, must be the same.</p>

<p>So, an analogy is a pair of word transformations with common parameters \(\mathcal{W}^+, \mathcal{W}^-\), but what are those parameters? Fortunately, we need not search or guess. We show in the 
<a href="https://arxiv.org/abs/1901.09813">paper</a> (Sec 6.4) that if an analogy holds, then <em>any</em> parameters that transform one of the word pairs, e.g. \(w_a\) to \(w_{a^*}\), <em>must also transform the other pair</em>.
We can therefore choose \(\mathcal{W}^+\!=\!\{w_{a^*}\!\}\), \(\mathcal{W}^-\!=\!\{w_{a}\}\). These trivially transform \(w_a\) to \(w_{a^*}\) since \(\{w_a, w_{a^*}\!\}\) exactly paraphrases \(\{w_{a^*\!}, 
w_a\}\) (word order is irrelevant). For the analogy to hold, those parameters must then also transform \(w_b\) to \(w_{b^*}\), i.e. \(\{w_b, w_{a^*}\}\) paraphrases \(\{w_{b^*}, w_a\}\), that is:</p>

\[\begin{equation}
  w_a \text{ is to } w_{a^*} \text{ as } w_b \text{ is to }  w_{b^*}\!\!" \quad\iff\quad  \{w_b, w_{a^*}\} \approx_\text{P} \{w_{b^*}, w_a\}.
  \tag{3}\label{eq:three}
\end{equation}\]

<p>This completes the chain:</p>
<ul>
  <li>analogies are equivalent to word transformations with common transformation parameters describing a common “semantic difference” \eqref{eq:three};</li>
  <li>those word transformations define a readily identifiable paraphrase;</li>
  <li>that paraphrase implies a geometric relationship between PMI vectors \eqref{eq:two} that depends on the paraphrase accuracy (\(\rho\)) and dependence error terms (\(\sigma, \tau\)); and</li>
  <li>under a low-dimensional projection induced by the loss function, that geometric relationship is reflected between the word embeddings of an analogy \eqref{eq:one}.</li>
</ul>

<p>Returning to an initial plot, we can now explain the “gap” in terms of paraphrase (\(\rho\)) and dependence \((\sigma, \tau\)) error terms, and understand why it is variable but often smallest for 
words that complete the analogy. This concludes an end-to-end explanation for the geometric relationship between word embeddings observed for word analogies.</p>

<p style="text-align: center"><img src="/assets/analogy/solution.png" alt="embedding gap explained" height="250px" /></p>

<hr />
<hr />

<h2 id="extensions">Extensions</h2>

<ul>
  <li><a href="https://arxiv.org/abs/1805.12164">“What the Vec? Towards Probabilistically Grounded Embeddings”</a> extends the principles of this work to show: how W2V and Glove (approximately) capture other relationships such as 
<em>relatedness</em> and <em>similarity</em>; what certain embedding interactions correspond to; and, in doing so, how the semantic relationships of <em>relatedness</em>, <em>similarity</em>, <em>paraphrasing</em> and <em>analogies</em> 
mathematically inter-relate.</li>
  <li><a href="https://arxiv.org/abs/1905.09791">“Multi-relational Poincaré Graph Embeddings”</a> <a href="https://github.com/ibalazevic/multirelational-poincare">[code]</a> draws a comparison between analogies and <em>relations</em> in Knowledge Graphs to develop state-of-the-art representation models 
in both Euclidean and Hyperbolic space.</li>
</ul>

<hr />
<hr />

<h2 id="related-work">Related Work</h2>
<p>Several other works aim to theoretically explain the analogy phenomenon, in particular:</p>
<ul>
  <li><a href="https://aclweb.org/anthology/Q16-1028">Arora et al. (2016)</a> propose a latent variable model for text generation that is claimed <em>inter alia</em> to explain analogies, however strong <em>a priori</em> assumptions are made about the 
arrangement of word vectors that we do not require.</li>
  <li><a href="https://www.aclweb.org/anthology/P17-1007">Gittens et al. (2017)</a> introduce the idea of paraphrasing to explain analogies, from which we drew much inspiration, but they include several assumptions that fail in practice, in particular 
that word frequencies follow a uniform distribution rather than their true, highly non-uniform, Zipf distribution.</li>
  <li><a href="https://arxiv.org/pdf/1810.04882v6.pdf">Ethayarajh et al. (2019)</a> aim to show that word embeddings of analogies form parallelograms by considering the latter’s geometric properties. However, several strong assumptions are made that we do not require (e.g.  all embedding must already be co-planar and embedding matrix \(\mathbf{W}\) must be a scalar multiple of \(\mathbf{C}\)) and analogies are ultimately related to a statistical relationship “csPMI” that lacks semantic meaning.</li>
</ul>]]></content><author><name>Carl Allen</name></author><category term="NLP" /><summary type="html"><![CDATA[]]></summary></entry></feed>