In the link below there's an implementation of a model based recommender system using LightFM library.
The recsys uses matrix factorization tecnique and SGD learning for computing gradient descent.
There's also a comparison between two widely used loss functions BPR and WARP that are included in LightFM.
https://colab.research.google.com/drive/1svcFAjSoNsw_7NSwrYaYihM0udEquGjC?usp=sharing