Recommendation systems

From food ordering to video on demand and audio streaming to fashion, recommendation systems power some of the most popular applications today. Explore how you can build production-ready recommendation systems with open source libraries and tools from the TensorFlow ecosystem.

Recommendation systems increase user engagement within your app and elevate user experience by providing the most desirable content. Modern recommenders are complex systems that are often broken down into multiple stages to achieve low latency in production. Through the retrieval, ranking, and potentially post-ranking stages, irrelevant items are gradually filtered out from a large pool of candidates and a list of options that users are the most likely to interact with are finally presented.

Start building with TensorFlow Recommenders, an easy-to-use framework that facilitates the full workflow of building a recommender system from data preparation to deployment.

When you've finished training your models, deploy them into production to serve recommendations to end users. TensorFlow Serving productionizes your models for high performance inference. It aims to maximize the throughput of machine learning models and can support large recommendation models that require distributed serving.

# Deploy the retrieval model with TensorFlow Serving
docker run -t --rm -p 8501:8501 \
  -v "RETRIEVAL/MODEL/PATH:/models/retrieval" \
  -e MODEL_NAME=retrieval tensorflow/serving &

# Retrieve top movies that user 42 may like
curl -X POST -H "Content-Type: application/json" \
  -d '{"instances":["42"]}'  \
  http://localhost:8501/v1/models/retrieval:predict

# Output
# {
#    "predictions":[
#       {
#          "output_1": [2.032, 1.969, 1.813],
#          "output_2": ["movie1”, “movie2”, “movie3”]
#       }
#    ]
# }

# Deploy the ranking model with TensorFlow Serving
docker run -t --rm -p 8501:8501 \
  -v "RANKING/MODEL/PATH:/models/ranking" \
  -e MODEL_NAME=ranking tensorflow/serving &

# Get the prediction score for user 42 and movie 3
curl -X POST -H "Content-Type: application/json" \
  -d '{"instances":[{"user_id":"42", "movie_title":"movie3"}]}' \
  http://localhost:8501/v1/models/ranking:predict

# Output:
# {"predictions": [[3.66357923]]}
code_blocks
Learn how to build and deploy a full stack recommendation system with TensorFlow

Improve the retrieval and ranking stages of recommendation engines

Large-scale recommendation systems require the most relevant items to be determined from millions of candidates through the retrieval and ranking stages in an effective and efficient manner. Complement TensorFlow Recommenders with state-of-the-art Approximate Nearest Neighbor (ANN) search algorithms and learning-to-rank (LTR) techniques to improve recommendations.

Google ScaNN

ScaNN is a library for vector similarity search at scale. It leverages state-of-the-art ANN techniques, such as asymmetric hashing and anisotropic quantization, to accelerate retrieval of top candidates.

TensorFlow Ranking

TensorFlow Ranking is a library for developing scalable, neural LTR models. It provides additional functionalities to rank candidate items to maximize the ranking utilities.

Optimize large embeddings for model training and inference

The embedding lookup operation is a critical component for large-scale recommendation systems. Leverage hardware acceleration and dynamic embedding technology to overcome performance bottlenecks common in large embedding tables.

TensorFlow TPUEmbedding

The TPUEmbedding layer API facilitates training and serving large embedding tables on Tensor Processing Units (TPUs).

TensorFlow Recommenders Addons

TensorFlow Recommenders Addons is a community-contributed project that leverages dynamic embedding technology that is particularly useful for online learning.

Preserve user privacy

Traditional recommendation engines rely on collecting user interaction logs and training recommendation models based on raw user activities. Ensure that user data remains private by incorporating Responsible AI development practices.

TensorFlow Lite on-device recommendation

TensorFlow Lite provides an on-device recommendation solution that achieves low-latency and high-quality recommendations, while keeping all user data on the mobile devices.

Federated Reconstruction with TensorFlow Federated

TensorFlow Federated is a framework for federated learning and other computations on decentralized data. Federated Reconstruction brings matrix factorization to the federated learning setting and better protects user privacy for recommendations.

Use advanced techniques for more sophisticated recommenders

While classical collaborative filtering models are widely used in the industry, there is a growing trend to adopt advanced techniques, such as reinforcement learning and Graph Neural Networks (GNNs), to build recommendation systems.

TensorFlow Agents Bandits

TensorFlow Agents Bandits is a comprehensive library of bandit algorithms that can explore and exploit effectively in the recommendation engine setting.

TensorFlow GNN

TensorFlow GNN is a library that can efficiently facilitate item recommendations based on network structures and be used in conjunction with retrieval and ranking models.

Generative AI

Learn how to use large language models (LLMs) like the PaLM API to augment your recommendation systems.

Reference state-of-the-art recommendation models

To benchmark performance for a well-known model or build your own recommendation models, check out official TensorFlow implementations of popular models – such as NCF, DLRM, and DCN v2 – for best practices.

Educational resources

Learn more about building recommendation systems by following step-by-step courses and videos.

Real-world recommendation systems

Explore examples and case studies of recommendation systems powering applications in every industry.

Online video

Learn how YouTube builds their powerful recommendation system in a responsible manner.

Ecommerce

Read about how Digitec Galaxus trains and serves millions of personalized newsletters per week with TFX and TensorFlow Agents.

Grocery

Learn how HarperDB uses TensorFlow Recommenders and TensorFlow.js to build a collaborative-filtering-based recommendation system for grocery store items.

Audio streaming

Learn how Spotify leveraged the TensorFlow ecosystem to design an extendable offline simulator and train RL Agents to generate playlist recommendations.