MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / train

Function train

tf_classify_demo/classify.py:28–43  ·  view source on GitHub ↗

利用无隐藏层的softmax实现简单的分类模型

(samples, sess, x, y, y_, train_step)

Source from the content-addressed store, hash-verified

26saver = tf.train.Saver()
27
28def 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
45def predict(samples, sess, x, y, y_, train_step):
46 x_s = samples.generate_xs('数据科学入门')

Callers 1

mainFunction · 0.70

Calls 3

clear_word_vectorMethod · 0.80
test_setsMethod · 0.80
next_batchMethod · 0.45

Tested by

no test coverage detected