model.py 文件源码

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

项目:rnnlab 作者: phueb 项目源码 文件源码
def make_phrase_pps(self,
                        terms):
        print('Making phrase_pps...')
        terms = ['PERIOD'] + terms  # to get pp value for very first term
        num_terms = len(terms)
        task_id = 0
        pps = []
        for n in range(num_terms):
            term_ids = [self.terms.item_id_dict[term] for term in
                        terms[:n + 2]]  # add to to compensate for 0index and y
            window_mat = np.asarray(term_ids)[:, np.newaxis][-self.bptt_steps:].T
            x, y = np.split(window_mat, [-1], axis=1)
            x2 = np.tile(np.eye(GlobalConfigs.NUM_TASKS)[task_id], [1, x.shape[1], 1])
            feed_dict = {self.graph.x: x, self.graph.x2: x2, self.graph.y: y}
            pp = np.asscalar(self.sess.run(self.graph.pps, feed_dict=feed_dict))
            pps.append(pp)
        pps = pps[:-1]  # compensate for PERIOD insertion
        return pps
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号