O'Reilly logo

Hands-On Natural Language Processing with Python by Rajalingappaa Shanmugamani, Rajesh Arumugam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interacting with the chatbot

Finally, we can interact with our chatbot by following the framework described in the previous sections. After each user utterance, we ask the memory network to predict a response based on the conversation history and the utterance. Then, the utterance and response are appended to the conversation history and we can enter an utterance once again:

    def interactive_mode(self):        facts = []        utterance = None        response = None        turn_count = 1        while True:            line = input("==> ").strip().lower()            if line == "exit":                break            if line == "restart":                facts = []                turn_count = 1                print("Restarting dialog...\n")                continue            utterance = tokenize(line)            data = [(facts, utterance, -1)]            # Vectorize data and make prediction f, q, a = vectorize_data(data, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required