YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

OpinionAI Sentiment DistilBERT

A fine-tuned DistilBERT model for 3-class sentiment classification of English product reviews.

The model classifies a review into one of three sentiment categories:

  • Negative
  • Neutral
  • Positive

Model Details

  • Base model: distilbert/distilbert-base-uncased
  • Architecture: DistilBERT
  • Task: Text Classification / Sentiment Analysis
  • Language: English
  • Number of labels: 3
  • Maximum sequence length: 128 tokens
  • Training epochs: 3
  • Learning rate: 2e-5
  • Batch size: 16
  • Optimizer: AdamW (via Hugging Face Trainer)
  • Weight decay: 0.01

Dataset

The model was fine-tuned on a dataset containing 1,453 product reviews.

Split Samples
Training 1,162
Validation 145
Test 146
Total 1,453

The sentiment labels were mapped as follows:

Negative โ†’ 0
Neutral  โ†’ 1
Positive โ†’ 2

Evaluation Results

The model achieved 97.26% accuracy on the held-out test set.

Class Precision Recall F1-Score Support
Negative 0.92 1.00 0.96 48
Neutral 1.00 0.96 0.98 49
Positive 1.00 0.96 0.98 49
Overall Accuracy 0.97 146

Confusion Matrix

[[48  0  0]
 [ 2 47  0]
 [ 2  0 47]]

Rows represent the true labels and columns represent the predicted labels in the order:

Negative, Neutral, Positive

Training

The model was fine-tuned using the Hugging Face transformers library and Trainer API.

Training was performed using a Google Colab Tesla T4 GPU.

The best model checkpoint was selected based on validation accuracy.

Usage

Install the required libraries:

pip install transformers torch

Load the model and tokenizer:

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_id = "rohanpython9229/OpinionAI-Sentiment-DistilBERT"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

text = "This product is amazing and works perfectly!"

inputs = tokenizer(
    text,
    return_tensors="pt",
    truncation=True,
    padding=True,
    max_length=128
)

with torch.no_grad():
    outputs = model(**inputs)

prediction = torch.argmax(outputs.logits, dim=-1).item()

print(model.config.id2label[prediction])

Example output:

Positive

Limitations

  • The model was trained on a relatively small dataset of 1,453 reviews.
  • Performance may vary on text that differs significantly from the training data.
  • The model is intended primarily for English product-review sentiment classification.
  • The reported test performance should not be interpreted as general performance across all types of text.

Intended Use

This model is intended for educational, experimental, and application-development purposes involving sentiment analysis of English product reviews.

It can be used as the NLP model component of the OpinionAI Sentiment Analysis project.

License

This model is fine-tuned from distilbert/distilbert-base-uncased, which is released under the Apache License 2.0. Please refer to the base model's license and terms when using or redistributing this model

Downloads last month
-
Safetensors
Model size
67M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support