Sıfır örnekli sınıflandırma ve QNLI

Python ile Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

Sıfır örnekli sınıflandırma

  • Modelin daha önce görmediği etiketlere metin atamasını sağlar
  • Çıktı için doğal dil tahmini kullanır
  • Şunlar için yararlıdır:
    • İçerik etiketleme
    • Müşteri desteği
    • Haber filtreleme

"Dün milli futbol takımı kupayı kazandı" metninin spor, teknoloji ve sağlık kategorilerine göre sınıflandırılması gerektiğini gösteren görsel.

Python ile Natural Language Processing (NLP)

Sıfır örnekli sınıflandırma hattı

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 ile Natural Language Processing (NLP)

Soru doğal dil çıkarımı (QNLI)

  • Bir sorunun yanıtının bir pasajda bulunup bulunmadığını belirler
  • Şunlar için yararlıdır:
    • Belge arama
    • Sohbet botları
    • Bilgi getirme

QNLI'nin bir pasaj ve soru alıp bir puan döndürdüğünü gösteren görsel.

Python ile Natural Language Processing (NLP)

QNLI hattı

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 ile Natural Language Processing (NLP)

QNLI hattı

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 ile Natural Language Processing (NLP)

Haydi pratik yapalım!

Python ile Natural Language Processing (NLP)

Preparing Video For Download...