モデル概要
モデル特徴
モデル能力
使用事例
🚀 命令事前学習: 言語モデルは教師付きマルチタスク学習器である (EMNLP 2024)
このリポジトリには、論文「命令事前学習: 言語モデルは教師付きマルチタスク学習器である」で開発された、Llama3-8B をベースにした金融モデルが含まれています。我々は、「命令事前学習」というフレームワークを提案することで、教師付きマルチタスク事前学習を探求しています。このフレームワークは、オープンソースモデルに基づく効率的な命令合成器によって生成された命令応答ペアを用いて、大量の生コーパスを拡張し、言語モデルを事前学習します。「命令事前学習」は、ゼロからの一般的な事前学習とドメイン適応型の継続的事前学習の両方において、「バニラ事前学習」を上回っています。
✨ 主な機能
- 「命令事前学習」フレームワークにより、言語モデルの事前学習性能を向上させます。
- ゼロからの事前学習とドメイン適応型の継続的事前学習の両方で、既存の方法を上回る性能を発揮します。
- 金融やバイオメディシンなどの特定ドメインに適応したモデルを提供します。
📦 インストール
ドメイン固有のタスクで Huggingface の言語モデルを評価するための依存関係をセットアップするには、以下のコマンドを実行します。
git clone https://github.com/microsoft/LMOps
cd LMOps/adaptllm
pip install -r requirements.txt
💻 使用例
基本的な使用法
finance-Llama3-8B モデルとチャットするには、以下のコードを使用します。
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("instruction-pretrain/finance-Llama3-8B")
tokenizer = AutoTokenizer.from_pretrained("instruction-pretrain/finance-Llama3-8B")
# Put your input here, NO prompt template is required
user_input = '''Use this fact to answer the question: Title of each class Trading Symbol(s) Name of each exchange on which registered
Common Stock, Par Value $.01 Per Share MMM New York Stock Exchange
MMM Chicago Stock Exchange, Inc.
1.500% Notes due 2026 MMM26 New York Stock Exchange
1.750% Notes due 2030 MMM30 New York Stock Exchange
1.500% Notes due 2031 MMM31 New York Stock Exchange
Which debt securities are registered to trade on a national securities exchange under 3M's name as of Q2 of 2023?'''
inputs = tokenizer(user_input, return_tensors="pt", add_special_tokens=True).input_ids.to(model.device)
outputs = model.generate(input_ids=inputs, max_new_tokens=400)[0]
answer_start = int(inputs.shape[-1])
pred = tokenizer.decode(outputs[answer_start:], skip_special_tokens=True)
print(pred)
高度な使用法
任意の Huggingface 言語モデルをドメイン固有のタスクで評価するには、以下の手順を実行します。
- 依存関係をセットアップします(上記の「📦 インストール」を参照)。
- 以下のコマンドを使用してモデルを評価します。
# Select the domain from ['biomedicine', 'finance']
DOMAIN='finance'
# Specify any Huggingface LM name (Not applicable to models requiring specific prompt templates)
MODEL='instruction-pretrain/finance-Llama3-8B'
# Model parallelization:
# - Set MODEL_PARALLEL=False if the model fits on a single GPU.
# We observe that LMs smaller than 10B always meet this requirement.
# - Set MODEL_PARALLEL=True if the model is too large and encounters OOM on a single GPU.
MODEL_PARALLEL=False
# Choose the number of GPUs from [1, 2, 4, 8]
N_GPU=1
# Whether to add a BOS token at the beginning of the prompt input:
# - Set to False for AdaptLLM.
# - Set to True for instruction-pretrain models.
# If unsure, we recommend setting it to False, as this is suitable for most LMs.
add_bos_token=True
# Run the evaluation script
bash scripts/inference.sh ${DOMAIN} ${MODEL} ${add_bos_token} ${MODEL_PARALLEL} ${N_GPU}
📚 ドキュメント
リソース
我々は、データとモデルをサンプルコードとともに共有しています。このページで自由に議論を始めることができます。
- 我々のアプローチを実装したデモ davanstrien/instruction-synthesizer に感謝します。
- コンテキストベースの命令合成器: instruction-synthesizer
- 合成器の微調整データ: ft-instruction-synthesizer-collection
- ゼロから事前学習された一般モデル (100Bトークン):
- Llama3-8B から事前学習されたドメイン固有モデル:
- 一般的な命令拡張コーパス: general-instruction-augmented-corpora
- ドメイン固有の命令拡張コーパス (倫理的な問題を避けるため、金融データは含まれません): medicine-instruction-augmented-corpora
ドメイン適応型の継続的事前学習
AdaptLLM に従い、コンテキストベースの命令合成器によって生成された命令応答ペアを用いて、ドメイン固有の生コーパスを拡張します。
Llama3 からの継続的事前学習に関する FAQ
Q1: 事前学習に公式の Llama3 命令プロンプトを使用していますか?
いいえ、提供されている Llama3 命令プロンプトは 命令微調整済みモデル 用に設計されていますが、我々の継続的事前学習は 事前学習済みベースモデル で行われており、BOS (<|begin_of_text|>
) と EOS (<|end_of_text|>
) トークンのみが必要です。
Q2: OpenOrca の一般的な命令について、各命令とその出力を \n
で連結していますか?
いいえ、事前学習の提案で述べたように、OpenOrca の一般的な命令データについては、各質問とその応答を単純な空白で連結しています。OpenOrca のデータはすでに多様な自然言語テンプレート(\n
を含むものなど)でテンプレート化されているため、空白で十分です。
我々のテンプレート化された命令拡張テキストを使用する場合は、連結を追加する必要はありません。
Q3: OpenOrca のシステムプロンプトはどうなりますか? 我々はシステムプロンプトを単純に破棄します。
トークン化前のテキストは次のようになります。
general_instruction_response_text = "<|begin_of_text|>{question} {response}<|end_of_text|>"
instruction_augmented_text = "<|begin_of_text|>{instruction augmented text}<|end_of_text|>"
そして、トークン化する際には、BOS と EOS トークン ID を追加する必要はありません。トークン化コードは次のようになります。
text_ids = tokenizer(text, add_special_tokens=False, **kwargs).input_ids
🔧 技術詳細
「命令事前学習」は、オープンソースモデルに基づく命令合成器を用いて生成された命令応答ペアを用いて、大量の生コーパスを拡張し、言語モデルを事前学習するフレームワークです。このアプローチは、ゼロからの事前学習とドメイン適応型の継続的事前学習の両方において、既存の方法を上回る性能を発揮します。
📄 ライセンス
このプロジェクトは llama3 ライセンスの下で提供されています。
📄 引用
我々の研究が役に立った場合は、以下のように引用してください。
命令事前学習 (EMNLP 2024)
@article{cheng2024instruction,
title={Instruction Pre-Training: Language Models are Supervised Multitask Learners},
author={Cheng, Daixuan and Gu, Yuxian and Huang, Shaohan and Bi, Junyu and Huang, Minlie and Wei, Furu},
journal={arXiv preprint arXiv:2406.14491},
year={2024}
}
適応型大規模言語モデル (ICLR 2024)
@inproceedings{
cheng2024adapting,
title={Adapting Large Language Models via Reading Comprehension},
author={Daixuan Cheng and Shaohan Huang and Furu Wei},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=y886UXPEZ0}
}
更新履歴
- 2024/11/30: 命令合成器のマルチモーダルバージョン Visual Instruction Synthesizer をリリースしました。
- 2024/9/20: 我々の論文が EMNLP 2024 メイン会議に採択されました🎉
- 2024/9/11: Llama3 からの継続的事前学習に関する FAQ を更新しました。
- 2024/8/29: 任意の 🤗Huggingface モデルをドメイン固有のタスクで評価するガイドライン を更新しました。
- 2024/7/31: 命令合成器 の
Advanced Usage
セクションの事前学習提案を更新しました。 - 2024/7/15: 事前学習トークンを 100B から 250B に拡大し、合成された命令応答ペアの数が 500M に達しました。事前学習プロセス全体を通じた下流タスクの性能傾向:



