Skip to content

Commit

Permalink
Colab Notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Joinn99 committed Feb 21, 2023
1 parent d1067c0 commit f726829
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 101 deletions.
207 changes: 108 additions & 99 deletions FPSR_Demonstration.ipynb → FPSR Demonstration.ipynb
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "1cN-BpEGaSf5"
},
"source": [
"# FPSR\n",
"------------\n",
Expand All @@ -28,37 +15,40 @@
"</p>\n",
"\n",
"> Tianjun Wei, Jianghong Ma, Tommy W.S. Chow. Fine-tuning Partition-aware Item Similarities for Efficient and Scalable Recommendation. In WWW 2023. [[arxiv](https://arxiv.org/abs/2207.05959)] [[Github](https://github.com/Joinn99/FPSR)]"
],
"metadata": {
"id": "1cN-BpEGaSf5"
}
]
},
{
"cell_type": "markdown",
"source": [
"## Preprocessing"
],
"metadata": {
"id": "8pxSpTa9ZoTy"
}
},
"source": [
"## Preprocessing"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"cellView": "form",
"id": "FrbhQmJjGF3I"
},
"outputs": [],
"source": [
"#@title Environment Setting\n",
"#@markdown FPSR is implemented based on the recommendation toolbox [RecBole](https://recbole.io/).\n",
"%%capture\n",
"! pip install recbole==1.1.1"
],
"metadata": {
"id": "FrbhQmJjGF3I",
"cellView": "form"
},
"execution_count": 1,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"cellView": "form",
"id": "pqa6o51yExY_"
},
"outputs": [],
"source": [
"#@title Download Dataset\n",
"#@markdown Here we use four public datasets:<br>\n",
Expand All @@ -72,16 +62,16 @@
"%%capture\n",
"! git clone https://github.com/Joinn99/FPSR\n",
"! cd FPSR && unzip -o \"Data/*.zip\" -d /content"
],
"metadata": {
"id": "pqa6o51yExY_",
"cellView": "form"
},
"execution_count": 2,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"cellView": "form",
"id": "7NnQ5JnKb-p1"
},
"outputs": [],
"source": [
"#@title Configuation\n",
"#@markdown Here we list the configurations of the experiment.\n",
Expand Down Expand Up @@ -119,26 +109,25 @@
" \"epochs\": 1,\n",
" \"eval_step\": 0,\n",
"}\n"
],
"metadata": {
"id": "7NnQ5JnKb-p1",
"cellView": "form"
},
"execution_count": 3,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f5ytkUIsbn_B"
},
"source": [
"### Hyperparameters\n",
"Here we list the hyperparameter setting of FPSR. To evaluate the performance of FPSR with different hyperparameters, modify the values in `FPSR_CONFIG` and select `Runtime->Run after`."
],
"metadata": {
"id": "f5ytkUIsbn_B"
}
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "k5R7vKwlMPfO"
},
"outputs": [],
"source": [
"DATASET = {\n",
" 'dataset': 'douban'\n",
Expand All @@ -158,24 +147,25 @@
"\n",
"CONFIG.update(DATASET)\n",
"CONFIG.update(FPSR_HYPER)"
],
"metadata": {
"id": "k5R7vKwlMPfO"
},
"execution_count": 4,
"outputs": []
]
},
{
"cell_type": "markdown",
"source": [
"## Model Implementation"
],
"metadata": {
"id": "7hNBSzOCZszh"
}
},
"source": [
"## Model Implementation"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"cellView": "form",
"id": "jHuhZcigM0lJ"
},
"outputs": [],
"source": [
"#@title FPSR\n",
"#@markdown This cell includes a complete implementation of FPSR model.\n",
Expand Down Expand Up @@ -377,25 +367,47 @@
" r = torch.sparse.mm(self.S, user.T).T\n",
" r += self.lambda_ * user * self.d_i.T @ self.V @ self.V.T * self.d_i_inv\n",
" return r"
],
"metadata": {
"cellView": "form",
"id": "jHuhZcigM0lJ"
},
"execution_count": 5,
"outputs": []
]
},
{
"cell_type": "markdown",
"source": [
"## Running"
],
"metadata": {
"id": "9spbyRBwb0dn"
}
},
"source": [
"## Running"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "htpZ3NxHYlKP",
"outputId": "391a5401-e505-4849-da12-2b8fd7a613e2"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"==========Preprocessing==========\n",
"Configuration loading complete.\n",
"Data loading complete.\n",
"============Training=============\n",
"(This step may last several minutes)\n",
"Training complete.\n",
"===========Evaluation============\n",
"Evaluation results:\n",
"RECALL@10 : 0.157929\n",
"RECALL@20 : 0.208824\n",
"NDCG@10 : 0.192254\n",
"NDCG@20 : 0.194117\n"
]
}
],
"source": [
"r\"\"\"\n",
"Code reference: https://recbole.io/docs/developer_guide/customize_models.html\n",
Expand All @@ -420,6 +432,7 @@
"print(\"Data loading complete.\")\n",
"\n",
"print('='* 12 + 'Training' + '=' * 13)\n",
"print(\"(This step may last several minutes)\")\n",
"# model loading and initialization\n",
"model = FPSR(config, train_data.dataset).to(config['device'])\n",
"\n",
Expand All @@ -437,34 +450,30 @@
"print(\"Evaluation results:\")\n",
"for metric, value in test_result.items():\n",
" print('{:10s}: {:.6f}'.format(metric.upper(), value))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "htpZ3NxHYlKP",
"outputId": "6ef4f54e-8e97-4923-cb35-56821f65584f"
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"==========Preprocessing==========\n",
"Configuration loading complete.\n",
"Data loading complete.\n",
"============Training=============\n",
"Training complete.\n",
"===========Evaluation============\n",
"Evaluation results:\n",
"RECALL@10 : 0.157921\n",
"RECALL@20 : 0.208826\n",
"NDCG@10 : 0.192252\n",
"NDCG@20 : 0.194120\n"
]
}
]
}
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "SparseRec",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.0"
},
"vscode": {
"interpreter": {
"hash": "933075f399f88ee3a7bc96289e7bedd6322a6307b0e261e2bc2c90799eef1243"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![RecBole](https://img.shields.io/badge/RecBole-1.1.1-orange)](https://recbole.io/)
[![arXiv](https://img.shields.io/badge/arXiv-2207.05959-red)](https://arxiv.org/abs/2207.05959)
[![License](https://img.shields.io/github/license/Joinn99/FPSR)](https://github.com/Joinn99/FPSR/blob/master/LICENSE.md)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Joinn99/FPSR/blob/torch/FPSR_Demonstration.ipynb)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Joinn99/FPSR/blob/torch/FPSR%20Demonstration.ipynb)

**PyTorch version** (Default) | [**CuPy version**](https://github.com/Joinn99/FPSR/)

Expand Down Expand Up @@ -55,7 +55,7 @@ The script `run.py` is used to reproduced the results presented in paper. Train
python run.py --dataset DATASET_NAME
```
## Google Colab
We also provide Colab notebook version of FPSR, you can click [here](https://colab.research.google.com/github/Joinn99/FPSR/blob/torch/FPSR_Demonstration.ipynb) to open Google Colab, select the runtime type as *GPU*, and run the model.
We also provide Colab notebook version of FPSR, you can click [here](https://colab.research.google.com/github/Joinn99/FPSR/blob/torch/FPSR%20Demonstration.ipynb) to open Google Colab, select the runtime type as *GPU*, and run the model.

## Citation
If you wish, please cite the following paper:
Expand Down

0 comments on commit f726829

Please sign in to comment.