コード例 #1
0
ファイル: main.py プロジェクト: monsterZeng/HGCN-JE-JR
from include.Load import *

seed = 12306
np.random.seed(seed)
tf.set_random_seed(seed)
'''
Followed the code style of GCN-Align:
https://github.com/1049451037/GCN-Align
'''

if __name__ == '__main__':
    e = len(set(loadfile(Config.e1, 1)) | set(loadfile(Config.e2, 1)))

    ILL = loadfile(Config.ill, 2)
    illL = len(ILL)
    np.random.shuffle(ILL)
    train = np.array(ILL[:illL // 10 * Config.seed])
    test = ILL[illL // 10 * Config.seed:]
    test_r = loadfile(Config.ill_r, 2)

    KG1 = loadfile(Config.kg1, 3)
    KG2 = loadfile(Config.kg2, 3)

    output_prel_e, output_joint_e, output_r, loss_1, loss_2, head, tail = build(
        Config.dim, Config.act_func, Config.gamma, Config.k,
        Config.language[0:2], e, train, KG1 + KG2)
    J = training(output_prel_e, output_joint_e, output_r, loss_1, loss_2,
                 0.001, Config.epochs, train, e, Config.k, Config.s, test,
                 test_r, head, tail)
    print('loss:', J)
コード例 #2
0
    e2 = set(loadfile(config.e2, 1))
    e = len(e1 | e2)

    ILL = loadfile(config.ill, 2)
    illL = len(ILL)
    np.random.shuffle(ILL)
    train = np.array(ILL[:illL // 10 * config.seed])
    test = ILL[illL // 10 * config.seed:]

    ILL_r = loadfile(config.ill_r, 2)

    KG1 = loadfile(config.kg1, 3)
    KG2 = loadfile(config.kg2, 3)

    r_kg_1 = set()
    r_kg = set()

    for tri in KG1:
        r_kg_1.add(tri[1])
        r_kg.add(tri[1])

    for tri in KG2:
        r_kg.add(tri[1])

    output_h, output_r, loss_pre, loss_all, M0, rel_type  = \
        build(config.dim, config.act_func, config.gamma, config.k, config.vec, e, KG1 + KG2)
    training(output_h, loss_pre, loss_all, config.lr, config.epochs,
             config.pre_epochs, train, e, config.k, config.save_suffix,
             config.dim, config.train_batchnum, test, M0, e1, e2, KG1 + KG2,
             rel_type, output_r, len(r_kg_1), len(r_kg), ILL_r)
コード例 #3
0
warnings.filterwarnings("ignore")
'''
Follow the code style of GCN-Align:
https://github.com/1049451037/GCN-Align
'''

seed = 12306
np.random.seed(seed)
tf.set_random_seed(seed)

if __name__ == '__main__':
    e = len(set(loadfile(Config.e1, 1)) | set(loadfile(Config.e2, 1)))

    ILL = loadfile(Config.ill, 2)
    illL = len(ILL)
    np.random.shuffle(ILL)
    train = np.array(ILL[:illL // 10 * Config.seed])
    test = ILL[illL // 10 * Config.seed:]

    KG1 = loadfile(Config.kg1, 3)
    KG2 = loadfile(Config.kg2, 3)

    output_layer, loss = build(Config.dim, Config.act_func, Config.alpha,
                               Config.beta, Config.gamma, Config.k,
                               Config.language[0:2], e, train, KG1 + KG2)
    vec, J = training(output_layer, loss, 0.001, Config.epochs, train, e,
                      Config.k, test)
    print('loss:', J)
    print('Result:')
    get_hits(vec, test)
コード例 #4
0
)

args = parser.parse_args()

if __name__ == '__main__':
    config = Config(args.dataset, args.lang)
    e1 = set(loadfile(config.e1, 1))
    e2 = set(loadfile(config.e2, 1))
    e = len(e1 | e2)

    ILL = loadfile(config.ill, 2)
    illL = len(ILL)
    np.random.shuffle(ILL)
    train = np.array(ILL[:illL // 10 * config.seed])
    test = ILL[illL // 10 * config.seed:]

    KG1 = loadfile(config.kg1, 3)
    KG2 = loadfile(config.kg2, 3)

    output_h, output_h_match, loss_all, sample_w, loss_w, M0, nbr_all, mask_all = \
        build(config.dim, config.dim_g, config.act_func, config.gamma,
            config.k, config.vec, e,
            config.all_nbr_num, config.sampled_nbr_num, config.beta, KG1 + KG2)
    se_vec, J = training(output_h, output_h_match, loss_all, sample_w, loss_w,
                         config.lr, config.epochs, config.pre_epochs, train, e,
                         config.k, config.sampled_nbr_num, config.save_suffix,
                         config.dim, config.dim_g, config.c,
                         config.train_batchnum, config.test_batchnum, test, M0,
                         e1, e2, nbr_all, mask_all)
    print('loss:', J)