DineshKumar1329 commited on
Commit
476aa0f
·
verified ·
1 Parent(s): 2b82cd7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -21
README.md CHANGED
@@ -19,31 +19,30 @@ The sentiment analysis model is trained using a Support Vector Machine (SVM) cla
19
 
20
  # Usage :
21
 
22
- from huggingface_hub import hf_hub_download
23
- import joblib
24
- from sklearn.preprocessing import LabelEncoder
25
 
26
- model = joblib.load(
27
- hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib")
28
- )
 
29
 
30
- tfidf_vectorizer = joblib.load('/content/vectorizer_model.joblib') # Replace with your path
 
31
 
32
- def clean_text(text):
33
- return text.lower()
 
 
 
 
 
 
34
 
35
- def predict_sentiment(user_input):
36
- """Predicts sentiment for a given user input."""
37
- cleaned_text = clean_text(user_input)
38
- input_matrix = tfidf_vectorizer.transform([cleaned_text])
39
- prediction = model.predict(input_matrix)[0]
40
- if isinstance(model.classes_, LabelEncoder):
41
- prediction = model.classes_.inverse_transform([prediction])[0]
42
- return prediction
43
-
44
- user_input = input("Enter a sentence: ")
45
- predicted_sentiment = predict_sentiment(user_input)
46
- print(f"Predicted Sentiment: {predicted_sentiment}")
47
 
48
 
49
 
 
19
 
20
  # Usage :
21
 
22
+ from huggingface_hub import hf_hub_download
23
+ import joblib
24
+ from sklearn.preprocessing import LabelEncoder
25
 
26
+ model = joblib.load(
27
+ hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib")
28
+ )
29
+ tfidf_vectorizer = joblib.load('/content/vectorizer_model.joblib') # Replace with your path
30
 
31
+ def clean_text(text):
32
+ return text.lower()
33
 
34
+ def predict_sentiment(user_input):
35
+ """Predicts sentiment for a given user input."""
36
+ cleaned_text = clean_text(user_input)
37
+ input_matrix = tfidf_vectorizer.transform([cleaned_text])
38
+ prediction = model.predict(input_matrix)[0]
39
+ if isinstance(model.classes_, LabelEncoder):
40
+ prediction = model.classes_.inverse_transform([prediction])[0]
41
+ return prediction
42
 
43
+ user_input = input("Enter a sentence: ")
44
+ predicted_sentiment = predict_sentiment(user_input)
45
+ print(f"Predicted Sentiment: {predicted_sentiment}")
 
 
 
 
 
 
 
 
 
46
 
47
 
48