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.

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! ๐Ÿค—

Validation Metrics

loss: 0.3681064248085022

precision_macro: 0.9189363693255532

precision_micro: 0.9142857142857143

precision_weighted: 0.917400667244694

accuracy: 0.9142857142857143

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

Model tree for SoloAlphus/ConSenBert-V1

Finetuned
(1567)
this model

Space using SoloAlphus/ConSenBert-V1 1