Search

Search papers and lessons

DeepFM: A Factorization-Machine based Neural Network for CTR Prediction

Huifeng Guo, Ruiming Tang, Yunming Ye et al. · 2017

DeepFM predicts clicks with one network that learns low-order and high-order feature interactions from raw inputs, sharing its embeddings, with no feature engineering.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Classical models
  • Linear algebra
  • Representation learning
  • ReadReady to readNot yet

TL;DR

DeepFM is a neural network that predicts how likely a user is to click an item, using only the raw input fields. It runs two parts on the same input: a factorization machine that models pairwise feature interactions, and a deep network that models interactions of higher order. Both parts share one set of learned feature vectors, so the model is trained end to end and needs no hand-built cross features. On two click datasets it beat the earlier models in the comparison on AUC and logloss.

Builds on: Factorization Machine, Wide & Deep, Embedding Layer, Logistic Regression · Leads to: later click-prediction models that combine a wide and a deep part on shared inputs

Why it mattered

Click-through rate (CTR) is the probability that a shown item gets clicked. Recommender systems rank items by it, and in advertising the ranking is often CTR times the bid, so a small gain in the estimate has direct money value. The paper's experiments use a 45 million record Criteo advertising dataset and about one billion click records from the game centre of an app store. Before this paper, a close prior model was Wide & Deep from Google, which needs hand-built cross features in its wide part. DeepFM keeps Wide & Deep's idea of learning both kinds of interaction and drops that feature engineering, which is why the paper's main pitch is learning from raw features with no expert design.

The problem

Some feature interactions are obvious to a person: app category with time of day (people download food apps at meal times), or app category with gender and age (teenage boys download shooting and RPG games). Most are not obvious, and they can only be found from data. The paper frames three older model families as each missing part of the answer.

  1. Linear models such as Logistic Regression, trained with FTRL, have no interaction terms. Adding pairs by hand does not extend to high-order or rare interactions.
  2. Factorization machines learn a vector for every feature and score a pair by the dot product of their vectors. They handle rare pairs well, but in practice only pairs are used, because higher orders are expensive.
  3. Deep models such as FNN, PNN and Wide & Deep capture high-order patterns, but PNN and FNN capture little low-order structure, and Wide & Deep depends on hand-built inputs for its wide part.

The paper's goal is one model that learns interactions of all orders from the raw fields, end to end.

How it works

The input is one record made of fields such as gender, location and app. Each categorical field is one-hot encoded, so almost every entry is zero. The model turns that into a score and then a probability.

flowchart LR
  A[Raw fields, one-hot] --> B[Shared embeddings V]
  B --> C[FM part: order-1 and order-2 terms]
  B --> D[Deep part: feed-forward layers]
  C --> E[Add the two outputs]
  D --> E
  E --> F[Sigmoid gives CTR]

Here is one tiny instance traced through. Two fields: gender (male or female) and app category (game, food or news). The record is male and game. Each field value has a weight w and an embedding vector V of length 2. Use these toy values: w(male) = 0.2, w(game) = 0.5, V(male) = (1, 0), V(game) = (0.5, 2). The deep part is a single hidden unit with weights 0.1 on each of the four embedding numbers, no bias, and output weight 1.

  1. Encode. The record becomes two one-hot blocks: male sets the first gender entry to 1, game sets the first app entry to 1. Check: each field contributes exactly one 1, the rest are 0.
  2. Look up the embeddings. The embedding layer takes the vector of each active field. Male gives (1, 0) and game gives (0.5, 2). The same two vectors will feed both parts below. This is the sharing the paper emphasises. Check: the lookup is a row of the embedding table, not a multiplication by the whole table.
  3. FM part, order 1. Add the two weights: 0.2 + 0.5 = 0.7. Check: this is the linear term of a factorization machine.
  4. FM part, order 2. Take the dot product of the two embeddings: 1 × 0.5 + 0 × 2 = 0.5. The FM output is y_FM = 0.7 + 0.5 = 1.2. Check: with only two fields there is one pair, so one dot product.
  5. Deep part. Concatenate the embeddings into (1, 0, 0.5, 2). The hidden unit computes 0.1 × (1 + 0 + 0.5 + 2) = 0.35, and with output weight 1 the deep output is y_DNN = 0.35. (A real network has many units and several layers.) Check: the deep part sees the same embedding numbers the FM part used.
  6. Combine and squash. Add the two outputs: 1.2 + 0.35 = 1.55. The sigmoid of 1.55 is about 0.82. Check: a sigmoid of 0 would give 0.5, and a large positive score gives a value near 1.
  7. Train. Compare 0.82 with the observed click (0 or 1), and update all weights, embeddings included, by gradient descent. The paper trains the whole network jointly, with no separate pre-training stage.

Worked examples

Example
Example 1: the FM part alone, two numbers

Two fields, one active entry each, with k=2k=2. Let Va=(1,2)V_a=(1,2) and Vb=(3,−1)V_b=(3,-1), and let both weights be zero.

  1. Write the pair sum for two active entries: ⟨Va,Vb⟩ xaxb\langle V_a,V_b\rangle\,x_a x_b. Both xx values are 1, so only the dot product matters.
  2. Compute the dot product: 1×3+2×(−1)=3−2=11\times 3+2\times(-1)=3-2=1.
  3. The FM output is therefore yFM=1y_{FM}=1.
  4. Interpretation: the model's order-2 score for this pair is 1. A positive score pushes the click probability above one half, as the sigmoid of a positive number is above 0.5.
Example
Example 2: the full toy instance from How it works

Use the male and game instance from the walkthrough, with w(male)=0.2w(\text{male})=0.2, w(game)=0.5w(\text{game})=0.5, V(male)=(1,0)V(\text{male})=(1,0) and V(game)=(0.5,2)V(\text{game})=(0.5,2).

  1. Linear term: 0.2+0.5=0.70.2+0.5=0.7.
  2. Pair term: ⟨(1,0),(0.5,2)⟩=0.5\langle(1,0),(0.5,2)\rangle=0.5, so yFM=0.7+0.5=1.2y_{FM}=0.7+0.5=1.2.
  3. Concatenate the embeddings: a(0)=(1,0,0.5,2)a^{(0)}=(1,0,0.5,2).
  4. Hidden unit: 0.1×(1+0+0.5+2)=0.350.1\times(1+0+0.5+2)=0.35, so yDNN=0.35y_{DNN}=0.35.
  5. Logit: 1.2+0.35=1.551.2+0.35=1.55.
  6. Probability: sigmoid⁡(1.55)=1/(1+e−1.55)≈1/(1+0.212)≈0.82\operatorname{sigmoid}(1.55)=1/(1+e^{-1.55})\approx 1/(1+0.212)\approx 0.82.
  7. Interpretation: the model gives this male-game record about an 82 percent click probability under these toy weights. Two parts agree here, and both read the same embedding of game.
Example
Example 3: the paper's Company* result, read from Table 2

The paper's Table 2 reports, on the Company* app-store dataset, AUC of 0.8640 for logistic regression (LR), 0.8678 for FM, 0.8673 for LR & DNN, and 0.8715 for DeepFM. The LR & DNN model is Wide & Deep with LR as the wide part. The second-best model in the table on this dataset is FNN at 0.8683.

  1. Find the best value in the Company* AUC column: DeepFM, at 0.8715.
  2. Subtract the second best, FNN at 0.8683: 0.8715−0.8683=0.00320.8715-0.8683=0.0032.
  3. Subtract LR: 0.8715−0.8640=0.00750.8715-0.8640=0.0075, which is the gap to the no-interaction baseline.
  4. Compare with the paper's text: it reports DeepFM beats the second-best model by more than 0.37 percent in AUC. Relative to the 0.8683 baseline, 0.0032/0.8683≈0.370.0032/0.8683\approx 0.37 percent, so the text and table agree.
  5. Try it: on the Criteo dataset DeepFM's logloss is 0.45083 and FNN's is 0.45738. Is DeepFM's logloss lower, and by how much in absolute terms? Answer: yes, lower, by 0.45738−0.45083=0.006550.45738-0.45083=0.00655.

The math

The paper writes the prediction as

y^=sigmoid⁡(yFM+yDNN),\hat{y}=\operatorname{sigmoid}\big(y_{FM}+y_{DNN}\big),

where y^\hat{y} is the predicted click probability. Each part is defined below.

Step 4 in symbols: the FM part

yFM=⟨w,x⟩+∑i=1d∑j=i+1d⟨Vi,Vj⟩ xi xjy_{FM}=\langle w,x\rangle+\sum_{i=1}^{d}\sum_{j=i+1}^{d}\langle V_i,V_j\rangle\,x_i\,x_j

Here xx is the encoded input of length dd, ww holds one weight per entry, and ViV_i is the length-kk latent vector of entry ii. Because xx is one-hot in each field, most xix_i are zero and the sum runs over active entries only. The inner product ⟨Vi,Vj⟩\langle V_i,V_j\rangle is a learned score for the pair. Factorization machines define this form; Rendle's original 2010 paper shows the pair sum can be rewritten to run in time linear in the number of features.

Step 5 in symbols: the embedding and the deep part

The embedding of field ii is the vector ei=Vactive(i)e_i=V_{\text{active}(i)} of the active entry in that field, and the network's input is

a(0)=[e1,e2,…,em]a^{(0)}=[e_1,e_2,\ldots,e_m]

for mm fields. Each hidden layer applies

a(l+1)=σ(W(l)a(l)+b(l))a^{(l+1)}=\sigma\big(W^{(l)}a^{(l)}+b^{(l)}\big)

with an activation σ\sigma such as Rectified Linear Unit (ReLU) or tanh. The deep output is a single number,

yDNN=W∣H∣+1 a(∣H∣)+b∣H∣+1,y_{DNN}=W^{|H|+1}\,a^{(|H|)}+b^{|H|+1},

passed through the final sigmoid to give y^\hat{y}. The paper's own notation reuses the symbol σ\sigma for both the hidden activation and the output sigmoid; the output sigmoid is the one in the first formula.

Why sharing matters, in symbols

The FM part and the deep part use the same ViV_i, so the gradient of the loss with respect to ViV_i collects signal from both orders. In Wide & Deep the wide part uses its own input, so no such sharing is possible. The paper's Table 1 summarises the comparison: DeepFM is the only one of the four models that needs no pre-training and no feature engineering and captures both orders.

Results

The paper evaluates on two datasets with two metrics. The Criteo dataset has 45 million users' click records, 13 continuous and 26 categorical fields, split 90 percent train and 10 percent test. The Company* dataset has seven consecutive days of training data and the next day for testing, around one billion records in total. Metrics are AUC and logloss. Nine models are compared: LR, FM, FNN, three PNN variants, Wide & Deep (as LR & DNN and FM & DNN), and DeepFM.

Table 2 numbers, Company* then Criteo, AUC and logloss:

  • LR: 0.8640 and 0.02648 on Company*; 0.7686 and 0.47762 on Criteo.
  • FM: 0.8678 and 0.02633; 0.7892 and 0.46077.
  • FNN: 0.8683 and 0.02629; 0.7963 and 0.45738.
  • PNN* (best PNN variant shown): 0.8672 and 0.02636; 0.7987 and 0.45214.
  • Wide & Deep as LR & DNN: 0.8673 and 0.02634; 0.7981 and 0.46772.
  • DeepFM: 0.8715 and 0.02618 on Company*; 0.8007 and 0.45083 on Criteo.

The paper reads these as three findings. Learning interactions beats plain LR. Learning both orders beats either order alone: the paper reports DeepFM ahead of the second-best model by more than 0.37 and 0.25 percent in AUC on Company* and Criteo. Sharing the embedding beats keeping separate embeddings, with DeepFM ahead of both Wide & Deep variants. The paper states the AUC gain over LR as 0.86 percent on Company* and 4.18 percent on Criteo, and the logloss gain as 1.15 and 5.60 percent.

Other results: relu beats tanh for all deep models except IPNN, which the paper attributes to relu's sparsity. Dropout works best between 0.6 and 0.9 keep probabilities. 200 or 400 neurons per layer was a good choice on this data. Efficiency was measured as the training time of each deep model divided by that of LR; DeepFM was almost the most efficient on CPU and GPU.

Limits. Two datasets, one proprietary. Offline metrics only. The efficiency numbers are ratios to LR and depend on the implementations. The hyper-parameter study is on the Company* data alone. The paper names two future directions: pooling layers to find more useful high-order interactions, and training at larger scale on a GPU cluster.

Common mistakes and tradeoffs

It is tempting to think DeepFM is just a deep network with a linear layer added on top. In fact the two parts are built on different structures: the FM part is an explicit, pairwise inner-product model with a fixed form, and the deep part is a general feed-forward network. Sharing the embedding is what couples them; without sharing it is a wide-and-deep model in which the wide part uses FM, and the paper reports it is weaker than DeepFM.

It is tempting to read the AUC gap as a large business gain. The paper itself cautions that a small offline AUC gain may translate into a much larger online CTR change, and it reports the online gain only for Wide & Deep, which it cites from the earlier paper. The gains here are measured offline on two datasets, one of them proprietary.

It is tempting to think that more layers and more neurons always help. The paper's hyper-parameter study finds that adding neurons can overfit, that more hidden layers help at first and then hurt, and that a constant layer width worked best among the four shapes it tried.

Tradeoffs. DeepFM needs no pre-training and no hand-built cross features, and the paper's efficiency comparison puts it close to the cheapest deep model. It is a good choice when the inputs are many sparse categorical fields and the goal is ranking by click probability. It is a weaker fit when the features are mostly continuous and dense, such as images or audio, because the design is built around one-hot categorical fields. Alternatives include Wide & Deep when the team already has good cross features, and product-based models when interactions are the main concern.

Reading guide

The paper has five numbered sections plus references. Read them in this order.

Check yourself

QuestionWhy does DeepFM use one shared embedding for the FM part and the deep part, instead of giving each part its own?Show answer

Sharing means both parts learn the same embedding vectors, so a feature's representation is shaped by both low-order and high-order interactions. The paper argues this represents features more precisely, and its Table 2 shows DeepFM ahead of the two Wide & Deep variants that use separate embeddings.

QuestionIn the toy instance, what is the FM output if the linear term were 0 instead of 0.7?Show answer

The pair term is still 0.5, so yFM=0+0.5=0.5y_{FM}=0+0.5=0.5. The deep output stays at 0.35, so the logit is 0.5+0.35=0.850.5+0.35=0.85. The sigmoid of 0.85 is about 0.70. The linear term added 0.7 to the logit, which moved the prediction from about 0.70 to about 0.82.

QuestionA colleague says DeepFM is faster than LR because it has fewer parameters. Is that right?Show answer

No. The paper measures training time as a ratio to the training time of LR. It reports DeepFM as almost the most efficient deep model, which is a claim about deep models and not a claim that DeepFM beats LR. A network with embeddings and hidden layers has more parameters than LR, so the efficiency claim is about the deep family, not about a linear model.

QuestionYou have a dataset of dense continuous sensor readings with no categorical fields. Would DeepFM's embedding design apply directly? Why or why not?Show answer

Mostly not. DeepFM's embedding step is built for one-hot categorical fields, where each field maps to one learned vector. Continuous readings do not have that lookup structure, so the paper's design would need a different input layer. The paper itself targets sparse, categorical CTR data.

Sources

  • Huifeng Guo, Ruiming Tang, Yunming Ye, Zhenguo Li, Xiuqiang He, DeepFM: A Factorization-Machine based Neural Network for CTR Prediction, arXiv:1703.04247 (2017): https://arxiv.org/abs/1703.04247
  • Heng-Tze Cheng et al., Wide & Deep Learning for Recommender Systems, arXiv:1606.07792 (2016): https://arxiv.org/abs/1606.07792

Read the full paper

Huifeng Guo, Ruiming Tang, Yunming Ye et al., 2017. arXiv:1703.04247