Created
November 26, 2018 13:38
-
-
Save yaronv/22b9d2b85d1146f1ad0620e95c8aeb6b to your computer and use it in GitHub Desktop.
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
from colorama import Fore | |
from IPython.display import clear_output | |
from IPython.display import display | |
from ipywidgets import Output | |
def chatbot(): | |
quit=False | |
responses = [] | |
while quit == False: | |
text = str(input('Message: ')) | |
if text == 'quit()': | |
quit=True | |
else: | |
tokens = text.split() | |
##infer vector for text the model may not have seen | |
new_vector = doc2vec_model.infer_vector(tokens) | |
##find the most similar [i] tags | |
index = doc2vec_model.docvecs.most_similar([new_vector], topn = 10) | |
response = Fore.RED + 'Chatbot: ' + train_data.iloc[int(index[0][0])].response | |
responses.append(response) | |
out = Output() | |
display(out) | |
with out: | |
clear_output() | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment