Phân loại zero-shot và QNLI

Natural Language Processing (NLP) bằng Python

Fouad Trad

Machine Learning Engineer

Phân loại zero-shot

  • Cho phép mô hình gán văn bản cho nhãn chưa từng thấy
  • Dùng suy luận ngôn ngữ tự nhiên để ra kết quả
  • Hữu ích cho:
    • Gắn thẻ nội dung
    • Hỗ trợ khách hàng
    • Lọc bài báo

Hình minh họa một văn bản "The national football team won the cup yesterday" cần được phân loại theo ba danh mục: sports, technology, và health.

Natural Language Processing (NLP) bằng Python

Pipeline phân loại zero-shot

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]}
Natural Language Processing (NLP) bằng Python

Suy luận ngôn ngữ tự nhiên cho câu hỏi (QNLI)

  • Xác định liệu câu trả lời cho câu hỏi có nằm trong đoạn văn hay không
  • Hữu ích cho:
    • Tìm kiếm tài liệu
    • Chatbot
    • Truy hồi thông tin

Hình cho thấy QNLI nhận một đoạn văn và một câu hỏi và trả về một điểm số.

Natural Language Processing (NLP) bằng Python

Pipeline 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}
Natural Language Processing (NLP) bằng Python

Pipeline 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}
Natural Language Processing (NLP) bằng Python

Ayo berlatih!

Natural Language Processing (NLP) bằng Python

Preparing Video For Download...