|
--- |
|
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`. |
|
|
|
# Model Usage : |
|
|
|
from huggingface_hub import hf_hub_download |
|
import joblib |
|
model = joblib.load( |
|
hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib") |
|
) |
|
# only load pickle files from sources you trust |
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html |
|
|
|
# Load the TF-IDF vectorizer used during training |
|
tfidf_vectorizer = joblib.load('/content/vectorizer_model.joblib') # Replace with your actual filename |
|
|
|
|
|
# Take user input |
|
user_input = input("Enter a sentence: ") |
|
|
|
# Clean the user input |
|
cleaned_input = clean_text(user_input) |
|
|
|
# Transform the cleaned text data using the TF-IDF vectorizer |
|
input_matrix = tfidf_vectorizer.transform([cleaned_input]) |
|
|
|
# Make prediction |
|
prediction = model.predict(input_matrix)[0] |
|
|
|
# Display the prediction |
|
print(f"Predicted Sentiment: {prediction}") |
|
# Create a DataFrame with the results |
|
df_result = pd.DataFrame({'User_Input': [user_input], 'Predicted_Sentiment': [prediction]}) |
|
|
|
# Save the DataFrame to an Excel file (append if the file already exists) |
|
excel_filename = '/content/output_predictions.xlsx' # Replace with your desired filename |
|
try: |
|
# Load existing predictions from the Excel file |
|
df_existing = pd.read_excel(excel_filename) |
|
|
|
# Append the new predictions to the existing DataFrame |
|
df_combined = pd.concat([df_existing, df_result], ignore_index=True) |
|
|
|
except FileNotFoundError: |
|
# If the file doesn't exist, create a new DataFrame |
|
df_combined = df_result |
|
|
|
# Save the combined DataFrame to the Excel file |
|
df_combined.to_excel(excel_filename, index=False) |