AleksandarDimitrov06/bg-ecommerce-sentiment-roberta
05
RoBERTa Base Sentiment BG - Fine-tuned
This model is a fine-tuned version of `rmihaylov/roberta-base-sentiment-bg` for binary sentiment analysis (Positive/Negative). It has been trained on custom review data to classify text sentiment in Bulgarian and English.
Model Description
- Developed by: Aleksandar Dimitrov
- Language(s): Bulgarian (bg), English (en)
- Model Type: Text Classification (Sentiment Analysis)
- Base Model: rmihaylov/roberta-base-sentiment-bg
- License: MIT
Как да използвате модела (How to Use)
Можете да използвате модела директно с библиотеката transformers в Python. Ето пример как да заредите модела и да направите предсказание:
You can use this model directly with the transformers library in Python. Here is a script to load the model and run inference:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_id = "AleksandarDimitrov06/bg-ecommerce-sentiment-roberta"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id).to(device)
model.eval()
def predict_sentiment(text: str):
with torch.no_grad():
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
outputs = model(**inputs)
probabilities = torch.softmax(outputs.logits, dim=1).tolist()[0]
# 0: NEGATIVE, 1: POSITIVE
if probabilities[1] >= probabilities[0]:
return "POSITIVE", probabilities[1]
return "NEGATIVE", probabilities[0]
# Тест / Test
text = "Този продукт е страхотен и работи перфектно!"
label, confidence = predict_sentiment(text)
print(f"Резултат: {label} ({confidence:.2%})")