Parlai: Blender - user session for websocket chat_service

Created on 21 May 2020  路  12Comments  路  Source: facebookresearch/ParlAI

Is your feature request related to a problem? Please describe.
It is a must have feature: make a user session consistent when interacting with model (not only Blender, but all models). Now if another user connect from another browser model respond like it continue conversation. How it should be: detect every new user and start new conversation.

Describe the solution you'd like

[I 200521 21:06:07 agents:55] Received new message: {'text': 'begin', 'payload': None, 'sender': {'id': 'a4f1cb74-3567-4e02-b570-b6dd177189ff'}, 'recipient': {'id': 0}}
2020-05-21 21:06:08: Adding agent a4f1cb74-3567-4e02-b570-b6dd177189ff to pool...
onboarding/overworld complete
starting pool
2020-05-21 21:06:08: Removing agent a4f1cb74-3567-4e02-b570-b6dd177189ff from pool...
Starting task t_1...
[I 200521 21:06:08 agents:40] Sending new message: {'id': 'World', 'text': 'Welcome to the ParlAI Chatbot demo. You are now paired with a bot - feel free to send a message.Type [DONE] to finish the chat.'}

In above traceback got from launching a websocket using https://parl.ai/docs/tutorial_chat_service.html#browser is seems that part of solution is here in Message dict:
'sender': {'id': 'a4f1cb74-3567-4e02-b570-b6dd177189ff'}, 'recipient': {'id': 0}

  • here sender is model instance, recipient is user that connected in browser. What i consider is to use these var to create new thread and track every user, for example recipient id can be some username or ip address of session.

Describe alternatives you've considered
description of any alternative solutions or features you've considered: i suggest reimplement browser_chat.py here and operate with model_response dict.

Most helpful comment

Solved

Could you describe how did you achieve this, please? I see the same context, even amongst two different browser sessions across 2 different machines.

All 12 comments

I found that if we print self.model.observe(a) from https://github.com/facebookresearch/ParlAI/blob/master/parlai/chat_service/tasks/chatbot/worlds.py#L77 we get a more detailed dict with additional text_vec with tensor that seems encapsulate dialog history:

{'episode_done': False, 'text': '"yes, i have completed all my work"', 'payload': None, 'full_text': '"hi"\nhello , how are you today ? i \' m having a great day , and i hope you are having a good day .\n"yes, i have completed all my work"', 'text_vec': tensor([  16,  792,   16,    4,  880,    6,  102,   46,   15,  472,   20,   14,
           8,   58,  397,   12,  238,  172,    6,    9,   14,  826,   15,   46,
         397,   12,  123,  172,    5,    4,   16,  142,    6,   14,   49, 1353,
          55,   42,  166,   16])}

If we will be able to make a post request to websocket API with not simple text like
resp = requests.post("http://localhost:35496/interact", json="what is your name?")
but a full dict with text_vec field
and
also if API will return to this request this dict {'id': 'Model', 'episode_done': False, 'text': 'my name is alex'}
with text_vec field - it looks like solution for user sessions ? @stephenroller

Solved

Solved

Could you describe how did you achieve this, please? I see the same context, even amongst two different browser sessions across 2 different machines.

@GraphGrailAi How did you solve this issue? Thank you!

We have a chat service tutorial.

@stephenroller right, and all that works really nicely and is super easy to use, but what I am not clear about is how you would have different human agents talk to the same model but have separate conversations. Like you run one instance of a Blender 90M model while N users can have different chats. Is that done through an extension of MessengerOverworld?

https://github.com/facebookresearch/ParlAI/blob/28df48cd299bedd89440db37d525ab7169c10ce7/parlai/chat_service/tasks/chatbot/worlds.py#L49

In the creation of the task World, we make a copy of the agent with an independent history and state, so different users connecting will have history tracked separately

I see, so in the current example the issue is that there is only a single agent available? namely agents[0]. If we use separate agents would that work?

We use the same method as we use in batching: We make many copies of the agent, each with its own independent dialogue history maintained, but the model weights are shared. It's essentially very manual memory management.

In the code I linked to, a copy of the model is created with the call to create_agent_from_shared. I'm not 100% sure, but I believe agents[0] there actually refers to the human.

Right, I believe you are correct that agents[0] is a human.

I'll have to dig deeper to find out how to have one server run and multiple humans have separate conversations. A clear indicator that the humans are considered the same user or being in the same world is that the second person connecting doesn't get the overworld info about typing begin to start, etc.

@klshuster will you weigh in here when you get a free moment?

In the case of the chatbot demo task, each user is assigned a MessengerBotChatTaskWorld. That is, we create a new world for each person that messages the bot. In this way, the model weights are shared across users, and each world instantiates it's own "copy" of an agent (that maintains dialogue history) as @stephenroller pointed out in this response

agents is just the list of agents in each world, where agents[0] will refer to the human connected to that world, and agents[1] will refer to the world's shared copy of the model

Was this page helpful?
0 / 5 - 0 ratings