ConvLab / ConvLab-3

Apache License 2.0
108 stars 31 forks source link

ValueError: too many values to unpack (expected 4) #195

Open nomawni opened 7 months ago

nomawni commented 7 months ago

Hi, I am facing the following error: ValueError: too many values to unpack (expected 4), while trying to simulate and generate dialogues between the user and the system:

To replicate the error, here is the code that I am using:

user_nlu = BERTNLU()
user_dst = RuleDST()
user_policy = RulePolicy(character='usr')
user_nlg = TemplateNLG(is_user=True)
user_agent = PipelineAgent(user_nlu, user_dst, user_policy, user_nlg, name='user')

sys_nlu = BERTNLU()
sys_nlg = TemplateNLG(is_user=False)
sys_dst = RuleDST()
policy_sys = PPO(is_train=True, seed=conf['model']['seed'],
vectorizer=conf['vectorizer_sys_activated'])
sys_policy = PPO(is_train=True, seed=0, dataset_name='multiwoz21')
sys_agent = PipelineAgent(sys_nlu, sys_dst, policy_sys, sys_nlg, name="sys")

evaluator = MultiWozEvaluator()
session = BiSession(sys_agent, user_agent, kb_query=None, evaluator=evaluator)
simulator = PipelineAgent(user_nlu, user_dst, user_policy, user_nlg, name='user')
env = Environment(sys_nlg, simulator, sys_nlu, sys_dst, evaluator=evaluator)

def set_seed(r_seed):
random.seed(r_seed)
np.random.seed(r_seed)
torch.manual_seed(r_seed)

set_seed(20200131)

num_dialogues = 30
dialog_data = []

sys_response = ''
success_threshold = 0
success_labels = []

for i in range(num_dialogues):
session.init_session()
dialog = []
session_over = False
cumulative_reward = 0
print(f"Turn round {i}")
print()
while not session_over:
response = session.next_turn(sys_response)
system_response, user_response, session_over, reward = response
dialog.append((system_response, user_response))
cumulative_reward += reward
print(f"User: {user_response}")
print(f"System: {system_response}")
print(f" Reward: {reward}")
print()
success_label = determine_success(cumulative_reward, success_threshold)
dialog_data.append((dialog, success_label))

success = session.evaluator.task_success()
success_labels.append(success)

Here is the full error that I am getting after running executing the code:

ValueError Traceback (most recent call last)
Cell In[24], line 13
11 print()
12 while not session_over:
---> 13 response = session.next_turn(sys_response)
14 system_response, user_response, session_over, reward = response
15 dialog.append((system_response, user_response))

File c:\users\convlab-3\convlab\dialog_agent\session.py:122, in BiSession.next_turn(self, last_observation)
100 def next_turn(self, last_observation):
101 """Conduct a new turn of dialog, which consists of the system response and user response.
102
103 The variable type of responses can be either 1) str or 2) dialog act, depends on the dialog mode settings of the
(...)
120 The reward given by the user.
121 """
--> 122 user_response = self.next_response(last_observation)
123 if self.evaluator:
124 self.evaluator.add_sys_da(self.user_agent.get_in_da_eval(), self.sys_agent.dst.state['belief_state'])

File c:\users\convlab-3\convlab\dialog_agent\session.py:96, in BiSession.next_response(self, observation)
94 def next_response(self, observation):
95 next_agent = self.next_agent()
---> 96 response = next_agent.response(observation)
...
29 new_acts['categorical'].append(
30 {"intent": intent, "domain": domain, "slot": slot, "value": value})
31 return new_acts

ValueError: too many values to unpack (expected 4)
Ahmed-Mahmod-Salem commented 7 months ago

hello you can print the response and see what it returns, I think this is due to some refactoring issue in this repo, I am facing a lot of similar issues myself with this refactoring and lack of proper support for unified data format, if that doesn't work please contact me directly maybe I can help you sort out this error.

nomawni commented 7 months ago

@Ahmed-Mahmod-Salem thanks. I have printed the error. But the it is throwing the error in this line: _response = session.next_turn(sysresponse). So before getting the response back. Read the text above and look where it indicates line 13.

Ahmed-Mahmod-Salem commented 7 months ago

can you please contact me directly, I may need to have a better look at your code, also, please edit the post and make sure you put code in a code block to make it a little more readable.

nomawni commented 7 months ago

@Ahmed-Mahmod-Salem thanks. I have updated and put the code in a block.