alistairmcleay commited on
Commit
81278c2
1 Parent(s): 57d41b7

Handle belief state values longer than 1 token

Browse files
scripts/UBAR_code/interaction/UBAR_interact.py CHANGED
@@ -127,11 +127,26 @@ class UbarSystemModel: # may inherit convlab or not, just like andy's
127
  # in the belief state and then if there is a match adding the next token.
128
  # This is not perfect as some are more than one word but its probably good enough.
129
  if not db_success:
 
 
 
 
130
  decoded_belief_states = decoded_belief_state_subseq.split()
131
  for idx, belief_state_slot in enumerate(decoded_belief_states):
132
  if token in slots_to_db_keys_map.keys():
133
  if slots_to_db_keys_map[token] == belief_state_slot:
134
- token = decoded_belief_states[idx + 1]
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  # Otherwise just leave the slot as it is as we have failed to fill it
137
 
 
127
  # in the belief state and then if there is a match adding the next token.
128
  # This is not perfect as some are more than one word but its probably good enough.
129
  if not db_success:
130
+ # The DB doesn't contain a postcode for the police station so fill it here
131
+ if token == "[value_postcode]" and self.turn_domain == ["police"]:
132
+ token = "CB11QD"
133
+ continue
134
  decoded_belief_states = decoded_belief_state_subseq.split()
135
  for idx, belief_state_slot in enumerate(decoded_belief_states):
136
  if token in slots_to_db_keys_map.keys():
137
  if slots_to_db_keys_map[token] == belief_state_slot:
138
+ curr_slot_resp = ""
139
+ # We dont know the length of the value we need to extract from the belief state
140
+ for belief_state_token in decoded_belief_states[idx + 1 :]:
141
+ if (
142
+ belief_state_token not in slots_to_db_keys_map.values()
143
+ and belief_state_token != "<eos_b>"
144
+ ):
145
+ curr_slot_resp += belief_state_token + " "
146
+ else:
147
+ break
148
+ token = curr_slot_resp[:-1]
149
+ continue
150
 
151
  # Otherwise just leave the slot as it is as we have failed to fill it
152