Principle:Recommenders team Recommenders NCF Prediction
| Knowledge Sources | |
|---|---|
| Domains | Recommender Systems, Deep Learning, Model Inference |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Generating predictions from a trained neural collaborative filtering model by performing a forward pass through the learned network for given user-item pairs.
Description
After a Neural Collaborative Filtering model has been trained, predictions are generated by feeding user-item pairs through the learned network. The model's forward pass maps each (user, item) pair through the trained embedding layers and neural network layers to produce a scalar score representing the predicted likelihood of interaction.
The prediction process involves three steps:
1. ID Resolution: Original user and item identifiers are converted to the model's internal integer indices using the user2id and item2id mappings that were stored during training.
2. Forward Pass: The internal indices are fed into the TensorFlow computation graph. Depending on the model variant (GMF, MLP, or NeuMF), the forward pass computes the appropriate combination of embedding lookups, element-wise products, concatenations, and dense layer transformations, culminating in a sigmoid activation that produces a score in the range (0, 1).
3. Score Extraction: The raw TensorFlow output tensor is reshaped into a Python float (for a single pair) or a Python list (for batch prediction). Batch (list-wise) prediction is significantly faster than repeated element-wise prediction because it avoids per-pair TensorFlow session overhead.
The output score represents the model's confidence that the user will interact with the item. Higher scores indicate stronger predicted preference. These scores can be used directly for ranking items for a given user or for computing evaluation metrics such as Hit Rate and NDCG.
Usage
Use the prediction function after training is complete to generate scores for evaluation or serving. For offline evaluation, predict scores for test user-item pairs (including negative samples) and rank by score to compute Hit Rate@K and NDCG@K. For online serving, predict scores for all candidate items for a given user and return the top-K items. Always prefer list-wise prediction (is_list=True) over element-wise prediction for efficiency.
Theoretical Basis
Forward Pass (NeuMF)
Given trained model f with parameters Theta:
For user u and item i:
u_idx = user2id[u]
i_idx = item2id[i]
# GMF pathway
p_gmf = GMF_user_embedding[u_idx]
q_gmf = GMF_item_embedding[i_idx]
phi_gmf = p_gmf (*) q_gmf # element-wise product
# MLP pathway
p_mlp = MLP_user_embedding[u_idx]
q_mlp = MLP_item_embedding[i_idx]
z = [p_mlp ; q_mlp] # concatenation
for each hidden layer W_l, b_l:
z = ReLU(W_l * z + b_l)
# Fusion
y_hat = sigmoid(h^T * [phi_gmf ; z]) # final score in (0, 1)
List-Wise vs. Element-Wise
Element-wise: For each (u, i) pair, run one session.run() call
Total calls = N (slow for large N)
List-wise: Stack all (u, i) pairs into arrays, run one session.run() call
Total calls = 1 (fast, vectorized)
List-wise prediction exploits GPU parallelism and avoids Python-loop overhead, making it orders of magnitude faster for batch scoring.