parser.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:iscnlp 作者: iscnlp 项目源码 文件源码
def create_beam_items(self, beam):
        beam_items = []
        for b in xrange(len(beam)):
            config = beam[b]
            prevScore = config.score
            dense_feats = self.template.feat_template(config.nodes,
                                                      config.stack,
                                                      config.b0)
            pr_scores = self.clf.predict_proba(dense_feats)[0]
            pr_scores = np.log(pr_scores)
            predictions = zip(pr_scores, self.clf.classes_)
            valid_trans = self.get_valid_transitions(config)
            for score, (action, label) in predictions:
                if self.transitions[action] in valid_trans:
                    next_transition = valid_trans[self.transitions[action]]
                    heapq.heappush(
                        beam_items,
                        (prevScore + score, b, next_transition, label))
                    if len(beam_items) > self.beamwidth:
                        heapq.heappop(beam_items)
        return beam_items
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号