in agent/affordance_extractors/lm_affordance_extractor.py [0:0]
def extract_single_object_actions(self, entity):
if id(entity) in self.cached_extractions:
return self.cached_extractions[id(entity)]
# Collect known actions for the given entity.
noun = entity.name
actions_to_try = []
unknown_actions_to_exclude = {}
for affordable_attribute in self.affordable_attributes:
est_prob = self.estimate_attribute_prob(noun, affordable_attribute.attribute_name)
if est_prob >= affordable_attribute.known_action_extraction_threshold:
for known_action in affordable_attribute.known_actions_to_try:
actions_to_try.append((known_action(entity), est_prob))
for unknown_action in affordable_attribute.unknown_actions_to_exclude:
unknown_actions_to_exclude[unknown_action] = True
# Collect unknown actions for the given entity.
unknown_actions_to_try = self.extract_unknown_actions_with_log_probs(noun)
for a_lp in unknown_actions_to_try:
if a_lp[0] not in self.action_prior_table:
self.action_prior_table[a_lp[0]] = -1. # Needs human review.
for a_lp in unknown_actions_to_try:
prob = self.estimate_unknown_action_prob(a_lp[1])
prob *= max(0., self.action_prior_table[a_lp[0]]) # Treat unreviewed actions (-1) as 0.0
if prob > self.unknown_action_extraction_threshold:
action_text = a_lp[0]
action_minus_the = action_text[:-4]
if action_minus_the not in unknown_actions_to_exclude.keys():
if action_minus_the in self.unknown_actions_to_promote:
target_action = rng.choice(self.unknown_actions_to_promote[action_minus_the])
action_object = target_action(entity)
else:
action_object = action.SingleAction(action_text, entity)
actions_to_try.append((action_object, prob))
# Sort by descending probability of expected value of taking the action.
actions_to_try.sort(key=lambda tup: tup[1], reverse=True)
self.cached_extractions[id(entity)] = actions_to_try
return actions_to_try