Qwen を使ったマルチモーダル感情分類
いよいよ Qwen2 Vision Language Model にあなたのプロンプトを統合します! 先ほど作成したプロンプトテンプレート chat_template を使用します。
この記事について、モデルはどう判断するでしょうか。モデル(vl_model)とプロセッサ(vl_model_processor)は読み込まれています。
この演習はコースの一部です
Hugging Face で学ぶマルチモーダルモデル
演習の手順
- プロセッサを使って
chat_templateを前処理します。 - モデルを使って出力 ID を生成し、新しいトークン数を
500に制限します。 - 特殊トークンをスキップして、トリミング済みの生成 ID をデコードします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
text = vl_model_processor.apply_chat_template(chat_template, tokenize=False, add_generation_prompt=True)
image_inputs, _ = process_vision_info(chat_template)
# Use the processor to preprocess the text and image
inputs = ____(
text=[____],
images=____,
padding=True,
return_tensors="pt",
)
# Use the model to generate the output IDs
generated_ids = vl_model.____(**inputs, ____)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
# Decode the generated IDs
output_text = vl_model_processor.____(
generated_ids_trimmed, skip_special_tokens=True
)
print(output_text[0])