제로샷 분류와 QNLI

Python으로 배우는 Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

제로샷 분류

  • 본 적 없는 레이블에도 텍스트를 할당할 수 있음
  • 자연어 추론으로 출력을 예측함
  • 활용 예:
    • 콘텐츠 태깅
    • 고객 지원
    • 뉴스 기사 필터링

세 가지 범주(스포츠, 기술, 건강)로 분류해야 하는 "The national football team won the cup yesterday" 텍스트를 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

제로샷 분류 파이프라인

from transformers import pipeline

zero_shot_classifier = pipeline(
task="zero-shot-classification",
model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli" )
text = "The national football team won the cup yesterday."
candidate_labels = ["sports", "technology", "health"]
result = zero_shot_classifier(text, candidate_labels)
print(result)
{'sequence': 'The national football team won the cup yesterday.',
 'labels': ['sports', 'technology', 'health'], 
 'scores': [0.9948731064796448, 0.0029330444522202015, 0.002193822991102934]}
Python으로 배우는 Natural Language Processing (NLP)

질문 자연어 추론(QNLI)

  • 질문의 답이 주어진 본문에 있는지 판별함
  • 활용 예:
    • 문서 검색
    • 챗봇
    • 정보 검색

QNLI가 본문과 질문을 받아 점수를 반환함을 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

QNLI 파이프라인

from transformers import pipeline

qnli_pipeline = pipeline( task="text-classification", model="cross-encoder/qnli-electra-base" )
passage = "Penguins are found primarily in the Southern Hemisphere."
question = "Where do penguins live?"
result = qnli_pipeline({"text": question, "text_pair": passage})
print(result)
{'label': 'LABEL_0', 'score': 0.9951545000076294}
Python으로 배우는 Natural Language Processing (NLP)

QNLI 파이프라인

from transformers import pipeline
qnli_pipeline = pipeline(
    task="text-classification", 
    model="cross-encoder/qnli-electra-base"
    )
passage = "Penguins are found primarily in the Southern Hemisphere."
question = "What is the capital of Paris?"
result = qnli_pipeline({"text": question, "text_pair": passage})
print(result)
{'label': 'LABEL_0', 'score': 0.008907231502234936}
Python으로 배우는 Natural Language Processing (NLP)

Vamos praticar!

Python으로 배우는 Natural Language Processing (NLP)

Preparing Video For Download...