Zero-shot classification और QNLI

Python में Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

Zero-shot classification

  • मॉडल को ऐसे लेबल्स से टेक्स्ट मिलाने देता है जिन्हें उसने पहले नहीं देखा
  • नैचुरल लैंग्वेज प्रेडिक्शन से आउटपुट लेता है
  • उपयोग के मामले:
    • कंटेंट टैगिंग
    • कस्टमर सपोर्ट
    • न्यूज़ आर्टिकल फ़िल्टरिंग

एक टेक्स्ट "The national football team won the cup yesterday" दिखाने वाली इमेज, जिसे तीन कैटेगरी: sports, technology, और health के अनुसार वर्गीकृत करना है.

Python में Natural Language Processing (NLP)

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]}
Python में Natural Language Processing (NLP)

Question natural language inference (QNLI)

  • तय करता है कि क्या सवाल का जवाब दिए गए पैसेज में मिलता है
  • उपयोग के मामले:
    • डॉक्यूमेंट सर्च
    • चैटबॉट्स
    • इन्फ़ॉर्मेशन रिट्रीवल

एक इमेज दिखाती है कि QNLI को एक पैसेज और एक सवाल मिलता है और वह एक स्कोर लौटाता है.

Python में Natural Language Processing (NLP)

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}
Python में Natural Language Processing (NLP)

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}
Python में Natural Language Processing (NLP)

अभ्यास करते हैं!

Python में Natural Language Processing (NLP)

Preparing Video For Download...