CLIP と CLAP による動画の感情分析
これまでに用意した広告動画を CLIP/CLAP で感情分析していきます。マルチモーダルに感情を分類するため、これらのモデルの予測を平均して組み合わせます(これは「late fusion」と呼ばれます)。
先ほど作成した動画(video)と対応する音声(audio_sample)は引き続き利用できます。

感情のリストは emotions として読み込まれています。
この演習はコースの一部です
Hugging Face で学ぶマルチモーダルモデル
演習の手順
laion/clap-htsat-unfusedモデルを使って、zero-shot-audio-classification用のオーディオ分類パイプラインを作成します。openai/clip-vit-base-patch32モデル(動画で使ったものの小型版)を使って、zero-shot-image-classification用の画像分類パイプラインを作成します。- 画像分類パイプラインを使って、動画内の各画像に対する予測を生成します。
- オーディオ分類パイプラインを使って、
audio_sampleに対する予測を生成します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Make an audio classifier pipeline
audio_classifier = ____(model="____", task="____")
# Make an image classifier pipeline
image_classifier = ____(model="____", task="____")
# Create emotion scores for each video frame
predictions = image_classifier(video, candidate_labels=emotions)
scores = [
{l['label']: l['score'] for l in prediction}
for prediction in predictions
]
avg_image_scores = {emotion: sum([s[emotion] for s in scores])/len(scores) for emotion in emotions}
# Make audio scores
audio_scores = ____(____, candidate_labels=____)
audio_scores = {l['label']: l['score'] for l in audio_scores}
multimodal_scores = {emotion: (avg_image_scores[emotion] + audio_scores[emotion])/2 for emotion in emotions}
print(f"Multimodal scores: {multimodal_scores}")