Skip to content

Instantly share code, notes, and snippets.

@yaronv
Created November 26, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronv/22b9d2b85d1146f1ad0620e95c8aeb6b to your computer and use it in GitHub Desktop.
Save yaronv/22b9d2b85d1146f1ad0620e95c8aeb6b to your computer and use it in GitHub Desktop.
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