Wujia / Haibo Wu

Blog 文章

What YouTube’s RL Papers Teach Recommender-System Builders 增强学习在推荐系统有什么最新进展?

A recommender-systems reading of YouTube’s RL work: long-term reward, off-policy correction, slate recommendation, and engineering constraints.

用 YouTube 推荐系统里的强化学习论文,讨论长期收益、离线策略校正、slate 推荐和推荐系统工程约束。

English edition adapted for native English readers; Chinese text follows the original Zhihu source. 英文版按英文读者习惯重写整理,中文版保留知乎原文。

Around that time, people in the industry started circulating the claim that YouTube had successfully applied reinforcement learning to recommendation and had achieved one of its most significant online gains in years. Two papers were especially worth reading: Top-K Off-Policy Correction for a REINFORCE Recommender System and Reinforcement Learning for Slate-based Recommender Systems.

YouTube reinforcement learning recommender paper diagram
One of the paper diagrams discussed in the original Zhihu answer.

Why recommendation is tempting for RL

A recommendation system is not just trying to predict the next click. It is shaping a sequence of user experiences. A short-term click may reduce long-term satisfaction; repeated similar content may raise immediate engagement while damaging exploration; and the value of one item often depends on what else appears around it. These are exactly the kinds of problems that make reinforcement learning attractive.

Reinforcement learning recommender-system challenge slide
Challenges of applying reinforcement learning to recommender systems.

But recommendation is also a hard RL environment. The action space is enormous, the reward is delayed and noisy, online exploration is expensive, and most teams only have logs generated by an old behavior policy. You cannot simply take a textbook RL algorithm and plug it into a production recommender.

Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 1 from the original answer.
Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 2 from the original answer.
Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 3 from the original answer.
Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 4 from the original answer.
Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 5 from the original answer.
Off-policy correction formula from the YouTube RL recommender paper
Off-policy correction figure 6 from the original answer.

The off-policy problem

YouTube’s Top-K off-policy correction work starts from a practical constraint: the training data was collected by an existing system, not by the policy you now want to learn. If you optimize REINFORCE directly on those logs, you will bias the model toward what the old system chose to expose. The paper’s core contribution is a correction method that makes this logged data more usable for learning a new ranking policy.

For a production team, the lesson is straightforward: before discussing RL, first ask how the logs were generated, what the exposure policy was, and whether your reward can be trusted. Most “RL for recommendation” failures begin before the model is trained.

The slate problem

The second paper looks at slate recommendation. In a real product, the user does not see one isolated item; the user sees a list. The value of the slate is not the sum of independent item values. Items interact with one another through position, substitution, diversity, and user attention.

The paper proposes a tractable way to reason about slate-level reward without enumerating the impossible number of all possible slates. That is important because the combinatorial action space is one of the main reasons recommender-system RL looks elegant in theory and painful in practice.

Slate recommendation formula from the YouTube RL recommender paper
Slate recommendation figure 1 from the original answer.
Slate recommendation formula from the YouTube RL recommender paper
Slate recommendation figure 2 from the original answer.
Slate recommendation formula from the YouTube RL recommender paper
Slate recommendation figure 3 from the original answer.

What I take from it

The practical path is not to worship the word “RL”. It is to identify where a recommender is being hurt by short-term objectives, where sequence effects matter, and where logged feedback can support a safer learning loop. Sometimes that means reinforcement learning; sometimes it means bandits, better counterfactual evaluation, better reward design, or simply a more honest offline experiment.

For most teams, the hard work is still engineering and product definition: define the reward, log exposure correctly, build offline evaluation, control exploration risk, and make sure the model can actually run inside the serving system.

前阵子正好写了一篇专栏分析google在youtube应用强化的两篇论文:

吴海波:以youtube的RL论文学习如何在推荐场景应用RL
284 赞同 · 14 评论 文章

正文如下:

2个月前,业界开始流传youtube成功将RL应用在了推荐场景,并且演讲者在视频(https://www.youtube.com/watch?v=HEqQ2_1XRTs)中说是youtube近几年来取得的最显著的线上收益。

放出了两篇论文:Top-K Off-Policy Correction for a REINFORCE Recommender System和Reinforcement Learning for Slate-based Recommender Systems: A Tractable Decomposition and Practical Methodology。本文不想做论文讲解,已经有同学做的不错了:http://wd1900.github.io/2019/06/23/Top-K-Off-Policy-Correction-for-a-REINFORCE-Recommender-System-on-Youtube/

YouTube 强化学习推荐论文示意图
原回答中讨论的 YouTube 强化学习推荐论文示意图。

个人建议两篇论文都仔细读读,TopK的篇幅较短,重点突出,比较容易理解,但细节上SlateQ这篇更多,对比着看更容易理解。而且,特别有意思的是,这两篇论文都说有效果,但是用的方法却不同,一个是off-policy,一个是value-base,用on-policy。很像大公司要做,把主流的几种路线让不同的组都做一遍,谁效果好谁上。个人更喜欢第二篇一些,会有更多的公式细节和工程实践的方案。

很多做个性化推荐的同学,并没有很多强化学习的背景,而RL又是一门体系繁杂的学科,和推荐中常用的supervised learning有一些区别,入门相对会困难一些。本文将尝试根据这两篇有工业界背景的论文,来解答下RL在推荐场景解决什么问题,又会遇到什么困难,我们入门需要学习一些哪些相关的知识点。本文针对有一定机器学习背景,但对RL领域并不熟悉的童鞋。

本文的重点如下:

目前推荐的问题是什么
RL在推荐场景的挑战及解决方案
常见的套路是哪些
推荐系统目前的问题

目前主流的个性化推荐技术的问题,突出的大概有以下几点:

优化的目标都是short term reward,比如点击率、观看时长,很难对long term reward建模。
最主要的是预测用户的兴趣,但模型都是基于logged feedback训练,样本和特征极度稀疏,大量的物料没有充分展示过,同时还是有大量的新物料和新用户涌入,存在大量的bias。另外,用户的兴趣变化剧烈,行为多样性,存在很多Noise。
pigeon-hole:在短期目标下,容易不停的给用户推荐已有的偏好。在另一面,当新用户或者无行为用户来的时候,会更倾向于用大爆款去承接。
RL应用在推荐的挑战

看slide

RL 在推荐场景中的挑战。
RL 在推荐场景中的挑战。

extremely large action space:many millions of items to recommend.如果要考虑真实场景是给用户看一屏的物料,则更夸张,是一个排列组合问题。
由于是动态环境,无法确认给用户看一个没有看过的物料,用户的反馈会是什么,所以无法有效模拟,训练难度增加。
本质上都要预估user latent state,但存在大量的unobersever样本和noise,预估很困难,这个问题在RL和其他场景中共存。
long term reward难以建模,且long/short term reward。tradeoff due to user state estimate error。
旅程开始

熟悉一个新领域,最有效率的做法是和熟悉的领域做结合。接下来,让我们先简单看下RL的基本知识点,然后从label、objective、optimization、evaluation来切入吧。

RL的基本知识

有一些基本的RL知识,我们得先了解一下,首先是场景的四元组结构:

RL最大的特点是和环境的交互,是一种trial-error的过程,通常我们会用MDP来描述整个过程,结合推荐场景,四元组数学定义如下:

• S: a continuous state space describing the user states;
• A: a discrete action space, containing items available for recommendation;
• P : S × A × S → R is the state transition probability;
• R : S × A → R is the reward function, where r(s, a) is the immediate reward obtained by performing action a at user state s;

RL在推荐场景的Label特点

众所周知,RL是典型的需要海量数据的场景,比如著名的AlphaGo采用了左右互博的方式来弥补训练数据不足的问题。但是在推荐场景,用户和系统的交互是动态的,即无法模拟。举个例子,你不知道把一个没有推荐过的商品a给用户,用户会有什么反馈。

老生常谈Bias

好在推荐场景的样本收集成本低,量级比较大,但问题是存在较为严重的Bias。即只有被系统展示过的物料才有反馈,而且,还会有源源不断的新物料和用户加入。很多公司会采用EE的方式去解决,有些童鞋表示EE是天问,这个点不能说错,更多的是太从技术角度考虑问题了。

EE要解决是的生态问题,必然是要和业务形态结合在一起,比如知乎的内容自荐(虽然效果是呵呵的)。这个点估计我们公司是EE应用的很成功的一个了,前阵子居然在供应商口中听到了准确的EE描述,震惊于我们的业务同学平时都和他们聊什么。

off-policy vs on-policy

论文[1]则采取off-policy的方式来缓解。off-policy的特点是,使用了两个policy,一个是用户behavior的β,代表产生用户行为Trajectory:(s0,A0,s1, · · · )的策略,另一个是系统决策的π,代表系统是如何在面对用户a在状态s下选择某个action的。

RL中还有on-policy的方法,和off-policy的区别在于更新Q值的时候是沿用既定策略还是用新策略。更好的解释参考这里:https://www.zhihu.com/question/57159315

importance weight

off-policy的好处是一定程度上带了exploration,但也带来了问题:

In particular, the fact that we collect data with a periodicity of several hours and compute many policy parameter updates before deploying a new version of the policy in production implies that the set of trajectories we employ to estimate the policy gradient is generated by a different policy. Moreover, we learn from batched feedback collected by other recommenders as well, which follow drastically different policies. A naive policy gradient estimator is no longer unbiased as the gradient in Equation (2) requires sampling trajectories from the updated policy πθ while the trajectories we collected were drawn from a combination of historical policies β.

常见的是引入importance weighting来解决。看下公式

Off-policy correction 相关公式。
Off-policy correction 相关公式。

从公式看,和标准的objective比,多了一个因子,因为这个因子是连乘和rnn的问题类似,梯度容易爆炸或消失。论文中用了一个近似解,并有人证明了是ok的。

RL在推荐场景的Objective特点

在前文中,我们提到,现有的推荐技术,大多是在优化短期目标,比如点击率、停留时长等,用户的反馈是实时的。用户的反馈时长越长,越难优化,比如成交gmv就比ctr难。

同时也说明,RL可能在这种场景更有优势。看下objective的形式表达:

可以发现,最大的特点是前面有个累加符号。这也意味着,RL可以支持和用户多轮交互,也可以优化长期目标。这个特点,也是最吸引做个性化推荐的同学,大家想象下自已在使用一些个性化产品的时候,是不是天然就在做多轮交互。

轮到Bellman公式上场了,先看下核心思想:

The value of your starting point is the reward you expect to get from being there, plus the value of wherever you land next.

看下公式,注意它包含了时间,有助于理解。

RL objective 公式。
RL objective 公式。

在论文[2]中,有更多关于bellman在loss中推导的细节。由于论文[1]采用的policy-gradient的优化策略,我们需要得到loss的梯度:

Policy-gradient 梯度公式。
Policy-gradient 梯度公式。

加入importance weighting和一些correction后,

加入 importance weighting 和 correction 后的形式。
加入 importance weighting 和 correction 后的形式。

更多细节可以去参考论文。

optimization和evaluation

通常,RL可以分成两种,value-base和policy-base,虽然不是完全以optimial的角度看,但两种套路的优化方法有较大的区别。其中value-base虽然直观容易理解,但一直被质疑不能稳定的收敛。

they are known to be prone to instability with function approximation。

而policy-base则有较好的收敛性质,所以在很多推荐场景的RL应用,大部分会选择policy-base。当然现在也很有很多二者融合的策略,比如A3C、DDPG这种,也是比较流行的。

怎么训练β和π

π的训练是比较常规的,有意思的是β的学习。用户的behavior是很难建模的,我们还是用nn的方式去学一个出来,这里有一个单独的分支去预估β,和π是一个网络,但是它的梯度不回传,如下图:

β 和 π 的网络结构示意。
β 和 π 的网络结构示意。

这样就不会干扰π。二者的区别如下:

(1) While the main policy πθ is effectively trained using a weighted softmax to take into account of long term reward, the behavior policy head βθ′ is trained using only the state-action pairs;
(2) While the main policy head πθ is trained using only items on the trajectory with non-zero reward 3, the behavior policy βθ′ is trained using all of the items on the trajectory to avoid introducing bias in the β estimate.

为何要把evaluation拿出来讲呢?通常,我们线下看AUC,线上直接看abtest的效果。本来我比较期待论文中关于长期目标的设计,不过论文[1]作者的方式还是比较简单,可借鉴的不多:

论文中的 reward 设计说明。
论文中的 reward 设计说明。

The immediate reward r is designed to reflect different user activities; videos that are recommended but not clicked receive zero reward. The long term reward R is aggregated over a time horizon of 4–10 hours.

论文[2]中没有细讲。

两篇论文中还有很大的篇幅来讲Simulation下的结果,[1]的目的是为了证明作者提出的correction和topK的作用,做解释性分析挺好的,[2]做了下算法对比,并且验证了对user choice model鲁棒,但我觉得对实践帮助不大。

论文中的 simulation 结果示意。
论文中的 simulation 结果示意。

One more thing:TopK在解决什么问题?
listwise的问题

主流的个性化推荐应用,都是一次性给用户看一屏的物料,即给出的是一个列表。而目前主流的个性化技术,以ctr预估为例,主要集中在预估单个物料的ctr,和真实场景有一定的gap。当然,了解过learning to rank的同学,早就听过pointwise、pairwise、listwise,其中listwise就是在解决这个问题。

通常,listwise的loss并不容易优化,复杂度较高。据我所知,真正在实践中应用是不多的。RL在推荐场景,也会遇到相同的问题。但直接做list推荐是不现实的,假设我们一次推荐K个物料,总共有N个物料,那么我们能选择的action就是一个排列组合问题,C_N_K * K!个,当N是百万级时,量级非常夸张。

这种情况下,如果不做些假设,问题基本就没有可能在现实中求解了。

youtube的两篇论文,都将问题从listwise(他们叫slatewise)转化成了itemwise。但这个itemwise和我们常规理解的pointwise的个性化技术还是有区别的。在于这个wise是reward上的表达,同时要引申出user choice model。

user choice model

pointwise的方法只考虑单个item的概率,论文中提出的itemwise,虽然也是认为最后的reward只和每个被选中的item有关,且item直接不互相影响,但它有对user choice做假设。比如论文[2]还做了更详细的假设,将目标函数的优化变成一个多项式内可解的问题:

Slate 推荐中的 user choice 假设。
Slate 推荐中的 user choice 假设。

这两个假设也蛮合理的,SC是指用户一次指选择一个item,RTDS是指reward只和当前选择的item有关。

有不少研究是专门针对user choice model的,一般在经济学中比较多。推荐中常见的有cascade model和mutilnomial logit model,比如cascade model,会认为用户选择某个item的概率是p,那么在一个list下滑的过程中,点击了第j个item的概率是(1-p(i))^j * p(j).

论文[1]中最后的objective中有一个因子,表达了user choice的假设:

Top-K off-policy correction 中的 user choice 因子。
Top-K off-policy correction 中的 user choice 因子。

简单理解就是,用π当做用户每次选择的概率,那上面就是K-1不选择a概率的连乘。而论文[2]中,RL模型和现有的监督模型是融合在一起的,直接用pCTR模型预估的pctr来当这个user choice的概率。

最后

这篇写的有点长,但就算如此,看了本文也很难让大家一下子就熟悉了RL,希望能起到抛砖引玉的作用吧。从实践角度讲,比较可惜的是long term reward的建模、tensorflow在训练大规模RL应用时的问题讲的很少。最后,不知道youtube有没有在mutil-task上深入实践过,论文[2]中也提到它在long term上能做一些事情,和RL的对比是怎么样的。

参考

[1] Top-K Off-Policy Correction for a REINFORCE Recommender System

[2] Reinforcement Learning for Slate-based Recommender Systems: A Tractable Decomposition and Practical Methodology*

[3] https://slideslive.com/38917655/reinforcement-learning-in-recommender-systems-some-challenges

[4] https://zhuanlan.zhihu.com/p/72669137

[5] 强化学习中on-policy 与off-policy有什么区别?https://www.zhihu.com/question/57159315

[6] http://wd1900.github.io/2019/06/23/Top-K-Off-Policy-Correction-for-a-REINFORCE-Recommender-System-on-Youtube/