in agent/affordance_extractors/lm_affordance_extractor.py [0:0]
def extract_double_object_actions(self, entity1, entity2):
key = (id(entity1), id(entity2))
if key in self.cached_double_object_actions:
return self.cached_double_object_actions[key]
action_prob_dict = {}
num_actions = 0
tie_breaker = 0.00000001
for verb, prep in complex_verbs:
phrase = verb + ' the ' + entity1.name + ' ' + prep + ' the ' + entity2.name
log_prob = self.get_joint_log_prob(self.forward_model, phrase, 5)
num_actions += 1
action_prob_dict[DoubleAction(verb, entity1, prep, entity2)] = log_prob + num_actions * tie_breaker
sorted_actions = sorted(action_prob_dict, key=action_prob_dict.get, reverse=True)
scored_actions = []
for action in sorted_actions:
log_prob = action_prob_dict[action]
prob = 1. / (1. + math.exp(min(20., -(log_prob + self.double_object_action_lp_offset) * self.double_object_action_lp_scale)))
if prob > self.double_object_action_extraction_threshold:
scored_actions.append((action, prob))
self.cached_double_object_actions[key] = scored_actions
return scored_actions