fancyzhx/ag_news
Viewer • Updated • 128k • 83k • 194
How to use nabeelshan/distilbert-finetuned-agnews with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="nabeelshan/distilbert-finetuned-agnews") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("nabeelshan/distilbert-finetuned-agnews")
model = AutoModelForSequenceClassification.from_pretrained("nabeelshan/distilbert-finetuned-agnews", device_map="auto")This is a distilbert-base-uncased model fine-tuned for text classification on the AG News dataset. It classifies news headlines into one of four categories: World, Sports, Business, and Sci/Tech.
This model was trained as part of a larger project, End-to-End NLP: From-Scratch Transformer vs. Deployed DistilBERT, which compares the performance of a Transformer built from scratch against this fine-tuned DistilBERT model.
You can interact with this model directly in the browser using the live Gradio demo hosted on Hugging Face Spaces:
distilbert-base-uncased, fine-tuned for sequence classification.0: World1: Sports2: Business3: Sci/TechYou can use this model directly with a text-classification pipeline.
from transformers import pipeline
# Load the classification pipeline
classifier = pipeline(
"text-classification",
model="nabeelshan/distilbert-finetuned-agnews",
return_all_scores=True
)
# Example news headline
text = "Formula 1: Hamilton wins the British Grand Prix after a dramatic last lap."
# Get prediction
result = classifier(text)
print(result)
Base model
distilbert/distilbert-base-uncased