शुरू करेंमुफ़्त में शुरू करें

Vision Language Transformers (ViLTs) के साथ VQA

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

Picture of a traffic light showing red

आपके लिए प्रीप्रोसेसर (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])
कोड संपादित करें और चलाएँ