Beispiel #1
0
def fetch_hidden_vector(hparam, vocab_size, data, model_path):
    task = transformer_nli_hidden(hparam, vocab_size, 0, False)
    sess = init_session()
    sess.run(tf.global_variables_initializer())

    load_model_w_scope(sess, model_path, ["bert"])
    batches = get_batches_ex(data, hparam.batch_size, 4)

    def batch2feed_dict(batch):
        x0, x1, x2, y = batch
        feed_dict = {
            task.x_list[0]: x0,
            task.x_list[1]: x1,
            task.x_list[2]: x2,
            task.y: y,
        }
        return feed_dict

    def pred_fn():
        outputs = []
        for batch in batches:
            x0, x1, x2, y = batch
            all_layers, emb_outputs = sess.run(
                [task.all_layers, task.embedding_output],
                feed_dict=batch2feed_dict(batch))
            outputs.append((all_layers, emb_outputs, x0))

        return outputs

    return pred_fn()
Beispiel #2
0
 def __init__(self, hparam, voca_size, start_model_path):
     print("AgreePredictor")
     tf.reset_default_graph()
     self.task = transformer_weight(hparam, voca_size, False)
     self.sess = init_session()
     self.sess.run(tf.global_variables_initializer())
     load_model_w_scope(self.sess, start_model_path, ['bert', 'cls_dense'])
Beispiel #3
0
def fetch_hidden_vector(hparam, vocab_size, run_name, data_loader, model_path):
    print("fetch_hidden_vector:", run_name)
    task = transformer_nli_hidden(hparam, vocab_size, 0, False)
    sess = init_session()
    sess.run(tf.global_variables_initializer())

    load_model_w_scope(sess, model_path, ["bert"])
    dev_batches = get_batches_ex(data_loader.get_dev_data(), hparam.batch_size,
                                 4)

    def batch2feed_dict(batch):
        x0, x1, x2, y = batch
        feed_dict = {
            task.x_list[0]: x0,
            task.x_list[1]: x1,
            task.x_list[2]: x2,
            task.y: y,
        }
        return feed_dict

    def pred_fn():
        outputs = []
        for batch in dev_batches[:100]:
            x0, x1, x2, y = batch
            all_layers, emb_outputs = sess.run(
                [vars], feed_dict=batch2feed_dict(batch))
            outputs.append((all_layers, emb_outputs, x0))

        return outputs

    return pred_fn()
Beispiel #4
0
 def __init__(self, hparam, voca_size, start_model_path):
     print("run_ukp_ex")
     tf.reset_default_graph()
     self.task = transformer_nli(hparam, voca_size, 5, True)
     self.sess = init_session()
     self.sess.run(tf.global_variables_initializer())
     load_model_w_scope(self.sess, start_model_path,
                        ['bert', 'cls_dense', 'aux_conflict'])
Beispiel #5
0
def fetch_params(hparam, vocab_size, run_name, data_loader, model_path):
    print("fetch_hidden_vector:", run_name)
    task = transformer_nli_hidden(hparam, vocab_size, 0, False)
    sess = init_session()
    sess.run(tf.global_variables_initializer())

    load_model_w_scope(sess, model_path, ["bert"])
    vars = tf.trainable_variables()
    names = list([v.name for v in vars])

    vars_out, = sess.run([vars])
    return names, vars_out
Beispiel #6
0
def init_fn_generic(sess, start_type, start_model_path):
    if start_type == "cls":
        load_model_with_blacklist(sess, start_model_path,
                                  ["explain", "explain_optimizer"])
    elif start_type == "cls_new":
        load_model_with_blacklist(
            sess, start_model_path,
            ["explain", "explain_optimizer", "optimizer"])
    elif start_type == "cls_ex":
        load_model(sess, start_model_path)
    elif start_type == "as_is":
        load_model(sess, start_model_path)
    elif start_type == "cls_ex_for_pairing":
        load_model_with_blacklist(sess, start_model_path,
                                  ["match_predictor", "match_optimizer"])
    elif start_type == "bert":
        load_model_w_scope(sess, start_model_path, ["bert"])
    elif start_type == "cold":
        pass
    else:
        assert False
Beispiel #7
0
 def load_fn(sess, model_path):
     return load_model_w_scope(sess, model_path, "bert")
Beispiel #8
0
 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)