Qwen के साथ मल्टी-मोडल सेंटिमेंट क्लासिफिकेशन
अब अपने प्रॉम्प्ट को Qwen2 Vision Language Model के साथ जोड़ते हैं! आप वह प्रॉम्प्ट टेम्पलेट उपयोग करेंगे जो आपने पहले बनाया था, जो chat_template के रूप में उपलब्ध है.
आइए देखें, यह मॉडल इस आर्टिकल के बारे में क्या सोचता है! मॉडल (vl_model) और प्रोसेसर (vl_model_processor) आपके लिए लोड कर दिए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Hugging Face के साथ मल्टी-मोडल मॉडल्स
अभ्यास निर्देश
- प्रोसेसर का उपयोग करके
chat_templateको प्रीप्रोसेस करें. - मॉडल का उपयोग करके आउटपुट IDs जनरेट करें और नए टोकन्स को
500तक सीमित रखें. - ट्रिम किए गए जनरेटेड IDs को डिकोड करें और special tokens को स्किप करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
text = vl_model_processor.apply_chat_template(chat_template, tokenize=False, add_generation_prompt=True)
image_inputs, _ = process_vision_info(chat_template)
# Use the processor to preprocess the text and image
inputs = ____(
text=[____],
images=____,
padding=True,
return_tensors="pt",
)
# Use the model to generate the output IDs
generated_ids = vl_model.____(**inputs, ____)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
# Decode the generated IDs
output_text = vl_model_processor.____(
generated_ids_trimmed, skip_special_tokens=True
)
print(output_text[0])