Sentiment Analysis (Random Forest + Bag of Words)

This model classifies text into emotional sentiment categories using a RandomForestClassifier and NLTK text lemmatization.

Usage

import joblib
import re
import nltk
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
from huggingface_hub import hf_hub_download

# Download dependencies
nltk.download('stopwords')
nltk.download('wordnet')

# Download model artifacts
repo_id = "Ttt37/sentiment-analysis-rf"
model_path = hf_hub_download(repo_id=repo_id, filename="sentiment_model.pkl")
vectorizer_path = hf_hub_download(repo_id=repo_id, filename="vectorizer.pkl")

# Load model and vectorizer
model = joblib.load(model_path)
cv = joblib.load(vectorizer_path)

# Text preprocessor
lemmatizer = WordNetLemmatizer()
stop_words = set(stopwords.words('english'))

def preprocess(text):
    review = re.sub('[^a-zA-Z]', ' ', text).lower().split()
    review = [lemmatizer.lemmatize(w) for w in review if w not in stop_words]
    return ' '.join(review)

# Inference
text = "I am feeling really happy today!"
cleaned = preprocess(text)
features = cv.transform([cleaned])
prediction = model.predict(features)

print("Predicted Sentiment:", prediction[0])
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support