开始使用免费开始使用

使用 Qwen 进行多模态情感分类

现在把您的提示词集成到 Qwen2 多模态视觉-语言模型中吧!您将使用之前创建的提示词模板,它已作为 chat_template 提供。

来看看模型对这篇文章的看法吧!模型(vl_model)和处理器(vl_model_processor)已经为您加载。

本练习是课程的一部分

使用 Hugging Face 的多模态模型

查看课程

练习说明

  • 使用处理器预处理 chat_template
  • 使用模型生成输出 ID,并将新标记数量限制为 500
  • 解码裁剪后的生成 ID,并跳过特殊标记。

交互式实操练习

通过完成这段示例代码来试试这个练习。

text = vl_model_processor.apply_chat_template(chat_template, tokenize=False, add_generation_prompt=True)
image_inputs, _ = process_vision_info(chat_template)

# Use the processor to preprocess the text and image
inputs = ____(
    text=[____],
    images=____,
    padding=True,
    return_tensors="pt",
)

# Use the model to generate the output IDs
generated_ids = vl_model.____(**inputs, ____)
generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]

# Decode the generated IDs
output_text = vl_model_processor.____(
    generated_ids_trimmed, skip_special_tokens=True
)
print(output_text[0])
编辑并运行代码