Detect CUDA device (CPU fallback for local validation).
2. Data Loading & Preprocessing
Load MovieLens-100k dataset (downloaded via URL).
Construct a CTR-style binary classification problem: label = 1 if user rated item ≥ 4, else 0.
Build categorical features: user_id, item_id (mapped to contiguous 0-indexed integers).
Build dense/continuous features: extracted from rating timestamp (hour of day, day of week) and user statistics (mean rating, rating count) — normalized to [0, 1].
Train/test split: 80/20 random split stratified by label.
Data shapes:
Categorical features: (batch, num_cat_features) — integer indices
Embedding tables:nn.ModuleList of nn.Embedding layers, one per categorical feature. Each maps vocabulary_size → embed_dim.
Bottom MLP:nn.Sequential of FC layers processing dense features. Architecture: [num_dense, 128, 64, embed_dim] with ReLU activations.
Interaction layer: Computes pairwise dot products between all processed vectors (embeddings + bottom MLP output). Takes upper triangular (i < j) to avoid redundancy and self-interactions. Returns n*(n-1)/2 scalar values.
Top MLP:nn.Sequential of FC layers. Input = concatenation of interaction outputs + processed dense vector. Architecture: [n*(n-1)/2 + embed_dim, 512, 256, 1] with ReLU activations, final sigmoid.
Forward pass:
Embedding lookup: each categorical feature → embedding vector (batch, embed_dim)
Bottom MLP: dense features → (batch, embed_dim)
Collect all vectors: [emb_1, emb_2, …, emb_n, dense_out]
Scale: Real DLRM uses Criteo dataset with millions of users/items and hundreds of categorical features. We use MovieLens-100k with 2 categorical features for tractability.
Embedding table sizes: Paper uses tables with millions of rows. Ours use actual vocabulary sizes from ML-100k (~943 users, ~1682 items).
Parallelization: Paper describes model-parallel embeddings + data-parallel MLPs across multiple GPUs. We run on a single device (GPU or CPU).
Feature count: Paper uses dozens of categorical + continuous features. We use 2 categorical + 4 continuous features.
Training duration: Paper trains for hours/days on full Criteo. We train 10 epochs for demonstration.
Interaction layer: Paper uses nn.EmbeddingBag for multi-hot lookups. We use simple nn.Embedding for single-valued categorical features.
NCF comparison: We implement a simplified NCF (MLP-only, no GMF/NeuMF fusion) rather than the full NeuMF model, to keep the comparison focused on interaction mechanism differences.