# How can I keep context in my chatbot

I have created a chatbot by Keras based on movie dialog. I used RNN more specifically GRU . My bot can reply well. But the problem is , it can't hold the context . As an example if I say Tell me a joke, the bot will reply something , and then if I say one more , the bot simply doesn't understand that I was asking for another joke and many more similar cases, like if I used a slang against the bot , the bot will reply me with something similar , but if I just say something romantic or good immediately after using slang , the bot will reply to me with something good . I want to keep context or environment . How can I do so . Any lead would be helpful .

• Could you add a little more context about your current model? I would guess it is a seq2seq model that "translates" a phrase input by user into a reply phrase. The behaviour you notice is definitely a limitation of using seq2seq like that. – Neil Slater Jul 25 at 14:49
• Yes u are right , I am using seq2seq . Is there any alternative which can solve my problem ? – Mithun Sarker Shuvro Jul 25 at 16:57
Say we are at timestamp $$t$$ and the two GRUCells are represented as $$GRU_c$$ and $$GRU_s$$ for GRU context network and state network. (Your output coming from the state network)
At time stamp $$t$$ , the input $$GRU_s(t) = concat(input, att(all~GRU_c~from ~[0, ~t-1]))$$ where $$att$$ is an attention mechanism to give importance to specific parts of the conversation uptil that point (This is what maintains context) and input $$GRU_c(t) = learned~representation~of~GRU_s(t)$$ , hence updating $$GRU_c$$ for that timestamp, which along with the historical information can be used for $$GRU_s(t+1)$$