utils.py 文件源码

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

项目:text-classification-theano 作者: syuoni 项目源码 文件源码
def predict_sent(self, sent, with_prob=False):
        if self.voting == 'hard':
            # sub_res -> (estimator_dim, )
            sub_res = np.array([estimator.predict_sent(sent) for estimator in self.estimators], 
                               dtype=np.float32)
            mode_res, count = mode(sub_res)
            return (mode_res[0], count[0]/self.n_estimators) if with_prob else mode_res[0]
        else:
            # sub_res -> (estimator_dim, target_dim)
            sub_res = np.array([estimator.predict_sent(sent, with_prob=True) for estimator in self.estimators], 
                               dtype=np.float32)
            sub_res = sub_res.mean(axis=0)
            max_res = np.argmax(sub_res)
            mean_prob = sub_res[max_res]
            return (max_res, mean_prob) if with_prob else max_res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号