Exemplo n.º 1
0
    def state_vectorize(self, state):
        """vectorize a state

        Args:
            state (tuple):
                Dialog state
            action (tuple):
                Dialog act
        Returns:
            state_vec (np.array):
                Dialog state vector
        """
        self.state = state['belief_state']

        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.

        inform = np.zeros(self.inform_dim)
        for domain in self.belief_domains:
            for slot, value in state['belief_state'][
                    domain.lower()]['semi'].items():
                dom_slot, p = domain + '-' + REF_USR_DA[domain][slot] + '-', 1
                key = dom_slot + str(p)
                while inform[self.inform2vec[key]]:
                    p += 1
                    key = dom_slot + str(p)
                    if key not in self.inform2vec:
                        break
                else:
                    inform[self.inform2vec[key]] = 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['terminal'] else 0.

        state_vec = np.r_[opp_act_vec, last_act_vec, inform, book, degree,
                          final]
        return state_vec
Exemplo n.º 2
0
    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']

        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
Exemplo n.º 3
0
 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