Exemplo n.º 1
0
def main(start_model_path,
         start_type,
         save_dir,
         modeling_option,
         target_idx_,
         num_gpu=1):
    num_gpu = int(num_gpu)
    tf_logging.info("train_from : nli_ex")
    hp = HPCommon()
    nli_setting = BertNLI()
    set_level_debug()
    reset_root_log_handler()
    train_config = NLIPairingTrainConfig()
    train_config.num_gpu = num_gpu

    tf_logging.info("loading batches")
    data = get_nli_data(hp, nli_setting)

    def init_fn(sess):
        return init_fn_generic(sess, start_type, start_model_path)

    class LMSConfig2(LMSConfigI):
        num_tags = 3
        target_idx = target_idx_
        use_embedding_out = True
        per_layer_component = 'linear'

    train_LMS(hp, train_config, LMSConfig2(), save_dir, data, modeling_option,
              init_fn)
Exemplo n.º 2
0
def get_params(start_model_path, start_type, info_fn_name, num_gpu):
    hp = hyperparams.HPSENLI3()
    nli_setting = BertNLI()
    set_level_debug()
    train_config = NLIExTrainConfig()
    train_config.num_gpu = num_gpu
    train_config.save_train_payload = True

    tokenizer = get_tokenizer()
    tf_logging.info("Intializing dataloader")
    data_loader = get_modified_data_loader(tokenizer, hp.seq_max,
                                           nli_setting.vocab_filename)
    tf_logging.info("loading batches")
    data = get_nli_data(hp, nli_setting)

    def init_fn(sess):
        start_type_generic = {
            'nli': 'cls',
            'nli_ex': 'cls_ex',
            'bert': 'bert',
            'cold': 'cold'
        }[start_type]
        return init_fn_generic(sess, start_type_generic, start_model_path)

    informative_fn = get_informative_fn_by_name(info_fn_name)
    return data, data_loader, hp, informative_fn, init_fn, train_config
Exemplo n.º 3
0
def main(_):
    print("Main")
    check("point2")
    tf_logging.info("Log")

    reset_root_log_handler()
    set_level_debug()
    check("point3")
    tf_logging.info("Log")
Exemplo n.º 4
0
def main(_):
    set_level_debug()
    tf_logging.info("Train horizon")
    config = JsonConfig.from_json_file(FLAGS.model_config_file)
    train_config = TrainConfigEx.from_flags(FLAGS)
    is_training = FLAGS.do_train
    input_files = get_input_files_from_flags(FLAGS)
    input_fn = input_fn_builder_unmasked(input_files, FLAGS, is_training)
    model_fn = model_fn_lm(config, train_config, BertologyFactory(HorizontalAlpha), get_masked_lm_output_albert)
    return run_estimator(model_fn, input_fn)
Exemplo n.º 5
0
def main(_):
    set_level_debug()
    tf_logging.info("Train reshape bert")
    config = JsonConfig.from_json_file(FLAGS.model_config_file)
    train_config = TrainConfigEx.from_flags(FLAGS)
    is_training = FLAGS.do_train
    input_files = get_input_files_from_flags(FLAGS)
    input_fn = input_fn_builder_unmasked(input_files, FLAGS, is_training)
    model_fn = model_fn_lm(config, train_config, ReshapeBertModel)
    return run_estimator(model_fn, input_fn)
Exemplo n.º 6
0
def train_nil_from_bert(model_path, save_dir):
    def load_fn(sess, model_path):
        return load_model_w_scope(sess, model_path, "bert")

    max_steps = 61358
    max_steps = 36250
    hp = hyperparams.HPSENLI3()
    set_level_debug()
    nli_setting = BertNLI()
    data = get_snli_data(hp, nli_setting)
    n_gpu = 2
    return train_nli_multi_gpu(hp, nli_setting, save_dir, max_steps, data,
                               model_path, load_fn, n_gpu)
Exemplo n.º 7
0
def main(start_model_path, modeling_option, num_gpu=1):
    num_gpu = int(num_gpu)
    hp = HPCommon()
    nli_setting = BertNLI()
    set_level_debug()
    reset_root_log_handler()
    train_config = NLIPairingTrainConfig()
    train_config.num_gpu = num_gpu

    def init_fn(sess):
        return init_fn_generic(sess, "as_is", start_model_path)

    data = get_nli_data(hp, nli_setting)
    do_predict(hp, train_config, data, LMSConfig(), modeling_option, init_fn)
Exemplo n.º 8
0
def main(start_model_path, modeling_option, input_path, save_name, num_gpu=1):
    num_gpu = int(num_gpu)
    hp = HPCommon()
    nli_setting = BertNLI()
    set_level_debug()
    reset_root_log_handler()
    train_config = NLIPairingTrainConfig()
    train_config.num_gpu = num_gpu

    def init_fn(sess):
        return init_fn_generic(sess, "as_is", start_model_path)

    batches = get_batches(input_path, nli_setting, HPCommon.batch_size)
    output_d = do_predict(hp, train_config, batches, LMSConfig(),
                          modeling_option, init_fn)
    save_to_pickle(output_d, save_name)
Exemplo n.º 9
0
def main(start_model_path, start_type, save_dir, modeling_option, num_gpu=1):
    num_gpu = int(num_gpu)
    tf_logging.info("train_from : nli_ex")
    hp = HPCommon()
    nli_setting = BertNLI()
    set_level_debug()
    reset_root_log_handler()
    train_config = NLIPairingTrainConfig()
    train_config.num_gpu = num_gpu

    tf_logging.info("loading batches")
    data = get_nli_data(hp, nli_setting)

    def init_fn(sess):
        return init_fn_generic(sess, start_type, start_model_path)

    train_LMS(hp, train_config, LMSConfig(), save_dir, data, modeling_option,
              init_fn)
Exemplo n.º 10
0
def train_nil_from(model_path, save_dir, resume=False):
    print("Load model path : ", model_path)
    print("Save dir : ", save_dir)

    def load_fn(sess, model_path):
        if not resume:
            return load_model_w_scope(sess, model_path, "bert")
        else:
            return load_model(sess, model_path)

    steps = 67000
    hp = hyperparams.HPSENLI3()
    nli_setting = BertNLI()
    data = get_nli_data(hp, nli_setting)
    set_level_debug()
    hp = hyperparams.HPSENLI3()
    n_gpu = 2
    return train_nli_multi_gpu(hp, nli_setting, save_dir, steps, data,
                               model_path, load_fn, n_gpu)
Exemplo n.º 11
0
def main(start_model_path, start_type, save_dir,
         modeling_option, num_gpu=1):
    num_gpu = int(num_gpu)
    tf_logging.info("Train with MLP")
    hp = HPCommon()
    hp.per_layer_component = 'mlp'
    nli_setting = BertNLI()
    set_level_debug()
    reset_root_log_handler()
    train_config = NLIPairingTrainConfig()
    train_config.num_gpu = num_gpu

    lms_config = LMSConfig()
    tf_logging.info("loading batches")
    data = get_nli_data(hp, nli_setting)

    def init_fn(sess):
        return init_fn_generic(sess, start_type, start_model_path)

    train_LMS(hp, train_config, lms_config, save_dir, data, modeling_option, init_fn)
Exemplo n.º 12
0
def train_nil_from(save_dir, model_path, load_fn, max_steps):
    hp = hyperparams.HPSENLI3()
    set_level_debug()
    nli_setting = BertNLI()
    data = get_nli_data(hp, nli_setting)
    train_nli(hp, nli_setting, save_dir, max_steps, data, model_path, load_fn)