시작하기무료로 시작하기

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])
코드 편집 및 실행