def state_vectorize(self, state): """vectorize a state Args: state (dict): Dialog state action (tuple): Dialog act Returns: state_vec (np.array): Dialog state vector """ self.state = state['belief_state'] # when character is sys, to help query database when da is booking-book # update current domain according to user action if self.character == 'sys': action = state['user_action'] for intent, domain, slot, value in action: if domain in self.db_domains: self.cur_domain = domain action = state['user_action'] if self.character == 'sys' else state['system_action'] opp_action = delexicalize_da(action, self.requestable) opp_action = flat_da(opp_action) opp_act_vec = np.zeros(self.da_opp_dim) for da in opp_action: if da in self.opp2vec: opp_act_vec[self.opp2vec[da]] = 1. action = state['system_action'] if self.character == 'sys' else state['user_action'] action = delexicalize_da(action, self.requestable) action = flat_da(action) last_act_vec = np.zeros(self.da_dim) for da in action: if da in self.act2vec: last_act_vec[self.act2vec[da]] = 1. belief_state = np.zeros(self.belief_state_dim) i = 0 for domain in self.belief_domains: for slot, value in state['belief_state'][domain.lower()]['semi'].items(): if value: belief_state[i] = 1. i += 1 book = np.zeros(len(self.db_domains)) for i, domain in enumerate(self.db_domains): if state['belief_state'][domain.lower()]['book']['booked']: book[i] = 1. degree = self.pointer(state['belief_state']) final = 1. if state['terminated'] else 0. state_vec = np.r_[opp_act_vec, last_act_vec, belief_state, book, degree, final] assert len(state_vec) == self.state_dim return state_vec
def action_vectorize(self, action): action = delexicalize_da(action, self.requestable) action = flat_da(action) act_vec = np.zeros(self.da_dim) for da in action: if da in self.act2vec: act_vec[self.act2vec[da]] = 1. return act_vec
def action_vectorize(self, action): action = delexicalize_da(action, self.requestable) action = flat_da(action) act_vec = np.zeros(self.da_dim) if self.composite_actions: composite_action = ';'.join(action) for act in self.act2vec: if set(action) == set(act.split(';')): act_vec[self.act2vec[act]] = 1. break else: for da in action: if da in self.act2vec: act_vec[self.act2vec[da]] = 1. return act_vec