Feature Crossing
š Before You Continue: Please read 3.1 Wide & Deep first. This chapter exists precisely to fix 3.1's shortcoming that "the Wide part needs manually designed cross features" ā understanding Wide's limitation is what makes FM's motivation click.
The Wide part of 3.1 uses manual cross features to memorize strong rules, but hand-designing features is laborious and can never be exhaustive. A natural follow-up question arises: can the machine learn feature interactions by itself? That is exactly the problem feature crossing solves.
The most direct idea is to automatically capture interactions between all feature pairs ā but recommender systems routinely have thousands of features; learning one parameter per pair would explode the parameter count; and the data is highly sparse, so most combinations have no training samples at all. In this chapter we start from FM's elegant factorization, walk all the way to automatic high-order crossing in xDeepFM and AutoInt, and include an interactive demo so you can "see" how high-order combinations are built step by step.
After reading this chapter, you will be able to:
- Explain how FM uses inner products of latent vectors to cut parameters down to and ease sparsity
- Distinguish the enhancements that AFM / NFM / PNN / FiBiNET each add on top of FM
- Explain how DeepFM replaces the manual Wide part with "shared Embedding" for an end-to-end model
- Compare the differing motivations of the three high-order crossings: DCN (element-wise) / xDeepFM (vector-wise) / AutoInt (adaptive)
- Work through 4 leveled practice problems, and use the interactive demo to understand how high-order combinations form
3.2.0 Motivation: From Manual to Automatic Crossing
The Wide part of Wide & Deep depends on experts hand-designing cross features, which has two pain points: (1) the combination space is too large for humans to enumerate; (2) newly appearing combinations have no ready-made feature. What we want is a mechanism that automatically learns interactions between arbitrary feature pairs without parameter explosion.
Recall FM from Part 2's retrieval: it factorizes users and items into vectors and uses inner products for efficient retrieval. At the ranking stage, FM shows a different face ā its core idea of "learn one vector per feature, then capture interactions with vector inner products" solves exactly the pain points above. The same technique appears twice at different stages.
š§ Mental Model: Give Every Feature a "Business Card"
Think of FM's latent vector as a "business card" handed to each feature, listing its interests. Want to know whether features A and B click? Instead of keeping a separate ledger for every AĆB pair, just take the inner product of the two cards ā high compatibility, large inner product. Even better: even if A and B have never appeared together in one sample, as long as each of their cards is well learned through other features, you can still infer the effect of AĆB. That is the power of parameter sharing.
3.2.1 FM: Factorization Machines (Second-Order Crossing)
To capture feature interactions, a straightforward idea adds all second-order combination terms of the features to a linear model (a polynomial model):
It has two fatal flaws: (1) the parameter count is , unaffordable with many features; (2) in sparse data, most crossing terms never co-occur, so the corresponding weights cannot be learned.
FM's essence is parameter sharing: factorize each interaction weight into the inner product of two low-dimensional latent vectors, . Thus:
where are the -dimensional embeddings of features (). Instead of learning independent 's, each feature now needs only one -dimensional vector, bringing the total parameter count down to . More crucially: even if and never co-occur, as long as each co-occurs and learns well with other features (e.g., ), and are still valid, so the model can generalize to predict the effect of . Moreover, via an algebraic transformation, the FM second-order term's computation drops from to linear :
Each feature learns one -dimensional latent vector; the interaction of any two features is given by an inner product, with no per-pair weights ā parameters drop from to .
Analysis: FM uses parameter sharing to solve both "parameter explosion" and "hard to learn under sparsity" at once, making it a widely used second-order crossing baseline in industry. Its limitation: it only models second-order pairwise interactions; higher-order combinations still rely on an upper DNN to learn implicitly, and the interaction form is a fixed "inner product" that cannot differentiate the importance of different crossings.
3.2.2 FM Family Enhancements: AFM / NFM / PNN / FiBiNET
FM treats all crossings "equally," but in practice different crossings matter to different degrees. Researchers have made various enhancements on top of it:
- AFM (Attention FM) introduces attention, assigning each pair a weight (Softmax normalized) so the model focuses on important interactions; the attention weights are visualizable and improve interpretability. Its interaction layer first computes the element-wise product , then does attention pooling: .
- NFM (Neural FM) feeds FM's second-order crossing result (in vector form) as "raw material" into a DNN to learn higher-order nonlinearity. The key is the Bi-Interaction pooling layer: , also optimizable to , then fed into an MLP. FM can be seen as the special case of NFM without hidden layers.
- PNN (Product-based NN) argues inner products / element-wise products each have limits, so its "product layer" uses inner products (IPNN) and outer products (OPNN) together to capture richer interactions, with matrix decomposition / superposition approximations reducing complexity from to .
- FiBiNET first learns feature importance (borrowing SENET from vision: Squeeze ā Excitation ā Re-weight), then uses bilinear interaction to break the symmetric-interaction constraint, combining "important features" with "flexible interactions."
From "all crossings equally important" (FM) to "attention weighting" (AFM), "feeding a DNN" (NFM), "multiple product operations" (PNN), "re-weight first then bilinear" (FiBiNET) ā the evolution always revolves around "more flexible, more expressive."
š” Key Insight: These models all answer "how to do better on top of FM's second-order crossing" ā some add attention (AFM), some attach deep networks (NFM), some change the product form (PNN), some select important features first (FiBiNET). But their second-order crossing form remains fairly fixed.
3.2.3 DeepFM: Unified Low-Order and High-Order Modeling
The Wide part of 3.1 needs heavy manual feature engineering. DeepFM simply replaces Wide with manual-free FM and lets FM and Deep share the same set of embeddings. Two benefits follow: (1) low-order and high-order interactions are learned together; (2) the shared embedding makes training more efficient.
DeepFM consists of two parallel components, FM and DNN, with shared inputs:
- The FM component captures first- + second-order crossings: .
- The Deep component concatenates all embeddings and feeds them to a DNN to learn high-order nonlinearity: , .
The two logits are summed and passed through Sigmoid: .
FM and DNN share one set of embeddings: FM learns low-order (first + second), DNN learns high-order, and their sum gives the final prediction ā manual Wide features eliminated entirely.
Analysis: DeepFM's biggest improvement over Wide & Deep is replacing the manual Wide part with automatically learned FM, achieving a truly end-to-end model. Complexity mainly comes from the parallel FM + DNN, but the shared embedding avoids doubling parameters. Limitation: FM explicitly models only second order; higher orders still rely on the DNN implicitly, and the interaction form is fixed.
3.2.4 High-Order Crossing: DCN (Residual High-Order)
The FM family explicitly models second order; higher orders are mostly learned implicitly by the DNN, and we can't tell which order the DNN actually learned. DCN (Deep & Cross Network) replaces the Wide part with a Cross Network, where every layer crosses with the original input , thereby explicitly learning high-order interactions:
This is a residual structure: layer adds a "cross with the original input" term on top of the previous layer's output. The deeper the network, the higher the crossing order ā layer 1 contains second order, layer 2 contains third order, and so on ā while the parameter count grows only linearly with the input dimension. The Cross Network runs in parallel with the Deep Network, and their concatenated outputs go through logistic regression:
Each layer : the residual connection preserves the original information, continual crossing with raises the order with depth, and parameters grow only linearly.
Analysis: DCN learns arbitrarily high-order crossings explicitly and controllably, with efficient (linear-in-dimension) parameters. But it is an element-wise (bit-wise) crossing ā every element of an embedding interacts separately, tearing the vector apart instead of treating the embedding as a whole feature. That is exactly what xDeepFM corrects.
3.2.5 xDeepFM: Vector-Wise CIN Interactions
DCN crosses at the element level; xDeepFM proposes the Compressed Interaction Network (CIN) and switches to vector-wise interactions, which better match intuition. xDeepFM has three components: linear + DNN (implicit high-order) + CIN (explicit high-order vector-wise), merged at the end.
The core of CIN: the layer- output is a weighted sum of all pairwise Hadamard products between the previous layer and the original input :
where is the vector-wise Hadamard product, preserving the -dimensional vector structure. Layer 's output contains all -order vector-wise interactions. The feature maps of each layer are concatenated after Sum Pooling, then merged with the linear and DNN outputs through Sigmoid:
Each CIN layer takes vector-wise Hadamard products of "previous layer's feature maps Ć original input," then compresses them with weights into new feature maps; stacked layer by layer, this yields vector-wise crossings from second order up to T+1 order.
Analysis: xDeepFM combines "explicit vector-wise interactions" with "implicit element-wise interactions," gaining expressiveness and interpretable interactions (which layer corresponds to which order). The cost is the extra computation of the weighted vector sums in CIN, so the number of feature maps must be set carefully.
3.2.6 AutoInt: Self-Attention Adaptive Interactions
Each DCN layer crosses with in a fixed way, and xDeepFM's CIN also interacts in a fixed manner. AutoInt changes the approach: let the model decide which features interact and how strongly ā using the Transformer's self-attention to adaptively learn interactions of arbitrary order.
For features , the relevance score of attention head :
The scores weight and sum the Values to obtain the new representation ; multi-head outputs are concatenated with residual connections added. Stacked layers: the first layer contains second order, the second contains third order, and so on ā the interaction pattern is entirely determined dynamically by attention weights. Finally, all layers' representations are concatenated and fed to logistic regression.
š” Key Insight: The motivational differences among the three high-order crossings are clear at a glance ā DCN crosses in a fixed residual way (element-wise), xDeepFM crosses in a fixed CIN way (vector-wise), and AutoInt crosses adaptively with attention. The first two hard-code the interaction pattern; AutoInt leaves "who interacts with whom, how strongly" to the data, which is more flexible and interpretable (inspect the attention matrices).
3.2.7 Interactive Demo: How High-Order Crossings Form Layer by Layer
The interactive demo below gives a hands-on feel for how combinations "second order ā third order ā higher" are constructed from base features step by step. Click "Next" to observe which new crossing combinations each layer adds.
The demo uses 4 base features (e.g., gender, city, category, price tier) and shows layer by layer: layer 1 produces all second-order combinations, layer 2 crosses second-order ones with base features to get third order, and so on ā exactly the intuition behind the explicit high-order crossings in DCN / CIN.
ā ļø Common Mistakes in 3.2
| # | Mistake | Example | Why It's Wrong | Fix |
|---|---|---|---|---|
| 1 | Thinking FM learns an independent weight per feature pair | "FM has crossing weights" | FM shares parameters via latent-vector inner products, only | Remember: ; parameters scale linearly in |
| 2 | Overlooking FM's significance for sparsity | "If features never co-occur, nothing can be learned" | Latent vectors are learned indirectly via co-occurrence with other features, enabling generalization | Parameter sharing is FM's core answer to sparsity |
| 3 | Treating DeepFM as identical to Wide & Deep | "DeepFM also needs manual cross features" | DeepFM replaces manual Wide with FM, end-to-end | Distinguish: Wide & Deep = manual crossing, DeepFM = automatic FM |
| 4 | Confusing DCN's and xDeepFM's crossing granularity | "Both are high-order crossing, no difference" | DCN is element-wise, xDeepFM is vector-wise | Check whether crossing happens on scalars or whole embedding vectors |
| 5 | Believing more high-order crossing is always better | "Stacking 10 Cross layers must be stronger" | Very high orders overfit, compute is expensive, and the business may not need it | Choose depth by data complexity and the validation set |
Chapter Summary
š Key Takeaways
| Concept | Key Points | Why It Matters |
|---|---|---|
| FM factorization | , parameters | Automatic second-order crossing solves parameter explosion + sparsity |
| FM family | AFM attention / NFM attaches DNN / PNN multiple products / FiBiNET re-weighting | Enhancements on top of second-order crossing |
| DeepFM shared Embedding | FM (low-order) + DNN (high-order) share input | End-to-end replacement of manual Wide |
| DCN residual high-order | (element-wise) | Explicit, controllable high-order crossing with linear parameters |
| xDeepFM CIN | Layer-by-layer compression of vector-wise Hadamard products | Vector-wise explicit high order, interpretable |
| AutoInt adaptive | Self-attention decides interactions and strength | Most flexible; interactions learned from data |
ā FAQ
Q1: Why not just let a DNN learn high-order crossings ā why FM/DCN?
A: A DNN can learn high orders implicitly, but we don't know which order or which combinations it learned, and sparse combinations are hard to guarantee. FM/DCN/xDeepFM make crossings explicit ā controllable, interpretable, and friendlier to sparsity.
Q2: DCN or xDeepFM ā which should I pick?
A: If feature interactions are better treated as "whole-vector" relations (e.g., semantic embeddings), xDeepFM's vector-wise form fits better; if simplicity and efficiency suffice and element-wise works, DCN is lighter. In practice, let the validation set and compute budget decide.
Q3: Can AutoInt's attention weights be used as feature importance?
A: Yes. The attention matrices directly show which feature pairs contribute to interactions ā a major source of interpretability and one of AutoInt's advantages over DCN/xDeepFM.
š Connections to Later Chapters
- 3.3 (Sequence Modeling) steps out of the "static feature bag" and adds the time dimension; DIN's attention shares its roots with the attention in AFM/AutoInt.
- The shared-bottom structures (Shared-Bottom/MMoE) of 3.4 (Multi-Objective) often use DeepFM-style models as the backbone.
- In Part 2 retrieval, FM is used for two-tower retrieval ā two ends of the same technique as its ranking use in this chapter.
Practice Problems
Work through all problems in order ā they get progressively harder. Each has a complete solution you can reveal after trying it yourself.
Problem 3.2.1 ā FM Parameter Sharing š¢ Easy
A recommendation scenario has features, and FM's latent vector dimension is . Answer:
- With the original polynomial model, roughly how many second-order crossing weights are there?
- With FM's latent-vector scheme, roughly how many parameters? How many orders of magnitude does that save?
š” Solution (click to reveal)
Approach: Apply the order-of-magnitude formulas directly.
- The polynomial model's second-order term has about weights.
- FM needs only one -dimensional vector per feature: parameters.
Key points:
- From down to ā roughly 2 orders of magnitude (a hundredfold).
- The gap widens as grows ā the key to FM's industrial viability.
Problem 3.2.2 ā Identify the Crossing Type š¢ Easy
Match each description to the correct model among FM / DeepFM / DCN / xDeepFM / AutoInt:
- (a) Does residual crossing with the original input layer by layer, but tears apart every element of the embedding.
- (b) FM and DNN share one set of feature embeddings, learning low-order and high-order separately.
- (c) Uses multi-head self-attention to let the model decide which features should interact and how strongly.
- (d) Takes vector-wise Hadamard products of the previous layer's feature maps with the original input, then compresses.
š” Solution (click to reveal)
Approach: Grasp each crossing's "granularity" and "whether it's adaptive."
- (a) DCN (element-wise / bit-wise residual crossing)
- (b) DeepFM (parallel FM + DNN with shared embeddings)
- (c) AutoInt (self-attention adaptive interaction)
- (d) xDeepFM (CIN vector-wise interaction)
Key points:
- Element-wise vs vector-wise: DCN vs xDeepFM.
- Adaptive vs fixed: AutoInt stands alone.
Problem 3.2.3 ā Motivation Follow-up š” Medium
Why can FM still give a reasonable prediction for the crossing when features and have never co-occurred in the training set? Explain using parameter sharing.
š” Solution (click to reveal)
Approach: Explain from the perspective of "indirect learning" of latent vectors.
In FM the interaction weight is . Even if and never co-occur, can be learned well from 's co-occurrence with other features (e.g., ), and likewise from 's co-occurrence with . As long as these latent vectors are sufficiently well learned, their inner product can infer the tendency of ā no direct samples of needed.
Key points:
- Parameter sharing lets "combinations never directly observed" still be estimated by generalization.
- This is FM's fundamental advantage over "independent weight per combination" in sparse settings.
Problem 3.2.4 ā Derive FM's Linear Complexity š“ Hard
Starting from FM's second-order term , prove it equals , so the computation cost is . Also explain: when a feature , how are its interactions with all other features naturally ignored?
š” Solution (click to reveal)
Approach: Expand the square and cancel terms.
. Rearranging gives . Both terms only require vector additions/squares over features followed by a sum ā total instead of .
When , it contributes nothing to and , so every interaction term involving vanishes automatically ā no explicit skipping needed; sparse features are ignored with zero wasted computation.
Key points:
- The algebraic transformation is what makes FM usable for high-dimensional sparse data.
- Interactions auto-zero when , a perfect fit for sparsity.
š Challenge: Design a Crossing Scheme
A news app has 500 sparse features. It needs to capture second-order strong rules like "age Ć category," hopes the model automatically discovers patterns of third order and above, and requires an interpretable structure (being able to see which crossings matter). Pick a combination of 2 from FM / AFM / DCN / xDeepFM / AutoInt and justify your choice (within 150 words).
š” Hint
Second-order + interpretable weights ā AFM (attention visualization); high-order + interpretable order ā xDeepFM (each CIN layer corresponds to a fixed order) or AutoInt (attention matrices). DCN is element-wise and can't directly show crossing importance, so you can skip it. A combination like "AFM + xDeepFM" covers interpretable low-order and interpretable vector-wise high-order.