Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Recommenders team Recommenders EmbDotBias Score

From Leeroopedia
Revision as of 16:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Recommenders_team_Recommenders_EmbDotBias_Score.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Collaborative Filtering, Scoring, Recommendation
Last Updated 2026-02-10 00:00 GMT

Overview

The score function and cartesian_product helper provide batch scoring and recommendation generation utilities for the EmbeddingDotBias model.

Description

The score function is the primary interface for generating recommendations from a trained EmbeddingDotBias model. It takes a trained model and a test DataFrame of user-item pairs, replaces unknown users/items with NaN, maps IDs to embedding indices using the model's _get_idx method, runs the model's forward pass on all pairs (with automatic GPU placement when available), and returns a DataFrame of predictions sorted by score in descending order per user. It supports optional top_k filtering to limit results to the highest-scoring items per user. The cartesian_product helper computes the Cartesian product of input numpy arrays using numpy broadcasting, which is useful for generating all possible user-item combinations for scoring.

Usage

Use the score function after training an EmbeddingDotBias model to generate predicted ratings for user-item pairs in a test set. This is the standard way to produce recommendations for evaluation or deployment. Use cartesian_product when you need to generate all possible user-item combinations, such as when computing full recommendation lists for all users.

Code Reference

Source Location

Signature

def cartesian_product(*arrays)

def score(
    model,
    test_df,
    user_col=DEFAULT_USER_COL,
    item_col=DEFAULT_ITEM_COL,
    prediction_col=DEFAULT_PREDICTION_COL,
    top_k=None,
)

Import

from recommenders.models.embdotbias.utils import score, cartesian_product

I/O Contract

Inputs

Name Type Required Description
model EmbeddingDotBias Yes Trained EmbeddingDotBias model with classes attribute set
test_df pandas.DataFrame Yes Test DataFrame containing user and item columns
user_col str No User column name (default DEFAULT_USER_COL)
item_col str No Item column name (default DEFAULT_ITEM_COL)
prediction_col str No Prediction column name (default DEFAULT_PREDICTION_COL)
top_k int No Number of top items to recommend per user; if None, return all scores
arrays (cartesian_product) tuple of numpy.ndarray Yes Input arrays for Cartesian product computation

Outputs

Name Type Description
score return pandas.DataFrame DataFrame with user_col, item_col, and prediction_col columns, sorted by prediction descending per user
cartesian_product return numpy.ndarray Array of shape (product_of_lengths, num_arrays) containing all combinations

Usage Examples

Basic Usage

from recommenders.models.embdotbias.utils import score, cartesian_product
import numpy as np
import pandas as pd

# Score user-item pairs from a test DataFrame
predictions = score(model, test_df, top_k=10)

# Generate all user-item combinations
users = np.array([1, 2, 3])
items = np.array([10, 20, 30, 40])
all_pairs = cartesian_product(users, items)
# Result shape: (12, 2) - all 12 combinations of 3 users x 4 items

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment