facebookresearch / ParlAI

A framework for training and evaluating AI models on a variety of openly available dialogue datasets.
https://parl.ai
MIT License
10.49k stars 2.09k forks source link

How to get a model with a specific persona? #928

Closed xiaokc closed 6 years ago

xiaokc commented 6 years ago

Hey guys, thanks for your work!

I read your paper Personalizing Dialogue Agents: I have a dog, do you have pets too? It's great, and I download this project, there is script _projects/personachat/scripts/kvmemnninteractive.py that I can interact with a pre-trained model, but in this script, the doc string contains a note: no persona in this example code is actually given to the model , so please tell me how to get a model with a specific or a configurable persona? I want to get a model with consistent personality, which personality I can specify.

Could you please help me? Thanks very much!

ar-ms commented 6 years ago

you can try:

your persona: I like to ski\nyour persona: My wife does not like me anymore\nyour persona: I have went to Mexico 4 times this year\nyour persona: I hate Mexican food\nyour persona: I like to eat cheetos\nGood choice. Do you watch Game of Thrones?

Don't replace the '\n' by carriage return, copy/paste as it is, it should be a single line. You can replace "Good choice. Do you watch Game of Thrones?" by any sentence. But, the answers are different for the same input..

By doing this, the persona should be added to the oberversation dict in observe function after it called maintain_dialog_history.

alexholdenmiller commented 6 years ago

@ar-ms is exactly right, you can write whatever you want at the beginning with "your persona:{}\n" for a number of personas and then talk to the model from there. keep in mind that if you don't pull a persona from the dataset (which you can see by running e.g. python ~/ParlAI/examples/display_data.py -t personachat -n 100) it might be out-of-vocabulary for the model.

xiaokc commented 6 years ago

@ar-ms @alexholdenmiller Thanks for your replys! @ar-ms Sorry, I still have two questions.

  1. I thought the first four sentences which start with "your persona" are configured for dialogue agent' persona, but I don't understand the role of last sentence. Can you explain it in detail?
  2. I add this line in kvmemnn.py in observe function after it called maintain_dialoghistory obs['text'] = "your persona: My name is Cristinao\nyour persona: My wife does not like me anymore\nyour persona: I have went to Mexico 4 times this year\nyour persona: I hate Mexican food\nyour persona: I like to eat cheetos\nGood choice. Do you watch Game of Thrones?"_ and then, I run kvememnn_train.sh to train a new model, after the end of training, I run kvememnn_interactive.py, however, It doesn't has a consistent profile, for example, when I type "What's your name?", it cannot answer "My name is Cristinao" which I configured in kvmemnn.py.

Maybe my understanding is wrong, what I want to do is configure some attributes for this dialogue agent, I want to specify some fixed attribute, such as name, age, gender, etc, when I ask a question about these attributes, it will give me a consistent answer no matter how many times I ask. I don't know how to implement it, could you please help me? Thank you very much!!

alexholdenmiller commented 6 years ago

1) you can check out my explanation in issue 932 here for more detail, but the personas are given to the agent first followed by the message sent by the conversation partner.

2) that step actually will teach the model to never say its name is Cristinao, because the model is being trained to say everything else in the dataset (e.g. not "My name is Cristinao") given the persona "My name is Cristinao...".

If you want to guarantee the model to say those things, you need to hardcode those responses in the model. If you just want to make it a very high likelihood of saying those specific things, you'll probably need to generate your own (possibly synthetic) dataset and further train the model on that.

The personachat dataset was not built to teach a model to provide perfectly consistent responses in a conversational setting, and I don't think it is large enough to train the kvmemnn model from our team to the level of precision you are asking for. Although maybe a more suitable model exists--if you find it, would love if you contributed it to the ParlAI repo! :)

xiaokc commented 6 years ago

Thank you so much!! And I checked out issue 932, it's great. Now, I think I understand this persona data set. Thanks again. :)

ar-ms commented 6 years ago

Sorry, perhaps my explanations mislead you, the following line should be given to the interactive.py script. your persona: I like to ski\nyour persona: My wife does not like me anymore\nyour persona: I have went to Mexico 4 times this year\nyour persona: I hate Mexican food\nyour persona: I like to eat cheetos\nGood choice. Do you watch Game of Thrones?

Each time you want to interact with the trained model, you should precise the persona, it can be any persona fron the trainning set. Followed by a sentence which correspond to the utterance you want to send to the model.

In our example, we give the following persona to the model:

your persona: I like to ski
your persona: My wife does not like me anymore
your persona: I have went to Mexico 4 times this year
your persona: I hate Mexican food\nyour persona: I like to eat cheetos

And we ask the following question to the previously given persona: Good choice. Do you watch Game of Thrones?

If you want to implement a model with a specific persona, you can follow the directions given by @alexholdenmiller :) !

You might also be interested by the following paper: Assigning Personality/Profile to a Chatting Machine for Coherent Conversation Generation Qiao Qian, Minlie Huang, Haizhou Zhao, Jingfang Xu, Xiaoyan Zhu http://coai.cs.tsinghua.edu.cn/hml/media/files/2018_IJCAI_Profile_-3.pdf

xiaokc commented 6 years ago

@ar-ms Yes, thanks so much! I will read this paper. :) 👍 But wait, actually, I just want to run _kvememnninteractive.py, there is line in this script:

Interact with pre-trained model
Key-Value Memory Net model trained on personachat using persona 'self'
[Note: no persona in this example code is actually given to the model.]

Sorry, I am confused by these scripts and persona message usage :( Do you know how to give a persona message to this script? Thank you!!

alexholdenmiller commented 6 years ago

Yes @ar-ms's instructions are exactly for this: when you run the interactive script, you start talking to the pretrained model. You can "give it a persona" by telling it a persona during your conversation. That is, the first thing you say to it is "your persona:......\n", etc. This tells the model that it has that persona.

alexholdenmiller commented 6 years ago

For example:

python ~/ParlAI/projects/personachat/scripts/kvmemnn_interactive.py
...
[ Interactive mode ]
Enter Your Message: your persona: you like pizza. \n what is your favorite food?
pizza . what is your favorite food ?

I tell the model its persona is to like pizza and ask it what it's favorite food is, it replies that it likes pizza and asks me what my favorite food is.

xiaokc commented 6 years ago

Yes, I have tried, the results are the same as you said. Thank you so much!!