Ejemplo n.º 1
0
    def __init__(self, args):
        super(model_class, self).__init__()
        self.args = args
        self.gpu = args.cuda

        #导入各种数据
        input_data = data_generator.input_data(args=self.args)
        #input_data.gen_het_rand_walk()

        self.input_data = input_data

        if self.args.train_test_label == 2:  #为每个node生成邻居
            #重启策略的随机游走,为每个节点采样固定数量的强相关的异构邻居,然后按类型分组
            #任意节点开始随机游走,以p概率返回。采样到固定数量后就停止。
            #为了采样采样的邻居包含所有类型的节点,不同类型节点的数量是受限的。
            #对每个类型都选出按频率的topk邻居
            input_data.het_walk_restart()
            print("neighbor set generation finish")
            exit(0)

#p是论文,a是作者,v是地点,然后可以组成一堆特征
        feature_list = [input_data.p_abstract_embed, input_data.p_title_embed,\
        input_data.p_v_net_embed, input_data.p_a_net_embed, input_data.p_ref_net_embed,\
        input_data.p_net_embed, input_data.a_net_embed, input_data.a_text_embed,\
        input_data.v_net_embed, input_data.v_text_embed]

        for i in range(len(feature_list)):
            feature_list[i] = torch.from_numpy(np.array(
                feature_list[i])).float()

        if self.gpu:
            for i in range(len(feature_list)):
                feature_list[i] = feature_list[i].cuda()
        #self.feature_list = feature_list

        #各自的邻居列表
        a_neigh_list_train = input_data.a_neigh_list_train
        p_neigh_list_train = input_data.p_neigh_list_train
        v_neigh_list_train = input_data.v_neigh_list_train

        a_train_id_list = input_data.a_train_id_list
        p_train_id_list = input_data.p_train_id_list
        v_train_id_list = input_data.v_train_id_list

        self.model = tools.HetAgg(args, feature_list, a_neigh_list_train, p_neigh_list_train, v_neigh_list_train,\
         a_train_id_list, p_train_id_list, v_train_id_list)#实例化model,tools会对异构的信息进行聚合

        if self.gpu:
            self.model.cuda()
        self.parameters = filter(lambda p: p.requires_grad,
                                 self.model.parameters())
        self.optim = optim.Adam(self.parameters,
                                lr=self.args.lr,
                                weight_decay=0)  #Adam优化器
        self.model.init_weights()
Ejemplo n.º 2
0
	def __init__(self, args):
		super(model_class, self).__init__()
		self.args = args
		self.gpu = args.cuda

		input_data = data_generator.input_data(args = self.args)
		#input_data.gen_het_rand_walk()

		self.input_data = input_data

		if self.args.train_test_label == 2: #generate neighbor set of each node
			input_data.het_walk_restart()
			print ("neighbor set generation finish")
			exit(0)

		if self.args.train_test_label == 3: #generate neighbor according to metapath and rwr
			input_data.mix_walk_restart()
			print ("neighbor set generation finish")
			exit(0)
			
		if self.args.train_test_label == 4: #generate neighbor according to metapath
			input_data.meta_walk()
			print ("neighbor set generation finish")
			exit(0)

			
		feature_list = [input_data.p_abstract_embed, input_data.p_title_embed,\
		input_data.p_v_net_embed, input_data.p_a_net_embed, input_data.p_ref_net_embed,\
		input_data.p_net_embed, input_data.a_net_embed, input_data.a_text_embed,\
		input_data.v_net_embed, input_data.v_text_embed]

		for i in range(len(feature_list)):
			feature_list[i] = torch.from_numpy(np.array(feature_list[i])).float()

		if self.gpu:
			for i in range(len(feature_list)):
				feature_list[i] = feature_list[i].cuda()
		#self.feature_list = feature_list

		a_neigh_list_train = input_data.a_neigh_list_train
		p_neigh_list_train = input_data.p_neigh_list_train
		v_neigh_list_train = input_data.v_neigh_list_train

		a_train_id_list = input_data.a_train_id_list
		p_train_id_list = input_data.p_train_id_list
		v_train_id_list = input_data.v_train_id_list

		self.model = tools.HetAgg(args, feature_list, a_neigh_list_train, p_neigh_list_train, v_neigh_list_train,\
		 a_train_id_list, p_train_id_list, v_train_id_list)

		if self.gpu:
			self.model.cuda()
		self.parameters = filter(lambda p: p.requires_grad, self.model.parameters())
		self.optim = optim.Adam(self.parameters, lr=self.args.lr, weight_decay = 0)
		self.model.init_weights()
Ejemplo n.º 3
0
c_reg = args.c_reg
margin_d = args.margin_d
c_tradeoff = args.c_tradeoff

batch_s = args.batch_size
lr = args.learn_rate
iter_max = args.train_iter_max
save_freq = args.save_model_freq

data_path = args.data_path
model_path = args.model_path

train_test_label = args.train_test_label

# input data and pre-train word embeddings
input_data = data_generator.input_data(args=args)
word_embed = input_data.word_embed

# generate negative paper ids in evaluation
if train_test_label == 2:
    input_data.gen_evaluate_neg_ids()

# TSR model (objective function formulation) begin #
if train_test_label == 0:
    # tensor preparation
    # direct and indirect relation triples
    a_p_p_dir = tf.placeholder(tf.int32, [None, 3])
    a_p_p_indir = tf.placeholder(tf.int32, [None, 3])
    # paper content in direct and indirect relations
    p_c_dir_input = tf.placeholder(tf.int32, [None, c_len])
    p_c_indir_input = tf.placeholder(tf.int32, [None, c_len])