เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การ Prompt Vision Language Models (VLMs)

ในแบบฝึกหัดสองข้อถัดไป คุณจะใช้โมเดล multi-modal เพื่อวิเคราะห์ความรู้สึก (sentiment) ของบทความข่าวและภาพหัวข่าวที่เกี่ยวข้องจาก BBC News dataset บน Hugging Face:

BBC News dataset card

เริ่มต้นด้วยการเตรียม chat template สำหรับโมเดล โดยให้รวมทั้งภาพและบทความข่าวไว้ด้วยกัน ชุดข้อมูล (dataset) และภาพหัวข่าว (image) ถูกโหลดไว้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

โมเดล Multi-Modal ด้วย Hugging Face

ดูคอร์ส

คำแนะนำการฝึกหัด

  • โหลดเนื้อหาบทความข่าว (content) จาก datapoint ที่ index 6 ใน dataset
  • เติมข้อความใน text query เพื่อแทรก content ลงใน text_query โดยใช้ f-string
  • เพิ่ม image และ text_query ลงใน chat template โดยระบุ content type ของ text_query เป็น "text"

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Load the news article content from datapoint 6
content = ____

# Complete the text query
text_query = f"Does the news article have a positive, negative, or neutral impact on championship winning chances: {____}. Provide reasoning."

# Add the text query dictionary to the chat template
chat_template = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": ____,
            },
            ____
        ],
    }
]
แก้ไขและรันโค้ด