Vision Language Transformers (ViLTs) के साथ VQA
अब मल्टी-मोडल जेनरेशन के साथ अभ्यास करने का समय है, शुरुआत करते हैं Visual Question-Answering (VQA) से। आप dandelin/vilt-b32-finetuned-vqa मॉडल का उपयोग करके नीचे दी गई इमेज में ट्रैफिक लाइट का रंग पहचानेंगे:

आपके लिए प्रीप्रोसेसर (processor), मॉडल (model) और इमेज (image) पहले से लोड हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Hugging Face के साथ मल्टी-मोडल मॉडल्स
अभ्यास निर्देश
textप्रॉम्प्ट औरimageको प्रीप्रोसेस करें.- मॉडल से answer टोकन जनरेट करें और
outputsमें असाइन करें. - आउटपुट logits का उपयोग करके सबसे अधिक confidence वाले answer का 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])