开始使用免费开始使用

提示 Vision Language Models (VLMs)

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

BBC News dataset card

首先,您将为模型准备一个聊天模板,其中同时包含图像和新闻文章。数据集(dataset)和头图(image)已加载。

本练习是课程的一部分

使用 Hugging Face 的多模态模型

查看课程

练习说明

  • dataset 中索引为 6 的数据点加载新闻文章内容(content)。
  • 使用 f-string 完成文本查询,将 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": ____,
            },
            ____
        ],
    }
]
编辑并运行代码