Skip to content
mlmentorship

Factorization machines

Share vectors across feature pairs, derive sparse interaction evaluation, and separate available unseen-pair estimates from validated generalization.

Published · 9 min read ·Role-specific ·Intermediate

Visual quick review

Explain how shared per-feature embeddings let a factorization machine estimate the interaction coefficient for a feature pair that never appeared together in training.

Parameter sharing

Pair-specific weights compared with shared feature embeddings for an unseen interaction

Pair-specific weights compared with shared feature embeddings for an unseen interaction An original three-feature example compares two parameterizations. In a polynomial model, training included pairs A-B and B-C, so their separate edge weights are learned, while the never-observed A-C edge has an unknown pair-specific weight. In a factorization machine, each feature instead owns one reusable two-dimensional vector: A is one-zero, B is point-eight-point-two, and C is point-six-point-four. The observed A-B and B-C pairs help learn those vectors. Even though A-C never appeared together, its coefficient is defined and computable as the dot product of A and C, one times point six plus zero times point four, which equals point six. This demonstrates availability of an estimate, not guaranteed accuracy on every unseen pair. PAIR-SPECIFIC MODEL · EDGE PARAMETERS feature A feature B feature C wAB wBC wAC = ? A–C never appeared together FACTORIZATION MACHINE · PARAMETERS LIVE ON FEATURES feature A vA = [1, 0] learned via A–B feature B vB = [.8, .2] shared by both feature C vC = [.6, .4] learned via B–C AB BC unseen pair · coefficient still defined wAC := ⟨vA, vC⟩ = 1 × .6 + 0 × .4 = .60 an available estimate, not a guarantee of accuracy O(d²) EDGE WEIGHTS → O(dk) FEATURE EMBEDDINGS
Explicit AB + AC + BC0.80 + 0.60 + 0.56 = 1.96
Squared norm of summed vectors2.4² + 0.6² = 6.12
Sum of individual squared norms1 + 0.68 + 0.52 = 2.20
Half the difference(6.12 − 2.20) / 2 = 1.96
Read it this way: one reusable vector per feature supplies the unseen A-C coefficient 0.60. With all inputs active, explicit pair summation and the aggregate identity below both give 1.96. Neither calculation validates unseen-pair accuracy. Original example based on Rendle (2010).
Check: Which learned objects supply an A-C estimate when there is no dedicated A-C parameter?
Full explanation 9 min read
Reading depth

Summary

Suppose training contains feature pairs A-B and B-C, but not A-C. A factorization machine assigns a shared vector to each feature, making the A-C dot product computable. That supplies an estimate, not evidence that the estimate is accurate.

For features, give feature a scalar weight and vector . With global bias , the prediction score is

An independent degree-two model stores pair coefficients; FM stores interaction parameters plus main effects. This changes statistical sharing as well as storage when . An absent pair’s independent coefficient lacks direct co-occurrence evidence; shared vectors impose an additional modeling assumption. The following vectors are chosen fixtures, not fitted outputs.

Parameter sharing

Reuse feature vectors for active pairs; computable interactions are not observed or validated ones

Reuse feature vectors for active pairs; computable interactions are not observed or validated onesShared feature vectors make an unseen pair coefficient computable, not validated. Multiply each pair coefficient by both active input values, then add bias and linear effects. This toy has zero main effects. Sum-coordinate squares, remove self-terms, and halve to evaluate sparse interactions without enumerating every pair. Deactivating B leaves only A with C. Storage depends on the full vocabulary; computation depends on active features. The score is not automatically a probability.Shared vectors estimate the missingA-C interactionTraining has A-B and B-C, not A-C.ABCToy vectors, not fitted outputsCoord 1Coord 2A10B0.80.2C0.60.4All three inputs active; zero biasand linear effectsA with B: 0.80A with C: unobserved pair: 0.60B with C: 0.56All-pair interaction: 1.96Sparse shortcut: square summedcoordinates, remove self-terms, thenhalve.Squared sum 6.12; self-terms 2.20;interaction 1.96Turn B off: only A with C remains,contributing 0.60.Only active pairs contribute. Addbias and linear effects for the fullscore; it is not automatically aprobability.Work scales with active features andvector width; storage still scaleswith the whole vocabulary. Validateunseen-pair predictionsindependently.
Read it this way: Shared feature vectors make an unseen pair coefficient computable, not validated. Multiply each pair coefficient by both active input values, then add bias and linear effects. This toy has zero main effects. Sum-coordinate squares, remove self-terms, and halve to evaluate sparse interactions without enumerating every pair. Deactivating B leaves only A with C. Storage depends on the full vocabulary; computation depends on active features. The score is not automatically a probability. When B is inactive, which pair contribution remains?
Reference drawing

Parameter sharing

Reuse feature vectors for active pairs; computable interactions are not observed or validated ones

Reuse feature vectors for active pairs; computable interactions are not observed or validated onesShared feature vectors make an unseen pair coefficient computable, not validated. Multiply each pair coefficient by both active input values, then add bias and linear effects. This toy has zero main effects. Sum-coordinate squares, remove self-terms, and halve to evaluate sparse interactions without enumerating every pair. Deactivating B leaves only A with C. Storage depends on the full vocabulary; computation depends on active features. The score is not automatically a probability.Shared vectors estimate the missingA-C interactionTraining has A-B and B-C, not A-C.ABCToy vectors, not fitted outputsCoord 1Coord 2A10B0.80.2C0.60.4All three inputs active; zero biasand linear effectsA with B: 0.80A with C: unobserved pair: 0.60B with C: 0.56All-pair interaction: 1.96Sparse shortcut: square summedcoordinates, remove self-terms, thenhalve.Squared sum 6.12; self-terms 2.20;interaction 1.96Turn B off: only A with C remains,contributing 0.60.Only active pairs contribute. Addbias and linear effects for the fullscore; it is not automatically aprobability.Work scales with active features andvector width; storage still scaleswith the whole vocabulary. Validateunseen-pair predictionsindependently.
Derivation
Pair-specific weights compared with shared feature embeddings for an unseen interaction An original three-feature example compares two parameterizations. In a polynomial model, training included pairs A-B and B-C, so their separate edge weights are learned, while the never-observed A-C edge has an unknown pair-specific weight. In a factorization machine, each feature instead owns one reusable two-dimensional vector: A is one-zero, B is point-eight-point-two, and C is point-six-point-four. The observed A-B and B-C pairs help learn those vectors. Even though A-C never appeared together, its coefficient is defined and computable as the dot product of A and C, one times point six plus zero times point four, which equals point six. This demonstrates availability of an estimate, not guaranteed accuracy on every unseen pair. PAIR-SPECIFIC MODEL · EDGE PARAMETERS feature A feature B feature C wAB wBC wAC = ? A–C never appeared together FACTORIZATION MACHINE · PARAMETERS LIVE ON FEATURES feature A vA = [1, 0] learned via A–B feature B vB = [.8, .2] shared by both feature C vC = [.6, .4] learned via B–C AB BC unseen pair · coefficient still defined wAC := ⟨vA, vC⟩ = 1 × .6 + 0 × .4 = .60 an available estimate, not a guarantee of accuracy O(d²) EDGE WEIGHTS → O(dk) FEATURE EMBEDDINGS
Explicit AB + AC + BC0.80 + 0.60 + 0.56 = 1.96
Squared norm of summed vectors2.4² + 0.6² = 6.12
Sum of individual squared norms1 + 0.68 + 0.52 = 2.20
Half the difference(6.12 − 2.20) / 2 = 1.96
Read it this way: one reusable vector per feature supplies the unseen A-C coefficient 0.60. With all inputs active, explicit pair summation and the aggregate identity below both give 1.96. Neither calculation validates unseen-pair accuracy. Original example based on Rendle (2010).
Check: Which learned objects supply an A-C estimate when there is no dedicated A-C parameter?
Read it this way: Shared feature vectors make an unseen pair coefficient computable, not validated. Multiply each pair coefficient by both active input values, then add bias and linear effects. This toy has zero main effects. Sum-coordinate squares, remove self-terms, and halve to evaluate sparse interactions without enumerating every pair. Deactivating B leaves only A with C. Storage depends on the full vocabulary; computation depends on active features. The score is not automatically a probability. When B is inactive, which pair contribution remains?

The mechanism

For each coordinate , expanding gives diagonal terms plus twice every pair. Subtract those self-terms, divide by two, and sum over coordinates:

For active inputs, this costs instead of enumerating vector pairs. Parameter storage still depends on the full feature vocabulary, .

Using the illustrated vectors and , pair coefficients are , summing to . The vector sum is ; half of also gives . Deactivating B leaves only A-C and score , with bias and linear terms zero.

Sparse one-hot inputs

Categorical IDs can be one-hot encoded; numeric inputs can also participate with their actual values. A pair contributes only when both input values are nonzero.

Change active inputs

New task: activate only one user indicator and one item indicator, both equal to one.

Picture and change: remove every inactive linear and interaction term:

Check: fitted values and vectors give . This is biased matrix factorization’s score, not an automatically bounded rating or probability. Adding category, time, or device features introduces their linear terms and active pairs, not explicit third-order terms.

Use when: compare FM with MF on matched features.

Change field specificity

New task: let a category feature interact differently with user and time fields.

Picture and change: field-aware FM uses for feature fields . In a separate one-dimensional fixture, category A uses value one against users and two against time. The counterpart vectors are three and four, respectively.

Check: category-user interaction is ; category-time is . Reusing A’s value one for both would give four for the latter pair. The plain-FM aggregate-square computation cannot simply reuse one vector per feature here.

Use when: measured field-specific benefits justify added storage and compute.

Variants

  • Field-aware FM has field-indexed feature vectors, increasing storage to roughly for fields.
  • DeepFM combines an FM component with a deep branch sharing feature embeddings.
  • xDeepFM uses a compressed interaction network; AutoInt uses attention; DCN uses cross layers. Their interaction computations differ.

Tradeoffs

FM shares pair coefficients instead of fitting them independently, trading flexibility for statistical reuse. Compare logistic regression, boosting, and interaction models with matched features and task metrics. Architectural complexity does not guarantee better accuracy, speed, or interpretation. Choose the loss/link separately: binary outcomes might use a sigmoid and logistic loss on the score.

Common pitfalls

Keep main effects: with one active feature, there is no pair term. Numeric-feature scaling changes interaction magnitudes; normalize or otherwise validate preprocessing rather than requiring arbitrary binning. Tune and regularization, especially for rare features. A new untrained feature needs an unknown-feature/initialization policy; an available unseen-pair coefficient does not solve unseen-feature support. Removing Gram diagonal terms does not imply the remaining off-diagonal matrix itself has rank .

Does plain FM explicitly model arbitrary third-order interactions?

Answer

No. Its explicit interaction polynomial has degree two; higher-order behavior requires another computation.

Original formulation: Rendle (2010).