Cardinality-Decomposed Loss for Heterogeneous GNNs

Parul Maheshwari, Amulya Paruchuri, Alireza Sahami ShiraziNeurIPS 2026

TL;DR

When training Graph Neural Networks (GNNs) for recommendation systems, practitioners routinely apply a single ranking loss to every edge in the graph—treating "a user is 30 years old" the exact same way as "a user liked The Matrix." This structural mismatch triggers a silent failure: demographic and attribute embeddings collapse into useless, nearly identical vectors while top-level recommendation accuracy looks totally fine. By simply matching the training loss to each edge's natural cardinality—ranking for preferences, classification for attributes—we can rescue the geometry of our representations without breaking the recommender.

What Problem Does This Paper Address?

Modern recommendation systems run on heterogeneous graphs. Alongside standard user–item interactions (like clicks or ratings), we wire in rich side-information: user age groups, cities, item genres, and behavioral segments.

Notice the structural difference here. User–item links are one-to-many (OTM): you watch dozens of movies, and the millions you haven't watched form a vast pool of implicitly less-preferred options. In contrast, user–attribute links are one-to-one (OTO): you belong to one age bracket out of a small, exhaustive list.

Yet standard GNN pipelines apply Bayesian Personalized Ranking (BPR) across the entire board. BPR works by pulling a positive connection closer and pushing a randomly sampled unobserved node away. For movies, that makes sense. For a binary attribute like gender, treating "not assigned to Node B" as "dispreferring Node B" is statistically ill-posed.

The authors discover that uniform BPR causes silent representational collapse. Distinct attribute embeddings smash together on the unit sphere (reaching pairwise cosine similarities of 0.93 to 0.98—essentially indistinguishable). Why hasn't anyone noticed? Because standard item-ranking metrics like NDCG@10 don't test attribute quality directly; the recommender keeps humming along while the underlying node representations quietly rot, ruining downstream tasks like user segmentation, cold-start initialization, and fairness auditing.

Uniform BPR collapses attribute geometry and discriminability while standard ranking metrics hide the underlying representational failure.

Methods

Instead of inventing a labyrinthine new neural architecture, the authors fix the problem at its root: the loss function. They propose Cardinality-Decomposed Loss (CDL).

Before training begins, you inspect your graph's schema to map each relation type to its structural cardinality:

  • One-to-many edges get standard BPR loss, preserving pairwise preference ranking.
  • One-to-one edges get a linear classification head trained with Cross-Entropy (CE) loss, treating exhaustive categories properly as mutually exclusive labels.

Both edge types still flow through the exact same shared message-passing encoder (here, a two-layer HeteroSAGE network). The final training objective is simply a weighted sum: $\mathcal{L}_{\text{CDL}} = \mathcal{L}_{\text{BPR}} + \lambda \cdot \mathcal{L}_{\text{CE}}$, introducing just a single scalar hyperparameter $\lambda$ to balance the two worlds.

Figure 2: CDL architecture overview. Left: The heterogeneous input graph contains two structurally distinct edge types: one-to-many user–item edges (dashed blue) and one-to-one user–attribute edges (solid teal). Centre: Both edge types pass through a shared two-layer HeteroSAGE encoder, allowing attribute structure to inform user representations via message passing. Right: The encoder output feeds two separate loss heads — BPR for one-to-many edges and cross-entropy classification heads for one-to-one edges — combined as L = LBPR +λ·LCE. The scalar λ is the only new hyperparameter; it is not learned but swept over a small grid.

Datasets

The authors evaluate CDL across five graphs spanning diverse domains and node configurations:

  • Four public benchmarks: MovieLens-1M (movies; user gender, age, occupation), Last.fm-360K (music; user gender, age, country), BookCrossing (books; user age), and Yelp (local businesses, where OTO attributes—city, state, star rating—live on the item side rather than the user side).
  • One large-scale industrial dataset: PayPal Audience Factory, an internal graph featuring 1 million users, 242 behavioral segments, and millions of interactions, annotated with user gender and age.

Key Insights and Ideas

  • Genuine gradient tug-of-war: By logging the cosine similarity between BPR and CE gradients inside the shared encoder, the authors prove mechanistically that the two objectives actively compete (yielding negative gradient cosine similarity). Ranking preferences and organizing categorical attributes pull shared node embeddings in opposing directions.
  • Cheaper than gradient surgery: Multi-task learning optimizers like PCGrad resolve conflicting gradients by projecting them away from each other, which requires two backward passes per step. CDL ties PCGrad on both ranking and representation quality using a single backward pass—fixing the statistical mismatch removes the need for expensive gradient surgery.
  • Two graph properties explain dataset quirks: Looking post-hoc at how different datasets react to varying $\lambda$, the authors identify two intuitive axes:
  • Semantic alignment: Does the attribute actually predict taste? (Country strongly predicts music taste on Last.fm, protecting ranking accuracy; occupation barely predicts movie taste on MovieLens, causing a trade-off).
  • Topology leakage: Does message passing over adjacent attribute nodes already encode demographic structure into user embeddings without explicit supervision? (In dense, low-class setups like Audience Factory, leakage alone gives near-perfect attribute linearly-probed accuracy!).

Key Results

The authors frame CDL honestly: it is an attribute-representation recovery tool at neutral ranking cost, not a magic bullet for boosting leaderboard NDCG.

  • Massive attribute recovery: Using a linear classifier ("probe") on frozen embeddings to predict held-out user attributes, CDL boosts macro-AUC over the standard collaborative-filtering baseline by +6.5 to +31.1 percentage points across the four public datasets (e.g., jumping from 0.541 to 0.852 on BookCrossing). It also significantly beats a strong, collision-checked multi-task BPR control (mtl_bpr) on MovieLens (+0.079 AUC), BookCrossing (+0.185 AUC), and Yelp (+0.051 AUC).
  • Neutral ranking impact: Across five random seeds, item ranking (NDCG@10) is a statistical tie on Last.fm (+1.7%), Yelp (+1.2%), and BookCrossing (+0.3%). Only MovieLens-1M pays a ranking tax (-25.3% NDCG@10) due to low semantic alignment between demographics and movie taste. On the massive Audience Factory graph (single seed), CDL improves ranking by +2.8% while maintaining a perfect 1.000 probe AUC.

Limitations and Future Work

  • Tuning $\lambda$: The optimal weight $\lambda$ varies by dataset and currently requires a small grid sweep. Because gradient cosine similarity directly tracks objective conflict, building an adaptive $\lambda$ scheduler driven by live gradient measurements is a natural next step.
  • Descriptive, not predictive axes: With only five datasets—and confounding factors like weak intrinsic signal on Last.fm—semantic alignment and topology leakage serve as post-hoc explanatory lenses rather than an a-priori formula for picking $\lambda$. Controlled synthetic graph studies are left for future work.
  • The messy middle of cardinality: CDL handles strict one-to-one and vast one-to-many relations. Real-world schemas also contain multi-label relations (e.g., a movie having three genres out of twenty) and partially observed high-cardinality links, each calling for its own tailored objective.
  • Dual-use representations: Sharper demographic embeddings cut both ways—they make fairness auditing and transparent segmentation much easier, right alongside enabling more surgical demographic ad targeting.

Summary updated

BibTeX
@inproceedings{maheshwari2026cardinality,
  author = {Parul Maheshwari and Amulya Paruchuri and Alireza Sahami Shirazi},
  title = {{Cardinality-Decomposed Loss for Heterogeneous GNNs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=j0w8m1D6QO},
}
Figure