def extract_unknown_actions_with_log_probs()

in agent/affordance_extractors/lm_affordance_extractor.py [0:0]


    def extract_unknown_actions_with_log_probs(self, entity_text):
        if entity_text in self.cached_unknown_actions.keys():
            return self.cached_unknown_actions[entity_text]

        noun_log_prob = self.get_joint_log_prob(self.forward_model, entity_text, 5)
        verbose = False
        commands = {}
        num_commands = 0
        tie_breaker = 0.00000001

        for action_text in self.filtered_action_list:
            verb_noun_phrase = action_text + ' ' + entity_text
            joint_log_prob = self.get_joint_log_prob(self.forward_model, verb_noun_phrase, 5)
            joint_log_prob -= noun_log_prob  # Make the prob conditional on the noun.
            if not action_text in commands:
                commands[action_text] = joint_log_prob + num_commands * tie_breaker
                num_commands += 1
                if verbose:
                    print("{:8.3f}  Command  {}    {}    {}".format(joint_log_prob, forward_string.rjust(30), tags, verb_noun_phrase))

        sorted_commands = sorted(commands, key=commands.get, reverse=True)
        scored_commands = []
        for command in sorted_commands[:self.num_commands_to_return]:
            scored_commands.append((command, commands[command]))

        self.cached_unknown_actions[entity_text] = scored_commands
        return scored_commands