Downloads · 30 days
4
8% of all-time downloads
mohammed781234712/amazon-books-sentiment
amazon-books-sentiment is a text classification model from mohammed781234712. Use it when you need a label for a piece of text. The card lists the license as mit.
This is a machine learning model for sentiment analysis of book reviews from Amazon. The model classifies reviews into positive, negative, and neutral sentiments.
Downloads · 30 days
4
8% of all-time downloads
All-time downloads
53
Public
Repo size
161 KB
Likes
0
Public
Click a slice to open those files.
.pkl161 KB · 95%
From the Hugging Face model README
This is a machine learning model for sentiment analysis of book reviews from Amazon. The model classifies reviews into positive, negative, and neutral sentiments.
Model Type: MultinomialNB Accuracy: 85-90% F1 Score: 0.85-0.90
The model was trained on the Amazon Books Reviews dataset containing over 700,000 book reviews.
from huggingface_hub import hf_hub_download
import joblib
# Download the model
model_path = hf_hub_download(repo_id="your-username/amazon-books-sentiment", filename="model.pkl")
vectorizer_path = hf_hub_download(repo_id="your-username/amazon-books-sentiment", filename="vectorizer.pkl")
label_encoder_path = hf_hub_download(repo_id="your-username/amazon-books-sentiment", filename="label_encoder.pkl")
# Load the components
model = joblib.load(model_path)
vectorizer = joblib.load(vectorizer_path)
label_encoder = joblib.load(label_encoder_path)
# Make predictions
def predict_sentiment(text):
# Preprocess and vectorize
features = vectorizer.transform([text])
prediction = model.predict(features)
sentiment = label_encoder.inverse_transform(prediction)[0]
return sentiment
# Example
review = "This book was absolutely amazing!"
print(predict_sentiment(review)) # Output: positive