Multimodal 실전·API — Transformers Pipeline
Multimodal 실전·API
Transformers의 pipeline() 은 복잡한 전처리·모델·후처리를 감싸서, 멀티모달 작업도 몇 줄로 실행하게 해줘요. 텍스트뿐 아니라 이미지·오디오 과제도 통일된 인터페이스로 다룰 수 있어요.
파이프라인 기본
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
result = classifier("I've been waiting for this movie my whole life.")
print(result)
# [{'label': 'POSITIVE', 'score': 0.99...}]
파이프라인은 모델·토크나이저를 자동으로 골라주니까, 첫 실험을 빠르게 해보기에 좋아요.
객체 사용
from transformers import pipeline
from transformers.pipelines.pt_utils import KeyDataset
pipe = pipeline("image-classification", model="google/vit-base-patch16-224")
images = [path1, path2, path3]
for out in pipe(images):
print(out)
여러 이미지 입력을 배치처럼 넘기면 파이프라인이 알아서 처리해요.
사용 가능한 파이프라인 예
image-classification: 이미지 분류image-to-text/text-to-image: 이미지↔텍스트 변환audio-classification/text-to-audio: 오디오 과제text-generation: 텍스트 생성
프레임워크(텐서플로·PyTorch·JAX)를 가리지 않고 같은 API로 동작한다는 게 특징이에요.