Пример #1
0
def train_siamese():
    # 读取配置
    # conf = Config()
    cfg_path = "./configs/config.yml"
    cfg = yaml.load(open(cfg_path, encoding='utf-8'), Loader=yaml.FullLoader)
    # 读取数据
    data_train, data_val, data_test = data_input.get_lcqmc()
    # data_train = data_train[:100]
    print("train size:{},val size:{}, test size:{}".format(
        len(data_train), len(data_val), len(data_test)))
    model = SiamenseRNN(cfg)
    model.fit(data_train, data_val, data_test)
    pass
Пример #2
0
        test_acc = accuracy_score(val_label, val_pred)
        return test_acc

    def predict(self, test_data):
        pbar = data_input.get_batch(test_data,
                                    batch_size=self.cfg['batch_size'],
                                    is_test=1)
        val_pred, val_prob = [], []
        for (t1_ids, t1_len, t2_ids, t2_len) in pbar:
            fd = self.feed_batch(t1_ids, t1_len, t2_ids, t2_len, is_test=1)
            pred_labels, pred_prob = self.sess.run(
                [self.predict_idx, self.predict_prob], feed_dict=fd)
            val_pred.extend(pred_labels)
            val_prob.extend(pred_prob)
        return val_pred, val_prob


if __name__ == "__main__":
    start = time.time()
    # 读取配置
    conf = Config()
    # 读取数据
    dataset = hub.dataset.LCQMC()
    data_train, data_val, data_test = data_input.get_lcqmc()
    # data_train = data_train[:10000]
    print("train size:{},val size:{}, test size:{}".format(
        len(data_train), len(data_val), len(data_test)))
    model = SiamenseRNN(conf)
    model.fit(data_train, data_val, data_test)
    pass