기타 파이프라인
from transformers import pipeline
질문 답변
qa = pipeline("question-answering")
지문
context = """
Seoul, officially the Seoul Special City, is the capital and largest metropolis
of South Korea. Seoul has a population of 9.7 million people, and forms
the heart of the Seoul Capital Area with the surrounding Incheon metropolis and
Gyeonggi province.
"""
질문: 한국의 수도는?
qa(question="where is the capital city of South Korea?", context=context)
{'answer': 'Seoul,', 'end': 7, 'score': 0.862982988357544, 'start': 1}
질문: 서울에 사는 사람은 몇 명?
qa(question="How many people live in Seoul?", context=context)
{'answer': '9.7 million', 'end': 135, 'score': 0.9299280643463135, 'start': 124}
NER
ner = pipeline("ner")
ner(context)
[{'entity': 'I-LOC', 'index': 1, 'score': 0.9995670318603516, 'word': 'Seoul'}, {'entity': 'I-LOC', 'index': 5, 'score': 0.9981557726860046, 'word': 'Seoul'}, {'entity': 'I-LOC', 'index': 6, 'score': 0.9772302508354187, 'word': 'Special'}, {'entity': 'I-LOC', 'index': 7, 'score': 0.9895073175430298, 'word': 'City'}, {'entity': 'I-LOC', 'index': 17, 'score': 0.9969215989112854, 'word': 'South'}, {'entity': 'I-LOC', 'index': 18, 'score': 0.9992411136627197, 'word': 'Korea'}, {'entity': 'I-LOC', 'index': 20, 'score': 0.9994530081748962, 'word': 'Seoul'}, {'entity': 'I-LOC', 'index': 37, 'score': 0.9821178317070007, 'word': 'Seoul'}, {'entity': 'I-LOC', 'index': 38, 'score': 0.9603081941604614, 'word': 'Capital'}, {'entity': 'I-LOC', 'index': 39, 'score': 0.9373542070388794, 'word': 'Area'}, {'entity': 'I-LOC', 'index': 43, 'score': 0.9985089898109436, 'word': 'Inc'}, {'entity': 'I-LOC', 'index': 44, 'score': 0.9781635403633118, 'word': '##he'}, {'entity': 'I-LOC', 'index': 45, 'score': 0.9987452626228333, 'word': '##on'}, {'entity': 'I-LOC', 'index': 49, 'score': 0.9987314939498901, 'word': 'G'}, {'entity': 'I-LOC', 'index': 50, 'score': 0.9916979074478149, 'word': '##ye'}, {'entity': 'I-LOC', 'index': 51, 'score': 0.997252345085144, 'word': '##ong'}, {'entity': 'I-LOC', 'index': 52, 'score': 0.9962428212165833, 'word': '##gi'}]
요약
summ = pipeline("summarization")
text = """
A zettelkasten consists of many individual notes with ideas and other short
pieces of information that are taken down as they occur or are acquired. The
notes are numbered hierarchically, so that new notes may be inserted at the
appropriate place, and contain metadata to allow the note-taker to associate
notes with each other. For example, notes may contain tags that describe key
aspects of the note, and they may reference other notes. The numbering,
metadata, format and structure of the notes is subject to variation depending on
the specific method employed. Creating and using a zettelkasten is made easier
by taking the notes down digitally and using appropriate knowledge management
software. But it can be and has long been done on paper using index cards. The
method not only allows a researcher to store and retrieve information related to
their research, but also intends to enhance creativity. Cross-referencing notes
through tags allows the researcher to perceive connections and relationships
between individual items of information that may not be apparent in isolation.
These emergent aspects of the method make the zettelkasten somewhat similar to a
neural network with which one may "converse"
"""
summ(text)
[{'summary_text': ' A zettelkasten consists of many individual notes with ideas that are taken down as they occur or are acquired . The numbering, metadata, format and structure of the notes is subject to variation depending on the specific method employed . Cross-referencing notes with tags allows the researcher to perceive connections and relationships between notes that may not be apparent in isolation . The method is made easier by taking the notes down digitally and using knowledge management software .'}]
Zero-Shot Classification
zs = pipeline('zero-shot-classification')
문장
sequence = 'Pizza is my favorite food'
레이블
label = ['food', 'ocean', 'space']
분류
zs(sequence, label)
{'labels': ['food', 'space', 'ocean'], 'scores': [0.9971833825111389, 0.0015179909532889724, 0.0012986798537895083], 'sequence': 'Pizza is my favorite food'}