Downloads · 30 days
8
11% of all-time downloads
KotYrod/tweet-sentiment-distilbert
tweet-sentiment-distilbert is a text classification model from KotYrod. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model classifies tweets into three sentiment classes: positive, and negative. It is fine-tuned from distilbert-base-uncased on a dataset of labeled tweets.
Downloads · 30 days
8
11% of all-time downloads
All-time downloads
70
Public
Parameters
67M
536 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors268 MB · 100%
From the Hugging Face model README
This model classifies tweets into three sentiment classes: positive, and negative.
It is fine-tuned from distilbert-base-uncased on a dataset of labeled tweets.
The model was fine-tuned using the Hugging Face 🤗 transformers library on the Sentiment140 dataset.
Training was done on a local machine using GPU.
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import re
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = AutoModelForSequenceClassification.from_pretrained("KotYrod/tweet-sentiment-distilbert").to(device)
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
def predict_sentiment(text):
model.eval()
text = re.sub(r"http\S+|www\S+|\@\w+|\#|\s+", ' ', text).strip()
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding='max_length', max_length=128).to(device)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=1)
pred = torch.argmax(probs, dim=1).item()
return ("Positive 😊" if pred == 1 else "Negative 😠", probs[0][pred].item())
if _name_ == "_main_":
label, conf = predict_sentiment("wow im so glad")
print(f"Prediction: {label} (Confidence: {conf:.2f})")