1 前言
读过 TensorFlow推荐系统(一)的朋友们应该还有印象,上回我们介绍的模型是信息检索(retrieval),而在推荐系统中还有另一个任务模型,即为信息排序(ranking)。在排序阶段,其主要任务是对检索模型产出的条目进行调整以选择最有可能被用户喜欢和选择的电影条目。
今天,我们将详细介绍一下排序模型的原理和调用实例。
2 源码解析
-
数据准备,获取数据并拆分数据集。
-
搭建排序模型。
-
拟合并评估模型。
2.1 数据准备
import os
import pprint
import tempfile
from typing import Dict, Text
import numpy as np
import tensorflow as tf
## TensorFlow Dataset Resource
import tensorflow_datasets as tfds
## TensorFlow 推荐系统
import tensorflow_recommenders as tfrs
从TensorFlow Dataset中引入和信息检索模型相同的movielens电影数据集,并只保留以下三个变量:
ratings = tfds.load("movielens/100k-ratings", split="train")
ratings = ratings.map(lambda x: {
"movie_title": x["movie_title"],
"user_id": x["user_id"],
"user_rating": x["user_rating"]
})
随机打乱数据,并取80%为训练数据集,其余的20%为测试数据集:
tf.random.set_seed(42)
shuffled = ratings.shuffle(100_000, seed=42, reshuffle_each_iteration=False)
train = shuffled.take(80_000)
test = shuffled.skip(80_000).take(20_000)

本文深入解析TensorFlow推荐系统的排序模型,包括数据准备、模型搭建和模型评估。通过词嵌入和全连接层构建模型,以用户喜好为依据对电影进行排名。
最低0.47元/天 解锁文章
6206

被折叠的 条评论
为什么被折叠?



