A PyTorch implementation of ESP for Top-N item recommendation.
ESP provides two model variants for collaborative filtering:
- ESP_GF (Graph Filtering): Spectral decoupling via a training-free generalized graph filter with continuous smoothing control
- ESP_GD (Graph Diffusion): Spatial decoupling via contrastive direction learning + degree-suppressed graph diffusion for popularity norms
torch >= 1.8
numpy
scipy
tqdm
Install dependencies:
pip install -r requirements.txtESP/
├── model/
│ ├── graph.py # GraphData class, sparse tensor utilities
│ ├── ESP_GF.py # ESP-GF model implementation
│ └── ESP_GD.py # ESP-GD model implementation
├── util/
│ ├── config.py # Argument parser, HYPER_PARAMS dict
│ ├── dataloader.py # load_data(), train/test data loading
│ ├── device.py # Auto GPU detection and selection
│ ├── evaluator.py # evaluate(): recall, precision, ndcg, hit_ratio
│ └── logger.py # info() logging utility
├── dataset/ # Each subdir: train.txt, test.txt
│ ├── yelp2018/
│ ├── gowalla/
│ └── amazon-book/
├── main.py # Training entry point
└── requirements.txt
Datasets should contain two files:
train.txt (space-separated):
user_id item_id_1 item_id_2 ... item_id_n
test.txt (space-separated):
user_id item_id_1 item_id_2 ... item_id_n
# Train ESP_GF on Yelp2018 (default settings)
python main.py
# Train ESP_GD on Gowalla
python main.py -m ESP_GD -d gowalla
# Custom hyperparameters
python main.py -m ESP_GF -d amazon-book -t 0.5 -a 0.5 -e 100 -es 64| Argument | Short | Default | Description |
|---|---|---|---|
--model |
-m |
ESP_GF | Model: ESP_GF or ESP_GD |
--dataset |
-d |
yelp2018 | Dataset name |
--dataset_path |
-dp |
dataset | Path to dataset directory |
--batch_size |
-bs |
2048 | Batch size (for ESP_GD) |
--epoch |
-e |
100 | Number of training epochs |
--embedding_size |
-es |
64 | Embedding dimension |
--validation_interval |
-vi |
10 | Epochs between validations |
--topN |
-tn |
20 | Top N for evaluation |
--t |
-t |
None | ESP_GD: InfoNCE temperature τ; ESP_GF: spectral smoothness t |
--a |
-a |
None | ESP_GD: diffusion decay α; ESP_GF: popularity offset (β=1-a) |
Default hyperparameters per model/dataset:
| Model | Dataset | t | a |
|---|---|---|---|
| ESP_GF | yelp2018 | 0.7 | 0.6 |
| ESP_GF | gowalla | 0.9 | 0.9 |
| ESP_GF | amazon-book | 0.5 | 0.5 |
| ESP_GD | yelp2018 | 0.15 | 0.6 |
| ESP_GD | gowalla | 0.12 | 0.6 |
| ESP_GD | amazon-book | 0.1 | 0.7 |
- Recall@N: Fraction of relevant items in top-N predictions
- Precision@N: Accuracy of top-N predictions
- NDCG@N: Normalized Discounted Cumulative Gain
- Hit Ratio@N: Whether any relevant item appears in top-N