Example #1
0
    tf.summary.scalar("accuracy", accurate)

summ = tf.summary.merge_all()

sess.run(tf.global_variables_initializer())


def trans(i):
    if i == 0:
        return [0, 1]
    if i == 1:
        return [1, 0]


for items in rd(max_records=2):
    X = [item["features"].toArray() for item in items]
    Y = [trans(item["label"]) for item in items]
    if len(X) > 0:
        _, gs = sess.run([train_step, global_step],
                         feed_dict={input_x: X, input_y: Y})
        [train_accuracy, s, loss] = sess.run([accurate, summ, xent],
                                             feed_dict={input_x: X, input_y: Y})
        print('train_accuracy %g, loss: %g, global step: %d' % (
            train_accuracy,
            loss,
            gs))
    sys.stdout.flush()
p = mlsql.params()
mlsql_model.save_model(p["internalSystemParam"]["tempModelLocalPath"], sess, input_x, input_y, True)
sess.close()
TEST_X, TEST_Y = mlsql.get_validate_data()
TEST_Y = [item.toArray() for item in TEST_Y]
for ep in range(epochs):
    for items in rd(max_records=batch_size):
        X = [item[input_col].toArray() for item in items]
        Y = [item[label_col].toArray() for item in items]
        _, gs = sess.run([train_step, global_step],
                         feed_dict={
                             input_x: X,
                             input_y: Y
                         })
        if gs % print_interval == 0:
            [train_accuracy, s, loss] = sess.run([accurate, summ, xent],
                                                 feed_dict={
                                                     input_x: X,
                                                     input_y: Y
                                                 })
            [test_accuracy, test_s,
             test_lost] = sess.run([accurate, summ, xent],
                                   feed_dict={
                                       input_x: TEST_X,
                                       input_y: TEST_Y
                                   })
            print(
                'train_accuracy %g,test_accuracy %g, loss: %g,test_lost: %g, global step: %d, ep:%d'
                % (train_accuracy, test_accuracy, loss, test_lost, gs, ep))
            sys.stdout.flush()

mlsql_model.save_model(tempModelLocalPath, sess, input_x, _logits, True)
sess.close()
sess.run(tf.global_variables_initializer())

TEST_X, TEST_Y = mlsql.get_validate_data()
TEST_Y = [item.toArray() for item in TEST_Y]

for ep in range(epochs):
    for items in rd(max_records=batch_size):
        X = [item[input_col].toArray() for item in items]
        Y = [item[label_col].toArray() for item in items]
        if len(X) == 0:
            print("bad news , this round no message fetched")
        if len(X) > 0:
            _, gs = sess.run([train_step, global_step],
                             feed_dict={input_x: X, input_y: Y})
            if gs % print_interval == 0:
                [train_accuracy, s, loss] = sess.run([accurate, summ, xent],
                                                     feed_dict={input_x: X, input_y: Y})
                [test_accuracy, test_s, test_lost] = sess.run([accurate, summ, xent],
                                                              feed_dict={input_x: TEST_X, input_y: TEST_Y})
                print('train_accuracy %g,test_accuracy %g, loss: %g, test_lost: %g,global step: %d, ep:%d' % (
                    train_accuracy,
                    test_accuracy,
                    loss,
                    test_lost,
                    gs, ep))
                sys.stdout.flush()

    mlsql_model.save_model(tempModelLocalPath, sess, input_x, _logits, True)
    sess.close()
Example #4
0

def trans(i):
    if i == 0:
        return [0, 1]
    if i == 1:
        return [1, 0]


for items in rd(max_records=2):
    X = [item["features"].toArray() for item in items]
    Y = [trans(item["label"]) for item in items]
    if len(X) > 0:
        _, gs = sess.run([train_step, global_step],
                         feed_dict={
                             input_x: X,
                             input_y: Y
                         })
        [train_accuracy, s, loss] = sess.run([accurate, summ, xent],
                                             feed_dict={
                                                 input_x: X,
                                                 input_y: Y
                                             })
        print('train_accuracy %g, loss: %g, global step: %d' %
              (train_accuracy, loss, gs))
    sys.stdout.flush()
p = mlsql.params()
mlsql_model.save_model(p["internalSystemParam"]["tempModelLocalPath"], sess,
                       input_x, input_y, True)
sess.close()