Vision Language Transformer (ViLT) による VQA
マルチモーダル生成に挑戦しましょう。まずは Visual Question-Answering (VQA) です。dandelin/vilt-b32-finetuned-vqa モデルを使って、次の画像に写っている信号機の色を判定します。

前処理器(processor)、モデル(model)、画像(image)は読み込まれています。
この演習はコースの一部です
Hugging Face で学ぶマルチモーダルモデル
演習の手順
textのプロンプトとimageを前処理します。- モデルから回答トークンを生成して
outputsに代入します。 - 出力の logits を使って、最も確信度の高い回答の ID を求めます。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
text = "What color is the traffic light?"
# Preprocess the text prompt and image
encoding = ____(____, ____, return_tensors="pt")
# Generate the answer tokens
outputs = ____
# Find the ID of the answer with the highest confidence
idx = outputs.logits.____
print("Predicted answer:", model.config.id2label[idx])