Skip to content

Introduction

本文摘抄及改编自 A Survey of Reinforcement Learning from Human Feedback ,具体引用与细节请参考原文.

Preliminaries

Reward Shaping1. 稀疏的成功信号不太适合 agent 学习.

Reward Hacking2. 奖励信号对虚假相关性敏感,agent 作出一些行为,他们与真实目标相关而获得奖励,但本身没有价值.

Reward Model. 我们在这里认为,一个 reward model 是关于目标的唯一信息来源. 它具有以下特征:

  • Reward Modeling. 我们使用的方法是:从人类反馈中学习奖励模型,然后使用该模型来训练策略. 在这种分离式的架构下,agent 可以使用有标签的数据训练奖励模型,使用无标签的数据来改善其行为和探索环境.

  • Human Defined. 我们聚焦于那些人类反馈是有关目标的唯一真理的方法. 因此我们排除了 reward shaping, feature engineering, etc.

  • Interactive and Online. 以互动的在线的方式提供反馈. 因此我们排除了 imitation learning, learning from demonstration, pure inverse RL.

  • Scalable and Asynchronous. 人类虽然参与其中,但是 agent 不被人类反馈阻碍,且人类不需要持续在场. 尽管人类可以扮演 oracle 的角色,但是这需要人类提供足够频繁的奖励,因此我们通过训练 reward model 的方式来实现异步性.

Reinforcement Learning. 强化学习可以被看做一个马尔科夫决策过程 MDP \((\mathcal{S}, \mathcal{A}, P, R, d_0, \gamma)\). 其中 \(\mathcal{S}\) 是状态空间,\(\mathcal{A}\) 是动作空间,\(P\) 是转移函数,\(R\) 是奖励函数.(在 RLHF 中,agent 可以向神谕 oracle 发出查询 \(q_i\),并收到标签 \(l_i\),这通常给出有关奖励的提示.)沿某个 trajectory 具有回报

\[R(\tau)=\sum_{h=0}^{H-1}\gamma^h R(s_h, a_h).\]

RL agent 旨在学习一个最大化期望回报的策略 \(J(\pi)=\mathbb{E}_{d_0, P,\pi}[R(\tau)]\). Model-based RL 旨在学习具体的 \(P, R\). Model-free RL 旨在在不学习 MDP 的情况下得到一个好的 policy. 在 deep RL 中,value function 和 policy 都通过神经网络进行近似. Model-free RL 主要有两种方式,value-based 和 policy search.

Value-based Methods. (DQN, etc.) 旨在学习最优策略的 \(Q^*\) 函数. 其中 \(Q\) 函数被称为 action-value function

\[Q_\pi(s_0,a_0)=Q_\pi(s,a)=\mathbb{E}_{P, \pi}\left[\sum_{h=0}^{H-1}\gamma^h R(s_h,a_h)\right].\]

其含义是,在初始状态为 \(s_0\),初始动作为 \(a_0\) 的情况下,采取 \(\pi\) 可以获得的期望回报. 通过贪心地取 \(\pi(s)=\arg \max_a Q(s,a)\) ,就可以得到确定性最优策略 \(\pi^*\) 满足 \(J(\pi^*)=\mathbb{E}_{d_0}[Q^*(s, \pi^*(s))]\). 类似于 action-value function,我们可以定义 state-value function

\[V_{\pi}(s)=\mathbb{E}_{P, \pi}\left[\sum_{h=0}^{H-1} \gamma^h R(s_h, a_h) \mid s_0=s\right].\]

其含义是,从状态 \(s_0\) 开始,始终使用策略 \(\pi\) 可以获得的期望回报. 显然 \(V_\pi(s)= \mathbb{E}_{a\sim \pi(s)} [Q_\pi (s,a)].\)

Policy-based Methods. (PPO, TD3, SAC, etc.) 旨在一个参数化的 policy space 中寻找良好的 policy. 最数据高效的方案是 actor-critic 方案,其中 actor 是 policy,critic 通常是 \(Q\) 函数,它们同时被学习.

On-policy RL vs. Off-policy RL. 前者只使用最近生成的 transition 进行训练,后者不一定使用当前策略生成的 transition 进行训练. 前者更稳定,但是后者通过构建 replay buffer 来重新使用过去的 sample,从而使得学习更高效.

Bradley-Terry Model. 该模型常用于从成对轨迹的比较中学习效用函数. 它规定了人类标注者的概率模型

\[\mathbb{P}(\tau_1\succ\tau_2)=\dfrac{1}{1+\exp(R(\tau_2)-R(\tau_1))}.\]

通过最大似然原则(或者等价地,交叉熵损失),学习这个参数化为 \(\psi\) 的 reward model 就是

\[\max_\psi \prod_{i=1}^N \dfrac{1}{1+\exp(R_\psi(\tau_2^i)-R_\psi(\tau_1^i))}.\]

总的来说,一个 off-policy 的 actor-critic 的 RL 算法形如

\[ { \begin{array}{l} \ \textbf{Generic RLHF Algorithm in an Actor-Critic Scheme} \\ \hline \begin{array}{rl} 1 & \text{Initialize parameters } \theta, \phi,\psi \text{ (policy, critic, reward)} \\ 2 & \text{Initialize replay buffer } \mathcal{B}\text{ with randomly-generated trajectories} \\ 3 & \textbf{for } i = 1,\cdots,N \textbf{ do} \\ 4 & \qquad\text{// Reward Learning} \\ 5 & \qquad\text{Generate queries from } \mathcal{B} \\ 6 & \qquad\text{Update } \mathcal{D} \text{ with answers to queries from the oracle} \\ 7 & \qquad\text{Update } \psi \text{ using } \mathcal{D} \\ 8 & \qquad\text{// RL Training} \\ 9 & \qquad\text{Update } \mathcal{B} \text{ with new trajectories generated with } \pi_\theta \\ 10 & \qquad\text{Update } \theta \text{ (actor) using } \mathcal{B} \text{ and } R_\psi \\ 11 & \qquad\text{Update } \phi \text{ (critic) using } \mathcal{B} \text{ and } R_\psi \\ 12 & \textbf{end for} \\ \end{array} \end{array} } \]

Difficulties in RLHF. RLHF 仍然面临一些问题.

  • Oracle 可能提供各种各样的反馈. 需要识别反馈中提供了什么信息,以及如何利用这些反馈.

  • 查询应当最小化 oracle 所需要的 effort. 这可以通过主动学习技术来实现.

  • RL agent 在一个非平稳的环境中训练(e.g., 奖励逼近器同时更新),因此需要使用 non-vanishing learning rates 等方法.

  • 在奖励函数未知时,如何有意义地评估 agent 的表现

  • 直接从人类收集反馈本身存在挑战,例如反馈的差异性和可靠性.

Feedback

Attibutes of Feedback Types

反馈以不同的形式给出.

  • Arity. 元数. 单一反馈往往面对一致性的挑战,而多元反馈(例如排名)则施加了更高的认知负担.

  • Involvement. 参与. 人类标签员可以被动观察实例、主动生成实例,或共同生成实例. 被动反馈对人类的负担最小,但可能无法提供足够的信息. 我们通常将这两种类型结合起来,首先使用(可能非常次优的)主动反馈初始化奖励模型,然后再使用被动反馈进行精炼.

  • Granularity. 粒度. 细粒度的反馈更易于学习,并简化了 credit assignment 问题,但是对人类来说往往不切实际或乏味.

  • Abstraction. 抽象. 人类反馈是针对原始实例给出还是针对实例的抽象特征给出.

  • Explicitness. 明确性. 人类可以给出显性或是隐性的偏好.

  • Intent. 意图. 人类的意图也会影响反馈. 字面反馈通过行为本身隐含的偏好信号来进行(例如,在某个短视频上停留少于一定时间),而评估性、指导性和描述性反馈则是旨在教授奖励函数. 研究表明3具有教学意图的人的行为可能与具有字面意图的人的行为不同.

Common Classes

下面的表格中是常见的人类反馈的类型. 其中 Primary 指可以单独用于学习奖励模型,Supplementary 指可以与 Primary 结合使用,Representation 指可以在学习奖励模型前用于学习 representation. / 表示任意类型.

\[ \begin{array}{cccccccc} \hline & \textbf{Class} & \textbf{Granularity} & \textbf{Involvement} & \textbf{Arity} & \textbf{Abstr.} & \textbf{Intent} & \textbf{Expl.} \\ \hline & \text{Critique} & / & \text{Observed} & \text{Unary} & / & \text{Evaluative} & \text{Explicit} \\ & \text{Comparisons} & / & \text{Observed} & 2+ & / & \text{Evaluative} & \text{Explicit} \\ & \text{Inter-Temporal} & \text{Segment} & \text{Observed} & \text{Unary} & / & \text{Evaluative} & \text{Explicit} \\ \text{Pri.} & \text{Proxy Rewards} & \text{Episode} & \text{Observed} & / & \text{Feature} & \text{Descriptive} & \text{Explicit} \\ & \text{Social Behavior} & \text{Segment} & \text{Observed} & \text{Unary} & \text{Instance} & \text{Literal} & \text{Implicit} \\ & \text{Improvements} & \text{Episode} & \text{Co-generative} & \text{Unary} & \text{Instance} & / & / \\ & \text{Natural Language} & / & \text{Observed} & \text{Unary} & / & \text{Descriptive} & \text{Explicit} \\ \hline \text{Sup.} & \text{E-Stops} & \text{Episode} & \text{Observed} & \text{Unary} & \text{Instance} & \text{Literal} & \text{Implicit} \\ & \text{Importance} & / & \text{Observed} & / & / & \text{Descriptive} & \text{Explicit} \\ \hline \text{Rep.} & \text{Feature Traces} & \text{Segment} & \text{Active} & \text{Unary} & \text{Instance} & \text{Descriptive} & \text{Explicit} \\ & \text{Similarity Queries} & / & \text{Observed} & \text{Ternary} & / & \text{Descriptive} & \text{Explicit} \\ \hline \end{array} \]
  • Critique. 人类通过直接观察并批评 agent 的行为的一个实例来表达偏好.

  • Comparisons. 人类对多个行为作出比较或排名. 当然,有时也可以给人类提供 equally preferred 的选项.

  • Inter-Temporal Feedback. 跨期反馈. 人类很难在不同 episode 之间比较. 一种方式是,人类对轨迹的多个点给出反馈,从而说明 agent 是进步还是退步.

  • Proxy Rewards. 代理奖励. 代理奖励是部分或者不准确的奖励函数,传达有关 agent 应该完成的任务的信息,但可能不会导致最佳行为.

  • Social Behavior. 人类与 agent 互动时,面部反应和手势的隐含反馈.

  • Improvements. 人类在 agent 行动后或行动时介入来纠正并改善其行为. 人类既观察又演示,形成共同生成. 例如,人类可以产生干预和纠正. 从干预中可以推断负奖励,而无需学习奖励模型.4 从纠正后的轨迹中也可以进行学习.5

  • Natural Language. 自然语言. 通过自然语言的方式来表达反馈. 一种方式是使用情感分析从语言反馈中提取有关奖励函数的信息.6

  • E-Stops. 紧急停止. 人类可以主动地通过停止 agent 的行为来进行干预.

  • Importance. 人类向 agent 传达哪些部分对于目标是重要的. 类似于特征选择.

  • Feature Traces. 通过人类反馈主动引出新特征. 例如,通过让人类驾驶员主动演示在接近其他车辆或在复杂交通情形中的平稳减速与加速行为,可以记录下“与其他车辆距离”、“车速变化”等随时间单调变化的特征. 这些特征轨迹可以扩充奖励模型,使自动驾驶系统更好地捕捉和模仿安全驾驶的细节.

  • Similarity Queries. 人类比较三个轨迹,一个锚点,两个替代方案.

  • Initialization. 奖励函数往往需要一个起点. 常见的方式有给出最终或目标状态、专家演示、带标记的演示、带排名的演示等.

Choice & Combination

不同的反馈类型在不同的任务上有不同的效果. 当然反馈类型也可以交给用户选择,或者自适应. 不同的反馈类型之间也可以组合,例如演示 + 比较微调.

Label Collection

Active Learning

训练过程有时可以主动生成查询. 例如,借助偏好的传递性,查询可以被减少. 为了有效地学习一个合适的奖励模型,agent 生成一系列查询,并计算它们的 acquisition function,从而比较这些查询,并进行查询的选择. 有趣的是,agent 提出的查询也可能揭示其当前的奖励学习阶段. 一个 acquisition function 通常需要考虑下面的因素.

  • Uncertainty. Agent 的 epistemic uncertainty(认知不确定性)可以通过额外的查询来减少. 因此,当决定查询的选择时,不确定性是需要考虑的重要因素. 基于 belief representation,在贝叶斯框架下可以考虑几种不同的 acquisition function,例如改进的概率、改进的期望或改进的上置信界.

Reward Model Training

References


  1. Andrew Y. Ng, Daishi Harada, and Stuart J. Russell. Policy Invariance Under Reward Transformations: Theory and Application to Reward Shaping. In Proceedings of the International Conference on Machine Learning (ICML). Morgan Kaufmann Publishers Inc., 1999. 

  2. Joar Max Viktor Skalse, Nikolaus Howe, Dmitrii Krasheninnikov, and David Krueger. Defining and Characterizing Reward Gaming. In Advances in Neural Information Processing Systems (NeurIPS), volume 35, 2022. 

  3. Smitha Milli and Anca D. Dragan. Literal or Pedagogic Human? Analyzing Human Model Misspecification in Objective Learning. In Proceedings of the Conference on Uncertainty in Artificial Intelligence (UAI). PMLR, 2020. 

  4. Jianlan Luo, Perry Dong, Yuexiang Zhai, Yi Ma, and Sergey Levine. RLIF: Interactive Imitation Learning as Reinforcement Learning. In Proceedings of the International Conference on Learning Representations (ICLR), 2024. 

  5. Josh Abramson, Arun Ahuja, Federico Carnevale, Petko Georgiev, Alex Goldin, Alden Hung, Jessica Landon, Jirka Lhotka, Timothy Lillicrap, Alistair Muldal, George Powell, Adam Santoro, Guy Scully, Sanjana Srivastava, Tamara von Glehn, Greg Wayne, Nathaniel Wong, Chen Yan, and Rui Zhu. Improving Multimodal Interactive Agents with Reinforcement Learning from Human Feedback, 2022. 

  6. Theodore R. Sumers, Mark K. Ho, Robert D. Hawkins, Karthik Narasimhan, and Thomas L. Griffiths. Learning Rewards From Linguistic Feedback. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, 2021.