推荐系统

从订餐到视频点播和音频在线播放,再到时尚内容, 推荐系统可为当今一些极受欢迎的应用提供助力。探索如何利用 TensorFlow 生态系统中的开源库和工具 构建可用于生产环境的推荐系统。

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.

完成模型训练后,您可以将模型部署到生产环境中,以向最终用户提供推荐内容。TensorFlow 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
了解如何使用 TensorFlow 构建和部署全栈推荐系统

改进推荐引擎的检索和排序阶段

大型推荐系统需要通过检索和排序阶段,以有效且高效的方式从数百万个候选项中确定最相关的推荐项。您可以使用 ScaNN 库中先进的近似最邻近 (ANN) 搜索算法和 TensorFlow Ranking 库中的排序学习 (LTR) 技术对 TensorFlow Recommenders 进行补充,提升推荐内容的契合度。

Google ScaNN

ScaNN 是一个用于进行大规模向量相似度搜索的库。该库利用先进的 ANN 技术(例如非对称哈希处理和各向异性量化)来加速检索热门候选项。

TensorFlow Ranking

TensorFlow Ranking 是一个用于开发可扩容的神经 LTR 模型的库。该库提供了额外的功能来对候选推荐项进行排序,以便最大限度发挥排序实用程序的效用。

优化大型嵌入以进行模型训练和推断

嵌入查询操作是大型推荐系统的关键组成部分。利用硬件加速和动态嵌入技术,克服大型嵌入表中常见的性能瓶颈。

TensorFlow TPUEmbedding

TPUEmbedding 层 API 有助于在张量处理单元 (TPU) 中训练和应用大型嵌入表。

TensorFlow Recommenders 插件

TensorFlow Recommenders 插件是一个由社区贡献的项目,利用了对在线学习特别有用的动态嵌入技术。

保护用户隐私

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 设备端推荐

TensorFlow Lite 提供了一种设备端推荐解决方案,可实现低延迟、高质量的推荐,同时将所有用户数据保存在移动设备上。

Federated Reconstruction 与 TensorFlow Federated

TensorFlow Federated 是一个可用于对分散式数据进行联邦学习和其他计算的框架。Federated Reconstruction 可将矩阵分解引入联邦学习设置,并且能够在推荐时更好地保护用户隐私。

为更复杂的 Recommender 采用先进的技术

虽然传统的协同过滤模型在业界得到广泛运用,但采用强化学习和图神经网络 (GNN) 等先进技术来构建推荐系统这一趋势日益明显。

TensorFlow Agents Bandits

TensorFlow Agents Bandits 是一个全面综合的老虎机算法库,可在推荐引擎设置中有效地进行探索和利用。

TensorFlow GNN

TensorFlow GNN 是一个库,不仅可基于网络结构高效协调项目推荐,还可与检索和排序模型结合使用。

参考先进的推荐模型

如需对知名模型进行性能基准测试或自行构建推荐模型,请参阅热门模型(例如 NCF、DLRM 和 DCN v2)的官方 TensorFlow 实现,以遵循最佳实践。

教育资源

跟随分步讲解的课程和视频,进一步了解如何构建推荐系统。

实际推荐系统

推荐系统可为各行各业中的应用提供助力,欢迎探索相关示例和案例研究。

在线视频

了解 YouTube 如何以负责的方式自行构建功能强大的推荐系统。

电子商务

了解 Digitec Galaxus 如何使用 TFX 和 TensorFlow Agents 训练模型,每周推送数百万份个性化简报。

杂货店

了解 HarperDB 如何使用 TensorFlow.js 针对杂货店商品构建基于协同过滤的推荐系统。