Fine-tuned DistilBERT for 3-class sentiment classification (negative, neutral, positive).
This model is a fine-tuned version of DistilBERT-base-uncased for sentiment analysis. It has been trained to classify text into three sentiment categories:
This model is intended for sentiment analysis tasks on English text. It can be used to:
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "your-username/my-sentiment-model"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Prepare text
10text = "I love this product!"
11inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
12
13# Get prediction
14with torch.no_grad():
15 outputs = model(**inputs)
16 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
17 predicted_class = torch.argmax(probabilities, dim=-1).item()
18
19# Map prediction to label
20labels = {0: "negative", 1: "neutral", 2: "positive"}
21confidence = probabilities[0][predicted_class].item()
22
23print(f"Text: {text}")
24print(f"Sentiment: {labels[predicted_class]} (confidence: {confidence:.2%})")
1@misc{my-sentiment-model,
2 author = {Your Name},
3 title = {Fine-tuned DistilBERT for Sentiment Analysis},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/your-username/my-sentiment-model}
7}
This model is released under the MIT License.