AyoubChLin/CNN_News_Articles_2011-2022
Viewer • Updated • 37.9k • 114 • 11
How to use AyoubChLin/DistilBERT_ZeroShot with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("zero-shot-classification", model="AyoubChLin/DistilBERT_ZeroShot") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")
model = AutoModelForSequenceClassification.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")
model = AutoModelForSequenceClassification.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")This repository contains a DistilBERT model trained for zero-shot classification on CNN articles. The model has been evaluated on CNN articles and achieved an accuracy of 0.956 and an F1 score of 0.955.
To use this model for zero-shot classification, you can follow the steps below:
Load the trained model:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")
model = AutoModelForSequenceClassification.from_pretrained("AyoubChLin/DistilBERT_ZeroShot")
Classify text using zero-shot classification:
from transformers import pipeline
# Create a zero-shot classification pipeline
classifier = pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
# Classify a sentence
sentence = "The latest scientific breakthroughs in medicine"
candidate_labels = ["politics", "sports", "technology", "business"]
result = classifier(sentence, candidate_labels)
print(result)
The output will be a dictionary containing the classified label and the corresponding classification score.
This work was created by Ayoub Cherguelaine.
If you have any questions or suggestions regarding this repository or the trained model, feel free to reach out to Ayoub Cherguelaine.
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="AyoubChLin/DistilBERT_ZeroShot")