# Recommendation systems | TensorFlow

# 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](https://blog.tensorflow.org/2020/11/tensorflow-recommenders-scalable-retrieval-feature-interaction-modelling.html),
an easy-to-use framework that facilitates the full workflow of building a recommender system from data preparation to deployment.
[Get started with TensorFlow Recommenders](https://www.tensorflow.org/recommenders) 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.
[Get started with TensorFlow Serving](https://www.tensorflow.org/tfx/guide/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](https://codelabs.developers.google.com/tfrecommenders-flutter)

### 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](https://github.com/google-research/google-research/tree/master/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.
[GitHub](https://github.com/google-research/google-research/tree/master/scann) [Blog Post](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) [Tutorial](https://www.tensorflow.org/recommenders/examples/efficient_serving) [TensorFlow Ranking](https://github.com/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.
[GitHub](https://github.com/tensorflow/ranking) [Blog Post](https://ai.googleblog.com/2018/12/tf-ranking-scalable-tensorflow-library.html) [Tutorial](https://www.tensorflow.org/recommenders/examples/listwise_ranking)

### 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](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/embedding/TPUEmbedding) The TPUEmbedding layer API facilitates training and serving large embedding tables on Tensor Processing Units (TPUs).
[Doc](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/embedding/TPUEmbedding) [Blog Post](https://cloud.google.com/blog/topics/developers-practitioners/building-large-scale-recommenders-using-cloud-tpus) [TensorFlow Recommenders Addons](https://github.com/tensorflow/recommenders-addons) TensorFlow Recommenders Addons is a community-contributed project that leverages dynamic embedding technology that is particularly useful for online learning.
[GitHub](https://github.com/tensorflow/recommenders-addons)

### 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](https://www.tensorflow.org/responsible_ai) development practices.
[TensorFlow Lite on-device recommendation](https://ai.google.dev/edge/lite/examples/recommendation/overview) 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.
[Doc](https://ai.google.dev/edge/lite/examples/recommendation/overview) [Blog Post](https://blog.tensorflow.org/2020/09/introduction-to-tflite-on-device-recommendation.html) [Federated Reconstruction with TensorFlow Federated](https://www.tensorflow.org/federated/tutorials/federated_reconstruction_for_matrix_factorization) 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.
[Tutorial](https://www.tensorflow.org/federated/tutorials/federated_reconstruction_for_matrix_factorization) [Blog Post](https://ai.googleblog.com/2021/12/a-scalable-approach-for-partially-local.html)

### 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](https://github.com/tensorflow/agents/tree/master/tf_agents/bandits) TensorFlow Agents Bandits is a comprehensive library of bandit algorithms that can explore and exploit effectively in the recommendation engine setting.
[GitHub](https://github.com/tensorflow/agents/tree/master/tf_agents/bandits) [Blog Post](https://blog.tensorflow.org/2021/07/using-tensorflow-agents-bandits-library-for-recommendations.html) [TensorFlow GNN](https://github.com/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.
[GitHub](https://github.com/tensorflow/gnn) [Blog Post](https://blog.tensorflow.org/2021/11/introducing-tensorflow-gnn.html) [Generative AI](https://blog.tensorflow.org/2023/04/training-recommendation-model-with-dynamic-embeddings.html) Learn how to use large language models (LLMs) like the PaLM API to augment your recommendation systems.
[Blog Post](https://blog.tensorflow.org/2023/04/training-recommendation-model-with-dynamic-embeddings.html) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/bg-diagram.png)

### 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.
[Visit TensorFlow Model Garden](https://github.com/tensorflow/models/tree/master/official#recommendation)

### Educational resources

Learn more about building recommendation systems by following step-by-step courses and videos.
![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/google-developers-recsys.jpeg) Course [Intro to recommendation systems](https://developers.google.com/machine-learning/recommendation) [Explore the course](https://developers.google.com/machine-learning/recommendation) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/tf-youtube-series.jpg) Video Series [Building recommendation systems with TensorFlow](https://www.youtube.com/watch?v=BthUPVwA59s&list=PLQY2H8rRoyvy2MiyUBz5RWZr5MPFkV3qz&index=1) [Watch the videos](https://www.youtube.com/watch?v=BthUPVwA59s&list=PLQY2H8rRoyvy2MiyUBz5RWZr5MPFkV3qz&index=1) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/building-a-fullstack-recsys.jpg) Codelab [Building a full stack recommendation system](https://codelabs.developers.google.com/tfrecommenders-flutter) [Try the codelab](https://codelabs.developers.google.com/tfrecommenders-flutter) ![](https://www.tensorflow.org/static/site-assets/images/marketing/home/home-join-header.png)

### Real-world recommendation systems

Explore examples and case studies of recommendation systems powering applications in every industry.
![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/recsys-video-app.png) [Online video](https://blog.youtube/inside-youtube/on-youtubes-recommendation-system/) Learn how YouTube builds their powerful recommendation system in a responsible manner.
[Read the blog](https://blog.youtube/inside-youtube/on-youtubes-recommendation-system/) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/recsys-digitac-galaxus.gif) [Ecommerce](https://blog.tensorflow.org/2021/08/how-digitec-galaxus-trains-and-serves-millions-of-personalized-newsletters-per-week-with-TFX.html) Read about how Digitec Galaxus trains and serves millions of personalized newsletters per week with TFX and TensorFlow Agents.
[Read the blog](https://blog.tensorflow.org/2021/08/how-digitec-galaxus-trains-and-serves-millions-of-personalized-newsletters-per-week-with-TFX.html) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/recsys-harperdb-tensorflow-js.jpeg) [Grocery](https://www.youtube.com/watch?v=JQksipdQiGI) Learn how HarperDB uses TensorFlow Recommenders and TensorFlow.js to build a collaborative-filtering-based recommendation system for grocery store items.
[View the video](https://www.youtube.com/watch?v=JQksipdQiGI) ![](https://www.tensorflow.org/static/site-assets/images/marketing/resources/recommendation-systems/spotify-tensorflow-agents-recommendations.png) [Audio streaming](https://blog.tensorflow.org/2023/10/simulated-spotify-listening-experiences-reinforcement-learning-tensorflow-tf-agents.html) Learn how Spotify leveraged the TensorFlow ecosystem to design an extendable offline simulator and train RL Agents to generate playlist recommendations.
[Read the blog](https://blog.tensorflow.org/2023/10/simulated-spotify-listening-experiences-reinforcement-learning-tensorflow-tf-agents.html)

## Start building with TensorFlow

[Install TensorFlow](https://www.tensorflow.org/install) [Explore the ecosystem](https://www.tensorflow.org/learn)