File size: 1,652 Bytes
89c40fe 5b7a180 89c40fe fbff6ba d4b6683 690a3df eef508e de1c173 212e319 de1c173 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
---
license: mit
language:
- en
metrics:
- accuracy
library_name: sklearn
pipeline_tag: text-classification
tags:
- code
---
## Model Training
The sentiment analysis model is trained using a Support Vector Machine (SVM) classifier with a linear kernel. The cleaned text data is transformed into a bag-of-words representation using the CountVectorizer. The trained model is saved as `Sentiment_classifier_model.joblib`, and the corresponding TF-IDF vectorizer is saved as `vectorizer_model.joblib`.
# Download the Vectorizer model first and load the model :
# Usage :
```python
from huggingface_hub import hf_hub_download
import joblib
from sklearn.preprocessing import LabelEncoder
# Download and load the sentiment analysis model from Hugging Face Model Hub
model = joblib.load(hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib"))
# Load the TF-IDF vectorizer
tfidf_vectorizer = joblib.load(hf_hub_download("DineshKumar1329/Sentiment_Analysis", "vectorizer_model.joblib"))
def clean_text(text):
return text.lower()
def predict_sentiment(user_input):
"""Predicts sentiment for a given user input."""
cleaned_text = clean_text(user_input)
input_matrix = tfidf_vectorizer.transform([cleaned_text])
prediction = model.predict(input_matrix)[0]
if isinstance(model.classes_, LabelEncoder):
prediction = model.classes_.inverse_transform([prediction])[0]
return prediction
# Get user input
user_input = input("Enter a sentence: ")
# Predict sentiment
predicted_sentiment = predict_sentiment(user_input)
# Output the prediction
print(f"Predicted Sentiment: {predicted_sentiment}")
|