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

首先,你會為模型準備一個聊天範本,內容同時包含圖片與新聞文章。資料集(dataset)與標題圖片(image)已載入。
本練習屬於課程
使用 Hugging Face 的多模態模型
練習說明
- 從
dataset中索引為6的資料點載入新聞文章內容(content)。 - 使用 f-strings 完成文字查詢,將
content插入到text_query中。 - 將
image與text_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": ____,
},
____
],
}
]