利用无隐藏层的softmax实现简单的分类模型
(samples, sess, x, y, y_, train_step)
| 26 | saver = tf.train.Saver() |
| 27 | |
| 28 | def train(samples, sess, x, y, y_, train_step): |
| 29 | """ |
| 30 | 利用无隐藏层的softmax实现简单的分类模型 |
| 31 | """ |
| 32 | |
| 33 | samples.clear_word_vector() |
| 34 | test_xs, test_ys = samples.test_sets() |
| 35 | |
| 36 | for i in range(10000): |
| 37 | batch_xs, batch_ys = samples.next_batch(1) |
| 38 | train_step.run({x: batch_xs, y_: batch_ys}) |
| 39 | |
| 40 | correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) |
| 41 | accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) |
| 42 | print(accuracy.eval({x: test_xs, y_: test_ys})) |
| 43 | saver.save(sess, 'data/model/model') |
| 44 | |
| 45 | def predict(samples, sess, x, y, y_, train_step): |
| 46 | x_s = samples.generate_xs('数据科学入门') |
no test coverage detected