as_reader_tf.py 文件源码

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

项目:attention-sum-reader 作者: cairoHy 项目源码 文件源码
def test(self, test_data, batch_size):
        # ????????
        questions_ok, documents_ok, context_mask, candidates_ok, y_true = self.preprocess_input_sequences(test_data)
        logging.info("Test on {} samples, {} per batch.".format(len(questions_ok), batch_size))

        # ??
        batch_num = len(questions_ok) // batch_size
        batch_idx = np.arange(batch_num)
        correct_num, total_num = 0, 0
        for i in range(batch_num):
            start = batch_idx[i % batch_num] * batch_size
            stop = (batch_idx[i % batch_num] + 1) * batch_size
            _slice = np.index_exp[start:stop]
            data = {self.q_input: questions_ok[_slice],
                    self.d_input: documents_ok[_slice],
                    self.context_mask_bt: context_mask[_slice],
                    self.candidates_bi: candidates_ok[_slice],
                    self.y_true: y_true[_slice]}
            correct, = self.sess.run([self.correct_prediction], feed_dict=data)
            correct_num, total_num = correct_num + correct, total_num + batch_size
        test_acc = correct_num / total_num
        logging.info("Test accuracy is : {:.5f}".format(test_acc))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号