Skip to content

ZR12345/Recommendation_System

 
 

Repository files navigation

Knowledge-Aware Graph Prompt Tuning for Cross-Domain Recommendation

A cross-domain recommendation system that combines knowledge graph embeddings, graph attention networks, and prompt tuning to transfer user preferences across Amazon product categories.

Table of Contents

Overview

Cross-domain recommendation addresses the data sparsity problem by transferring knowledge from a data-rich source domain to a target domain. Traditional approaches require retraining the full model for each domain pair. This project proposes adaptive prompt tuning — small learnable modules that adapt frozen graph embeddings — to efficiently bridge domains without costly retraining.

The system constructs a unified knowledge graph across two Amazon product categories, learns structural and semantic embeddings via TransE and a Graph Attention Network, and applies prompt-based adaptation for the final recommendation task.

Architecture

┌─────────────────┐     ┌──────────────┐     ┌──────────────┐     ┌──────────────────┐     ┌───────────────┐
│  Amazon Reviews  │────►│ Knowledge    │────►│   TransE     │────►│  GAT Encoder     │────►│ Prompt Tuning │
│  (Two Domains)   │     │ Graph (KG)   │     │ (Embeddings) │     │ (Contrastive)    │     │ + BPR Ranker  │
└─────────────────┘     └──────────────┘     └──────────────┘     └──────────────────┘     └───────────────┘

Stage 1: Knowledge Graph Construction

  • Identifies overlapping users between two Amazon product categories
  • Constructs triples with three relation types:
    • Purchase (user → item)
    • Produced by (item → brand, from product metadata)
    • Described as (item → keyword, via TF-IDF extraction)

Stage 2: TransE Embedding

  • Learns 64-dimensional entity and relation embeddings
  • Trained with margin ranking loss and negative sampling over 20 epochs

Stage 3: GAT Encoder

  • 2-layer Graph Attention Network with contrastive self-supervised learning
  • Dual-view generation via stochastic edge dropout
  • Gradient checkpointing for GPU memory efficiency

Stage 4: Prompt-Tuned Recommendation

Three prompt strategies are compared in an ablation study:

  • Baseline (No Prompt): Raw GAT embeddings fed to the BPR predictor
  • Static Prompt: A single learnable vector added uniformly to all user embeddings
  • Adaptive Prompt (Ours): A density-aware gating mechanism that blends global domain knowledge with personalized user signals derived from neighbor item aggregation

Results

Experiment 1: Electronics ↔ Cell Phones & Accessories

Method HR@10 Improvement
Baseline (Pure GAT) 0.3403
Static Prompt 0.3452 +1.45%
Adaptive Prompt (Ours) 0.4033 +18.53%

Electronics ↔ Cell Phones Results

Experiment 2: Electronics ↔ Beauty

Method HR@10 Improvement
Baseline (Pure GAT) 0.4662
Static Prompt 0.4701 +0.83%
Adaptive Prompt (Ours) 0.4667 +0.09%

Electronics ↔ Beauty Results

Key Findings

  • The adaptive prompt achieves a significant +18.53% improvement on the Electronics ↔ Cell Phones pair, where domain overlap is structurally strong (both are technology categories).
  • On the more distant Electronics ↔ Beauty pair, all methods perform similarly, suggesting that prompt tuning benefits are largest when domains share meaningful structural and semantic connections.

Project Structure

├── WSC_Cell_Phones_electronics.ipynb   # Experiment 1: Electronics ↔ Cell Phones
├── WSC_Electronics_Beauty.ipynb        # Experiment 2: Electronics ↔ Beauty
├── assets/                             # Result visualizations
│   ├── results_cell_phones_electronics.png
│   └── results_electronics_beauty.png
├── requirements.txt                    # Python dependencies
└── README.md

Getting Started

Prerequisites

  • Python 3.9+
  • CUDA-compatible GPU (recommended for training)

Installation

git clone https://github.com/deepanshu-prog/Recommendation_System.git
cd Recommendation_System
pip install -r requirements.txt

Running the Experiments

The notebooks are designed for Google Colab with a GPU runtime:

  1. Open either notebook in Google Colab
  2. Set runtime to GPU (Runtime → Change runtime type → T4 GPU)
  3. Run all cells sequentially

The notebooks handle data download, preprocessing, training, and evaluation end-to-end.

Dataset

All data is sourced from the Amazon Reviews 2023 dataset (McAuley Lab, UCSD).

Domain Pair Overlapping Users Items KG Triples
Electronics ↔ Cell Phones 100,000 (capped) 249,277 826,177
Electronics ↔ Beauty 355,607 467,363 3,253,649

Data files are downloaded automatically within the notebooks. No manual setup is required.

Technical Details

Component Configuration
Embedding Dimension 64
TransE Epochs 20
GAT Layers 2 (1 attention head each)
GAT Training 10 epochs, contrastive loss
Dropout 0.2
BPR Batch Size 2048
Optimizer Adam
Evaluation Metric HR@10 (99 negative samples)
Seed 42

Training Strategy

  1. Warmup Phase: Train only the BPR predictor with frozen embeddings (10–20 epochs)
  2. Joint Phase: Train prompt module and predictor jointly with differential learning rates (25 epochs)

References

  • Knowledge-Aware Graph Prompt Tuning for Cross-Domain Recommendation
  • Amazon Reviews 2023 Dataset
  • Bordes et al., Translating Embeddings for Modeling Multi-relational Data (TransE)
  • Velickovic et al., Graph Attention Networks (GAT)
  • Rendle et al., BPR: Bayesian Personalized Ranking from Implicit Feedback

Authors

IT752 Term Project — Group 13

About

Knowledge-Aware Graph Prompt Tuning for Cross-Domain Recommendation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 100.0%