def beam_search(self, speaker):
    '\n        :param speaker: The speaker to be used in searching.\n        :return:\n        {\n            "scan": XXX\n            "instr_id":XXX,\n            "instr_encoding": XXX\n            "dijk_path": [v1, v2, ...., vn]\n            "paths": [{\n                "trajectory": [viewoint_id0, viewpoint_id1, viewpoint_id2, ..., ],\n                "action": [act_1, act_2, ..., ],\n                "listener_scores": [log_prob_act1, log_prob_act2, ..., ],\n                "speaker_scores": [log_prob_word1, log_prob_word2, ..., ],\n            }]\n        }\n        '
    self.env.reset()
    results = self._dijkstra()
    '\n        return from self._dijkstra()\n        [{\n            "scan": XXX\n            "instr_id":XXX,\n            "instr_encoding": XXX\n            "dijk_path": [v1, v2, ...., vn]\n            "paths": [{\n                    "trajectory": [viewoint_id0, viewpoint_id1, viewpoint_id2, ..., ],\n                    "action": [act_1, act_2, ..., ],\n                    "listener_scores": [log_prob_act1, log_prob_act2, ..., ],\n                    "visual_feature": [(f1_step1, f2_step2, ...), (f1_step2, f2_step2, ...)\n            }]\n        }]\n        '
    for result in results:
        lengths = []
        num_paths = len(result['paths'])
        for path in result['paths']:
            assert (len(path['trajectory']) == (len(path['visual_feature']) + 1))
            lengths.append(len(path['visual_feature']))
        max_len = max(lengths)
        img_feats = torch.zeros(num_paths, max_len, 36, (self.feature_size + args.angle_feat_size))
        can_feats = torch.zeros(num_paths, max_len, (self.feature_size + args.angle_feat_size))
        for (j, path) in enumerate(result['paths']):
            for (k, feat) in enumerate(path['visual_feature']):
                (img_feat, can_feat) = feat
                img_feats[j][k] = img_feat
                can_feats[j][k] = can_feat
        (img_feats, can_feats) = (img_feats.cuda(), can_feats.cuda())
        features = ((img_feats, can_feats), lengths)
        insts = np.array([result['instr_encoding'] for _ in range(num_paths)])
        seq_lengths = np.argmax((insts == self.tok.word_to_index['<EOS>']), axis=1)
        insts = torch.from_numpy(insts).cuda()
        speaker_scores = speaker.teacher_forcing(train=True, features=features, insts=insts, for_listener=True)
        for (j, path) in enumerate(result['paths']):
            path.pop('visual_feature')
            path['speaker_scores'] = (- speaker_scores[j].detach().cpu().numpy()[:seq_lengths[j]])
    return results
:param speaker: The speaker to be used in searching.
:return:
{
    "scan": XXX
    "instr_id":XXX,
    "instr_encoding": XXX
    "dijk_path": [v1, v2, ...., vn]
    "paths": [{
        "trajectory": [viewoint_id0, viewpoint_id1, viewpoint_id2, ..., ],
        "action": [act_1, act_2, ..., ],
        "listener_scores": [log_prob_act1, log_prob_act2, ..., ],
        "speaker_scores": [log_prob_word1, log_prob_word2, ..., ],
    }]
}
def beam_search(self, speaker):
    '\n        :param speaker: The speaker to be used in searching.\n        :return:\n        {\n            "scan": XXX\n            "instr_id":XXX,\n            "instr_encoding": XXX\n            "dijk_path": [v1, v2, ...., vn]\n            "paths": [{\n                "trajectory": [viewoint_id0, viewpoint_id1, viewpoint_id2, ..., ],\n                "action": [act_1, act_2, ..., ],\n                "listener_scores": [log_prob_act1, log_prob_act2, ..., ],\n                "speaker_scores": [log_prob_word1, log_prob_word2, ..., ],\n            }]\n        }\n        '
    self.env.reset()
    results = self._dijkstra()
    '\n        return from self._dijkstra()\n        [{\n            "scan": XXX\n            "instr_id":XXX,\n            "instr_encoding": XXX\n            "dijk_path": [v1, v2, ...., vn]\n            "paths": [{\n                    "trajectory": [viewoint_id0, viewpoint_id1, viewpoint_id2, ..., ],\n                    "action": [act_1, act_2, ..., ],\n                    "listener_scores": [log_prob_act1, log_prob_act2, ..., ],\n                    "visual_feature": [(f1_step1, f2_step2, ...), (f1_step2, f2_step2, ...)\n            }]\n        }]\n        '
    for result in results:
        lengths = []
        num_paths = len(result['paths'])
        for path in result['paths']:
            assert (len(path['trajectory']) == (len(path['visual_feature']) + 1))
            lengths.append(len(path['visual_feature']))
        max_len = max(lengths)
        img_feats = torch.zeros(num_paths, max_len, 36, (self.feature_size + args.angle_feat_size))
        can_feats = torch.zeros(num_paths, max_len, (self.feature_size + args.angle_feat_size))
        for (j, path) in enumerate(result['paths']):
            for (k, feat) in enumerate(path['visual_feature']):
                (img_feat, can_feat) = feat
                img_feats[j][k] = img_feat
                can_feats[j][k] = can_feat
        (img_feats, can_feats) = (img_feats.cuda(), can_feats.cuda())
        features = ((img_feats, can_feats), lengths)
        insts = np.array([result['instr_encoding'] for _ in range(num_paths)])
        seq_lengths = np.argmax((insts == self.tok.word_to_index['<EOS>']), axis=1)
        insts = torch.from_numpy(insts).cuda()
        speaker_scores = speaker.teacher_forcing(train=True, features=features, insts=insts, for_listener=True)
        for (j, path) in enumerate(result['paths']):
            path.pop('visual_feature')
            path['speaker_scores'] = (- speaker_scores[j].detach().cpu().numpy()[:seq_lengths[j]])
    return results