模型指标与参数调整

来自人类反馈的强化学习(RLHF)

Mina Parham

AI Engineer

为何使用参考模型?

  • 输出无意义

一系列表情符号。

来自人类反馈的强化学习(RLHF)

检查模型输出

带有响应检查的 RLHF 过程示意图。

来自人类反馈的强化学习(RLHF)

解决方案:KL 散度

包含 KL 散度的 RLHF 过程示意图。

来自人类反馈的强化学习(RLHF)

解决方案:KL 散度

  • 向"奖励模型"添加"惩罚"
  • 当输出不相关时,用惩罚"纠偏"模型
  • "KL 散度"比较当前模型与奖励模型

代表天平的图标。

  • 介于"0"和"10"之间,且"从不为负"
来自人类反馈的强化学习(RLHF)

调整参数

generation_kwargs = {

"min_length": -1, # don't ignore the EOS token
"top_k": 0.0, # no top-k sampling
"top_p": 1.0, "do_sample": True, "pad_token_id": tokenizer.eos_token_id, "max_new_tokens": 32}

 

  • 将参数传给策略模型
来自人类反馈的强化学习(RLHF)

检查奖励模型

  • 检查奖励模型

  • 检查输出(奖励)

reward_model_results.head()
|ID | Comment                                     |Sentiment |Reward|
|---|---------------------------------------------|----------|------|
| 1 | This event was lit! So much fun!            | Positive |  0.9 |
| 2 | Terrible experience, never attending again. | Negative | -0.8 |
| 3 | It was okay, nothing extraordinary.         | Neutral  |  0.2 |
| 4 | The event was poorly organized and chaotic. | Negative | -0.85|
| 5 | Had an amazing time with great people!      | Positive |  0.95|
来自人类反馈的强化学习(RLHF)

检查奖励模型

  • 👍 👎 检查极端情况
    extreme_positive = reward_model_results[reward_model_results['Reward'] >= 0.9]
    extreme_negative = reward_model_results[reward_model_results['Reward'] <= -0.8]
    
  • 🧘 确保数据集均衡

    sentiment_distribution = reward_model_results['Sentiment'].value_counts()
    
  • 📊 归一化奖励值

    from sklearn.preprocessing import MinMaxScaler
    scaler = MinMaxScaler(feature_range=(-1, 1))
    scaler.fit_transform(reward_model_results[['Reward']])
    
来自人类反馈的强化学习(RLHF)

Passons à la pratique !

来自人类反馈的强化学习(RLHF)

Preparing Video For Download...