How to Train Deep AutoEncoders for Collaborative Filtering

Dec 23, 2022 | Data Science

Welcome to the fascinating world of collaborative filtering using Deep AutoEncoders! This research-driven approach helps in building recommendations systems that can suggest the next best item to a user based on previous interactions. In this blog post, we’ll guide you step by step on how to set up and run your very own Deep AutoEncoder recommendation system using Python, PyTorch, and data from the Netflix prize dataset.

Requirements

Before diving in, ensure you have the following at hand:

  • Python 3.6
  • Pytorch: Install using pipenv
  • CUDA (Recommended version = 8.0)

The Model

The core of this project is based on Deep AutoEncoders. Think of an AutoEncoder like a talented artist who learns to reconstruct a lost photograph. The artist analyzes what remains, gathers insights about textures and patterns, and creatively fills in the missing pieces to produce a beautiful reconstruction. Similarly, the AutoEncoder learns from available user data to predict and fill in gaps in user preferences.

AutoEncoder Structure

Getting Started

Run Unit Tests First

It’s crucial to run unit tests to ensure that everything is working correctly right from the outset. The code is designed to operate on a GPU, and the last test might take a little while to complete.

$ python -m unittest testdata_layer_tests.py
$ python -m unittest testtest_model.py

Tutorial

For an in-depth understanding of recommendation systems, check out this tutorial by miguelgfierro.

Get the Data

It’s time to gather data for training our model. Be sure to run these commands inside your DeepRecommender folder:

  • Download the Netflix prize dataset from here.
  • Fetch the dataset using this link and place it in your DeepRecommender folder:
  • $ tar -xvf nf_prize_dataset.tar.gz
    $ tar -xf downloadtraining_set.tar
    $ python .data_utils/netflix_data_convert.py training_set Netflix

Data Stats

Here is a snapshot of what the dataset looks like:

Dataset Netflix 3 months Netflix 6 months Netflix 1 year Netflix full
Ratings train 13,675,402 29,179,009 41,451,832 98,074,901
Users train 311,315 390,795 345,855 477,412
Items train 17,736 17,757 16,907 17,768
Time range train 2005-09-01 to 2005-11-31 2005-06-01 to 2005-11-31 2004-06-01 to 2005-05-31 1999-12-01 to 2005-11-31

Train the Model

In the example presented, the model will be trained over 12 epochs. To execute this, use the following command:

$ python run.py --gpu_ids 0 --path_to_train_data Netflix/NF_TRAIN --path_to_eval_data Netflix/NF_VALID --hidden_layers 512,512,1024 --non_linearity_type selu --batch_size 128 --logdir model_save --drop_prob 0.8 --optimizer momentum --lr 0.005 --weight_decay 0 --aug_step 1 --noise_prob 0 --num_epochs 12 --summary_frequency 1000

You can run Tensorboard simultaneously to visualize progress:

$ tensorboard --logdir=model_save

Run Inference on the Test Set

After training, it’s time to evaluate model performance on a test set:

$ python infer.py --path_to_train_data Netflix/NF_TRAIN --path_to_eval_data Netflix/NF_TEST --hidden_layers 512,512,1024 --non_linearity_type selu --save_path model_save/model.epoch_11 --drop_prob 0.8 --predictions_path preds.txt

Compute Test RMSE

Lastly, to compute the Root Mean Square Error (RMSE) of your predictions:

$ python compute_RMSE.py --path_to_predictions=preds.txt

After 12 epochs, aim for an RMSE around 0.927; training longer could help achieve below 0.92.

Results

It is possible to achieve various RMSE results based on the dataset used. Here are some example outcomes:

DataSet RMSE Model Architecture
Netflix 3 months 0.9373 n,128,256,256,dp(0.65),256,128,n
Netflix 6 months 0.9207 n,256,256,512,dp(0.8),256,256,n
Netflix 1 year 0.9225 n,256,256,512,dp(0.8),256,256,n
Netflix full 0.9099 n,512,512,1024,dp(0.8),512,512,n

Troubleshooting

Should you encounter any issues throughout this journey, consider the following troubleshooting tips:

  • Check if you have the correct versions of Python, PyTorch, and CUDA installed.
  • Ensure your GPU is compatible and configured correctly for CUDA usage.
  • Verify all command inputs for accuracy when running scripts.
  • Refer to the log files to identify any errors during model training or inference.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox