def train_model(args):

    class Dummy():
        pass
    train_env = Dummy()
    infer_env = Dummy()
    (train_graph, infer_graph) = model(args, train_env, infer_env)
    args.data = 'wikisql'
    args.load_data = True
    args.load_model = False
    (X_train, y_train) = load_data(maxlen=args.maxlen, load=args.load_data, s='train')
    (X_test, y_test) = load_data(maxlen=args.maxlen, load=args.load_data, s='test')
    (X_dev, y_dev) = load_data(maxlen=args.maxlen, load=args.load_data, s='dev')
    model2load = 'model/{}'.format(args.subset)
    (max_em, global_test_em, best_base) = ((- 1), (- 1), (- 1))
    acc = 0
    sess1 = tf.InteractiveSession(graph=train_graph)
    sess1.run(tf.global_variables_initializer())
    sess1.run(tf.local_variables_initializer())
    sess2 = tf.InteractiveSession(graph=infer_graph)
    sess2.run(tf.global_variables_initializer())
    sess2.run(tf.global_variables_initializer())
    for base in range((args.total_epochs / args.epochs)):
        print(('\nIteration: %d (%d epochs)' % (base, args.epochs)))
        model2load = train(sess1, train_env, X_train, y_train, epochs=args.epochs, load=args.load_model, name=args.subset, batch_size=args.batch_size, base=base, model2Bload=model2load)
        args.load_model = True
        infer_env.infer_saver.restore(sess2, model2load)
        print('===========dev set============')
        dev_em = decode_data(sess2, infer_env, X_dev, y_dev)
        dev_em = decode_data_recover(sess2, infer_env, X_dev, y_dev, 'dev')
        print('==========test set===========')
        test_em = decode_data(sess2, infer_env, X_test, y_test)
        test_em = decode_data_recover(sess2, infer_env, X_test, y_test, 'test')
        if (dev_em > max_em):
            max_em = dev_em
            global_test_em = test_em
            best_base = base
            print('\n Saving model for best testing')
            train_env.saver.save(sess1, 'best_model/{0}-{1}-{2:.2f}'.format(args.subset, base, max_em))
        print(('Max EM acc: %.4f during %d iteration.' % (max_em, best_base)))
        print(('test EM acc: %.4f ' % global_test_em))
    return
def train_model(args):

    class Dummy():
        pass
    train_env = Dummy()
    infer_env = Dummy()
    (train_graph, infer_graph) = model(args, train_env, infer_env)
    args.data = 'wikisql'
    args.load_data = True
    args.load_model = False
    (X_train, y_train) = load_data(maxlen=args.maxlen, load=args.load_data, s='train')
    (X_test, y_test) = load_data(maxlen=args.maxlen, load=args.load_data, s='test')
    (X_dev, y_dev) = load_data(maxlen=args.maxlen, load=args.load_data, s='dev')
    model2load = 'model/{}'.format(args.subset)
    (max_em, global_test_em, best_base) = ((- 1), (- 1), (- 1))
    acc = 0
    sess1 = tf.InteractiveSession(graph=train_graph)
    sess1.run(tf.global_variables_initializer())
    sess1.run(tf.local_variables_initializer())
    sess2 = tf.InteractiveSession(graph=infer_graph)
    sess2.run(tf.global_variables_initializer())
    sess2.run(tf.global_variables_initializer())
    for base in range((args.total_epochs / args.epochs)):
        print(('\nIteration: %d (%d epochs)' % (base, args.epochs)))
        model2load = train(sess1, train_env, X_train, y_train, epochs=args.epochs, load=args.load_model, name=args.subset, batch_size=args.batch_size, base=base, model2Bload=model2load)
        args.load_model = True
        infer_env.infer_saver.restore(sess2, model2load)
        print('===========dev set============')
        dev_em = decode_data(sess2, infer_env, X_dev, y_dev)
        dev_em = decode_data_recover(sess2, infer_env, X_dev, y_dev, 'dev')
        print('==========test set===========')
        test_em = decode_data(sess2, infer_env, X_test, y_test)
        test_em = decode_data_recover(sess2, infer_env, X_test, y_test, 'test')
        if (dev_em > max_em):
            max_em = dev_em
            global_test_em = test_em
            best_base = base
            print('\n Saving model for best testing')
            train_env.saver.save(sess1, 'best_model/{0}-{1}-{2:.2f}'.format(args.subset, base, max_em))
        print(('Max EM acc: %.4f during %d iteration.' % (max_em, best_base)))
        print(('test EM acc: %.4f ' % global_test_em))
    return