提示 Vision Language Models (VLMs)
在接下来的两个练习中,您将使用多模态模型来分析一篇新闻文章及其对应的头图情感。这些数据来自 Hugging Face 上的 BBC News 数据集:

首先,您将为模型准备一个聊天模板,其中同时包含图像和新闻文章。数据集(dataset)和头图(image)已加载。
本练习是课程的一部分
使用 Hugging Face 的多模态模型
练习说明
- 从
dataset中索引为6的数据点加载新闻文章内容(content)。 - 使用 f-string 完成文本查询,将
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": ____,
},
____
],
}
]