🚀 Mistral-7B-Instruct-v0.1モデルカード
Mistral-7B-Instruct-v0.1大規模言語モデル(LLM)は、Mistral-7B-v0.1生成テキストモデルを、様々な公開されている会話データセットを使用して命令に関する微調整を行ったバージョンです。
このモデルの詳細については、論文とリリースブログ記事をご覧ください。
🚀 クイックスタート
💻 使用例
基本的な使用法
mistral_common
を使用したエンコードとデコード
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
from mistral_common.protocol.instruct.messages import UserMessage
from mistral_common.protocol.instruct.request import ChatCompletionRequest
mistral_models_path = "MISTRAL_MODELS_PATH"
tokenizer = MistralTokenizer.v1()
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
tokens = tokenizer.encode_chat_completion(completion_request).tokens
高度な使用法
mistral_inference
を使用した推論
from mistral_inference.transformer import Transformer
from mistral_inference.generate import generate
model = Transformer.from_folder(mistral_models_path)
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
result = tokenizer.decode(out_tokens[0])
print(result)
hugging face transformers
を使用した推論
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
model.to("cuda")
generated_ids = model.generate(tokens, max_new_tokens=1000, do_sample=True)
result = tokenizer.decode(generated_ids[0].tolist())
print(result)
💡 使用ヒント
transformers
トークナイザーを修正して、mistral_common
のリファレンス実装と1対1で同じ結果を得るPRを大歓迎です!
📚 ドキュメント
命令形式
命令に関する微調整を活用するためには、プロンプトを[INST]
と[/INST]
トークンで囲む必要があります。最初の命令は文頭IDで始める必要があります。次の命令はその必要はありません。アシスタントの生成は文末トークンIDで終了します。
例:
text = "<s>[INST] What is your favourite condiment? [/INST]"
"Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> "
"[INST] Do you have mayonnaise recipes? [/INST]"
この形式は、apply_chat_template()
メソッドを介してチャットテンプレートとして利用できます。
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
messages = [
{"role": "user", "content": "What is your favourite condiment?"},
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
{"role": "user", "content": "Do you have mayonnaise recipes?"}
]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
model_inputs = encodeds.to(device)
model.to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
モデルアーキテクチャ
この命令モデルはMistral-7B-v0.1に基づいており、以下のアーキテクチャが選択されているトランスフォーマーモデルです。
- グループ化クエリアテンション
- スライディングウィンドウアテンション
- バイトフォールバックBPEトークナイザー
トラブルシューティング
以下のエラーが表示された場合:
Traceback (most recent call last):
File "", line 1, in
File "/transformers/models/auto/auto_factory.py", line 482, in from_pretrained
config, kwargs = AutoConfig.from_pretrained(
File "/transformers/models/auto/configuration_auto.py", line 1022, in from_pretrained
config_class = CONFIG_MAPPING[config_dict["model_type"]]
File "/transformers/models/auto/configuration_auto.py", line 723, in getitem
raise KeyError(key)
KeyError: 'mistral'
ソースからtransformers
をインストールすることで問題が解決するはずです。
pip install git+https://github.com/huggingface/transformers
これはtransformers-v4.33.4
以降では必要ないはずです。
制限事項
Mistral 7B Instructモデルは、ベースモデルを簡単に微調整して魅力的なパフォーマンスを達成できることをすばやく実証するものです。
このモデルにはモデレーションメカニズムがありません。モデルがガードレールをきめ細かく尊重し、モデレーションされた出力が必要な環境でのデプロイを可能にする方法について、コミュニティと協力することを楽しみにしています。
ミストラルAIチーム
Albert Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lélio Renard Lavaud, Lucile Saulnier, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed.
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。
⚠️ 重要なお知らせ
個人情報の処理方法について詳しく知りたい場合は、プライバシーポリシーをご覧ください。