Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Recommenders

Documentation Status

What's New (October 19, 2020)

Microsoft News Recommendation Competition Winners Announced, Leaderboard Reopen!

Congratulations to all participants and winners of the Microsoft News Recommendation Competition! In the last two months, over 200 participants from more than 90 institutions in 19 countries and regions joined the competition and collectively advanced the state of the art of news recommendation.

The competition is based on the recently released MIND dataset, an open, large-scale English news dataset with impression logs. Details of the dataset are available in this ACL paper.

With the competition successfully closed, the leaderboard is now reopen. Want to see if you can grab the top spot? Get familiar with the news recommendation scenario. Then dive into some baselines such as DKN, LSTUR, NAML, NPA and NRMS and start hacking!

See past announcements in NEWS.md.

Introduction

This repository contains examples and best practices for building recommendation systems, provided as Jupyter notebooks. The examples detail our learnings on five key tasks:

  • Prepare Data: Preparing and loading data for each recommender algorithm
  • Model: Building models using various classical and deep learning recommender algorithms such as Alternating Least Squares (ALS) or eXtreme Deep Factorization Machines (xDeepFM).
  • Evaluate: Evaluating algorithms with offline metrics
  • Model Select and Optimize: Tuning and optimizing hyperparameters for recommender models
  • Operationalize: Operationalizing models in a production environment on Azure

Several utilities are provided in reco_utils to support common tasks such as loading datasets in the format expected by different algorithms, evaluating model outputs, and splitting training/test data. Implementations of several state-of-the-art algorithms are included for self-study and customization in your own applications. See the reco_utils documentation.

For a more detailed overview of the repository, please see the documents on the wiki page.

Getting Started

Please see the setup guide for more details on setting up your machine locally, on a data science virtual machine (DSVM) or on Azure Databricks.

To setup on your local machine:

  1. Install Anaconda with Python >= 3.6. Miniconda is a quick way to get started.

  2. Clone the repository

git clone https://github.com/Microsoft/Recommenders
  1. Run the generate conda file script to create a conda environment: (This is for a basic python environment, see SETUP.md for PySpark and GPU environment setup)
cd Recommenders
python tools/generate_conda_file.py
conda env create -f reco_base.yaml 
  1. Activate the conda environment and register it with Jupyter:
conda activate reco_base
python -m ipykernel install --user --name reco_base --display-name "Python (reco)"
  1. Start the Jupyter notebook server
jupyter notebook
  1. Run the SAR Python CPU MovieLens notebook under the 00_quick_start folder. Make sure to change the kernel to "Python (reco)".

NOTE - The Alternating Least Squares (ALS) notebooks require a PySpark environment to run. Please follow the steps in the setup guide to run these notebooks in a PySpark environment. For the deep learning algorithms, it is recommended to use a GPU machine.

Algorithms

The table below lists the recommender algorithms currently available in the repository. Notebooks are linked under the Environment column when different implementations are available.

AlgorithmEnvironmentTypeDescription
Alternating Least Squares (ALS)PySparkCollaborative FilteringMatrix factorization algorithm for explicit or implicit feedback in large datasets, optimized by Spark MLLib for scalability and distributed computing capability
Attentive Asynchronous Singular Value Decomposition (A2SVD)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism
Cornac/Bayesian Personalized Ranking (BPR)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting item ranking with implicit feedback
Convolutional Sequence Embedding Recommendation (Caser)Python CPU / Python GPUCollaborative FilteringAlgorithm based on convolutions that aim to capture both user’s general preferences and sequential patterns
Deep Knowledge-Aware Network (DKN)*Python CPU / Python GPUContent-Based FilteringDeep learning algorithm incorporating a knowledge graph and article embeddings to provide powerful news or article recommendations
Extreme Deep Factorization Machine (xDeepFM)*Python CPU / Python GPUHybridDeep learning based algorithm for implicit and explicit feedback with user/item features
FastAI Embedding Dot Bias (FAST)Python CPU / Python GPUCollaborative FilteringGeneral purpose algorithm with embeddings and biases for users and items
LightFM/Hybrid Matrix FactorizationPython CPUHybridHybrid matrix factorization algorithm for both implicit and explicit feedbacks
LightGBM/Gradient Boosting Tree*Python CPU / PySparkContent-Based FilteringGradient Boosting Tree algorithm for fast training and low memory usage in content-based problems
LightGCNPython CPU / Python GPUCollaborative FilteringDeep learning algorithm which simplifies the design of GCN for predicting implicit feedback
GeoIMCPython CPUHybridMatrix completion algorithm that has into account user and item features using Riemannian conjugate gradients optimization and following a geometric approach.
GRU4RecPython CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using recurrent neural networks
Multinomial VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Neural Recommendation with Long- and Short-term User Representations (LSTUR)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with long- and short-term user interest modeling
Neural Recommendation with Attentive Multi-View Learning (NAML)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with attentive multi-view learning
Neural Collaborative Filtering (NCF)Python CPU / Python GPUCollaborative FilteringDeep learning algorithm with enhanced performance for implicit feedback
Neural Recommendation with Personalized Attention (NPA)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with personalized attention network
Neural Recommendation with Multi-Head Self-Attention (NRMS)*Python CPU / Python GPUContent-Based FilteringNeural recommendation algorithm with multi-head self-attention
Next Item Recommendation (NextItNet)Python CPU / Python GPUCollaborative FilteringAlgorithm based on dilated convolutions and residual network that aims to capture sequential patterns
Restricted Boltzmann Machines (RBM)Python CPU / Python GPUCollaborative FilteringNeural network based algorithm for learning the underlying probability distribution for explicit or implicit feedback
Riemannian Low-rank Matrix Completion (RLRMC)*Python CPUCollaborative FilteringMatrix factorization algorithm using Riemannian conjugate gradients optimization with small memory consumption.
Simple Algorithm for Recommendation (SAR)*Python CPUCollaborative FilteringSimilarity-based algorithm for implicit feedback dataset
Short-term and Long-term preference Integrated Recommender (SLi-Rec)*Python CPU / Python GPUCollaborative FilteringSequential-based algorithm that aims to capture both long and short-term user preferences using attention mechanism, a time-aware controller and a content-aware controller
Standard VAEPython CPU / Python GPUCollaborative FilteringGenerative Model for predicting user/item interactions
Surprise/Singular Value Decomposition (SVD)Python CPUCollaborative FilteringMatrix factorization algorithm for predicting explicit rating feedback in datasets that are not very large
Term Frequency - Inverse Document Frequency (TF-IDF)Python CPUContent-Based FilteringSimple similarity-based algorithm for content-based recommendations with text datasets
Vowpal Wabbit (VW)*Python CPU (online training)Content-Based FilteringFast online learning algorithms, great for scenarios where user features / context are constantly changing
Wide and DeepPython CPU / Python GPUHybridDeep learning algorithm that can memorize feature interactions and generalize user features
xLearn/Factorization Machine (FM) & Field-Aware FM (FFM)Python CPUContent-Based FilteringQuick and memory efficient algorithm to predict labels with user/item features

NOTE: * indicates algorithms invented/contributed by Microsoft.

Independent or incubating algorithms and utilities are candidates for the contrib folder. This will house contributions which may not easily fit into the core repository or need time to refactor or mature the code and add necessary tests.

AlgorithmEnvironmentTypeDescription
SARplus *PySparkCollaborative FilteringOptimized implementation of SAR for Spark

Preliminary Comparison

We provide a benchmark notebook to illustrate how different algorithms could be evaluated and compared. In this notebook, the MovieLens dataset is split into training/test sets at a 75/25 ratio using a stratified split. A recommendation model is trained using each of the collaborative filtering algorithms below. We utilize empirical parameter values reported in literature here. For ranking metrics we use k=10 (top 10 recommended items). We run the comparison on a Standard NC6s_v2 Azure DSVM (6 vCPUs, 112 GB memory and 1 P100 GPU). Spark ALS is run in local standalone mode. In this table we show the results on Movielens 100k, running the algorithms for 15 epochs.

AlgoMAPnDCG@kPrecision@kRecall@kRMSEMAER2Explained Variance
ALS0.0047320.0442390.0484620.0177960.9650380.7530010.2556470.251648
SVD0.0128730.0959300.0911980.0327830.9386810.7426900.2919670.291971
SAR0.1105910.3824610.3307530.1763851.2538051.048484-0.5693630.030474
NCF0.1077200.3961180.3472960.180775N/AN/AN/AN/A
BPR0.1053650.3899480.3498410.181807N/AN/AN/AN/A
FastAI0.0255030.1478660.1303290.0538240.9430840.7443370.2853080.287671

Contributing

This project welcomes contributions and suggestions. Before contributing, please see our contribution guidelines.

Build Status

These tests are the nightly builds, which compute the smoke and integration tests. master is our main branch and staging is our development branch. We use pytest for testing python utilities in reco_utils and papermill for the notebooks. For more information about the testing pipelines, please see the test documentation.

DSVM Build Status

The following tests run on a Windows and Linux DSVM daily. These machines run 24/7.

Build TypeBranchStatusBranchStatus
Linux CPUmasterBuild StatusstagingBuild Status
Linux GPUmasterBuild StatusstagingBuild Status
Linux SparkmasterBuild StatusstagingBuild Status

Related projects

Reference papers

  • A. Argyriou, M. González-Fierro, and L. Zhang, "Microsoft Recommenders: Best Practices for Production-Ready Recommendation Systems", WWW 2020: International World Wide Web Conference Taipei, 2020. Available online: https://dl.acm.org/doi/abs/10.1145/3366424.3382692
  • L. Zhang, T. Wu, X. Xie, A. Argyriou, M. González-Fierro and J. Lian, "Building Production-Ready Recommendation System at Scale", ACM SIGKDD Conference on Knowledge Discovery and Data Mining 2019 (KDD 2019), 2019.
  • S. Graham, J.K. Min, T. Wu, "Microsoft recommenders: tools to accelerate developing recommender systems", RecSys '19: Proceedings of the 13th ACM Conference on Recommender Systems, 2019. Available online: https://dl.acm.org/doi/10.1145/3298689.3346967

About

Best Practices on Recommendation Systems

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages