← All projects
Graph Neural NetworksMLAI/ML

GraphRec Social Recommender

Attention-Based GNN for Social Recommendation (from scratch)

GraphRec Social Recommender - Attention-Based GNN for Social Recommendation (from scratch)

Problem

Classic collaborative filtering ignores who users trust. On a platform like Epinions, a rating is shaped both by the items a user has rated and by the opinions of people in their social network. Capturing both signals - interactions and social trust - in one model is the core challenge of social recommendation.

Approach

A from-scratch PyTorch implementation of GraphRec (Fan et al., 2019). Two coordinated GNN modules: a User model that aggregates the user's rated items (item-space) and their trusted friends' opinions (social-space), each with attention so more relevant items/friends weigh more; and an Item model that aggregates the users who rated an item. Rating-aware opinion embeddings combine item identity with the score given. User and item latent factors are concatenated and passed through an MLP to predict the rating. No graph library - the message passing, masking, and attention are built by hand in nn.Module.

At a glance

Model

GraphRec (from scratch)

Dataset

Epinions (ratings + trust)

Graphs

User-item + user-user trust

Attention

Item-level + social-level

Eval

MAE · RMSE

Stack

Pure PyTorch

Tech decisions

  • Implement GraphRec from scratch (no PyG / DGL)

    Building the attention aggregators by hand forced a real understanding of message passing, masking, and opinion embeddings instead of treating the GNN as a black box.

  • Dual item-space + social-space aggregation

    A user's preferences come from both what they've rated and whom they trust; modeling only one loses the signal social recommendation depends on.

  • Attention over items and friends

    Not every rated item or trusted friend is equally informative for a prediction; learned attention weights the relevant ones.

  • Rating-aware opinion embeddings

    Encoding the score alongside item identity lets the model distinguish a 5-star from a 1-star interaction on the same item.

Stack

PythonPyTorchNumPyPandasSciPyGraph Neural Networks
GitHub