Edit model card

ConSenBert: Context-Aware Sentiment Analysis using roBerta

Model Name: ConSenBert
base Model: FacebookAI/roberta-base

Model Overview

ConSenBert is a fine-tuned model based on the FacebookAI/roberta-base architecture, designed to perform sentiment analysis with a focus on context-aware entity-based sentiment classification. The model is fine-tuned to identify whether a comment expresses a positive, negative or neutral sentiment towards a specific entity (product, company, etc.).

Model Usage

This model can be used for any task requiring entity-specific sentiment analysis, such as:

  • Product reviews analysis
  • Opinion mining from social media
  • Sentiment analysis on user feedback

Example Use Case

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
from scipy.special import softmax

model_name = "SoloAlphus/ConSenBert-V1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

def analyze_sentiment(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512, padding=True)
    
    with torch.no_grad():
        outputs = model(**inputs)
    
    scores = outputs.logits.squeeze().numpy()
    scores = softmax(scores)
    
    labels = ['Negative', 'Neutral', 'Positive']
    result = {label: float(score) for label, score in zip(labels, scores)}
    
    predicted_sentiment = max(result, key=result.get)
    
    return result, predicted_sentiment

# Example usage
comment = "abc product looks much better compared to xyz product!"
entity = "xyz"
text = comment + "[SEP]" + entity
sentiment_scores, predicted_sentiment = analyze_sentiment(text)

print(f"Comment: {comment}")
print(f"Entity: {entity}")
print(f"Sentiment Scores: {sentiment_scores}")
print(f"Predicted Sentiment: {predicted_sentiment}")

#Result
#Comment: abc product looks much better compared to xyz product
#Entity: xyz
#Sentiment Scores: {'Negative': 0.9783487915992737, 'Neutral': 0.001976581523194909, 'Positive': 0.01967463828623295}
#Predicted Sentiment: Negative

Input Format

  • Comment (string): The sentence or comment containing an opinion.
  • Supporting Entity (string): The entity for which you want to assess the sentiment (e.g., a product, brand, etc.).

Output Format

  • Sentiment: The model outputs either Positive, Negative or Neutral (along with score), indicating the sentiment of the comment towards the specified entity.

Validation Metrics

loss: 0.3585984408855438

f1_macro: 0.906113448881465

f1_micro: 0.9126373626373626

f1_weighted: 0.9129374345535766

precision_macro: 0.9039499022115488

precision_micro: 0.9126373626373626

precision_weighted: 0.9134430635912558

recall_macro: 0.9085609170738854

recall_micro: 0.9126373626373626

recall_weighted: 0.9126373626373626

accuracy: 0.9126373626373626

Future Versions

  • Extracting Suggestions from Comments

  • Multi-Aspect Sentiment Analysis

  • Emotion Detection

  • Entity Recognition and Linking

  • Aspect-Based Sentiment Categorization

Note: Kindly upvote the model if you like my work! 🤗

Downloads last month
110
Safetensors
Model size
125M params
Tensor type
F32
·
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.

Model tree for SoloAlphus/ConSenBert-V1

Finetuned
(1273)
this model

Space using SoloAlphus/ConSenBert-V1 1