parlai/tasks/light_dialog/builder.py [16:86]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def use_feat(opt, field, ttype):
    if 'all' in opt.get(field) or opt.get(field) == ttype:
        return True
    else:
        return False


mx = 0


def fix_labels(act, opt):
    labels = act.get('labels', act.get('eval_labels'))
    clip = int(opt.get('light_use_clip_cands', 1000))
    while len(act['label_candidates']) >= clip:
        act['label_candidates'].pop()
    is_label_cand = {}
    is_label_cand[labels] = False
    for c in act['label_candidates']:
        if c in is_label_cand:
            is_label_cand[c] = True
    for l, has in is_label_cand.items():
        if has is False:
            print("***ADDING A LABEL CAND****")
            act['label_candidates'].append(l)


def get_no_affordance_actions(in_room, carrying, other_carrying, other_name):
    all_actions = []
    # Drop "a" prefix from all
    in_room = [i[2:] for i in in_room]
    carrying = [i[2:] for i in carrying]
    other_carrying = [i[2:] for i in other_carrying]
    for obj in other_carrying:
        all_actions.append('steal {} from {}'.format(obj, other_name))
    for obj in in_room:
        all_actions.append('get {}'.format(obj))
    for obj in carrying:
        for f in ['drop {}', 'wield {}', 'wear {}', 'remove {}', 'eat {}', 'drink {}']:
            all_actions.append(f.format(obj))
        all_actions.append('give {} to {}'.format(obj, other_name))
        for obj2 in in_room:
            all_actions.append('put {} in {}'.format(obj, obj2))
        for obj2 in carrying:
            if obj2 == obj:
                continue
            all_actions.append('put {} in {}'.format(obj, obj2))
    return list(set(all_actions))


def gen_no_affordance_actions_for_dialogue(d):
    characters = [d['agents'][0]['name'], d['agents'][1]['name']]
    other_char = 1
    no_affordance_actions = []
    last_carry = []
    for idx in range(len(d['speech'])):
        char = characters[other_char]
        curr_carry = d['carrying'][idx] + d['wearing'][idx] + d['wielding'][idx]
        no_affordance_actions_turn = get_no_affordance_actions(
            d['room_objects'][idx], curr_carry, last_carry, char
        )
        no_affordance_actions_turn += d['available_actions'][idx]
        no_affordance_actions.append(list(set(no_affordance_actions_turn)))
        last_carry = curr_carry
        other_char = 1 - other_char
    d['no_affordance_actions'] = no_affordance_actions


def write_dialog(opt, fw, d, label_type, split):
    l = len(d['speech'])
    msgs = []
    text = ''
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



parlai/tasks/light_dialog_wild/builder.py [131:201]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def use_feat(opt, field, ttype):
    if 'all' in opt.get(field) or opt.get(field) == ttype:
        return True
    else:
        return False


mx = 0


def fix_labels(act, opt):
    labels = act.get('labels', act.get('eval_labels'))
    clip = int(opt.get('light_use_clip_cands', 1000))
    while len(act['label_candidates']) >= clip:
        act['label_candidates'].pop()
    is_label_cand = {}
    is_label_cand[labels] = False
    for c in act['label_candidates']:
        if c in is_label_cand:
            is_label_cand[c] = True
    for l, has in is_label_cand.items():
        if has is False:
            print("***ADDING A LABEL CAND****")
            act['label_candidates'].append(l)


def get_no_affordance_actions(in_room, carrying, other_carrying, other_name):
    all_actions = []
    # Drop "a" prefix from all
    in_room = [i[2:] for i in in_room]
    carrying = [i[2:] for i in carrying]
    other_carrying = [i[2:] for i in other_carrying]
    for obj in other_carrying:
        all_actions.append('steal {} from {}'.format(obj, other_name))
    for obj in in_room:
        all_actions.append('get {}'.format(obj))
    for obj in carrying:
        for f in ['drop {}', 'wield {}', 'wear {}', 'remove {}', 'eat {}', 'drink {}']:
            all_actions.append(f.format(obj))
        all_actions.append('give {} to {}'.format(obj, other_name))
        for obj2 in in_room:
            all_actions.append('put {} in {}'.format(obj, obj2))
        for obj2 in carrying:
            if obj2 == obj:
                continue
            all_actions.append('put {} in {}'.format(obj, obj2))
    return list(set(all_actions))


def gen_no_affordance_actions_for_dialogue(d):
    characters = [d['agents'][0]['name'], d['agents'][1]['name']]
    other_char = 1
    no_affordance_actions = []
    last_carry = []
    for idx in range(len(d['speech'])):
        char = characters[other_char]
        curr_carry = d['carrying'][idx] + d['wearing'][idx] + d['wielding'][idx]
        no_affordance_actions_turn = get_no_affordance_actions(
            d['room_objects'][idx], curr_carry, last_carry, char
        )
        no_affordance_actions_turn += d['available_actions'][idx]
        no_affordance_actions.append(list(set(no_affordance_actions_turn)))
        last_carry = curr_carry
        other_char = 1 - other_char
    d['no_affordance_actions'] = no_affordance_actions


def write_dialog(opt, fw, d, label_type, split):
    l = len(d['speech'])
    msgs = []
    text = ''
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



