Zero-shot classification และ QNLI

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Fouad Trad

Machine Learning Engineer

Zero-shot classification

  • โมเดลจัดหมวดหมู่ข้อความด้วย label ที่ไม่เคยเห็นมาก่อน
  • ใช้การทำนายด้วยภาษาธรรมชาติเพื่อให้ได้ผลลัพธ์
  • ประโยชน์ในการใช้งาน:
    • การติดแท็กเนื้อหา
    • การสนับสนุนลูกค้า
    • การกรองบทความข่าว

ภาพแสดงข้อความ "The national football team won the cup yesterday" ที่ต้องจำแนกตามหมวดหมู่ 3 หมวด ได้แก่ sports, technology และ health

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Zero-shot classification pipeline

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]}
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Question natural language inference (QNLI)

  • ตรวจสอบว่าคำตอบของคำถามปรากฏอยู่ในข้อความหรือไม่
  • ประโยชน์ในการใช้งาน:
    • การค้นหาเอกสาร
    • Chatbot
    • การดึงข้อมูล

ภาพแสดงว่า QNLI รับข้อความและคำถาม แล้วส่งคืนค่าคะแนน

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

QNLI pipeline

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}
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

QNLI pipeline

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}
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

มาฝึกกันเถอะ!

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Preparing Video For Download...