CLIP CLAP के साथ वीडियो sentiment analysis
अब आप पहले से तैयार किए गए विज्ञापन का emotion analysis CLIP/CLAP से करेंगे। मल्टी-मोडल emotion classification के लिए, आप इन मॉडलों की भविष्यवाणियों का औसत लेकर उन्हें संयोजित करेंगे (इसे late fusion कहा जाता है).
आपने पहले जो वीडियो (video) और उसका संबंधित ऑडियो (audio_sample) बनाया था, वह अभी भी उपलब्ध है:

emotions की एक लिस्ट emotions के रूप में लोड की गई है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Hugging Face के साथ मल्टी-मोडल मॉडल्स
अभ्यास निर्देश
laion/clap-htsat-unfusedमॉडल का उपयोग करकेzero-shot-audio-classificationके लिए एक audio classifier पाइपलाइन बनाइए.openai/clip-vit-base-patch32मॉडल का उपयोग करकेzero-shot-image-classificationके लिए एक image classifier पाइपलाइन बनाइए (यह उस मॉडल का छोटा वेरिएंट है जिसे हमने वीडियो में इस्तेमाल किया था).- वीडियो की हर image के लिए प्रेडिक्शन जनरेट करने के लिए image classifier पाइपलाइन का उपयोग करें.
audio_sampleके लिए प्रेडिक्शन जनरेट करने के लिए audio classifier पाइपलाइन का उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# 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}")