NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
NCF for TensorFlow1
Resource
NVIDIA Deep Learning Examples
NVIDIA Deep Learning Examples
NCF for TensorFlow1

The NCF model focuses on providing recommendations. This is a modified implementation with improved overfitting and better accuracy.

To train your model using mixed or TF32 precision with Tensor Cores or using FP32, perform the following steps using the default parameters of the NCF model on the ml-20m dataset.

  1. Clone the repository.

    git clone https://github.com/NVIDIA/DeepLearningExamples
    cd DeepLearningExamples/TensorFlow/Recommendation/NCF
    
  2. Build the NCF TensorFlow NGC container.

    After Docker is correctly set up, you can build the NCF image with:

    docker build . -t nvidia_ncf
    
  3. Launch the NCF TensorFlow Docker container.

    mkdir data
    docker run --runtime=nvidia -it --rm --ipc=host -v ${PWD}/data:/data nvidia_ncf bash
    

    This will launch the container and mount the ./data directory as a volume to the /data directory inside the container. Any datasets and experiment results (logs, checkpoints etc.) saved to /data will be accessible in the ./data directory on the host.

  4. Download and preprocess the dataset.

    ml-20m

    Preprocessing consists of downloading the data, filtering out users that have less than 20 ratings (by default), sorting the data and dropping the duplicates. No data augmentation techniques are used in the preprocessing stage.

    To download and preprocess the ml-20m dataset, run:

    ./prepare_dataset.sh
    

    ml-1m

    To download and preprocess the ml-1m dataset, run:

    ./prepare_dataset.sh ml-1m
    

    This will store the preprocessed training and evaluation data in the /data directory, so that it can be later used to train the model (by passing the appropriate --data argument to the ncf.py script).

  5. Start the training.

    After the Docker container is launched, the training with the default hyper-parameters can be started with:

    mpirun -np 4 --allow-run-as-root python ncf.py --amp --data /data/cache/ml-20m --checkpoint-dir /data/checkpoints/
    

    After the training is complete, the model parameters that provide the best evaluation accuracy are saved to the directory passed to the --checkpoint-dir argument. By default, this will be in the /data/checkpoints/ directory.

  6. Perform a validation/evaluation.

    To run evaluation on a specific checkpoint, simply run the following command:

    python ncf.py --data /data/cache/ml-20m --mode test --load-checkpoint-path /data/checkpoints/model.ckpt
    

    Note: TensorFlow checkpoints consist of three files each with a *.ckpt prefix.