Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a question about interact_strat #12

Closed
jeesoobang opened this issue Jun 7, 2022 · 3 comments
Closed

a question about interact_strat #12

jeesoobang opened this issue Jun 7, 2022 · 3 comments

Comments

@jeesoobang
Copy link

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 run interact_strat.sh.
However, I get errors in inputters/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'

@jeesoobang
Copy link
Author

according to #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
    })
    

@jeesoobang
Copy link
Author

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

@jeesoobang jeesoobang reopened this Jun 7, 2022
@chujiezheng
Copy link
Member

  1. This line should not be modified (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).
  2. See this line, we apply the strategy sampling to diversify the strategy selection. It also reduces the influence of strategy imbalance in training data (the Question one occupies the most part), which also illustrates why encoded_info['pred_strat_id_top3'].tolist()[0][0] is always 0.
  3. As a solution, you should use strat_id_out = encoded_info['pred_strat_id'][0] to get the used strategy.

youralien added a commit to youralien/Emotional-Support-Conversation that referenced this issue Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants