キャプション品質の自動評価
ワンピースの画像は正しく分類できましたが、元の説明文はどれくらい的確だったでしょうか?
Maa Fab wrap with a Trendy design dress with Vibrant color for an elegant touch of Fabric completely Soft and Comfortable wear with amazing design of Solid Boat ? Neck Flared Dress to make a perfect addition to your wardrobe collection.
これから CLIP モデルを使い、CLIP スコアでこの説明がどれほど正確かを定量的に評価します。キャプション(description)、画像(image)、ToTensor クラス、そして torchmetrics の clip_score() 関数は読み込まれています。
この演習はコースの一部です
Hugging Face で学ぶマルチモーダルモデル
演習の手順
- 画像を、画素強度が 0~255 の範囲になるように PyTorch テンソルへ変換します。
clip_score()関数を使い、openai/clip-vit-base-patch32モデルでimage_tensorとdescriptionを比較してキャプションの品質を評価します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Convert the image to a PyTorch tensor
image_tensor = ____()(image)*____
# Use the clip_score function to assess the quality of the caption
score = ____(____, ____, "____")
print(f"CLIP score: {score}")