Ejemplo n.º 1
0
def post_process_act(das):
    #return das
    das = das[0]
    #print 'in das:', das
    #import pdb
    da_des = get_dialogue_act_metadata(das)
    #FILTER from/to borough out of user act if this turn doesn' include from/to street, stop and also keep inform borough with prob. of 0.5
    if 'inform' in da_des and 'from_borough' in da_des['inform']['slots'] and len(da_des['inform']['slots'])>1:
        lst = matlab.subtract(['from_stop'], da_des['inform']['slots'])
        prob = 0.7
        if len(lst)<1:
            prob=0.3
        if is_only_borough(da_des):
            prob = 0.0
        if sample_a_prob(prob):
            das.dais.remove('inform(from_borough="' + da_des['inform']['slot_value']['from_borough'] + '")')
            print 'remove from_borough'
            #pdb.set_trace()

    if 'inform' in da_des and 'to_borough' in da_des['inform']['slots'] and len(da_des['inform']['slots'])>1:
        lst = matlab.subtract(['to_stop'], da_des['inform']['slots'])
        prob = 0.7#70% remove borough from inform
        if len(lst)<1:#has to_stop, remove with 30%
            prob=0.3
        if is_only_borough(da_des):#only borough don't remove
            prob = 0.0
        if sample_a_prob(prob):
            das.dais.remove('inform(to_borough="' + da_des['inform']['slot_value']['to_borough'] + '")')
            print 'remove to_borough'
            #pdb.set_trace()

    return [das]
Ejemplo n.º 2
0
    def _get_answer_da(self, da_in):
        '''Answer a sytem dialogue act.'''
        da_out = DialogueAct()
        out_of_patience=False

        reply_sys_acts = self.metadata['reply_system_acts']
        da_metadata = self._get_dialogue_act_metadata(da_in)
        for act_in in da_metadata.keys():
            #debug_print('------Handling the sys_act' +  act_in)
            #print '------Handling the sys_act', act_in
            reply = reply_sys_acts[act_in]
            if isinstance(reply, dict):#this action has different definition for different goal
                reply = reply[self.goal_id]
            answer = self._sample_element_from_list_dict(reply)
            if 'ordered_return_acts' in answer:#process list of answer in order, and stop for first appliable
                for solution in answer['ordered_return_acts']:
                    case = self._sample_element_from_list_dict(solution)
                    da_items = self._build_one_answer(da_metadata[act_in], case, True)
                    if len(da_items)>0:
                        answer = case# for filtering acts with add_to_da_prob propertiy
                        break
            else:
                da_items = self._build_one_answer(da_metadata[act_in], answer)
                
            for item in da_items:#process action can be whether add to da_out or not like impl_confirmi
                act_out_des = self._get_act_out_description(item.dat, answer)
                if 'add_to_da_prob' in act_out_des.keys():
                    if sample_a_prob(act_out_des['add_to_da_prob']) and item not in da_out:
                        da_out.append(item)
                else:
                    if item not in da_out:
                        da_out.append(item)
                #-------update patience history
                if item.name is not None:#have slot, the sys act ask repeated the sema slot anserd, ignore the case of over answer
                    if act_in not in self.patience_history.keys():
                        self.patience_history[act_in] = {}
                    if item.name not in self.patience_history[act_in]:
                        self.patience_history[act_in][item.name]=1
                    else:
                        self.patience_history[act_in][item.name]+=1
                        if self.patience_level>=1 and self.patience_history[act_in][item.name]>self.patience_level:
                            out_of_patience = True
                            break#only break the inner loop
            #da_out.extend(da_items)
        if out_of_patience:
            if random.random()>0.5:
                da_out = DialogueAct(self.config['out_of_patience_act'])
                print '!!!!ANGRY...'
            else:
                print '!!Almost ANGRY...'
        return da_out
Ejemplo n.º 3
0
def test_random_dialogues(user):
    metadata = get_metadata()
    for i in range(100):
        print '=======================Dialogue %i============================'%(i+1)
        user.new_dialogue()
        print 'Goal:', user.goal
        print '-'*60
        goal_des = metadata['goals'][user.goal['task']]
        ordered_acts = goal_des['acts']
        slots = goal_des['slots']
        for acts in ordered_acts:
            da = DialogueAct()
            for act in acts.split('&'):
                act_des = metadata['act_definitions'][act]
                slot = None
                if act_des['slot_included']:
                    slot = sample_from_list(slots)
                value = None
                if act_des['value_included']:
                    if slot not in user.goal.keys():
                        for s in get_equivalent_slots(goal_des, slot):
                            if s in user.goal.keys():
                                slot = s
                                break
                    if slot in user.goal.keys():
                        if sample_a_prob(0.5):
                            value = user.goal[slot]
                        else:
                            value = 'lct'
                    else:
                        value = 'lct'

                item = DialogueActItem(act, slot, value)
                da.append(item)
            print 'sys_da:\t\t', da
            user.da_in(da)
            da = user.da_out()
            print 'user_da:\t', da[0]
            if len(da[0])==0:
                raise RuntimeError('User simulator doesnt reply anything!!')
                pdb.set_trace()