<?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://elena-orlova.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://elena-orlova.github.io/" rel="alternate" type="text/html" /><updated>2025-12-18T12:13:37-08:00</updated><id>https://elena-orlova.github.io/feed.xml</id><title type="html">Elena Orlova</title><subtitle>personal description</subtitle><author><name>Elena Orlova</name><email>egorlova68@gmail.com</email></author><entry><title type="html">Deep Stochastic Mechanics</title><link href="https://elena-orlova.github.io/dsm/" rel="alternate" type="text/html" title="Deep Stochastic Mechanics" /><published>2024-06-01T00:00:00-07:00</published><updated>2024-06-01T00:00:00-07:00</updated><id>https://elena-orlova.github.io/dsm</id><content type="html" xml:base="https://elena-orlova.github.io/dsm/"><![CDATA[<p>This post is based on <a href="https://proceedings.mlr.press/v235/orlova24a.html">“Deep Stochastic Mechanics”</a> paper. Here, we’d like to explain the main ideas and show some results from this paper.</p>

<p>In quantum physics, accurately simulating and predicting the behavior of particles is a computationally challenging task due to the curse of dimensionality. The computational complexity grows exponentially as the number of particles in the system increases, making it difficult to study large-scale quantum systems using traditional methods.</p>

<p>Enter Deep Stochastic Mechanics (DSM), a novel approach that leverages deep learning to simulate quantum dynamics efficiently. It is a neural network(NN)–based method that directly samples from the probability density of the wave function, bypassing the need to estimate the wave function itself explicitly.</p>

<h1 id="solving-schrödinger-equation">Solving Schrödinger equation</h1>

<p>At the heart of quantum mechanics lies the <strong>Schrödinger equation</strong> (SE) for $0 &lt; t \le T$ and $\forall x\in \mathbb{R}^d$:</p>

\[i \hbar \partial_{t} \psi (x, t) = \Big[-\frac{\hbar^2}{2m} \frac{\partial^2}{\partial x^2} + V(x, t)\Big] \psi(x, t),\]

<p>given an initial condition</p>

\[\psi(x, 0) = \psi_{0}(x),\]

<p>where $m$ is a particle’s mass, $V(x, t)$ is a potential funtion that describes physics, $\psi(x, t): \mathbb{R}^d \times [0, T]\rightarrow \mathbb{C}$ is a <strong>wave function</strong>.</p>

<p>The <strong>probability density</strong> of finding a particle at position $x$ at time $t$￼is</p>

\[\rho(x,t) = |\psi (x, t)|^2.\]

<hr />

<h2 id="goal-given-an-initial-wave-function--psi_0x-draw-samples-from-psi-x-t2-for-t-in-0t">Goal: given an initial wave function  $\psi_0(x)$, draw samples from $|\psi (x, t)|^2$ for $t \in (0,T]$.</h2>

<p>One of the possible solutions is to directly solve the SE for $\psi (x, t)$ using, for example, finite difference methods. Another approach is Monte-Carlo methods which rely on random sampling. They use a variational ansatz (a parametrized wave function) to approximate the true wave function. Existing methods for solving the time-dependent SE face significant challenges:</p>
<ul>
  <li><em>Classical numerical solvers</em> require discretizing the problem on a grid, leading to an <em>exponential growth</em> in computational complexity as the dimensionality increases.</li>
  <li><em>Physics-informed neural networks (PINNs)</em> <a href="https://www.sciencedirect.com/science/article/pii/S0021999118307125">[Raissi, 2017]</a> are an NN-based version of numerical solver that also suffer from an <em>exponential growth</em> of collocation points.</li>
  <li>Variational methods like <em>time-dependent Variational Monte Carlo (t-VMC)</em> <a href="https://journals.aps.org/prx/abstract/10.1103/PhysRevX.7.031026">[Carleo, 2017]</a> can bypass the curse of dimensionality. However, their accuracy heavily depends on choosing a suitable ansatz (good priors on $\psi$￼ to be effective). Additionally, the optimization process used to find the optimal ansatz parameters may suffer from numerical instabilities, depending on the method and initial conditions.</li>
</ul>

<blockquote>
  <p>What if we can directly sample from the density $\vert \psi (x, t)\vert^2$ without estimating the wave function $\psi(x, t)$?</p>
</blockquote>

<h1 id="dsm-method">DSM method</h1>

<p>DSM takes a different approach by leveraging Nelson’s stochastic mechanics <a href="https://journals.aps.org/pr/abstract/10.1103/PhysRev.150.1079">[Nelson, 1966]</a>, which establishes an equivalence between the time-dependent Schrödinger equation and a diffusion process. Assuming $\psi (x, t) = \sqrt{\rho(x, t)}e^{iS(x, t)}$, we define</p>

\[\begin{align*}
\text{ current velocity: } v(x, t) &amp;= \frac{\hbar}{m} \nabla S(x, t), \\
\text{ osmotic velocity: } u(x, t) &amp;= \frac{\hbar}{2m} \nabla \log \rho(x, t).
\end{align*}\]

<p>Our method relies on the following stochastic process:</p>

\[\mathrm{d}{\color{2D9090}X(t)} = \Big( {\color{982715}v} \big( {\color{2D9090}X(t)}, t \big)+ {\color{982715}u} \big({\color{2D9090}X(t)}, t \big) \Big)\mathrm{d}t + \sqrt{\frac{ \hbar}{m} }\mathrm{d} W, \qquad {\color{2D9090}X(0)} \sim \big|\psi_{0}\big|^2,\]

<p>which <strong>corresponds to sampling from</strong> $\rho = \vert \psi (x, t)\vert^2$; where $u$ is an osmotic velocity, $v$ is a current velocity and $\overset{\rightarrow}{W}$ is a standard (forward) Wiener process. Process $X(t)$ is called the <em>Nelsonian process</em>.</p>

<p>We parametrize velocities $u, v$￼ via NNs, yielding a new process ${\color{2D9090}X^\theta(t)} \in \mathbb{R}^d$￼ that approximates the true process ￼$X(t)$:</p>

\[\mathrm{d}{\color{2D9090}X^\theta(t)} = \Big({\color{982715}v_{\theta}} \big({\color{2D9090}X^\theta(t)}, t \big)+ {\color{982715}u_{\theta} }\big({\color{2D9090}X^\theta(t)}, t \big) \Big)\mathrm{d}t + \sqrt{\frac{ \hbar}{m} }\mathrm{d} {W}.\]

<p>After integration over time, we get</p>

\[{\color{2D9090}X^\theta_{i+1}} = {\color{2D9090}X^\theta_{i}} + \big({\color{982715}v_{\theta}}({\color{2D9090}X^\theta_{i}}, t_{i})+ {\color{982715}u_{\theta}}({\color{2D9090}X^\theta_{i}}, t_{i}) \big)\epsilon + z,\]

<p>where $\epsilon &gt; 0$ is a time step size, $0 \le i &lt; \frac{T}{\epsilon}$, and ￼$z \sim \mathcal{N}\big(0, \frac{\hbar}{m}  \epsilon I_{d}\big)$.</p>

<hr />

<p>Given trained velocities $u_\theta, v_\theta$, and the initial condition $X_0 \sim \vert \psi_{0}\vert^2$, we can produce samples from ￼$\rho$.</p>

<hr />

<h3 id="how-to-train-velocities-u_theta-v_theta">How to train velocities $u_\theta, v_\theta$?</h3>

<p>The Schrödinger equation tells us the velocities should satisfy</p>

\[\begin{align}
\partial_{t} v_\theta &amp;= -\frac{1}{m} \nabla V + \langle u_\theta, \nabla u_\theta \rangle - \langle v_\theta, \nabla v_\theta \rangle + \frac{\hbar}{2m} \nabla \big(\text{div }  u_\theta \big) &amp;&amp;&amp;&amp; \label{eq1}\
\\
\partial_{t} u_\theta &amp;=  - \nabla \langle v_\theta, u_\theta\rangle - \frac{\hbar}{2m} \nabla \big(\text{div }  v_\theta \big)&amp;&amp;&amp;&amp; \label{eq2}
\end{align}\]

<p>where $\nabla = \Big(\frac{\partial}{\partial x_{1}} , \ldots,\frac{\partial}{\partial x_{d}} \Big)$ is a gradient, $\langle \cdot , \cdot  \rangle$ is a scalar product, $\text{div } f(x) = \sum_{i=1}^d \frac{\partial}{\partial x_i}f(x)$ is a divergence operator.</p>

<p>Additionally, the initial velocities should follow the initial conditions</p>

\[v_\theta(x, 0) = \frac{\hbar}{m}\nabla S_0(x) \quad \text{and} \quad u_\theta(x, 0) = \frac{\hbar}{2m}  \nabla \log \rho_0(x) \label{eq:ic}\]

<p>These equations (\ref{eq1}), (\ref{eq2}) and (\ref{eq:ic}) define</p>

\[\begin{align}
  \mathcal{L}_1 (v_{\theta}, u_{\theta}) &amp;= \Big\| \partial_{t} v_\theta +\frac{1}{m} \nabla V - \langle u_\theta, \nabla u_\theta\rangle + \langle v_\theta, \nabla v_\theta\rangle - \frac{\hbar}{2m} \nabla \big(\text{div }  u_\theta \big) \Big\|_2, \\
  \mathcal{L}_2 (v_{\theta}, u_{\theta}) &amp;= \Big \| \partial_{t} u_\theta + \nabla \langle v_\theta, u_\theta\rangle + \frac{\hbar}{2m} \nabla \big(\text{div }  v_\theta \big) \Big \|_2,\\
  \mathcal{L}_3 (v_{\theta}, u_{\theta}) &amp;= \| u_\theta (x, 0) - u_0(x) \|_2 + \| v_\theta (x, 0) - v_0(x) \|_2
\end{align}\]

<p>Then, our loss function to minimize is</p>

\[\mathcal{L} (v_{\theta}, u_{\theta}) = \sum_{i=1}^3 \mathcal{L}_i (v_{\theta}, u_{\theta}).\]

<ul>
  <li>The trajectories are generated iteratively in time: $X^\theta_{i+1} = X^\theta_{i} + \big(v_{\theta}(X^\theta_{i}, t_{i})+ u_{\theta}(X^\theta_{i}, t_{i}) \big)\epsilon + z$.</li>
  <li>At every epoch, generate a batch of trajectories ${ X^\theta_{i, j} }$, where $i$ corresponds to the time step and ￼$j$ is the number of samples.</li>
  <li>These trajectories are used to evaluate the loss function and update the models’ weights.</li>
</ul>

<pre>

</pre>

<p><img src="../../../../images/DSM_plot.pdf?raw=true | width=10" alt="F1" /></p>
<div align="center">(a) DSM training scheme: at every epoch $\tau$, we generate $B$ full trajectories $\{ X_{ij}\}_{ij}$, $i=0, ..., N$, $j=1, ..., B$. Then, we update the weights of our NNs.  (b) An illustration of sampled trajectories at the early epoch. (c) An illustration of sampled trajectories at the final epoch.  (d) Collocation points for a grid-based solver where it should predict values of $\psi(x, t)$. Blue regions in the plots correspond to higher-density regions. </div>

<pre>

</pre>

<hr />

<h2 id="instead-of-explicitly-estimating-the-wave-function-psix-t-dsm-directly-samples-from-the-corresponding-probability-density-vert-psix-tvert2-by-parametrizing-the-velocities-of-the-diffusion-process-using-neural-networks">Instead of explicitly estimating the wave function $\psi(x, t)$, DSM directly samples from the corresponding probability density $\vert \psi(x, t)\vert^2$ by parametrizing the velocities of the diffusion process using neural networks.</h2>

<h3 id="theoretical-guarantee">Theoretical guarantee</h3>

<table>
  <tbody>
    <tr>
      <td><strong>Theorem (Strong convergence bound)</strong>  We have the following bound between the processes $X$ (the Nelsonian process) and $X^\theta$ (its approximation with  $u_\theta, v_\theta$):</td>
    </tr>
  </tbody>
</table>

\[\begin{align*}
    \sup_{t\le T} \mathbb{E}\|X(t) - X^\theta(t)\|^2 \le C_{T} \mathcal{L}(v_{\theta}, u_{\theta}),
  \end{align*}\]

<table>
  <tbody>
    <tr>
      <td>where the constant $C_T$ depends on a time horizon $T$ and Lipschitz constants of  $u, v, u_\theta, v_\theta$.</td>
    </tr>
  </tbody>
</table>

<p>This theorem means that optimizing the loss leads to a convergence of the neural process $X^\theta$ to the Nelsonian process  $X$, and that the loss value directly translates into an improvement of error between the processes.</p>

<h1 id="experimental-results">Experimental results</h1>

<p>Interacting bosons in a harmonic potential:</p>

\[\begin{align*}
  V(x, t) = \sum_i \frac{1}{2} m \omega^2 x_i^2 + \frac{1}{2} g \sum_{i, j} \frac{1}{\sqrt{2 \pi \sigma^2}} e^{-(x_i - x_j)^2 / 2 \sigma^2},
\end{align*}\]

<p>with an initial condition</p>

\[\begin{align*}
  \psi(x, 0) = e^{-\omega^2x^2/(2\hbar)},
\end{align*}\]

<p>where $g$ controls the interaction strength.</p>

<ul>
  <li>A numerical solution (Crank-Nicolson method) as a baseline. Comparison with PINNs and t-VMC.</li>
  <li>Comparing density and some statistics (mean and variance of coordinate as a function of time).</li>
  <li>An NN architecture for DSM/PINN: a feed-forward linear model with skip connections and tanh activations.</li>
  <li>A t-VMC ansatz representation: Hermite polynomials with two-body interaction terms that inherently incorporate knowledge about the ground truth solution. NN ansatz parameterization did not yield satisfactory results.</li>
</ul>

<pre>

</pre>

<p><img src="../../../../images/tVMC-plots-camera-copy.pdf?raw=true | width=10" alt="F2" /></p>
<div align="center"> Simulation results for two interacting bosons in the harmonic oscillator. </div>

<pre>

</pre>

<p>Let’s try to run the simulation for more particles:</p>
<ul>
  <li>The proposed DSM approach demonstrates robust performance, accurately following the ground truth and providing reasonable predictions for $d = 3, 4, 5$ interacting bosons</li>
  <li>Our findings indicate that the t-VMC method can perform reasonably for low-dimensional systems, but its performance degrades as the number of interacting particles increases. This highlights the need for a scalable and carefully designed ansatz representation capable of capturing the complex behavior of particles in high-dimensional quantum systems.</li>
</ul>

<pre>

</pre>

<p><img src="../../../../images/densities_compare_high_d.pdf?raw=true | width=10" alt="F3" /></p>
<div align="center"> Probability density plots for different numbers of interacting particles $d$. For five particles, our computer system does not allow running the Crank-Nicolson solver. </div>

<pre>

</pre>

<p>There are more experiments, including scaling studies, in our <a href="https://proceedings.mlr.press/v235/orlova24a.html">full paper</a>.</p>

<h2 id="conclusions">Conclusions</h2>

<!-- -   Developed ${\color{2D9090}\textbf{new efficient computational method}}$ for simulating quantum dynamics based on ${\color{2D9090}\textbf{Nelson’s stochastic mechanics}}$

  -   Relies on **Markovian diffusion** and **does not require training data** 
  -   **Adaptiv**e to latent low-dimensional support of density

-   ${\color{2D9090}\text{Theoretical guarantees}}$ for our DSM method
-   The experiments show ${\color{2D9090}\text{better performance}}$  of our method compared to the numerical solvers/PINNs/t-VMC both in terms of prediction quality and computation time
 -->

<ul>
  <li>
    <p>Developed the <strong>new efficient computational method</strong> for simulating quantum dynamics based on <strong>Nelson’s stochastic mechanics</strong></p>
  </li>
  <li>Relies on <em>Markovian diffusion</em> and <em>does not require training data</em></li>
  <li>
    <p><em>Adaptive</em> to latent low-dimensional support of density</p>
  </li>
  <li><strong>Theoretical guarantees</strong> for our DSM method</li>
  <li>The experiments show <em>better performance</em>  of our method compared to the numerical solvers/PINNs/t-VMC both in terms of prediction quality and computation time</li>
</ul>

<hr />
<p>Since our DSM algorithm is a new approach for simulating quantum dynamics (solving time-dependent Schrodinger equation), which could be an alternative to t-VMC methods,  there are still some <strong>challenges to resolve</strong>. For example:</p>
<ul>
  <li>We studied relatively simple bosonic systems (though existing methods still struggle). How to extend our approach to fermions?</li>
  <li>We considered a linear spinless SE on a flat manifold with a smooth potential</li>
  <li>More detailed study of our algorithms itself, including more precise error bounds</li>
</ul>

<h2 id="references">References</h2>

<ol>
  <li>
    <p>Nelson, Edward. “Derivation of the Schrödinger equation from Newtonian mechanics.” Physical review 150.4 (1966): 1079.</p>
  </li>
  <li>
    <p>Raissi, Maziar, Paris Perdikaris, and George E. Karniadakis. “Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations.” Journal of Computational physics 378 (2019): 686-707.</p>
  </li>
  <li>
    <p>Carleo, Giuseppe, et al. “Unitary dynamics of strongly interacting bose gases with the time-dependent variational monte carlo method in continuous space.” Physical Review X 7.3 (2017): 031026.</p>
  </li>
</ol>]]></content><author><name>Elena Orlova</name><email>egorlova68@gmail.com</email></author><category term="quantum_mechanics" /><category term="ML" /><category term="generative_models" /><summary type="html"><![CDATA[This post is based on “Deep Stochastic Mechanics” paper. Here, we’d like to explain the main ideas and show some results from this paper.]]></summary></entry><entry><title type="html">Tensor Train and Tensor Ring Decompositions for Neural Networks Compression</title><link href="https://elena-orlova.github.io/posts/TT_TR_NN_compression/" rel="alternate" type="text/html" title="Tensor Train and Tensor Ring Decompositions for Neural Networks Compression" /><published>2023-01-27T00:00:00-08:00</published><updated>2023-01-27T00:00:00-08:00</updated><id>https://elena-orlova.github.io/posts/TT_TR_NN_compression</id><content type="html" xml:base="https://elena-orlova.github.io/posts/TT_TR_NN_compression/"><![CDATA[<p>This post is based on <a href="https://arxiv.org/pdf/1901.10787.pdf">“Tenzorized Embedding Layers” paper</a>. Here, I’d like to explain the main ideas from this paper and show some results.</p>

<p>One of the key components of natural language processing (NLP) models is embedding layers, which transform input words into real vectors. This can be represented as a lookup table (or a matrix). The large vocabulary leads to enormous weight matrices. State-of-the-art  NLP networks are large, with millions to billions of parameters. However, computational resources are oftern limited, which is an essential problem in NLP research. What can we do about that?</p>

<blockquote>
  <p>The purpose of tensor decompositions is to represent a given tensor as a product of smaller tensors called cores with fewer parameters while preserving important information.</p>
</blockquote>

<p>Tensor decompositions, such as Tucker decomposition, canonical decomposition, and Tensor Train (TT) decomposition <a href="https://doi.org/10.1137/090752286">(1)</a>, can be applied for dimensionality reduction in a varity of tasks. For instance, signal and data compression, or compression of neural networks layers. In the last case, model parameters are factorized into smaller cores of the corresponding tensor decomposition. For example, TT decomposition was utilized for a compression of a linear layer <a href="https://proceedings.neurips.cc/paper/2015/hash/6855456e2fe46a9d49d3d3af4f57443d-Abstract.html">(2)</a>, what was extended to a compression of convolutional layer with canonical decomposition <a href="https://arxiv.org/pdf/1412.6553">(3)</a>. The same holds for Tensor Ring (TR) decomposition <a href="https://openaccess.thecvf.com/content_cvpr_2018/papers/Wang_Wide_Compression_Tensor_CVPR_2018_paper.pdf">(4)</a>.</p>

<p>Here, I’d like to show how TT and TR decompositions can be used to compress the embedding layer. 
$\def\uuX{\underline{\bf X}}$
$\def\uuG{\underline{\bf G}}$
$\newcommand\R{\mathbb{R}}$
$\newcommand\bG{\bf G}$
$\newcommand\bX{\bf X}$
$\newcommand\bU{\bf U}$
$\newcommand\bV{\bf V}$</p>

<h1 id="tensor-train-decomposition">Tensor Train decomposition</h1>

<p>Suppose we have a $N$th-order tensor $\uuX \in \R^{I_1 \times I_2 \times \dots \times I_N}$. The TT representation of $\uuX$ is given as</p>

\[x_{i_1, i_2, \dots, i_N} = \sum_{r_1=1}^{R_1} \sum_{r_1=2}^{R_2} \dots \sum_{r_{N-1}=1}^{R_{N-1}} g^{(1)}_{1, i_1, r_1} \cdot g^{(2)}_{r_1, i_1, r_2} \cdot \dots \cdot g^{(N)}_{r_{N-1}, i_N, 1},\]

<p>or, equivalently,</p>

\[x_{i_1, i_2, \dots, i_N} =  {\bG}^{(1)}_{i_1} \cdot {\bG}^{(2)}_{i_1} \cdot ... \cdot {\bG}^{(N)}_{i_N},\]

<p>where slice matrices are defined as
\({\bG}_{i_n}^{(n)} =\) $\uuG^{(n)}(:, i_n, :) \in \mathbb{R}^{R_{n-1} \times R_n}, i_n = 1, 2, \dots, I_N$
with $\uuG^{(n)}$ being the $i_n$th lateral slice of A core tensor $\uuG^{(n)} \in \mathbb{R}^{R_{n-1}\times I_n \times R_n},$ $n=1, 2, \dots,N$ and $R_0 = R_N = 1$ by definition.</p>

<p>The key idea of TT decomposition is demonstrated in the next figure. The minimal values of ${R_k}_{k=1}^{N-1}$ are called TT–ranks for which the TT–decomposition exists.</p>
<pre>

</pre>

<p><img src="../../../../images/TT.png?raw=true | width=10" alt="TT" />
<!-- <img src="https://github.com/favicon.ico" width="48"> --></p>
<div align="center">TT decompostion illustration</div>

<pre>

</pre>

<p>The total number of parameters in TT decomposition can be evaluated as $\sum_{k=1}^N R_{k-1} I_k R_{k}$. Hence, <strong>if there are core tensors with small ranks, the total number of elements required to represent a given tensor in TT–format is significantly smaller than the number of elements in a full tensor $\sum_{k=1}^N I_k$.</strong> This remark makes the application of TT decomposition appealing in a lot of problems related to extremely large data.</p>

<h1 id="tensor-ring-decomposition">Tensor Ring decomposition</h1>
<p>The tensor ring format of a tensor $\uuX \in \mathbb{R}^{I_1 \times \cdots \times I_N}$ is defined as</p>

\[x_{i_1, i_2, \dots, i_N} = \text{Trace}\left( \bG^{(1)}_{i_1} \cdot \ldots \cdot \bG^{(N)}_{i_N} \right),\]

<p>or in index-form</p>

\[x_{i_1, i_2, \dots, i_N} = \sum_{r_0 = 1 }^{R_{0}} \cdots  \sum_{r_{N-1} = 1 }^{R_{N-1}} g^{(1)}_{r_0, i_1, r_1} \cdot \ldots \cdot g^{(N)}_{r_{N-1}, i_N, r_0},\]

<p>where \({\bG}^{(n)}_{i_n}\) is an $i_n$th slice matrix of a tensor $\uuG^{(n)}$ $\in 
\R^{R_{n-1}\times I_n \times R_n}$. The last latent tensor $\uuG^{(N)}$ is of size $R_{N-1} \times I_N \times R_0$, i.e., $R_{N} = R_0$.
<!-- is an $i_n$th slice matrix of the tensor $\uuG^{(n)} \in \mathbb{R}^{R_{n-1}\times I_n \times R_n}$.  The last latent tensor $\uuG^{(N)}$ is of size $R_{N-1} \times I_N \times R_0$, i.e., $R_{N} = R_0$. --></p>

<p>The TR-format can be seen as a natural extension of the TT decomposition where $R_0=R_N=1$. The illustration of TR-format is given in next figure.</p>

<p><img src="../../../../images/TR.png?raw=true" alt="TR" /></p>
<div align="center">TR decompostion illustration</div>

<pre>

</pre>

<p>However, the TR-format is known to have theoretical drawbacks compared to TT decomposition <a href="https://arxiv.org/pdf/1302.7121">(5)</a>. For example, it was found that in case of TR decomposition, minimal TR-ranks for a tensor need not be unique <a href="https://arxiv.org/pdf/1801.02662.pdf">(6)</a> (not even up to permutation of the indices $i_1, \dots , i_N$), resulting in problems in their estimation. On the other hand, numerical experiments show that the TR-format leads to lower ranks of the core tensors compared to the TT-format <a href="https://arxiv.org/pdf/1907.01011">(7)</a>, which means higher compression ratios and lower storage costs.</p>

<h1 id="tt-and-tr-embeddings">TT and TR embeddings</h1>

<p>We aim to replace a regular embedding matrix with a more compact, yet powerful and trainable, format which would allow us to efficiently transform input words into vector representations.</p>

<p>Let $\bX \in \mathbb{R}^{I \times J}$ be a matrix of size $I \times J$. The goal is to get natural factors of its dimensions $I = \prod_{n=1}^N I_n$ and $J = \prod_{n=1}^N J_n$ and then reshape this matrix to $N$th-order tensor $\uuX \in \mathbb{R}^{I_1 J_1 \times I_2 J_2 \times \dots \times I_N J_N}$ whose $n$-th dimension is of length $I_n J_n$ and is indexed by the tuple
$(i_n , j_n)$. We also can treat this procedure as the bijection that map rows and columns of the original matrix to the $N$-dimensional vector-indices. Than TT decomposition according to Eq. (1) is applied to this tensor to get a compact representation:</p>

\[\uuX((i_1, j_1), (i_2, j_2), \dots, (i_N, j_N)) =  \uuG^{(1)}((i_1, j_1), :)  \ldots \uuG^{(N)}(:, (i_N, j_N)).\]

<p>The described representation of a matrix in the TT–format is called a TT–matrix. The obtained factorizations $(I_1, I_2, \dots I_N ) \times (J_1,J_2, \dots J_N)$ will be treated as shapes of a TT– matrix, or TT–shapes. The idea of constructing the TT– matrix from a given matrix is showed in next figure for a 3-dimensional tensor.</p>

<p><img src="../../../../images/tt_matrix.png?raw=true" alt="TT-matrix" /></p>
<div align="center">TT compression of an embedding layer: reshaping a matrix into a tensor, then using TT decomposition</div>
<pre>

</pre>

<p>Similarly, we can define a TR-matrix by reshaping a given matrix $\bX$ into a tensor $\uuX \in \mathbb{R}^{I_1 J_1 \times I_2 J_2 \times \dots \times I_N J_N}$:</p>

\[\uuX((i_1, j_1), (i_2, j_2), \dots, (i_N, j_N)) =  \text{Trace}(\uuG^{(1)}((:,i_1, j_1), :)  \ldots \uuG^{(N)}(:, (i_N, j_N), :)).\]

<p>A concept of building the TR– matrix from the given matrix is showed in next figure for a
3-dimensional tensor.</p>

<p><img src="../../../../images/tr_matrix.png?raw=true" alt="TT-matrix" /></p>
<div align="center">TR compression of an embedding layer: reshaping a matrix into a tensor, then using TR decomposition</div>
<pre>

</pre>

<p>Now we can introduce a concept of a tensorized embedding layer:</p>

<blockquote>
  <p>A TT/TR-embedding layer is a layer where TT/TR–cores are trainable parameters, and they are represented as a TT/TR–matrix which can be transformed into an embedding layer $\bX \in \mathbb{R}^{I \times J}$. The algorithm requires to set the ranks in advance to define the cores size, and they are considered to be hyperparameters of the layer. The ranks values are crucially important since they determine and control the compression ratio.</p>
</blockquote>

<p>To obtain an embedding for a specific word indexed $i$ in a vocabulary, we transform
a row index $i$ into an N-dimensional vector index $(i_1; : : : ; i_N)$, and compute components of TT or TR embedding. Note, that the evaluation of all its components is equal to choosing the specific slices and running a sequence of matrix multiplications, which is implemented efficiently in modern linear algebra modules.</p>

<h1 id="results">Results</h1>

<p>Let me show results on a simple task – sentiment analysis. Sentiment analysis refers to predicting a polarity of a sentence.</p>

<p>The proposed approach is compared with the following baselines:</p>
<ul>
  <li>Standard embedding layer with the baseline compression ratio 1.</li>
  <li>Embedding layer is parametrized by two matrices $\bX = \bU \bV^T$ where $\bU \in \R^{I\times R}$  and $\bU \in \R^{J\times R}$. Then the compression ratio is $\frac{IJ}
{(I+J)R} \sim \frac{J}{R}$.</li>
</ul>

<!-- Transformers in language modeling and machine translation tasks ulilize the same weight
matrix for their embedding and softmax layers which already significantly reduces model
size. So, in our tests, we apply two separate TT/TR decompositions of the same shape for embedding and softmax layers and report the compression ratio as $\frac{|V|d_\text{model}}{2 \times \text{nb. of TT params }}$. -->

<p>We test our approach on popular datasets such as the IMDB dataset with two classes, and the Stanford Sentiment Treebank (SST)  with five classes. Our model consists of a standard bidirectional two-layer LSTM with a hidden size of 128 and a dropout rate of 0.5. For the embedding layer, we used the most frequent 25,000 words for IMDB and 17,200 for SST, and transformed them into a J-dimensional space with a regular embedding layer or a TT/TR embedding layer.</p>

<p><img src="../../../../images/red_imbdb.png?raw=true" alt="res1" /></p>
<div align="center">Sentiment analysis, LSTM with either TT-embedding or TR-embedding on IMDB dataset.
The model is trained for 10 epochs. Embedding compression is calculated as the fraction between
the number of parameters in the full embedding layer and TT/TR–embedding layer.</div>
<pre>

</pre>

<p><img src="../../../../images/res_sst.png?raw=true" alt="res2" /></p>
<div align="center">Sentiment analysis, LSTM with either TT-embedding or TR-embedding on SST dataset.
The model is trained for 10 epochs. Ranks were set to 8 or 16.</div>
<pre>

</pre>

<p>The results of our experiments reveal that the models with the compressed embedding layer performed similarly or even better than the models with standard embedding layers. For example, on the IMDB dataset, the TT embedding layer with a rank of 16 and a test accuracy of 89.7% outperformed our baseline model with a test accuracy of 88.6%. Furthermore, the compressed model had significantly fewer parameters than the full model (7.19 million vs less than a million). Similarly, on the SST dataset, the model with the TR-embedding layer outperformed both the model with the regular embedding layer and the TT layer. In the case of matrix low-rank factorization, we would obtain compression ratios $\frac{J}{R} = \frac{256}{8} =32$ or $\frac{256}{16}= 16$ which are definitely worse compared to tensor factorization techniques.</p>

<p>The obtained slightly better test accuracy of the models with tenzorized embedding layers
suggests that imposing specific tensorial low–rank structure on the matrix of embedding layer can be considered as a particular case of regularization, thus, potentially the model generalize better.</p>

<h1 id="conclusion">Conclusion</h1>

<p>To conclude, TT and TR decompositions can be used to compress neural networks. We use them to compress embedding layers in NLP models. This method can be easily integrated into any deep learning framework and trained via backpropagation, while capitalizing on reduced memory requirements and increased training batch size. More details can be found in the <a href="https://arxiv.org/pdf/1901.10787.pdf">paper</a> and code is available <a href="https://github.com/tt-embedding/tt-embeddings">here</a>.</p>

<h2 id="references">References</h2>
<ol>
  <li>Oseledets, Ivan V. “Tensor-train decomposition.” <em>SIAM Journal on Scientific Computing</em> 33.5 (2011): 2295-2317.</li>
  <li>Novikov, Alexander, et al. “Tensorizing neural networks.” <em>Advances in neural information processing systems</em> 28 (2015).</li>
  <li>Lebedev, Vadim, et al. “Speeding-up convolutional neural networks using fine-tuned cp-decomposition.” <em>arXiv preprint arXiv:1412.6553 (2014)</em>.</li>
  <li>Wang, Wenqi, et al. “Wide compression: Tensor ring nets.” <em>Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition.</em> 2018.</li>
  <li>Grasedyck, Lars, Daniel Kressner, and Christine Tobler. “A literature survey of low‐rank tensor approximation techniques.” <em>GAMM‐Mitteilungen</em> 36.1 (2013): 53-78.</li>
  <li>Ye, Ke, and Lek-Heng Lim. “Tensor network ranks.” a<em>rXiv preprint arXiv:1801.02662 (2018).</em></li>
  <li>Zhao, Qibin, et al. “Learning efficient tensor representations with ring-structured networks.” <em>ICASSP 2019-2019 IEEE international conference on acoustics, speech and signal processing (ICASSP).</em> IEEE, 2019.</li>
</ol>]]></content><author><name>Elena Orlova</name><email>egorlova68@gmail.com</email></author><category term="tensor_networks" /><category term="compression" /><category term="TT_decomposition" /><category term="TR_decomposition" /><category term="ML" /><category term="NLP" /><summary type="html"><![CDATA[This post is based on “Tenzorized Embedding Layers” paper. Here, I’d like to explain the main ideas from this paper and show some results.]]></summary></entry></feed>