-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
blockchain_integration/pi_network/pi_network_university/ml_chatbots/ml_chatbots.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import nltk | ||
from nltk.stem import LancasterStemmer | ||
from sklearn.naive_bayes import MultinomialNB | ||
|
||
# Load chatbot model | ||
chatbot_model = nltk.load('nlp_models/chatbot_model.pkl') | ||
|
||
# Define ML chatbot function | ||
def respond_to_user_input(user_input): | ||
# Preprocess user input | ||
stemmed_input = LancasterStemmer().stem(user_input) | ||
|
||
# Classify user input using chatbot model | ||
classification = chatbot_model.classify(stemmed_input) | ||
|
||
# Return response based on classification | ||
if classification == 'hello': | ||
return 'Hello! How can I assist you today?' | ||
elif classification == 'help': | ||
return 'I\'m here to help. What do you need assistance with?' | ||
else: | ||
return 'I didn\'t understand that. Can you please rephrase?' |