Search

Search papers and lessons

Deep Interest Network for Click-Through Rate Prediction

Guorui Zhou, Chengru Song, Xiaoqiang Zhu et al. · 2017

DIN gives each ad its own summary of a user's past behaviour, weighting the behaviours that relate to that ad, so one fixed-length user vector no longer has to hold every interest.

On this page

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

TL;DR

Display advertising ranks each ad by how likely the user is to click it, and that prediction is made from the user's past behaviour. Most deep models squeeze the whole history into one fixed-length vector that is the same for every ad, so it cannot hold all of a user's interests at once. The Deep Interest Network (DIN) builds a different user vector for each candidate ad: it weights each past behaviour by how relevant that behaviour is to the ad and adds the results up. It is deployed in Alibaba's display advertising system, where it serves the main traffic.

Builds on: Embedding Layer, Attention Mechanism, Feedforward Neural Network, Parametric ReLU (PReLU) · Leads to: ranking models for ads and products

Why it mattered

Alibaba's display advertising system ranks ads by eCPM, the bid price times the predicted click-through rate (CTR), so every gain in prediction quality flows into revenue. The paper describes a model that was built, trained on about 2 billion samples, and deployed. In a live A/B test run from May to June 2017, DIN trained with its two training techniques raised CTR by up to 10.0 percent and revenue per mille (RPM) by 3.8 percent over the production baseline. The authors note that the training techniques "can be easily generalized to other industrial deep learning tasks", which is why the paper is read as a method and not only as an Alibaba system.

The problem

Most deep CTR models of the time shared one design, which the paper calls Embedding&MLP. Each sparse category, such as a shop, a category or a visited item, is looked up in an embedding table. A user's behaviour list is a variable-length list of such vectors, so it is pooled into one fixed-length vector, usually by summing or averaging, and that vector is fed to a multilayer perceptron (MLP) together with the ad's own features.

The trouble is that the pooled user vector is the same for every ad. The paper's example is a young mother who has recently browsed a woollen coat, T-shirts, earrings, a tote bag, a leather handbag and a children's coat. If the system shows her a new handbag, only the tote bag and the leather handbag matter for that click. Pooling all six into one vector blurs them together. The usual fix, a longer vector, adds parameters, invites Overfitting and costs compute and storage that an online system with hundreds of millions of users cannot easily pay. The paper also tried an LSTM over the behaviour sequence and found no improvement. The authors suspect that a user's behaviours jump between several concurrent interests, so the sequence looks noisy.

How it works

The walkthrough builds the user vector for one user and two different ads. The numbers are tiny and round. A dot product stands in for the paper's small network that scores relevance, so the arithmetic can be done by hand.

Setup: the user has three past behaviours, each already an embedding (two numbers here): a tote bag, e1 = (2, 0); running shoes, e2 = (0, 1); and a handbag, e3 = (1, 1). Ad A is a handbag, with embedding v_A = (1, 0).

  1. Look up the behaviours. Each item the user visited is one row of the embedding table, so the history is the list e1, e2, e3. Check: the list has three vectors, and a different user would have a list of a different length, which is why pooling is needed at all.
  2. Score each behaviour against the ad. The activation unit compares every behaviour with the ad. Here the score is the dot product with v_A. For e1 it is 2 times 1 plus 0 times 0, which is 2. For e2 it is 0 times 1 plus 1 times 0, which is 0. For e3 it is 1 times 1 plus 1 times 0, which is 1. Check: the tote bag, the most related behaviour, gets the largest score, and the running shoes get zero.
  3. Pool with the scores as weights. The user vector for ad A is the weighted sum of the behaviours: 2 times (2, 0), plus 0 times (0, 1), plus 1 times (1, 1). That is (4, 0) + (0, 0) + (1, 1) = (5, 1). Check: the result points mostly along the tote bag direction, as the scores said it should.
  4. Keep the weights unnormalised. The weights are 2, 0 and 1, and they add up to 3. A softmax would rescale them to about 0.67, 0.09 and 0.24, which add up to 1. DIN skips that rescaling, so the total of 3 is kept. Check: a user with more relevant history gets a larger total weight, so the size of the vector carries information.
  5. Change the ad, keep the history. Candidate B is running shoes, with embedding v_B = (0, 1). The scores are now 0 for the tote bag (0 times 0 plus 0 times 1), 1 for the running shoes (0 plus 1) and 1 for the handbag (0 plus 1). The pooled vector is 0 times (2, 0), plus 1 times (0, 1), plus 1 times (1, 1), which is (1, 2). Check: the same history gives (5, 1) for ad A and (1, 2) for ad B, so the user vector follows the ad.
  6. Feed the result forward. The pooled vector is joined with the ad's embedding and the other features, and passed through the MLP. The paper's Alibaba model uses layers of size 192, 200, 80 and 2. The last two numbers become a click and no-click score, and a softmax turns them into the predicted click probability. Check: the MLP sees a different user vector for each ad, so it can answer each ad on its own relevance.
  7. Regularise only what the batch touched. Normal L2 regularisation would recompute a penalty over all embedding rows at every step, which is far too costly when the table has hundreds of millions of parameters. DIN's mini-batch aware version penalises only the rows whose ids appear in the current batch. Example: a batch that contains only the tote bag and the running shoes penalises those two rows this step, and every other row is left out. Check: the cost depends on the batch, not on the size of the table.
  8. Activate with Dice. The MLP's activation is Dice, a version of PReLU whose switch point moves with the mean of the batch instead of staying at zero. The math section works out the numbers. Check: when the batch mean is 0.5, the switch sits at 0.5.
flowchart LR
  H["User behaviours: list of embeddings"] --> A["Activation unit: score each behaviour against the ad"]
  AD["Candidate ad embedding"] --> A
  A --> P["Weighted sum pooling: user vector for this ad"]
  AD --> C["Join with ad and other features"]
  P --> C
  C --> M["MLP with Dice activations"]
  M --> O["Softmax: predicted click probability"]
−2−1012300.20.40.60.81input scontrol p(s)
  • Dice, batch mean 0.5
  • batch mean 0
The control function decides how much of an input stays on its own line and how much is scaled down. Dice centres the switch on the batch mean, so with mean 0.5 the curve crosses one half at s = 0.5. With mean 0 it is a smooth switch at zero.

The math

Definition: DIN user vector

For a candidate ad with embedding vA\mathbf{v}_A and a user with behaviour embeddings e1,…,eH\mathbf{e}_1, \dots, \mathbf{e}_H, the user's interest representation is a weighted sum of the behaviours. Each weight is a learned function of that behaviour and the ad, so the vector changes with the ad.

Step 2 in symbols: the activation weights

Each weight is the output of a small feed-forward network a(⋅)a(\cdot) applied to the behaviour and the ad:

wj=a(ej,vA)w_j = a(\mathbf{e}_j, \mathbf{v}_A)

Besides the two embeddings, the unit feeds the network their product, which the paper describes as explicit knowledge that helps relevance modelling. The walkthrough replaces a(⋅)a(\cdot) with a dot product, so wj=ej⊤vAw_j = \mathbf{e}_j^{\top}\mathbf{v}_A. For the tote bag, w1=2⋅1+0⋅0=2w_1 = 2 \cdot 1 + 0 \cdot 0 = 2, as in step 2.

Step 3 in symbols: weighted sum pooling

vU(A)=∑j=1Hwj ej\mathbf{v}_U(A) = \sum_{j=1}^{H} w_j\,\mathbf{e}_j

Average pooling would be 1H∑jej\frac{1}{H}\sum_{j}\mathbf{e}_j, which gives every behaviour the same weight 1H\frac{1}{H} whatever the ad. DIN replaces that fixed weight with the learned, ad-dependent wjw_j. With the walkthrough's numbers, vU(A)=2(2,0)+0(0,1)+1(1,1)=(5,1)\mathbf{v}_U(A) = 2(2,0) + 0(0,1) + 1(1,1) = (5, 1).

Step 4 in symbols: no normalisation

A softmax version would use αj=ewj/∑kewk\alpha_j = e^{w_j} / \sum_k e^{w_k}, so that ∑jαj=1\sum_j \alpha_j = 1. DIN does not normalise, so ∑jwj\sum_j w_j is kept as an approximation of how strongly the user's interests are activated by this ad. The paper's example is a user whose history is 90 percent clothes and 10 percent electronics. A T-shirt ad activates most of the clothes history and gets a larger vector than a phone ad. A softmax would erase that difference in scale.

Step 7 in symbols: the mini-batch aware penalty

Let njn_j be the number of times feature jj occurs in the whole training set, and let αmj=1\alpha_{mj} = 1 if feature jj occurs in mini-batch mm and 00 otherwise. The paper's approximation of the L2 penalty is ∑j∑mαmjnj∥wj∥22\sum_j \sum_m \frac{\alpha_{mj}}{n_j}\lVert \mathbf{w}_j \rVert_2^2, so the update for an embedding row wj\mathbf{w}_j is

wj←wj−η[1∣Bm∣∑(x,y)∈Bm∂L∂wj+λαmjnjwj]\mathbf{w}_j \leftarrow \mathbf{w}_j - \eta\left[\frac{1}{|\mathcal{B}_m|}\sum_{(\mathbf{x},y)\in\mathcal{B}_m}\frac{\partial L}{\partial \mathbf{w}_j} + \lambda\frac{\alpha_{mj}}{n_j}\mathbf{w}_j\right]

Here η\eta is the learning rate, Bm\mathcal{B}_m is the batch and λ\lambda is the penalty strength, which the paper sets to 0.01 for both this method and DiFacto's variant. In the walkthrough, a row not in the batch has αmj=0\alpha_{mj} = 0, so its penalty term is zero for that step.

Step 8 in symbols: Dice

Dice replaces PReLU's hard switch p(s)=I(s>0)p(s) = I(s > 0) with a smooth one centred on the batch mean:

f(s)=p(s) s+(1−p(s)) αs,p(s)=11+e−s−E[s]Var[s]+ϵf(s) = p(s)\,s + (1 - p(s))\,\alpha s, \qquad p(s) = \frac{1}{1 + e^{-\frac{s - E[s]}{\sqrt{\mathrm{Var}[s] + \epsilon}}}}

Here E[s]E[s] and Var[s]\mathrm{Var}[s] are the mean and variance of the input over the mini-batch during training, and moving averages of them at test time. α\alpha is the learned slope of the second channel, and ϵ=10−8\epsilon = 10^{-8} in the paper. When the mean and variance are both zero, Dice becomes PReLU.

Worked check with E[s]=0.5E[s] = 0.5, Var[s]=0.25\mathrm{Var}[s] = 0.25 (so the square root is 0.5, and ϵ\epsilon is negligible) and a fixed α=0.2\alpha = 0.2 for the arithmetic:

  • Input s=1s = 1 is 0.5 above the mean, so p=1/(1+e−1)≈0.731p = 1/(1 + e^{-1}) \approx 0.731 and f(1)=0.731⋅1+0.269⋅0.2⋅1≈0.785f(1) = 0.731 \cdot 1 + 0.269 \cdot 0.2 \cdot 1 \approx 0.785. PReLU would give 11, because 1>01 \gt 0.
  • Input s=−1s = -1 is 1.5 below the mean, so p=1/(1+e3)≈0.047p = 1/(1 + e^{3}) \approx 0.047 and f(−1)=0.047⋅(−1)+0.953⋅0.2⋅(−1)≈−0.238f(-1) = 0.047 \cdot (-1) + 0.953 \cdot 0.2 \cdot (-1) \approx -0.238. PReLU would give −0.2-0.2.

The first input stays mostly on its own line and the second is mostly on the scaled line. Dice has moved the rectified point to the batch mean, which is the paper's stated purpose.

Results

The paper reports offline AUC, the area under the ROC curve, and relative improvement over a baseline, RelaImpr. For a model with AUC xx and a baseline with AUC bb, the paper defines RelaImpr as (x−0.5b−0.5−1)×100%\left(\frac{x - 0.5}{b - 0.5} - 1\right) \times 100\%, which measures the gain above a random guesser that scores 0.5. The Alibaba results are below, with the paper's values copied exactly.

Model (Alibaba, full features)AUCRelaImpr over BaseModel
LR0.5738-23.92%
BaseModel0.59700.00%
Wide & Deep0.59770.72%
PNN0.59831.34%
DeepFM0.59932.37%
DIN0.60296.08%
DIN with MBA regularization0.60609.28%
DIN with Dice0.60447.63%
DIN with MBA and Dice0.608311.65%

DIN alone adds 0.0059 absolute AUC over BaseModel on this dataset. The mini-batch aware regularizer adds a further 0.0031 over dropout, and Dice adds 0.0015 over PReLU. Together, the two techniques give 0.0113 absolute AUC over BaseModel. The paper argues that 0.001 of absolute AUC is significant at commercial scale.

On the two public datasets, the paper's Table 3 gives the following values for the same metric.

ModelMovieLens AUCMovieLens RelaImprAmazon (Electronics) AUCAmazon RelaImpr
LR0.7263-1.61%0.7742-24.34%
BaseModel0.73000.00%0.86240.00%
Wide & Deep0.73040.17%0.86370.36%
PNN0.73210.91%0.86791.52%
DeepFM0.73241.04%0.86831.63%
DIN0.73371.61%0.88185.35%
DIN with Dice0.73482.09%0.88716.82%

The regularisers were compared on Alibaba with the fine-grained goods-id features, which have a dimension of about 0.6 billion. Without any regulariser, the model overfits after the first epoch. Here RelaImpr is measured against the model without goods-id features and without regularisation (AUC 0.5940). Dropout, which discards half the feature ids in each sample, reaches AUC 0.5970 (3.19 percent RelaImpr). Filtering to the 20 million most frequent goods ids reaches 0.5983 (4.57 percent). DiFacto's regulariser reaches 0.5954 (1.49 percent). The mini-batch aware method reaches 0.6031 (9.68 percent), the best of the options tested.

In the online test, the system served the production baseline for almost a month, and the new model raised CTR by up to 10.0 percent and RPM by 3.8 percent. The serving section adds an engineering result. The system must score hundreds of ads per visitor in under 10 milliseconds, at peaks of more than 1 million users per second. Request batching, GPU memory access changes and concurrent CUDA kernels together doubled the queries per second one machine can handle.

The results have limits. All the industrial numbers come from one company's traffic and one ad system, and the paper's own argument for its regularisers depends on that scale. On the public datasets, which have about 0.1 million features, the paper notes that overfitting was not a serious problem, so the regularisers help mostly at Alibaba's scale. The paper does not compare DIN with the attention-based sequence models that were developed later, and it reports the LSTM attempt only briefly.

Reading guide

Read the paper in this order, with the lessons each section needs.

  • Section 1 (Introduction) uses CTR and eCPM. The key claim, that a fixed-length user vector cannot hold diverse interests, needs Embedding Layer for what the vector is built from.
  • Section 2 (Related work) traces the lineage. Read Attention Mechanism first: the paper says its local activation unit shares ideas with NMT attention, and it compares its design with DeepIntent's global attention. Wide & Deep is the nearest architecture.
  • Section 3 (Background) describes the matching and ranking stages of the Alibaba system and the young-mother example. It needs only the floor.
  • Section 4.1 (Feature representation) uses One-Hot Encoding. The paper's multi-hot vector is a version with several 1s, one for each item the user visited.
  • Section 4.2 (Base model) uses the embedding table, sum or average pooling, an MLP and the loss. The loss is the negative log-likelihood, which is the same quantity as binary cross-entropy.
  • Section 4.3 (DIN) is the core of the paper. Equation (3) is the weighted sum of step 3. The argument for dropping the softmax, which the paper names as the difference from traditional attention, needs Softmax.
  • Section 5.1 (Mini-batch aware regularization) needs L2 Regularization and Stochastic Gradient Descent, and it compares with Dropout. Overfitting explains the Figure 4 curves.
  • Section 5.2 (Data adaptive activation) needs Parametric ReLU (PReLU) and Rectified Linear Unit (ReLU). The Dice control function in Figure 3 extends the PReLU switch.
  • Section 6.1 to 6.3 (Datasets, baselines, metrics) use Adam Optimizer, Learning Rate and AUC. Read the AUC definition before the RelaImpr formula.
  • Section 6.8 (Visualisation) uses t-SNE to project the learned goods embeddings to two dimensions.

Check yourself

QuestionRecall: what limitation of the Embedding&MLP base model does the local activation unit remove?Show answer
The base model pools all of a user's behaviours into one fixed-length vector that is the same for every candidate ad, so that vector has to hold all of the user's interests at once. The local activation unit builds a user vector for each ad by weighting each behaviour by its relevance to that ad. The vector then changes with the ad, and it does not need to be very large to cover diverse interests.
QuestionComputation: a user has behaviour embeddings e1 = (1, 2) and e2 = (3, 0), and the ad embedding is v = (1, 1). Using the dot product as the activation score, as in the walkthrough, find the weights and the user vector. What would a softmax make the weights add up to?Show answer
The weights are w1 = 1 times 1 plus 2 times 1, which is 3, and w2 = 3 times 1 plus 0 times 1, which is 3. The user vector is 3(1, 2) + 3(3, 0) = (3, 6) + (9, 0) = (12, 6). The weights add up to 6 here. A softmax would make them add up to 1. Answer: w1 = 3, w2 = 3, v_U = (12, 6), and a softmax would give a total of 1 instead of 6.
QuestionWhy: the paper drops the softmax normalisation of the activation weights. What does DIN keep that a softmax would lose?Show answer
A softmax forces the weights to add up to 1, so a user with many relevant behaviours and a user with a few look the same in scale. Only the relative weights survive. Without normalisation the total weight is an approximation of how strongly the user's relevant interests are activated, so the size of the vector carries intensity. In the paper's example, a user with a clothes-heavy history may get a larger vector for a T-shirt ad than for a phone ad.
QuestionApplied: your CTR model has an embedding table with 100 million rows and an L2 penalty that touches every row at every step, which is too slow. Using the paper's argument, what would you change, and what do you give up?Show answer
Use the mini-batch aware penalty. Only the rows whose ids appear in the current batch are penalised at that step, each scaled by one over the feature's count in the whole training set, so the cost per step follows the batch rather than the table. What you give up is exactness: the penalty is an approximation, and a rarely seen id is penalised only in the batches where it occurs. The paper reports that this approximation gave the best result among the regularisers it tested.

Sources

Read the full paper

Guorui Zhou, Chengru Song, Xiaoqiang Zhu et al., 2017. arXiv:1706.06978