예제 #1
0
파일: main.py 프로젝트: MinkOrange/MGGCF
    dataset = GDataset(config.user_dataset, config.group_dataset,config.num_negatives)

    # get group number
    num_users, num_items, num_groups = dataset.num_users, dataset.num_items, dataset.num_groups

    # build NCF model
    ncf = NCF(num_users, num_items, num_groups, config.factor_num, config.num_layers , config.drop_ratio)

    # config information
    print("NCF at embedding size %d, run Iteration:%d, NDCG and HR at %d" %(config.factor_num, config.epoch, config.topK))
    # train the model
    for epoch in range(config.epoch):
        ncf.train()
        # 开始训练时间
        t1 = time()
        training(ncf, dataset.get_user_dataloader(config.batch_size), epoch, config, 'user')
        training(ncf, dataset.get_group_dataloader(config.batch_size), epoch, config, 'group')
        print("training time is: [%.1f s]" % (time()-t1))
        # evaluation
        t2 = time()
        u_hr, u_ndcg = evaluation(ncf, helper, dataset.user_testRatings, dataset.user_testNegatives, config.topK, 'user')
        print('User Iteration %d [%.1f s]: HR = %.4f, NDCG = %.4f, [%.1f s]' % (
            epoch, time() - t1, u_hr, u_ndcg, time() - t2))
        g_hr, g_ndcg = evaluation(ncf, helper, dataset.group_testRatings, dataset.group_testNegatives, config.topK, 'group')
        print('Group Iteration %d [%.1f s]: HR = %.4f, NDCG = %.4f, [%.1f s]' % (
            epoch, time() - t1, g_hr, g_ndcg, time() - t2))
    print("Done!")



예제 #2
0
    num_group = len(g_m_d)
    num_users, num_items = dataset.num_users, dataset.num_items

    # build AGREE model
    agree = AGREE(num_users, num_items, num_group, config.embedding_size,
                  g_m_d, config.drop_ratio)

    # config information
    print("AGREE at embedding size %d, run Iteration:%d, NDCG and HR at %d" %
          (config.embedding_size, config.epoch, config.topK))
    # train the model
    for epoch in range(config.epoch):
        agree.train()
        # 开始训练时间
        t1 = time()
        training(agree, dataset.get_user_dataloader(config.batch_size), epoch,
                 config, 'user')

        training(agree, dataset.get_group_dataloader(config.batch_size), epoch,
                 config, 'group')
        print("user and group training time is: [%.1f s]" % (time() - t1))
        # evaluation
        t2 = time()
        u_hr, u_ndcg = evaluation(agree, helper, dataset.user_testRatings,
                                  dataset.user_testNegatives, config.topK,
                                  'user')
        print('User Iteration %d [%.1f s]: HR = %.4f, NDCG = %.4f, [%.1f s]' %
              (epoch, time() - t1, u_hr, u_ndcg, time() - t2))

        hr, ndcg = evaluation(agree, helper, dataset.group_testRatings,
                              dataset.group_testNegatives, config.topK,
예제 #3
0
    num_group = max(g_m_d.keys()) + 1
    num_users, num_items = dataset.num_users, dataset.num_items
    # print('num_users',num_users)
    # build AGREE model
    agree = AGREE(num_users, num_items, num_group,
                  args.embedding_size, g_m_d, args.drop_ratio).to(device)
    # config information
    print("AGREE at embedding size %d, run Iteration:%d" %
          (args.embedding_size, args.epoch))
    history = []
    tops = [5, 10, 15, 20]
    for epoch in range(args.epoch):
        # training
        agree.train()
        t1 = time()
        training(agree, dataset.get_user_dataloader(
            args.batch_size), epoch, args, 'user')
        training(agree, dataset.get_group_dataloader(
            args.batch_size), epoch, args, 'group')
        print("user and group training time is: [%.1f s]" % (time() - t1))
        t2 = time()

        # evaluation
        u_hrs, u_ndcgs = [0, 0, 0, 0], [0, 0, 0, 0]
        hrs, ndcgs = evaluation(
            agree, helper, dataset.group_testRatings, dataset.group_testNegatives, 'group')
        for i, _ in enumerate(tops):
            print('top%d:Group Iteration %d [%.1f s]: HR = %.4f, '
                  'NDCG = %.4f, [%.1f s]' % (tops[i], epoch, time() - t1, hrs[i], ndcgs[i], time() - t2))

        history.append([u_hrs, u_ndcgs, hrs, ndcgs])