CTU logo
NIE-PML · CTU FIT

Autoencoders for Collaborative Filtering

Personalised Machine Learning

What Is an Autoencoder?

input image
$\mathbf{x} \in \mathbb{R}^{49}$
$7 \times 7$ pixel values
encoder
$\mathcal{E}$
0.8−1.20.3code
$\mathbf{z} \in \mathbb{R}^{3}$
decoder
$\mathcal{D}$
reconstruction
$\hat{\mathbf{x}} = \mathcal{D}(\mathcal{E}(\mathbf{x}))$
close to the input, not identical
reconstruction loss
$\|\mathbf{x} - \hat{\mathbf{x}}\|^2$
No labels
The input is its own target: an autoencoder learns from unlabelled data.
A narrow code
49 values must pass through 3: the network has to keep what matters.
Objective
$$\min_{\mathcal{E},\,\mathcal{D}}\ \sum_i \big\|\mathbf{x}_i - \mathcal{D}\big(\mathcal{E}(\mathbf{x}_i)\big)\big\|^2$$

The Simplest Autoencoder

$\mathbf{x}$
$n$
$\mathbf{z}$
$d$
$\hat{\mathbf{x}}$
$n$
$\mathcal{E}$
(encoder)
$\mathcal{D}$
(decoder)
One linear hidden layer, squared error
$$\min_{\mathcal{E},\,\mathcal{D}}\ \sum_i \|\mathbf{x}_i - \mathbf{x}_i \mathcal{E}\mathcal{D}\|^2, \qquad \mathcal{E} \in \mathbb{R}^{n\times d},\ \mathcal{D} \in \mathbb{R}^{d \times n}$$
Question
What happens if $d \geq n$?
Answer
Then $\mathcal{E}\mathcal{D} = I$ is allowed: a perfect, trivial copy that learns nothing. With $d < n$, $\mathcal{E}\mathcal{D} \neq I$ and the code must compress.

PCA vs. Autoencoder

PCA: a linear code
projections onto the best line
Autoencoder: a nonlinear code
same points, shorter residuals
Remember lecture 2
A linear autoencoder with squared error learns the same subspace as the truncated SVD: the best rank-$d$ approximation.
Linear code = low-rank factorisation. Nonlinear encoders can follow curved structure.

What Are We Compressing?

itemsusersinteraction matrix
$X$
input
$\mathbf{x}_i$
10010100
encodercode
$z_i$
1.2−0.40.7decoderreconstruction
$\hat{\mathbf{x}}_i$
0.910.070.010.840.030.950.620.09
reconstruction loss
$\|\mathbf{x}_i-\hat{\mathbf{x}}_i\|^2$
← a high score wherethe input was 0:a recommendation

The Copy Problem

input
$\mathbf{x}_i$
output
$\hat{\mathbf{x}}_i$
11.0000.0000.0011.0000.0011.00
$\hat{\mathbf{x}}_i = \mathbf{x}_i$
Training error
A perfect copy produces zero training error.
Can this happen if $\dim(z_i) < \dim(\mathbf{x}_i)$?
A narrower code can still reach it when the data are simple: with only 4 distinct inputs, 2 bits suffice, independently of the size of $\mathbf{x}_i$.
Every zero entry of $\mathbf{x}_i$ is reproduced as a zero entry of $\hat{\mathbf{x}}_i$: no unseen item receives a score.
For recommendation, reproducing the input is the failure mode: the score $\hat{x}_{ij}$ of item $j$ for user $i$ must be predicted from the other entries $x_{ik}$, $k \neq j$, and not from $x_{ij}$ itself.

EASE: The Shallowest Autoencoder

$X$
$m \times n$
$\hat{X}$
$m \times n$
$B$
$n \times n$
$\times$
$=$
00000
$\mathrm{diag}(B) = 0$
No hidden layer
No encoder and no decoder: the item–item matrix $B$ maps a history directly to scores, $\hat{\mathbf{x}}_i = \mathbf{x}_i B$.
Optimisation problem
$\displaystyle\min_{B}\ \|X - XB\|_F^2$$\displaystyle\ + \lambda \|B\|_F^2$$\displaystyle\text{s.t.}\ \ \mathrm{diag}(B) = 0$
Question
What is the solution of this problem?
Answer
Unconstrained, $B = I$ is optimal: a perfect copy with zero error. Hence $\mathrm{diag}(B) = 0$.

EASE Intuition: Rows of B

$\mathbf{x}_i$
$B$
111222333444555666010010000000
$\times$
$=$
00
$B_{22} = B_{55} = 0$
$\hat{\mathbf{x}}_i$
1234560.40.00.20.80.30.80.30.80.50.70.00.60.00.00.70.80.71.50.31.4
$\text{row }2\text{ of }B$
$\text{row }5\text{ of }B$
$\hat{\mathbf{x}}_i\text{ = sum}$
$+$
$=$
Row $i$ of $B$ says how much item $i$ votes for every other item; its diagonal entry is zero, so no item votes for itself. Thus, a user's scores are the sum of the rows of the items in the history.

EASE Intuition: Columns of B

$X$
$B$
$\hat{X}$
000000
$\times$
$=$
$j$
$j$
$\|X_{\bullet,j} - XB_{\bullet,j}\|^2 + \lambda\|B_{\bullet,j}\|^2$
$j$
0
Column $j$ of $B$
Multiplying $X$ by the column $B_{\bullet,j}$ gives column $j$ of $\hat{X}$: $\hat{X}_{\bullet,j} = XB_{\bullet,j}$.
A ridge regression
$B_{\bullet,j}$ is fitted so that $XB_{\bullet,j}$ matches column $j$ of $X$. Since $B_{jj} = 0$, item $j$ is predicted from the other items.
As in lecture 2 (ALS), one item is a ridge regression on the other items. That gives $n$ independent regressions, or one closed form for all of $B$ at once.

EASE: Closed Form (1/5)

Problem
$$\min_B\ \|X - XB\|_F^2 + \lambda \|B\|_F^2 \quad \text{s.t.}\ \mathrm{diag}(B) = 0, \qquad X \in \mathbb{R}^{m \times n},\ B \in \mathbb{R}^{n\times n}$$
Lagrangian: one multiplier $\gamma_j$ per diagonal entry
$$\mathcal{L}(B, \boldsymbol{\gamma}) = \|X - XB\|_F^2 + \lambda \|B\|_F^2 + 2\,\boldsymbol{\gamma}^\top \mathrm{diag}(B)$$
$\mathrm{diag}(B) \in \mathbb{R}^{n}$ is the vector of the diagonal entries of $B$. The factor 2 only makes the derivative tidy.

EASE: Closed Form (2/5)

Set the derivative to zero
$$\frac{\partial \mathcal{L}}{\partial B} = 2X^\top(XB - X) + 2\lambda B + 2\,\mathrm{diagMat}(\boldsymbol{\gamma})$$
$$0 = X^\top X B - X^\top X + \lambda B + \mathrm{diagMat}(\boldsymbol{\gamma})$$
$$(X^\top X + \lambda I)\,B = X^\top X - \mathrm{diagMat}(\boldsymbol{\gamma})$$
$$\hat{B} = (X^\top X + \lambda I)^{-1}\big(X^\top X - \mathrm{diagMat}(\boldsymbol{\gamma})\big)$$
$\mathrm{diagMat}(\boldsymbol{\gamma}) \in \mathbb{R}^{n \times n}$ is the diagonal matrix with $\boldsymbol{\gamma}$ on its diagonal.

EASE: Closed Form (3/5)

Define $Q$ and substitute, step by step
$\displaystyle \hat{B} = \textcolor{#1f5fbf}{(X^\top X + \lambda I)^{-1}}\big(\textcolor{#2e7d32}{X^\top X} - \mathrm{diagMat}(\boldsymbol{\gamma})\big)$from the previous slide
$\displaystyle \textcolor{#1f5fbf}{Q} := \textcolor{#1f5fbf}{(X^\top X + \lambda I)^{-1}}$define $\textcolor{#1f5fbf}{Q}$ (regularised inverse Gram matrix)
$\displaystyle \hat{B} = \textcolor{#1f5fbf}{Q}\big(\textcolor{#2e7d32}{X^\top X} - \mathrm{diagMat}(\boldsymbol{\gamma})\big)$substitute $\textcolor{#1f5fbf}{Q}$
$\displaystyle \textcolor{#2e7d32}{X^\top X} = \textcolor{#1f5fbf}{(X^\top X + \lambda I)} - \lambda I$$\displaystyle \; = \textcolor{#b26a00}{Q^{-1} - \lambda I}$add and subtract $\lambda I$
recognise $\textcolor{#b26a00}{Q^{-1}}$
$\displaystyle \hat{B} = \textcolor{#1f5fbf}{Q}\big(\textcolor{#b26a00}{Q^{-1} - \lambda I} - \mathrm{diagMat}(\boldsymbol{\gamma})\big)$substitute $\textcolor{#2e7d32}{X^\top X}$
$\displaystyle \hat{B} = Q Q^{-1} - Q\lambda I - Q\,\mathrm{diagMat}(\boldsymbol{\gamma})$distribute $Q$: split the parentheses
$\displaystyle \hat{B} = Q Q^{-1} - Q\,\mathrm{diagMat}(\lambda\mathbf{1}) - Q\,\mathrm{diagMat}(\boldsymbol{\gamma})$write $\lambda I = \mathrm{diagMat}(\lambda\mathbf{1})$
$\displaystyle \hat{B} = Q Q^{-1} - Q\,\mathrm{diagMat}(\lambda\mathbf{1} + \boldsymbol{\gamma})$join both inside $\mathrm{diagMat}$
$\displaystyle \hat{B} = I - Q\,\mathrm{diagMat}(\lambda\mathbf{1} + \boldsymbol{\gamma})$$QQ^{-1} = I$

EASE: Closed Form (4/5)

Impose the constraint $\mathrm{diag}(\hat{B}) = 0$
$\displaystyle \hat{B} = \textcolor{#2e7d32}{I} - \textcolor{#1f5fbf}{Q}\,\textcolor{#b26a00}{\mathrm{diagMat}(\lambda\mathbf{1} + \boldsymbol{\gamma})}$from the previous slide
$\displaystyle \hat{B}_{jj} = \textcolor{#2e7d32}{I_{jj}} - \textcolor{#1f5fbf}{Q_{jj}}\,\textcolor{#b26a00}{(\lambda + \gamma_j)}$diagonal entry $(j,j)$: the matrix is diagonal, so only one term survives
$\displaystyle \hat{B}_{jj} = \textcolor{#2e7d32}{1} - \textcolor{#1f5fbf}{Q_{jj}}\,\textcolor{#b26a00}{(\lambda + \gamma_j)}$$I_{jj} = 1$
$\displaystyle \textcolor{#2e7d32}{1} - \textcolor{#b26a00}{(\lambda + \gamma_j)}\,\textcolor{#1f5fbf}{Q_{jj}} = 0$impose $\hat{B}_{jj} = 0$
$\displaystyle \lambda + \gamma_j = \textcolor{#D50032}{\frac{1}{Q_{jj}}}$solve for $\lambda + \gamma_j$
Each multiplier is now fixed: $\gamma_j = 1/Q_{jj} - \lambda$.

EASE: Closed Form (5/5)

The off-diagonal entries, step by step
$\displaystyle \hat{B} = \textcolor{#2e7d32}{I} - \textcolor{#1f5fbf}{Q}\,\textcolor{#b26a00}{\mathrm{diagMat}(\lambda\mathbf{1} + \boldsymbol{\gamma})}$from the previous slides
$\displaystyle \lambda + \gamma_j = \textcolor{#D50032}{\frac{1}{Q_{jj}}}$from the constraint
$\displaystyle \hat{B}_{ij} = \textcolor{#2e7d32}{I_{ij}} - \textcolor{#1f5fbf}{Q_{i,\bullet}}\,\textcolor{#b26a00}{\mathrm{diagMat}(\lambda\mathbf{1} + \boldsymbol{\gamma})_{\bullet,j}}$entry $(i,j)$: row $i$ of $Q$ times column $j$ of diagMat
$\displaystyle \hat{B}_{ij} = \textcolor{#2e7d32}{0} - \textcolor{#1f5fbf}{Q_{ij}}\,\textcolor{#b26a00}{(\lambda + \gamma_j)} \qquad (i \neq j)$only one term survives; $I_{ij} = 0$ for $i \neq j$
$\displaystyle \hat{B}_{ij} = -\textcolor{#1f5fbf}{Q_{ij}}\cdot\textcolor{#D50032}{\frac{1}{Q_{jj}}} = -\frac{\textcolor{#1f5fbf}{Q_{ij}}}{\textcolor{#1f5fbf}{Q_{jj}}} \qquad (i \neq j)$substitute $\lambda + \gamma_j = 1/Q_{jj}$
Why $(\lambda + \gamma_j)$? The factors of $\hat{B}_{ij}$: row $i$ of $Q$ is dense, column $j$ of the diagonal matrix has one entry
010000000000000100000000000001000000000000010000000000000100000000000001
$=$
$-$
$\times$
$\hat{B}$
$I$
$Q$
$\mathrm{diagMat}(\lambda\mathbf{1}+\boldsymbol{\gamma})$
$\hat{B}_{ij}$
$I_{ij} = 0$
$Q_{ij}$
$\lambda + \gamma_j$
EASE closed form
$$\hat{B}_{ij} = -\frac{Q_{ij}}{Q_{jj}}\ \ (i \neq j), \qquad \hat{B}_{jj} = 0, \qquad Q = (X^\top X + \lambda I)^{-1}$$

EASE in Four Lines of Code

EASE closed form
$$\hat{B}_{ij} = -\frac{Q_{ij}}{Q_{jj}}\ \ (i \neq j), \qquad \hat{B}_{jj} = 0, \qquad Q = (X^\top X + \lambda I)^{-1}$$
Four lines of numpy
G = X.T @ X                     # item co-occurrences
Q = np.linalg.inv(G + lam * np.eye(n))
B = -Q / np.diag(Q)             # divide column j by Q[j, j]
np.fill_diagonal(B, 0.0)

Predicting with EASE

$\mathbf{x}_i$
$B$
111222333444555666100100000000
$\times$
$=$
$\hat{\mathbf{x}}_i$
10.821.131.440.651.560.7
seenseenrecommend: top unseen score
Prediction is reconstruction: $\hat{\mathbf{x}}_i = \mathbf{x}_i B$. Each item the user has not interacted with is scored through the rows of $B$ of the items in the history.

Is EASE Any Good?

Ranking accuracy, Steck (2019), Table 1
ML-20MNetflixMSD
modelR@20N@100R@20N@100R@20N@100
popularity0.1620.1910.1160.1590.0430.058
EASE0.3910.4200.3620.3930.3330.389
SLIM0.3700.4010.3470.379did not finish
WMF0.3600.3860.3160.3510.2110.257
CDAE0.3910.4180.3430.3760.1880.237
Mult-VAE0.3950.4260.3510.3860.2660.316
Mult-DAE0.3870.4190.3440.3800.2660.313
Steck (2019), Table 1 (selected columns: Recall@20, NDCG@100). Standard errors about 0.001–0.002.

Not Scalable for Large Catalogues

Storing one dense $B$
01 TB2 TB3 TB4 TB
$1\,000$
4 MB
$3\,000$
36 MB
$10\,000$
0.4 GB
$30\,000$
3.6 GB
$100\,000$
40 GB
$300\,000$
360 GB
$1\,000\,000$
4 TB
$n$
memory
$10\times \text{ more items} \Rightarrow 100\times \text{ more memory}$
Memory
$X^\top X$, $Q$ and $B$ are $n \times n$: $O(n^2)$, even when $X$ is very sparse.
Time
Inverting $X^\top X + \lambda I$: $O(n^3)$.
Real catalogues have millions of items.
Can we keep the idea of EASE but not the dense square?

ELSA: EASE with Item Embeddings

$B$
$\text{EASE: free, dense}$
000000
$n \times n$
$B =$
$\rightsquigarrow$
$A$
$\text{item embeddings}$
$n \times d$
$\times$
$A^{\top}$
$d \times n$
$-$
$I$
$n \times n$
EASE learns a free $n \times n$ matrix. ELSA writes $B = AA^\top - I$ with a thin $n \times d$ matrix $A$, $d \ll n$, assuming every row has unit length, $\|\mathbf{a}_j\| = 1$.

ELSA: Unit-Length Rows Give a Zero Diagonal

$A$
$A^{\top}$
$AA^{\top}$
1.000.000.600.800.001.00−0.600.801.000.600.00−0.600.000.801.000.801.000.600.00−0.600.601.000.800.280.000.801.000.80−0.600.280.801.00
$\times$
$=$
$\|\mathbf{a}_j\| = 1$
$\text{diagonal} = 1$
$-$
$I$
1000010000100001
$=$
$B$
00.600.00−0.600.6000.800.280.000.8000.80−0.600.280.800
$\mathrm{diag}(B) = 0$
$AA^{\top} = (AA^{\top})^{\top}$
$B = B^{\top}$
Each row of $A$ has length one, so $(AA^\top)_{jj} = \mathbf{a}_j \cdot \mathbf{a}_j = \|\mathbf{a}_j\|^2 = 1$. Subtracting $I$ removes exactly these ones: $B_{jj} = 1 - 1 = 0$, for free. Off the diagonal both matrices hold the cosines between item embeddings, so they are symmetric: $B_{ij} = B_{ji}$.

ELSA: The Optimisation Problem

ELSA: optimisation problem
$$\min_{\textcolor{#0e7490}{A}}\ \big\|\, \textcolor{#6b7280}{N}(X) - \textcolor{#6b7280}{N}\big(X(\textcolor{#0e7490}{AA^\top} - I)\big) \big\|_F^2 \quad \text{s.t.}\ \ \textcolor{#2e7d32}{\|\mathbf{a}_j\|_2 = 1}\ \text{ for every item } j$$
$\textcolor{#0e7490}{A \in \mathbb{R}^{n \times d}}$
latent matrix; row $\mathbf{a}_j$ is the embedding of item $j$. The size $d \ll n$ is the main hyperparameter.
$\textcolor{#b26a00}{X(AA^\top - I)}$
the usual reconstruction $\hat{X} = XB$ with $B = AA^\top - I$: neither $B$ nor $n \times n$ numbers are stored.
$\textcolor{#6b7280}{N(\cdot)}$
each user row is normalised to unit $\ell_2$ length in both terms.
$\textcolor{#2e7d32}{\|\mathbf{a}_j\|_2 = 1}$
unit rows give $\mathrm{diag}(B) = 0$ for free. They are enforced by normalising $A$ in every step, so the problem is unconstrained in practice.
Trained by gradient descent (Adam with Nesterov momentum), not by inverting $X^\top X + \lambda I$.

ELSA Is a Shallow Autoencoder

input
$\mathbf{x}$
10010100
$A$
encodercode
$\mathbf{z} = \mathbf{x}A$
2.001.331.00
$A^{\top}$
decoder
$-$
reconstruction
$\hat{\mathbf{x}} = \mathbf{z}A^{\top} - \mathbf{x}$
$\text{skip connection: subtract the input}$
1.001.331.001.561.561.22−0.220.78
$\hat{\mathbf{x}} = (\mathbf{x}A)A^\top - \mathbf{x}$: only $d$ numbers in the middle, and no $n \times n$ matrix anywhere.

ELSA vs. EASE: Memory

1 MB10 MB100 MB1 GB10 GB100 GB1 TB10 TB
$1\,000$
$10\,000$
$100\,000$
$1\,000\,000$
$n$
4 MB4 MB400 MB40 MB40 GB400 MB4 TB4 GBEASEELSA
$1000\times$
$\text{memory of } B$
EASE
stores $B$: $n \times n$ numbers, so memory grows with $n^2$.
ELSA
stores $A$: $n \times d$ numbers with $d \ll n$ (here $d = 1000$), so memory grows with $n$.
The gain
The ratio is $n^2 / (nd) = n/d$: $1000\times$ at $n = 10^6$ and $d = 1000$.
Same idea as EASE, but memory grows linearly with the number of items.

SANSA: EASE with Sparse Factors

$X^{\top}X + \lambda I$
$\text{sparse}$
$n \times n$
$Q = (X^{\top}X + \lambda I)^{-1}$
$\text{dense: } n^2 \text{ numbers}$
$n \times n$
$\text{inverse}$
EASE needs $Q$, and the inverse of a sparse matrix is dense. SANSA never forms $Q$: it works with sparse factors.
Step 1
sparse factorisation of $X^\top X + \lambda I$
Step 2
sparse inverse of one factor
Step 3
sparse encoder and decoder

SANSA, Step 1: A Sparse Factorisation

$Q^{-1} = X^{\top}X + \lambda I$
$\text{sparse, symmetric}$
$\approx$
$L$
$\text{sparse, lower triangular}$
11111111
$\text{ones on the diagonal}$
$\times$
$D$
$\text{diagonal}$
$\times$
$L^{\top}$
$\text{sparse, upper}$
11111111
Factorise, but stay sparse
A (Cholesky-type) factorisation $Q^{-1} \approx LDL^\top$ is incomplete: tiny entries are dropped and the number of new non-zeros is limited, so $L$ stays sparse.
Why factorise?
A sparse triangular matrix is easy to invert and to multiply with. We never need $Q$ itself.

SANSA, Step 2: A Sparse Inverse of L

$L$
$\text{sparse, unit lower triangular}$
$\rightarrow$
$\text{start}$
$\textcolor{#2e7d32}{I} - \textcolor{#6d28d9}{N} = 2\textcolor{#2e7d32}{I} - L$
$\text{free first guess}$
$\rightarrow$
$\text{refine}$
$K \approx L^{-1}$
$\text{still sparse}$
1 · The inverse of $L$ as a series
$L$ comes from the factorisation, so it is unit lower triangular: $L = \textcolor{#2e7d32}{I} + \textcolor{#6d28d9}{N}$ with $\textcolor{#6d28d9}{N}$ strictly lower triangular. Then $L^{-1} = \textcolor{#2e7d32}{I} - \textcolor{#6d28d9}{N} + \textcolor{#6d28d9}{N^2} - \cdots$ is exact and ends after $n$ terms ($\textcolor{#6d28d9}{N^n} = 0$, $n$ = number of items).
2 · Start with two terms
We start with $L^{-1} \approx \textcolor{#2e7d32}{I} - \textcolor{#6d28d9}{N}$.
Since $\textcolor{#6d28d9}{N} = L - \textcolor{#2e7d32}{I}$, this is $\textcolor{#2e7d32}{I} - (L - \textcolor{#2e7d32}{I}) = 2\textcolor{#2e7d32}{I} - L$: flip the signs of the off-diagonal entries of $L$. It is free and has the same sparsity as $L$.
3 · Refine
A few residual-reducing (minimal-residual) steps improve the guess by correcting the terms we dropped. After each step small entries are dropped. The result of the last step is called $K$.
4 · Result
$K \approx L^{-1}$ is sparse, so we can store and multiply with it. It is not exact, so the final model approximates EASE.

SANSA, Step 2: Inverting the Product

$Q^{-1}$
$\approx$
$L$
$\times$
$D$
$\times$
$L^{\top}$
$Q$
$\text{dense}$
$\approx$
$K^{\top} = (L^{\top})^{-1}$
$\times$
$D^{-1}$
$\times$
$K = L^{-1}$
$\text{all factors sparse}$
$\text{invert both sides:}\ (AB)^{-1} = B^{-1}A^{-1}$
Invert the product
$Q^{-1} \approx LDL^\top \;\Rightarrow\; Q \approx (LDL^\top)^{-1} = (L^\top)^{-1} D^{-1} L^{-1}$, using $(AB)^{-1} = B^{-1}A^{-1}$ twice.
Name the pieces
$K \approx L^{-1}$ and $(L^\top)^{-1} = (L^{-1})^\top \approx K^\top$, so $Q \approx K^\top D^{-1} K$: the dense $Q$ is a product of sparse matrices.

SANSA, Step 3: Defining W and Z

From $Q$ to a sparse encoder $W$ and decoder $Z$
$\displaystyle B = I - Q\,\mathrm{diagMat}\big(1/\mathrm{diag}(Q)\big)$EASE's closed form
$\displaystyle Q \approx \textcolor{#1f5fbf}{K^{\top}}\textcolor{#b26a00}{D^{-1}}\textcolor{#1f5fbf}{K}$from the previous slide
$\displaystyle B \approx I - \textcolor{#1f5fbf}{K^{\top}}\textcolor{#b26a00}{D^{-1}}\textcolor{#1f5fbf}{K}\,\mathrm{diagMat}\big(1/\mathrm{diag}(Q)\big)$substitute $Q$
$\displaystyle B \approx I + \textcolor{#1f5fbf}{K^{\top}}\big(- \textcolor{#b26a00}{D^{-1}}\textcolor{#1f5fbf}{K}\,\mathrm{diagMat}\big(1/\mathrm{diag}(Q)\big)\big)$move the minus sign inside the bracket
$\displaystyle \textcolor{#1f5fbf}{W} := K, \qquad \textcolor{#2e7d32}{Z} := - \textcolor{#b26a00}{D^{-1}}\textcolor{#1f5fbf}{K}\,\mathrm{diagMat}\big(1/\mathrm{diag}(Q)\big)$define the sparse encoder $W$ and decoder $Z$
$\displaystyle B \approx I + \textcolor{#1f5fbf}{W}^{\top}\textcolor{#2e7d32}{Z}$so $B$ is the identity plus a product of two sparse matrices
$\displaystyle \mathrm{diag}(Q)_j = \sum_k K_{kj}^2 / \textcolor{#b26a00}{D_k}$from $Q = K^\top D^{-1}K$: computed from $K$, without forming $Q$
$\displaystyle \hat{\mathbf{x}} = \mathbf{x}B \approx \mathbf{x} + (\mathbf{x}\textcolor{#1f5fbf}{W}^{\top})\textcolor{#2e7d32}{Z}$unseen items have $x_j = 0$: their scores are $(\mathbf{x}W^\top)Z$

SANSA, Step 3: A Sparse Encoder and Decoder

$\mathbf{x}$
$\text{history}$
10010100
$\times$
$W^{\top}$
$\text{sparse encoder}$
$=$
$\mathbf{x}W^{\top}$
$\text{code}$
$\times$
$Z$
$\text{sparse decoder}$
$=$
$\hat{\mathbf{x}}$
$\text{scores}$

The Shallow Family

Shallow linear autoencoders
modelstructure of Btrainingmemoryno self-copy by
EASEfull, denseclosed form$O(n^2)$ memory, $O(n^3)$ time$\mathrm{diag}(B)=0$
ELSAlow-rank: $AA^\top - I$gradient descent$O(nd)$unit-length rows
SANSAsparse factors $W^\top Z$sparse factorisation$\propto$ nonzerosmask / residual
All three reconstruct $X$ through an item–item map; they differ in how they store it.

From Shallow to Deep Autoencoders

history
$\mathbf{x}$
10010100hiddenhiddencode
$\mathbf{z}$
logits
$\mathbf{s}$
softmaxprobabilities
$\boldsymbol{\pi}$
0.320.050.030.210.030.260.080.02encoderdecoder123
Ingredient 1 · Denoising
hide part of the history during training
Ingredient 2 · Multinomial loss
items compete for a probability budget
Ingredient 3 · Variational code
a user is a distribution, regularised by a prior
The network is an ordinary autoencoder; the three ingredients are what make it work for recommendation.

Ingredient 1: Denoising

history
$\mathbf{x}$
10010100dropoutinput
$\tilde{\mathbf{x}}$
1000100hatched = hidden
encoderdecoderscores
$\boldsymbol{\pi}$
0.320.050.030.210.030.260.080.02
target
$\mathbf{x}$
10010100loss
A new mask every time
Each epoch hides different items (each with probability 0.5), so copying the input never works.
Why it helps
The network practises the real task: predicting interactions it cannot see from the ones it can.
At recommendation time
No dropout: the whole available history is the input.

Ingredient 2: A Multinomial Likelihood

logits s (one per item)2.0010.102−0.5031.604−0.3051.806softmaxprobabilities π0.3510.0520.0330.2440.0450.296they add up to 1probabilities π0.3510.0520.0330.2440.0450.296they add up to 1one stepafter one step0.3710.0320.0230.2540.0250.316the others must go down
The loss
$L = -\sum_{j}x_{ij}\log \pi_{ij}$: only the observed items contribute, through the negative log of their probabilities.
Competition
Probabilities add up to 1, so raising an observed item lowers all the others, as a top-$N$ list must choose.
Not squared error or logistic
Those treat every item as an independent target. The multinomial makes items compete.

Ingredient 3: A Variational Code

dimension 1dimension 2
$\text{prior } \mathcal{N}(\mathbf{0}, I)$
$\boldsymbol{\mu}$
$\sigma_1$
$\sigma_2$
$\mathbf{z}$
$\text{KL pull}$
1 · Encoder: a distribution
$q_\phi(\mathbf{z}\mid\mathbf{x}_i) = \mathcal{N}\big(\boldsymbol{\mu}_i,\ \mathrm{diag}(\boldsymbol{\sigma}_i^2)\big)$: a user is a small cloud, not a point.
2 · Sample the noise
$\mathbf{z} = \boldsymbol{\mu} + \boldsymbol{\sigma} \odot \boldsymbol{\varepsilon}$ with $\boldsymbol{\varepsilon} \sim \mathcal{N}(\mathbf{0}, I)$: gradients flow through $\boldsymbol{\mu}$ and $\boldsymbol{\sigma}$.
3 · Objective
$-\mathbb{E}_q\big[\sum_j x_{ij}\log \pi_{ij}\big] + \beta\,\mathrm{KL}\big(q_\phi \,\|\, \mathcal{N}(\mathbf{0}, I)\big)$: fit the history, but stay close to the prior.

Recommending with VAE

user
$\mathbf{x}$
10010100no dropoutencodermean
$\boldsymbol{\mu}$
0.80−0.300.50no sampling
decoderscores
$\boldsymbol{\pi}$
0.320.050.030.210.030.260.080.02
← a high score wherethe input was 0:a recommendation
Depth helps less than the CF-specific choices.

The Cold-Start Gap

110011000110011000101010
$X$
$\text{users} \times \text{items}$
I1I2I3I4U1U2U3U4U5U6no interactions yetI4 (new): description“A retired detective follows astolen painting from Lisbon toa remote fishing village.”language model
$\bar{\mathbf{s}}_4$
0.80.6its text embedding
Every model so far
EASE, ELSA, SANSA and Mult-VAE learn from item columns: an empty column gets no weights.
But we know what I4 is
A language model turns its description into an embedding $\bar{\mathbf{s}}_4$, a short vector of numbers.
Goal
Recommend cold items to warm users, using only the users' interactions with warm items.

The Role of S: Item Text as Features

I1: item textI2: item textI3: item textwarm itemslanguagemodel1.00.00.60.80.01.0
$S$
$\text{fixed, } n \times d$
s1s2s3I4 (new): item textI5 (new): item textcold items0.80.6−1.00.0
$\bar{S}$
$\text{one row per cold item}$
s̄4s̄5
$\text{same text space:}$
$\text{dimension } d \text{ per item}$
$S$ is fixed
It comes from a pretrained language model and is not trained here: no interactions are needed.
Rows are points in text space
Items with similar descriptions get similar rows $\mathbf{s}_j$. Warm and cold items live in the same space.
$S$ and $\bar{S}$: the decoder
$S$ will be the decoder for training, and $\bar{S}$ the decoder for prediction. A new item only needs a new row of $\bar{S}$.

Inductive Autoencoder: Fix the Decoder

$X$
$\times$
$\mathcal{E}$
$\times$
$S^{\top}$
$\approx$
$\hat{X}$
warm items: reconstruct the historythe same encoder is reused
$\mathcal{E}$
$X$
$\times$
$\times$
$\bar{S}^{\top}$
$\approx$
$\hat{\bar{X}}$
cold items: predict new columnsthe same X

Learning the Encoder

The encoder $\mathcal{E}$ can be learned by this ALS algorithm, or by gradient descent.
ALS algorithm for the encoder $\mathcal{E}$
$\textbf{Input: } X,\ S,\ \lambda$
$\textbf{Initialise: } \mathcal{E} \leftarrow 0$
$\textbf{repeat until convergence}$
$\quad \textbf{for } j = 1, \dots, n$
$\qquad \mathbf{e}_j \leftarrow \Big(n_j\,[S^{-j}]^{\top}S^{-j} + \lambda I_d\Big)^{-1}[S^{-j}]^{\top}\big(\mathcal{X}^{-j}\big)^{\top}\mathbf{1}_{n_j}$
$\quad \textbf{end for}$
$\textbf{return } \mathcal{E}$

What About Explicit Feedback? AutoRec

42451?3?4?5?323315?4?4?5?2??31?5??21314?
$X$
ratings: users × items1234512345678item jinput
$X_{\bullet,j}$
4?35???1? not used
0.80−0.300.50encoderobserved inputs onlydecoderall outputs computedcodereconstruction
$\hat{X}_{\bullet,j}$
3.92.73.24.63.42.24.11.2
target
$X_{\bullet,j}$
4?35???1no lossno lossno lossno loss
Explicit feedback
Ratings 1–5. A ? is an unknown rating, not a low one.
I-AutoRec
Input: the ratings $X_{\bullet,j}$ of item $j$. Unknown ratings are not connected to the network.
Loss on observed ratings only
$\min_{\theta}\ \sum_j \big\|X_{\bullet,j} - \hat{X}_{\bullet,j}\big\|^2_{\mathcal{O}} + \tfrac{\lambda}{2}\big(\|W\|^2 + \|V\|^2\big)$

Why Not Fill the Gaps with Zeros?

input40350001reconstruction3.90.33.24.60.20.10.41.2target40350001loss on every entry: the zeros are targetsinput4?35???1reconstruction3.92.73.24.63.42.24.11.2target4?35???1no lossno lossno lossno loss? not connected, and no loss on itFill ? with 0 everywhereAutoRec: ? is skipped
Filling with 0 teaches the model to predict 0 stars for every unrated item: a rating that does not even exist.
What AutoRec does
An unknown rating has no input connection and no loss term. (Implicit feedback is different: there 0 is a real, weak signal.)
AutoRec skips what it does not observe: no input, no loss.

Summary

modelinputstops copying withnew items?training
EASEuser history$\mathrm{diag}(B)=0$noclosed form, $O(n^2)$ memory
ELSAuser historyunit-length rowsnogradient descent, $O(nd)$
SANSAuser historymask / residualnosparse factorisation
Mult-DAE / VAEuser historydenoising (+ prior)nodeep network, SGD
Inductive AEuser history + item textdiagonal gatingyesclosed-form ALS-like
AutoRecitem ratingsbottleneck, observed-only lossnodeep network, explicit
Every model answers the same question differently: what must be preserved, and what must not be copied?
CTU logo
NIE-PML · CTU FIT

Obrigado!

Questions?