開始使用免費開始

使用 Qwen 進行多模態情緒分類

現在把你的提示結合到 Qwen2 Vision Language Model!你會使用先前建立並已提供為 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])
編輯並執行程式碼