開始使用免費開始

提示 Vision Language Models(VLM)

在接下來的兩個練習中,你會使用一個多模態模型,分析來自 Hugging Face 上 BBC News 資料集 的新聞文章及其對應的標題圖片的情緒:

BBC News dataset card

首先,你會為模型準備一個聊天範本,內容同時包含圖片與新聞文章。資料集(dataset)與標題圖片(image)已載入。

本練習屬於課程

使用 Hugging Face 的多模態模型

檢視課程

練習說明

  • dataset 中索引為 6 的資料點載入新聞文章內容(content)。
  • 使用 f-strings 完成文字查詢,將 content 插入到 text_query 中。
  • imagetext_query 加入聊天範本,並將 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": ____,
            },
            ____
        ],
    }
]
編輯並執行程式碼