Ejemplo n.º 1
0
def export_features():
    train_data = read_libsvm(FLAGS.data_dir)
    feat_ids, feat_vals, label = slice_libsvm(train_data)
    fea = model.run_step(model.fea_out, feat_ids, feat_vals, label)
    with open(FLAGS.feature_dir, 'w') as f:
        for i in range(len(fea)):
            f.write(str(label[i]) + ' ')  # label
            for j in range(len(fea[i])):  # features
                f.write(str(j + 1) + ':' + str(round(fea[i][j], 3)) + ' ')
            f.write('\n')
    print('export feature done, file : %s' % FLAGS.feature_dir)
    exit()
Ejemplo n.º 2
0
tf.app.flags.DEFINE_string("loss_type", 'log_loss',
                           "loss type {square_loss, log_loss}")
tf.app.flags.DEFINE_integer("log_steps", 1000, "save summary every steps")
tf.app.flags.DEFINE_boolean("batch_norm", False,
                            "perform batch normaization (True or False)")
tf.app.flags.DEFINE_float(
    "batch_norm_decay", 0.9,
    "decay for the moving average(recommend trying decay=0.9)")

if FLAGS.dt_dir == "":
    FLAGS.dt_dir = (date.today() + timedelta(1 - 1)).strftime('%Y%m%d')
FLAGS.model_dir = FLAGS.model_dir + FLAGS.dt_dir

if FLAGS.train:
    data = read_libsvm(FLAGS.data_dir)
    random.shuffle(data)
    train_data = data[:(int)(len(data) * FLAGS.split_ratio)]
    test_data = data[(int)(len(data) * FLAGS.split_ratio):]
    print('read finish')
    print('train data size:', (len(train_data), len(train_data[0][0])))
    print('test data size:', (len(test_data), len(test_data[0][0])))
    train_size = len(train_data)
    test_size = len(test_data)
    min_round = FLAGS.min_round
    num_round = FLAGS.num_round
    early_stop_round = FLAGS.early_stop_round
    batch_size = FLAGS.batch_size

afm_params = {
    'field_size': FLAGS.field_size,
Ejemplo n.º 3
0
tf.app.flags.DEFINE_string("dropout", '0.5,0.5,0.5', "dropout rate")
tf.app.flags.DEFINE_string("dt_dir", '', "data dt partition")
tf.app.flags.DEFINE_integer("num_round", 20000, "Number of round")
tf.app.flags.DEFINE_integer("min_round", 200, "Number of min round")
tf.app.flags.DEFINE_integer("early_stop_round", 2000, "Number of early stop round")

tf.app.flags.DEFINE_string("loss_type", 'log_loss', "loss type {square_loss, log_loss}")
tf.app.flags.DEFINE_integer("log_steps", 1000, "save summary every steps")
tf.app.flags.DEFINE_boolean("batch_norm", False, "perform batch normaization (True or False)")
tf.app.flags.DEFINE_float("batch_norm_decay", 0.9, "decay for the moving average(recommend trying decay=0.9)")

if FLAGS.dt_dir == "":  FLAGS.dt_dir = (date.today() + timedelta(1 - 1)).strftime('%Y%m%d')
FLAGS.model_dir = FLAGS.model_dir + FLAGS.dt_dir

if FLAGS.train:
    data = read_libsvm(FLAGS.data_dir);    random.shuffle(data)
    train_data = data[:(int)(len(data) * FLAGS.split_ratio)];    test_data = data[(int)(len(data) * FLAGS.split_ratio):]
    print('read finish');  print('train data size:', (len(train_data), len(train_data[0][0])));  print('test data size:', (len(test_data), len(test_data[0][0])))
    train_size = len(train_data); test_size = len(test_data)
    min_round = FLAGS.min_round;  num_round = FLAGS.num_round;  early_stop_round = FLAGS.early_stop_round;  batch_size = FLAGS.batch_size

nfm_params = {
    'field_size': FLAGS.field_size,
    'feature_size': FLAGS.feature_size,
    'embedding_size': FLAGS.embedding_size,
    'l2_reg': FLAGS.l2_reg,
    'learning_rate': FLAGS.learning_rate,
    'optimizer': FLAGS.optimizer,
    'layer_sizes': FLAGS.deep_layers,
    'layer_acts': FLAGS.active_function,
    'drop_out': FLAGS.dropout,
Ejemplo n.º 4
0
tf.app.flags.DEFINE_string("loss_type", 'log_loss',
                           "loss type {square_loss, log_loss}")
tf.app.flags.DEFINE_integer("log_steps", 1000, "save summary every steps")
tf.app.flags.DEFINE_boolean("batch_norm", False,
                            "perform batch normaization (True or False)")
tf.app.flags.DEFINE_float(
    "batch_norm_decay", 0.9,
    "decay for the moving average(recommend trying decay=0.9)")

if FLAGS.dt_dir == "":
    FLAGS.dt_dir = (date.today() + timedelta(1 - 1)).strftime('%Y%m%d')
FLAGS.model_dir = FLAGS.model_dir + FLAGS.dt_dir

if FLAGS.train:
    data = read_libsvm(FLAGS.data_dir)
    random.shuffle(data)
    valid_data = read_libsvm(FLAGS.valid_dir)
    train_data = data[:(int)(len(data) * FLAGS.split_ratio)]
    test_data = data[(int)(len(data) * FLAGS.split_ratio):]
    print('read finish')
    print('train data size:', (len(train_data), len(train_data[0][0])))
    print('test data size:', (len(test_data), len(test_data[0][0])))
    train_size = len(train_data)
    test_size = len(test_data)
    min_round = FLAGS.min_round
    num_round = FLAGS.num_round
    early_stop_round = FLAGS.early_stop_round
    batch_size = FLAGS.batch_size

deep_afm_params = {