🚀 HH - RLHF報酬モデル
本プロジェクトでは、LMFlowフレームワークを基に訓練された報酬モデルを提供しています。このモデルは、[HH - RLHFデータセット](Dahoas/full - hh - rlhf)(有用部分のみ)に対して、[openlm - research/open_llama_3b](https://huggingface.co/openlm - research/open_llama_3b)をベースモデルとして訓練されており、良好な汎化能力を持ち、様々なデータセットに適用できます。
🚀 クイックスタート
この報酬モデルは、LMFlowフレームワークを用いて、[HH - RLHFデータセット](Dahoas/full - hh - rlhf)(有用部分のみ)に対して訓練されています。ベースモデルは[openlm - research/open_llama_3b](https://huggingface.co/openlm - research/open_llama_3b)です。
モデルカードのメタデータを参照する場合は、以下の規範を確認してください:https://github.com/huggingface/hub - docs/blob/main/modelcard.md?plain = 1
ドキュメント/ガイド:https://huggingface.co/docs/hub/model - cards
⚠️ 重要提示
本報酬モデルにご関心いただき、ありがとうございますの使用をおすすめします。
✨ 主な機能
データセットの前処理
HH - RLHF - Helpfulデータセットの訓練セットには112K個の比較サンプルが含まれ、テストセットには12.5K個の比較サンプルが含まれています。まず、データセット内の \n\nHuman
と \n\nAssistant
をそれぞれ ###Human
と ###Assistant
に置き換えます。
次に、データセットを以下のように分割します:
- SFTデータセット:112K個の訓練サンプル + テストセットの最初の6275個のサンプル。選択された応答のみを使用します。
- 報酬モデリング訓練セット:112K個の訓練サンプル + テストセットの最初の6275個のサンプル。選択された応答と拒否された応答の両方を使用します。
- 報酬モデリングテストセット:元のテストセットの最後の6226個のサンプル。
訓練
データをより効率的に使用するために、テキストを結合して1024サイズのブロックに分割し、最長のテキスト(バッチごと)でパディングするのではなく、SFTデータセットでベースモデルを2エポック微調整します。学習率は2e - 5で、線形減衰スケジュールを使用します。
データをより効率的に利用するため、テキストを連結して1024のサイズのブロックに分割し、(バッチごとの)最長のテキストでパディングする代わりに行います。その後、SFTデータセットでベースモデルを2エポック微調整し、学習率は2e - 5で線形減衰スケジュールを使用します。
報酬モデリングでは、学習率5e - 6で1エポック訓練し、線形減衰スケジュールを使用します。なぜなら、モデルは1エポックを超えると過学習しやすいからです。長さが512トークンを超えるサンプルは破棄するため、報酬モデリングの訓練セットには約106K個のサンプル、テストセットには約5K個のサンプルが含まれます。
両段階ともbf16を使用し、LoRAは使用しません。
最終モデルの評価損失は0.5、評価精度は75.48%です。(なお、[HH - RLHFデータセット](Dahoas/full - hh - rlhf)にはデータリークの問題がある可能性があります。)
汎化能力
報酬モデルの汎化能力をさらにテストし、別の研究プロジェクトで同じハイパーパラメータでもう1回訓練を行いました。オープンアシスタントデータセットとチャットボットデータセットで精度をテストし、この報酬モデルをこれら2つのデータセットで直接訓練した報酬モデルと比較しました。結果は以下の通りです:
データセットの訓練/テスト状況 |
オープンアシスタント |
チャットボット |
hh_rlhf |
オープンアシスタント |
69.5 |
61.1 |
58.7 |
チャットボット |
66.5 |
62.7 |
56.0 |
hh_rlhf |
69.4 |
64.2 |
77.6 |
これからわかるように、HH - RLHFで訓練された報酬モデルは、オープンアシスタントとチャットボットデータセットでも同等以上の精度を達成しています。つまり、これらのデータセットで直接訓練されていなくても使用できます。
💻 使用例
基本的な使用法
rm_tokenizer = AutoTokenizer.from_pretrained("weqweasdas/hh_rlhf_rm_open_llama_3b")
rm_pipe = pipeline(
"sentiment-analysis",
model="weqweasdas/hh_rlhf_rm_open_llama_3b",
device="auto",
tokenizer=rm_tokenizer,
model_kwargs={"torch_dtype": torch.bfloat16}
)
pipe_kwargs = {
"return_all_scores": True,
"function_to_apply": "none",
"batch_size": 1
}
test_texts = [
"###Human: My daughter wants to know how to convert fractions to decimals, but I'm not sure how to explain it. Can you help? ###Assistant: Sure. So one way of converting fractions to decimals is to ask “how many halves are there?” and then write this as a decimal number. But that's a little tricky. Here's a simpler way: if a fraction is expressed as a/b, then it's decimal equivalent is just a/b * 1.0 So, for example, the decimal equivalent of 1/2 is 1/2 * 1.0 = 0.5.",
"###Human: I have fresh whole chicken in my fridge. What dish can I prepare using it that will take me less than an hour to cook? ###Assistant: Are you interested in a quick and easy recipe you can prepare with chicken you have on hand, or something more involved? In terms of both effort and time, what are you looking for?"]
pipe_outputs = rm_pipe(test_texts, **pipe_kwargs)
rewards = [output[0]["score"] for output in pipe_outputs]
RAFTの例
RAFTを使用して報酬モデルをテストし、EleutherAI/gpt - neo - 2.7Bを開始チェックポイントとして使用します。
各反復で、HH - RLHFデータセットから2048個のプロンプトをサンプリングします。各プロンプトに対して、現在のモデルがK = 8個の応答を生成し、報酬が最も高い応答を選択します。そして、この選択されたセットでモデルを微調整して新しいモデルを得ます。報告する学習曲線は以下の通りです:

また、LLaMA - 7Bモデルを使用して実験を行いましたが、最初にHH - RLHFデータセットで選択された応答を使用してベースモデルを1エポック微調整し、学習率は2e - 5でした。RAFTのハイパーパラメータはGPT - Neo - 2.7Bと同じで、報酬曲線は以下の通りです:

📚 ドキュメント
参考文献
このモデルが役に立った場合は、以下のBibTeXを使用して私たちのフレームワークと論文を引用してください:
@article{diao2023lmflow,
title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models},
author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong},
journal={arXiv preprint arXiv:2306.12420},
year={2023}
}
@article{dong2023raft,
title={Raft: Reward ranked finetuning for generative foundation model alignment},
author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong},
journal={arXiv preprint arXiv:2304.06767},
year={2023}
}
この報酬モデルや報酬モデリングに関する質問があれば、wx13@illinois.eduまでメールを送信してください。お話しするのを楽しみにしています!