Instructions to use 21f1000330/sentiment-analysis-movie-reviews with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use 21f1000330/sentiment-analysis-movie-reviews with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("21f1000330/sentiment-analysis-movie-reviews", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Sentiment Analysis Model for Movie Reviews
This model classifies movie reviews as positive or negative.
Model Details
- Model Type: Logistic Regression with TF-IDF features
- Training Dataset: IMDB Movie Reviews (40,000 training samples)
- Accuracy: ~88.92% on test set
- Vectorizer: TF-IDF with n-grams (1-3)
Usage
from huggingface_hub import hf_hub_download
import joblib
# Download model files
model_path = hf_hub_download(repo_id="21f1000330/sentiment-analysis-movie-reviews", filename="sentiment_model.pkl")
vectorizer_path = hf_hub_download(repo_id="21f1000330/sentiment-analysis-movie-reviews", filename="sentiment_vectorizer.pkl")
# Load model and vectorizer
model = joblib.load(model_path)
vectorizer = joblib.load(vectorizer_path)
# Preprocess text (same as training)
def preprocess_text(text):
from bs4 import BeautifulSoup
import re
text = BeautifulSoup(text, "html.parser").get_text() if text else ""
text = re.sub(r'[^a-zA-Z0-9\s]', '', text) if text else ""
return text.lower().strip()
# Make prediction
text = "This movie was amazing! I loved it."
preprocessed = preprocess_text(text)
text_vector = vectorizer.transform([preprocessed])
prediction = model.predict(text_vector)[0]
sentiment_result = "positive" if prediction == 1 else "negative"
print(f"Sentiment: {sentiment_result}")
Files
sentiment_model.pkl: Trained Logistic Regression classifiersentiment_vectorizer.pkl: TF-IDF vectorizer with vocabulary
Citation
Trained on IMDB Movie Reviews dataset for sentiment classification.
- Downloads last month
- -