Closed jeesoobang closed 1 year ago
according to https://github.com/thu-coai/Emotional-Support-Conversation/issues/11
I solved the problem.
in interact.py
added the code snippets
id2strategy = {
0: "Question",
1: "Restatement or Paraphrasing",
2: "Reflection of feelings",
3: "Self-disclosure",
4: "Affirmation and Reassurance",
5: "Providing Suggestions",
6: "Information",
7: "Others"
}
...
# generate response
history['dialog'].append({ # dummy tgt
'text': 'n/a',
'speaker': 'sys',
'strategy': 'Others'
})
inputs = inputter.convert_data_to_inputs(history, toker, **dataloader_kwargs)
inputs = inputs[-1:]
features = inputter.convert_inputs_to_features(inputs, toker, **dataloader_kwargs)
batch = inputter.prepare_infer_batch(features, toker, interact=True)
batch = {k: v.to(device) if isinstance(v, Tensor) else v for k, v in batch.items()}
batch.update(generation_kwargs)
encoded_info, generations = model.generate(**batch)
# out = generations[0].tolist()
# out = cut_seq_to_eos(out, eos)
# text = toker.decode(out).encode('ascii', 'ignore').decode('ascii').strip()
# print(" AI: " + text)
out = generations[0].tolist()
out = cut_seq_to_eos(out, eos)
text = toker.decode(out).encode('ascii', 'ignore').decode('ascii').strip()
strat_id_out = encoded_info['pred_strat_id_top3'].tolist()[0][0] # 取top1 策略id
strategy = id2strategy[strat_id_out]
print(" AI: " + "[" + strategy + "] " + text)
history['dialog'].pop()
history['dialog'].append({
'text': text,
'speaker': 'sys',
'strategy': strategy
})
I have another question,
It seems like the strategy is not changed (it rarely is changed) through the interaction.
I've tried the code in strat_blenderbot_small.py/predict_strategy
modified (logits = logits[:, 0, -8:] -> logits = logits[:, -1, -8:] ),
however, the selected strategy barely changes.
How can I try the interaction with strategy correctly? can you give me some guides?
Below is the interaction examples: the selected strategy is not aligned to its generated response.
A new conversation starts! Human: Hi there. I feel sadness because my friend has a drinking problem. AI: [Question] so he is having a drinking problem. <-- This is not a question Human: I think he just got used to drink every day and I can't pursue him to stop at least for a week. AI: [Question] i am sorry to hear that. would you be willing to give him some time to get his problem out of your mind? Human: Well he is working from home. So he is drinking almost 24/7. I feel so exhausted as well. AI: [Question] i know that it can be very hard to keep someone who has a drinking problem from being able to get help for themselves. it can feel like he is not trying very hard. <-- This is not a question
A new conversation starts! Human: Hi there. I feel sadness because my friend has a drinking problem. AI: [Question] oh, i am sorry to hear that. is he drinking? Human: I think he just got used to drink every day and I can't pursue him to stop at least for a week. AI: [Question] do you think that would make you feel better about the situation? Human: Well he is working from home. So he is drinking almost 24/7. I feel so exhausted as well. AI: [Question] i can understand how you feel. it must be very difficult to be in such a situation. <-- This is not a question Human: I just need a way to make him stop drinking. Maybe I should stop any communication with him for a while? AI: [Question] have you tried speaking to him about it? Human: Yes, I have. I feel such a sadness inside me. I am trying to help him but he won't listen. AI: [Question] i have also been in a similar situation. i would try to speak to him about it and try to keep in touch with him. <-- This is not a question
logits = logits[:, 0, -8:]
) for training, since it takes the output of <bos>
for predicting the strategy token. However, it does not affect inference (or interaction) since the target input is only <bos>
(and the strategy token and response are to be generated).encoded_info['pred_strat_id_top3'].tolist()[0][0]
is always 0
.strat_id_out = encoded_info['pred_strat_id'][0]
to get the used strategy.
Hi! Great work! I wanted to interact with the bot with strategy, so I trained the model following
train_strat.sh
. then I wanted to interact with the trained model and runinteract_strat.sh
. However, I get errors ininputters/strat.py
How could I solve the problem?/workspace/Dialogue/Emotional-Support-Conversation/codes_zcj# bash RUN/interact_strat.sh 06/07/2022 00:58:18 - INFO - utils.building_utils - loading finetuned model from /workspace/Dialogue/Emotional-Support-Conversation/codes_zcj/DATA/strat.strat/2022-06-07004140.3e-05.16.1gpu/epoch-1.bin 06/07/2022 00:58:19 - INFO - utils.building_utils - deploying model...
A new conversation starts! Human: Hi! Traceback (most recent call last): File "interact.py", line 168, in
inputs = inputter.convert_data_to_inputs(history, toker, **dataloader_kwargs)
File "/workspace/Dialogue/Emotional-Support-Conversation/codes_zcj/inputters/strat.py", line 87, in convert_data_to_inputs
strat_id = process('[' + dialog[i]['strategy'] + ']')
KeyError: 'strategy'