Downloads · 30 days
6
11% of all-time downloads
mahekgheewala/sentimental_analysis_updated
sentimental_analysis_updated is a text classification model from mahekgheewala. Use it when you need a label for a piece of text. It is set up for sentence-transformers. The card lists the license as mit.
Downloads · 30 days
6
11% of all-time downloads
All-time downloads
53
Public
Repo size
439 MB
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 99%
From the Hugging Face model README
🎯 Test Accuracy: 0.9966
This hybrid sentiment analysis model combines Sentence Transformers for semantic embeddings with XGBoost for classification. Trained on Reddit comments for multiclass sentiment analysis: Negative, Positive, and Neutral.
Input Text → SentenceTransformer → Embeddings (768D) →
Feature Engineering (Length + Sentiment + POS) → XGBoost → Prediction
import pickle
import numpy as np
from sentence_transformers import SentenceTransformer
from textblob import TextBlob
import nltk
from huggingface_hub import hf_hub_download
# Download NLTK data
nltk.download('punkt', quiet=True)
nltk.download('averaged_perceptron_tagger', quiet=True)
# Load models
xgb_path = hf_hub_download(repo_id="USERNAME/sentimental_analysis_updated", filename="xgboost_model.pkl")
sentence_path = hf_hub_download(repo_id="USERNAME/sentimental_analysis_updated", filename="sentence_transformer")
# Load XGBoost model
with open(xgb_path, 'rb') as f:
pipeline_data = pickle.load(f)
xgb_model = pipeline_data['xgboost_model']
label_names = pipeline_data['label_names']
# Load SentenceTransformer
sentence_model = SentenceTransformer(sentence_path)
def predict_sentiment(text):
# Extract features
embedding = sentence_model.encode([text])
comment_length = np.array([len(text.split())]).reshape(-1, 1)
sentiment_polarity = np.array([TextBlob(text).sentiment.polarity]).reshape(-1, 1)
# POS counts
try:
tags = nltk.pos_tag(nltk.word_tokenize(text))
pos_counts = np.array([[
sum(1 for _, tag in tags if tag.startswith('J')), # Adjectives
sum(1 for _, tag in tags if tag.startswith('N')), # Nouns
sum(1 for _, tag in tags if tag.startswith('V')) # Verbs
]])
except:
pos_counts = np.array([[0, 0, 0]])
# Combine features
features = np.hstack([embedding, comment_length, sentiment_polarity, pos_counts])
# Predict
prediction = xgb_model.predict(features)[0]
confidence = xgb_model.predict_proba(features)[0].max()
return {
'label': label_names[prediction],
'confidence': confidence,
'prediction_id': int(prediction)
}
# Example usage
result = predict_sentiment("I love this new phone! It's amazing!")
print(f"Sentiment: {result['label']} (confidence: {result['confidence']:.3f})")
paraphrase-mpnet-base-v2@misc{reddit-sentiment-hybrid,
title={Reddit Sentiment Analysis - Hybrid Model},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/USERNAME/sentimental_analysis_updated}
}
MIT License