Transformers4Rec Example Notebooks

We have collection of example Jupyter notebooks using different datasets to demonstrate how to use Transformers4Rec with PyTorch and TensorFlow APIs. Each example notebook provides incremental information about Transformers4Rec features and modules.

Inventory

Getting started - Session-based recommendation with Synthetic Data

This example notebook is focusing primarily on the basic concepts of Transformers4Rec, which includes:

  • Generating synthetic data of user interactions

  • Preprocessing sequential data with NVTabular on GPU

  • Using the NVTabular dataloader with Pytorch

  • Training a session-based recommendation model with a Transformer architecture (XLNET)

End-to-end session-based recommendation

This end-to-end example notebook is focuses on:

  • Preprocessing the Yoochoose e-commerce dataset

  • Generating session features with on GPU

  • Using the NVTabular dataloader with the Pytorch

  • Training a session-based recommendation model with a Transformer architecture (XLNET)

  • Exporting the preprocessing workflow and trained model to Triton Inference Server (TIS)

  • Sending request to TIS and generating next-item predictions for each session

Tutorial - End-to-End Session-Based Recommendation on GPU

This tutorial was presented at the ACM RecSys 2021. It covers the following topics:

  • The main concepts for session-based recommendation

  • Implementation of preprocessing and feature engineering techniques for session-based recommendation model with NVTabular on GPU

  • How to build, train and evaluate a session-based recommendation models based on RNN and Transformer architectures with Transformers4Rec library

  • How to deploy a session-based recommendation pipeline (preprocessing workflow and trained model) to the Triton Inference Server

Transformers4Rec paper experiments reproducibility

This example contains scripts to reproduce the experiments reported in the Transformers4Rec paper at RecSys 2021. The experiments focused in the session-based recommendation using incremental training and evaluation over time on two e-commerce and two news datasets.

Running the Example Notebooks

You can run the examples with Docker containers. Docker containers are available from the NVIDIA GPU Cloud. Access the catalog of containers at http://ngc.nvidia.com/catalog/containers.

Depending on which example you want to run, you should use any one of these Docker containers:

  • Merlin-Tensorflow-Training (contains Merlin Core, Merlin Models, Merlin Systems, NVTabular and TensorFlow)

  • Merlin-PyTorch-Training (contains Merlin Core, Merlin Models, Merlin Systems, NVTabular and PyTorch)

  • Merlin-Inference (contains Merlin Core, Merlin Models, Merlin Systems, NVTabular, TensorFlow, PyTorch, HugeCTR and Triton Inference Server)

To run the example notebooks using Docker containers, perform the following steps:

  1. If you haven’t already created a Docker volume to share models and datasets between containers, create the volume by running the following command:

    docker volume create merlin-examples
    
  2. Pull and start the container by running the following command:

    docker run --gpus all --rm -it \
      -p 8888:8888 -p 8797:8787 -p 8796:8786 --ipc=host \
      -v merlin-examples:/workspace/data \
      <docker container> /bin/bash
    

    The container opens a shell when the run command execution is completed. Your shell prompt should look similar to the following example:

    root@2efa5b50b909:
    
  3. Install JupyterLab with pip by running the following command:

    pip install jupyterlab
    

    For more information, see the JupyterLab Installation Guide.

  4. Start the JupyterLab server by running the following command:

    jupyter-lab --allow-root --ip='0.0.0.0'
    

    View the messages in your terminal to identify the URL for JupyterLab. The messages in your terminal show similar lines to the following example:

    Or copy and paste one of these URLs:
    http://2efa5b50b909:8888/lab?token=9b537d1fda9e4e9cadc673ba2a472e247deee69a6229ff8d
    or http://127.0.0.1:8888/lab?token=9b537d1fda9e4e9cadc673ba2a472e247deee69a6229ff8d
    
  5. Open a browser and use the 127.0.0.1 URL provided in the messages by JupyterLab.

  6. After you log in to JupyterLab, navigate to the /transformers4rec/examples directory to try out the example notebooks.