트랜스포머 파이프라인 예시
필요한 모듈 설치하기
Zero-shot classification (문장 분류)
from transformers import pipeline
classifier = pipeline("zero-shot-classification")
classifier(
"This is a course about the Transformers library",
candidate_labels=["education", "politics", "business"],
)
실행결과)
{'sequence': 'This is a course about the Transformers library',
'labels': ['education', 'business', 'politics'],
'scores': [0.8445963859558105, 0.111976258456707, 0.043427448719739914]}
Text generation (문장 생성)
from transformers import pipeline
generator = pipeline("text-generation")
generator("In this course, we will teach you how to")
#help(generator)
#print(generator)
실행결과)
[{'generated_text': 'In this course, we will teach you how to understand and use '
'data flow and data interchange when handling user data. We '
'will be working with one or more of the most commonly used '
'data flows ? data flows of various types, as seen by the '
'HTTP'}]