Search

Search papers and lessons

Deep Learning Recommendation Model for Personalization and Recommendation System

Maxim Naumov, Dheevatsa Mudigere, Hao-Jun Michael Shi et al. · 2019

DLRM is a neural recommender that embeds categorical features, mixes them through pairwise dot products, and trains across GPUs by sharding the embedding tables and replicating the MLPs.

On this page

  • Colour = topic mix
  • Systems
  • Discrete math
  • Probability
  • Calculus
  • Linear algebra
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

DLRM, the deep learning recommendation model, is a neural network that estimates how likely a user is to click on an item. It reads two kinds of input: categorical features such as a user ID, a country or an ad slot, and numeric features such as counts. It turns each category into a learned vector with an Embedding Layer, takes dot products between pairs of vectors to capture how features interact, and passes the result to a small output network. Because its embedding tables can be very large, the paper also shows how to split training across many GPUs.

Builds on: Embedding Layer, Factorization Machine, Feedforward Neural Network · Leads to: the embedding-based recommenders that large internet companies deploy, as the paper's introduction notes

Why it mattered

The paper's introduction and conclusion state that personalization and recommendation still drive much of the practical success of deep learning in industry. One of the main tasks is ad click-through rate (CTR) prediction: given a user and an ad, estimate the chance of a click. The authors note that these models had received little academic attention, and that they differ from the image and language networks that dominated the field, because they must handle categorical features.

The release was as important as the design. The authors published PyTorch and Caffe2 implementations and presented the model as a benchmark for algorithm experiments and for co-designing hardware and systems. Its layout, with one embedding per categorical feature, pairwise dot products and two MLPs, is the structure the rest of this lesson walks through.

Public data made the model testable. Criteo released click logs for ad CTR prediction. Each record has 13 numeric and 26 categorical features. The Kaggle version has about 45 million samples over 7 days, and the Terabyte version covers 24 days.

The problem

Two views of recommendation meet in the paper. The recommender-systems view began with content filtering and collaborative filtering. Latent factor methods such as Matrix Factorization represent each user and each product as a short vector and predict a rating from the dot product of the two vectors. The predictive-analytics view began with simple models such as Logistic Regression and moved to deep networks. Those networks needed a way to read categorical data, and the bridge was the embedding: a trainable table that turns a category into a dense vector.

Deep models for this data still had two problems, which the abstract names directly. First, these networks "are not well studied or understood". Second, their size. Embedding tables can take several gigabytes each, which makes the model limited by memory capacity and bandwidth. Data parallelism copies the whole model onto every device, so it cannot handle tables this large. Training can take several weeks.

The paper's answer has two parts. The model computes the interactions between features in a simple, explicit way. The training scheme shards the embedding tables across devices and replicates the smaller MLPs.

How it works

The walkthrough uses toy sizes so every number can be checked by hand. The full model follows the same steps with longer vectors and more features.

  1. Input. A user ID that is index 2 of 4 possible users, an item ID that is index 0 of 3 possible items, and one numeric feature with value 0.5 after the log(1+x) transform used on Criteo data. Check: each categorical feature is just an index, and the numeric feature is a single number.

  2. Embedding lookup. Each categorical feature has its own table with one row per category and d = 2 numbers per row. Row 2 of the user table is u = (1, 0). Row 0 of the item table is v = (0.5, 2). This row selection is the same as multiplying a One-Hot Encoding vector by the table. Check: the lookup returns a row, so its cost does not depend on the number of categories.

  3. Bottom MLP. A small MLP turns the numeric feature into a vector of the same length as the embeddings. Pretend its output is b = (0.5, 1). Check: both vectors have length 2, so they can be compared in the next step.

  4. Pairwise dot products. Take every dot product between two different vectors among b, u and v. b·u = 0.5 × 1 + 1 × 0 = 0.5. b·v = 0.5 × 0.5 + 1 × 2 = 2.25. u·v = 1 × 0.5 + 0 × 2 = 0.5. This is the interaction step. A large dot product means two features point in similar directions in the shared space. Check: three vectors give three pairs, and in general n vectors give n(n−1)/2 pairs.

  5. Concatenate and score. Stack the bottom vector and the three interactions into (0.5, 1, 0.5, 2.25, 0.5). The top MLP is a toy here: one weighted sum with weight 0.2 on each entry and no bias. The score is s = 0.2 × 4.75 = 0.95. Check: five inputs, one score.

  6. Sigmoid to probability. p = 1 / (1 + e^(−0.95)) ≈ 0.72. A score of 0 would give 0.5, and very large scores approach 1. Check: the output is a probability between 0 and 1.

  7. Compare with the label. The user clicked, so the label is 1. The Cross-Entropy Loss is −log(0.72) ≈ 0.33. Training adjusts the weights so this loss falls across millions of examples. Check: a confident wrong answer, such as p = 0.01 for a click, would cost about 4.6.

The model as a whole:

flowchart LR
  C["Categorical features"] --> E["Embedding tables"]
  N["Numeric features"] --> B["Bottom MLP"]
  E --> I["Pairwise dot products"]
  B --> I
  B --> K["Concatenate"]
  I --> K
  K --> T["Top MLP"]
  T --> S["Sigmoid: click probability"]

Neither PyTorch nor Caffe2 supported model parallelism for this model out of the box, so the authors built the training scheme themselves.

Splitting training across devices

  1. Shard the embedding tables. Each table lives on one device, so a lookup is done where the table sits. This is model parallelism.
  2. Exchange the lookups. After the lookups, each device holds the vectors for its tables for every sample in the mini-batch. A butterfly shuffle, an all-to-all communication, sends each slice to the device that needs it for the interaction and top MLP.
  3. Replicate the MLPs. Every device holds a full copy of the bottom and top MLPs and processes a different slice of the mini-batch. This is data parallelism, which suits MLPs because they are small in memory but costly in compute.
  4. Synchronise the updates. The MLP gradients are combined with an All-Reduce and applied identically on every device before the next iteration, so the copies stay equal.

Check: the large tables are never copied, and only the small MLP weights are.

The math

Let W∈Rm×dW \in \mathbb{R}^{m \times d} be an embedding table with mm rows, one per category, each of length dd. Let ei\bm{e}_i be the one-hot vector for category ii.

Step 1 in symbols: the embedding lookup

wiT=eiTW\bm{w}_i^T = \bm{e}_i^T W

For a mini-batch of tt lookups, put the multi-hot weight vectors into the columns of a sparse matrix A=[a1,…,at]A = [\bm{a}_1, \dots, \bm{a}_t]. Then S=ATWS = A^T W gives all tt embedding outputs at once. A single feature's output can be a weighted sum of several rows, which is why the weights a\bm{a} can have more than one nonzero entry.

Step 2 in symbols: the bottom MLP

Let x\bm{x} be the numeric feature vector. The bottom MLP maps it to

z0=MLPbot(x)∈Rd\bm{z}_0 = \mathrm{MLP}_{\mathrm{bot}}(\bm{x}) \in \mathbb{R}^d

so that z0\bm{z}_0 has the same length as every embedding vector.

Step 3 in symbols: the interaction

Let nn be the number of categorical features, and let z1,…,zn\bm{z}_1, \dots, \bm{z}_n be their embedding vectors, each in Rd\mathbb{R}^d. Together with z0\bm{z}_0 they form n+1n+1 vectors. The interaction step keeps every dot product between two different vectors:

I={ziTzj  :  0≤i<j≤n}\mathcal{I} = \left\{ \bm{z}_i^T \bm{z}_j \;:\; 0 \le i \lt j \le n \right\}

This set has (n+12)\binom{n+1}{2} elements. The paper's profiling model has 8 categorical features, so there are 9 vectors and (92)=36\binom{9}{2} = 36 interactions.

Step 4 in symbols: the top MLP and output

Concatenate the bottom vector with the interactions, t=[z0; I]\bm{t} = [\bm{z}_0;\, \mathcal{I}], and pass it through the top MLP:

p^=sigmoid(MLPtop(t))\hat{p} = \mathrm{sigmoid}\big(\mathrm{MLP}_{\mathrm{top}}(\bm{t})\big)

Here p^\hat{p} is the predicted click probability.

Step 5 in symbols: the loss

For a label y∈{0,1}y \in \{0, 1\} (no click, click), the binary form of cross-entropy is

L=−[ ylog⁡p^+(1−y)log⁡(1−p^) ]\mathcal{L} = -\big[\, y \log \hat{p} + (1 - y) \log(1 - \hat{p}) \,\big]

The paper's table lists a cross-entropy loss for each framework. With y=1y = 1 and p^=0.72\hat{p} = 0.72, the loss is −log⁡0.72≈0.33-\log 0.72 \approx 0.33, which matches the walkthrough.

Worked examples

Example
Counting interactions

A DLRM has 4 categorical features and one bottom-MLP output, all of length d=3d = 3.

  1. Count the vectors: 4 embeddings plus 1 bottom vector gives m+1=5m + 1 = 5.
  2. Count the pairs of different vectors: (52)=5×42=10\binom{5}{2} = \frac{5 \times 4}{2} = 10.
  3. Count the top-MLP inputs: the bottom vector has 3 entries and the interactions add 10 more, so the top MLP reads 13 numbers.

Interpretation: the interaction step grows with the square of the number of features, but it stays small enough to compute for dozens of features.

Example
Table size and memory

Take one embedding table with 50 million rows, dimension 64, stored in fp32 (4 bytes per number).

  1. Numbers per row: 64.
  2. Bytes per row: 64×4=25664 \times 4 = 256.
  3. Bytes per table: 50,000,000×256=12.8×10950{,}000{,}000 \times 256 = 12.8 \times 10^9, which is 12.8 GB.
  4. Three such tables: 3×12.8=38.43 \times 12.8 = 38.4 GB.

Interpretation: 38.4 GB does not fit on one 16 GB GPU, so the tables must be spread over devices. The much smaller MLPs can be copied everywhere.

Example
A realistic click decision

A CTR model has been trained, and for one user and one ad it outputs p^=0.9\hat{p} = 0.9. The user clicks (y=1y = 1), and in another case, for a different ad, it outputs p^=0.1\hat{p} = 0.1 and the user does not click (y=0y = 0).

  1. For the first case, the loss is −log⁡0.9≈0.105-\log 0.9 \approx 0.105.
  2. For the second case, the loss is −log⁡(1−0.1)=−log⁡0.9≈0.105-\log(1 - 0.1) = -\log 0.9 \approx 0.105.
  3. Both cases are right and cost the same, so the loss is small.
  4. Now suppose the model says p^=0.1\hat{p} = 0.1 for an ad that is clicked. The loss is −log⁡0.1≈2.30-\log 0.1 \approx 2.30.

Interpretation: the loss punishes confident wrong answers much more than uncertain ones, which is the signal that moves the weights during training.

Try it: if the model outputs p^=0.5\hat{p} = 0.5 for a clicked ad, what is the loss? Answer: −log⁡0.5≈0.69-\log 0.5 \approx 0.69, the same as guessing a coin flip.

Results

Accuracy on Criteo Kaggle. The authors compare DLRM with a Deep and Cross Network (DCN) without extensive tuning. Both models have about 540 million parameters and an embedding dimension of 16. DLRM's bottom MLP has hidden layers of 512, 256 and 64 nodes, and its top MLP has hidden layers of 512 and 256 nodes. Over one epoch, with SGD and Adagrad and no regularization, DLRM reaches slightly higher training and validation accuracy than DCN. The margin is small, and the paper stresses that the models were not extensively tuned.

Single-device profile. The sample model has 8 categorical features, each with a table of 1 million rows and dimension 64, plus 512 numeric features. Its bottom MLP has two layers and its top MLP has four. It processes 2,048,000 random samples in 1,000 mini-batches of 2,048. The Caffe2 implementation takes about 256 seconds on the CPU and 62 seconds on one GPU. Most of the time goes to embedding lookups and fully connected layers. On the CPU the fully connected layers take a significant share, while on the GPU they are almost negligible. The hardware is a Big Basin platform with two Intel Xeon 6138 CPUs and eight Nvidia Tesla V100 GPUs with 16 GB each.

Limits. The accuracy comparison uses one public dataset and one baseline, without extensive tuning. The timings come from a single device, so the distributed scheme is described but not benchmarked here; the authors say its detailed study will come later. The argument that interactions beyond second order are not worth their cost is a reasoned claim in the paper, not a measured comparison. Read the speed results as a profile of one configuration, not a general speed claim.

Reading guide

Check yourself

QuestionWhich part of DLRM reads the categorical features, and which part reads the numeric ones?Show answer

Each categorical feature goes through its own embedding table, which returns the row for that category as a dense vector. Numeric features go through the bottom MLP, which outputs a vector of the same length as the embeddings so that the two can be compared in the interaction step.

QuestionA DLRM has 4 categorical features and one bottom-MLP output. How many pairwise dot products does its interaction step compute?Show answer

There are 5 vectors in total. The number of pairs of different vectors is (52)=10\binom{5}{2} = 10, so the interaction step computes 10 dot products.

QuestionWhy do the authors use model parallelism for the embedding tables but data parallelism for the MLPs?Show answer

The embedding tables hold most of the parameters and can take several gigabytes each. Data parallelism would copy them onto every device, which is impossible at that size, so they are split across devices. The MLPs are small in memory but expensive in compute. Copying them is cheap, and it lets different devices process different samples at the same time. Their gradients are combined with an all-reduce so every copy takes the same step.

QuestionA CTR model has three embedding tables of 50 million rows each, with dimension 64 in fp32. Each GPU has 16 GB. Can one GPU hold all three tables, and what should the training scheme do?Show answer

Each table takes 50,000,000×64×4=12.850{,}000{,}000 \times 64 \times 4 = 12.8 GB, so the three tables take 38.4 GB. That is more than one 16 GB GPU can hold. The tables must be sharded across devices (model parallelism). The MLPs are small enough to replicate, so they can use data parallelism with an all-reduce on their gradients.

Sources

Read the full paper

Maxim Naumov, Dheevatsa Mudigere, Hao-Jun Michael Shi et al., 2019. arXiv:1906.00091