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.
-
Clone the repository.
git clone https://github.com/NVIDIA/DeepLearningExamples cd DeepLearningExamples/TensorFlow/Recommendation/NCF -
Build the NCF TensorFlow NGC container.
After Docker is correctly set up, you can build the NCF image with:
docker build . -t nvidia_ncf -
Launch the NCF TensorFlow Docker container.
mkdir data docker run --runtime=nvidia -it --rm --ipc=host -v ${PWD}/data:/data nvidia_ncf bashThis will launch the container and mount the
./datadirectory as a volume to the/datadirectory inside the container. Any datasets and experiment results (logs, checkpoints etc.) saved to/datawill be accessible in the./datadirectory on the host. -
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.shml-1m
To download and preprocess the ml-1m dataset, run:
./prepare_dataset.sh ml-1mThis will store the preprocessed training and evaluation data in the
/datadirectory, so that it can be later used to train the model (by passing the appropriate--dataargument to thencf.pyscript). -
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-dirargument. By default, this will be in the/data/checkpoints/directory. -
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.ckptNote: TensorFlow checkpoints consist of three files each with a
*.ckptprefix.