Ejemplo n.º 1
0
def eval_config(config):
    lr = config['lr']
    embedding_dim = config['embedding_dim']
    train_ws = config['train_ws']
    batch_size = config['batch_size']
    num_sampled = config['num_sampled']
    hidden_units = config['hidden_units']
    shuffle_batch = config['shuffle_batch']
    optimizer_type = config['optimizer_type']
    use_batch_normalization = config['use_batch_normalization']
    train_nce_biases = config['train_nce_biases']

    hidden_units = get_hidden_units(hidden_units, embedding_dim)

    opts = Options()
    opts.train_data_path = '../../data/train_data.in'
    opts.eval_data_path = '../../data/eval_data.in'
    opts.lr = lr
    opts.embedding_dim = embedding_dim
    opts.train_ws = train_ws
    opts.min_count = 30
    opts.t = 0.025
    opts.verbose = 1
    opts.min_count_label = 5
    opts.label = "__label__"
    opts.batch_size = batch_size
    opts.num_sampled = num_sampled
    opts.max_train_steps = None
    opts.epoch = 2
    opts.hidden_units = hidden_units
    opts.model_dir = 'model_dir'
    opts.export_model_dir = 'export_model_dir'
    opts.prefetch_size = 100000
    opts.save_summary_steps = 100
    opts.save_checkpoints_secs = 600
    opts.keep_checkpoint_max = 2
    opts.log_step_count_steps = 1000
    opts.recall_k = 10
    opts.dict_dir = 'dict_dir'
    opts.use_saved_dict = False
    opts.use_profile_hook = False
    opts.profile_steps = 100
    opts.root_ops_path = 'lib/'
    opts.remove_model_dir = 1
    opts.optimize_level = 1
    opts.receive_ws = 100
    opts.use_subset = True
    opts.dropout = 0.0
    opts.ntargets = 1
    opts.chief_lock = 'model_dir/chief.lock'
    opts.max_distribute_train_steps = -1
    opts.train_nce_biases = train_nce_biases
    opts.shuffle_batch = shuffle_batch
    opts.predict_ws = 20
    opts.sample_dropout = 0.0
    opts.optimizer_type = optimizer_type
    opts.tfrecord_file = ''
    opts.num_tfrecord_file = 1
    opts.train_data_format = 'fasttext'
    opts.tfrecord_map_num_parallel_calls = 1
    opts.train_parallel_mode = 'train_op_parallel'
    opts.num_train_op_parallel = 4
    opts.use_batch_normalization = use_batch_normalization

    opts.tf_config = None
    opts.task_type = model_keys.TaskType.LOCAL  # default mode

    result = {}
    try:
        result = train.train(opts, export=False)
    except Exception as e:
        print(e)
    return -result.get('loss', -1)
Ejemplo n.º 2
0
def eval_config(id, config, f):
    opts = Options()
    opts.train_data_path = '../../data/train_data.in'
    opts.eval_data_path = '../../data/eval_data.in'
    opts.lr = get_lr(config)
    opts.embedding_dim = get_embedding_dim(config)
    opts.train_ws = get_train_ws(config)
    opts.min_count = 30
    opts.t = 0.025
    opts.verbose = 1
    opts.min_count_label = 5
    opts.label = "__label__"
    opts.batch_size = get_batch_size(config)
    opts.num_sampled = get_num_sampled(config)
    opts.max_train_steps = None
    opts.epoch = 2
    opts.hidden_units = get_hidden_units(config)
    opts.model_dir = 'model_dir'
    opts.export_model_dir = 'export_model_dir'
    opts.prefetch_size = 100000
    opts.save_summary_steps = 100
    opts.save_checkpoints_secs = 600
    opts.keep_checkpoint_max = 2
    opts.log_step_count_steps = 1000
    opts.recall_k = 10
    opts.dict_dir = 'dict_dir'
    opts.use_saved_dict = False
    opts.use_profile_hook = False
    opts.profile_steps = 100
    opts.root_ops_path = 'lib/'
    opts.remove_model_dir = 1
    opts.optimize_level = 1
    opts.receive_ws = 100
    opts.use_subset = True
    opts.dropout = 0.0
    opts.ntargets = 1
    opts.chief_lock = 'model_dir/chief.lock'
    opts.max_distribute_train_steps = -1
    opts.train_nce_biases = get_train_nce_biases(config)
    opts.shuffle_batch = get_shuffle_batch(config)
    opts.predict_ws = 20
    opts.sample_dropout = 0.0
    opts.optimizer_type = get_optimizer_type(config)
    opts.tfrecord_file = ''
    opts.num_tfrecord_file = 1
    opts.train_data_format = 'fasttext'
    opts.tfrecord_map_num_parallel_calls = 1
    opts.train_parallel_mode = 'train_op_parallel'
    opts.num_train_op_parallel = 4
    opts.use_batch_normalization = get_use_batch_normalization(config)

    opts.tf_config = None
    opts.task_type = model_keys.TaskType.LOCAL  # default mode

    result = {}
    start = int(time.time())
    try:
        result = train.train(opts, export=False)
    except Exception:
        pass
    end = int(time.time())
    elapsed = end - start
    f.write(str(opts.lr))
    f.write('\t')
    f.write(str(opts.embedding_dim))
    f.write('\t')
    f.write(str(opts.train_ws))
    f.write('\t')
    f.write(str(opts.batch_size))
    f.write('\t')
    f.write(str(opts.num_sampled))
    f.write('\t')
    f.write(str(opts.hidden_units))
    f.write('\t')
    f.write(str(opts.shuffle_batch))
    f.write('\t')
    f.write(str(opts.optimizer_type))
    f.write('\t')
    f.write(str(opts.use_batch_normalization))
    f.write('\t')
    f.write(str(opts.train_nce_biases))
    f.write('\t')

    f.write(str(result.get('loss', -1)))
    f.write('\t')
    f.write(str(result.get('precision_at_top_10', -1)))
    f.write('\t')
    f.write(str(result.get('recall_at_top_10', -1)))
    f.write('\t')
    f.write(str(result.get('average_precision_at_10', -1)))
    f.write('\t')
    f.write(str(result.get('accuracy', -1)))
    f.write('\t')
    f.write(str(elapsed))
    f.write('\n')
    f.flush()