การจำแนกความรู้สึกแบบ Multi-modal ด้วย Qwen
ถึงเวลานำ prompt ไปใช้งานร่วมกับ Qwen2 Vision Language Model แล้ว! เราจะใช้ prompt template ที่สร้างไว้ก่อนหน้านี้ ซึ่งเก็บอยู่ในตัวแปร chat_template
มาดูกันว่าโมเดลคิดอย่างไรกับบทความนี้! โมเดล (vl_model) และ processor (vl_model_processor) ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
โมเดล Multi-Modal ด้วย Hugging Face
คำแนะนำการฝึกหัด
- ใช้ processor เพื่อประมวลผล
chat_template - ใช้โมเดลเพื่อสร้าง output IDs โดยจำกัดจำนวน token ใหม่ไว้ที่
500 - ถอดรหัส generated 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])