Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Model] BPHGNN #246

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

[Model] BPHGNN #246

wants to merge 6 commits into from

Conversation

LaooBaoo
Copy link

@LaooBaoo LaooBaoo commented Aug 6, 2024

No description provided.

@gyzhou2000 gyzhou2000 changed the title MHGCN-check-for 周光煜 [Model] BPHGNN Aug 9, 2024
@gyzhou2000
Copy link

gyzhou2000 commented Aug 9, 2024

  1. 需要在提交之前,重新拉取主分支上的代码,保证代码是最新的
  2. 拉取最新代码之后,解决代码冲突

docs/source/api/model.rst Outdated Show resolved Hide resolved
docs/source/api/trainerflow.rst Outdated Show resolved Hide resolved
openhgnn/trainerflow/MHGCN_trainer.py Outdated Show resolved Hide resolved
Comment on lines 95 to 101
train_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/MHGCN_dataset/train.txt')
valid_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/MHGCN_dataset/valid.txt')
test_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/MHGCN_dataset/test.txt')

train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
valid_loader = DataLoader(valid_dataset, batch_size=32, shuffle=False)
test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分代码考虑一下是否要放在 __init__ 函数中


output = self.model(features=features, hg=self.hg, encode=features)

loss = F.cross_entropy(output, labels) # 计算损失

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要出现中文注释

@@ -10,7 +10,7 @@ Models
{% for cls in openhgnn.models.classes %}
{{ cls }}
{% endfor %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要添加无意义的空行

@@ -10,7 +10,7 @@ Trainerflow
{% for cls in openhgnn.trainerflow.classes %}
{{ cls }}
{% endfor %}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

main.py Outdated
@@ -7,7 +7,7 @@

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--model', '-m', default='RGCN', type=str, help='name of models')
parser.add_argument('--model', '-m', default='BPHGNN', type=str, help='name of models')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要修改 main.py 中默认的超参数,如果想运行自己的模型的话,可以在命令行中设置,python mian.py --model BPHGNN

@@ -28,7 +28,7 @@ class NodeClassification(BaseTask):
def __init__(self, args):
super(NodeClassification, self).__init__()
self.logger = args.logger
self.dataset = build_dataset(args.dataset, 'node_classification', logger=self.logger)
self.dataset = build_dataset(args.dataset, 'node_classification', logger=self.logger) # 返回node_classificationDataset对象

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除中文注释

@@ -137,11 +137,11 @@ def init_feature(self, act):
if isinstance(self.hg.ndata['h'], dict):
# The heterogeneous contains more than one node type.
input_feature = HeteroFeature(self.hg.ndata['h'], get_nodes_dict(self.hg),
self.args.hidden_dim, act=act).to(self.device)
self.args.hidden, act=act).to(self.device)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要修改 base_flow.py 中的默认参数名称,可将 config.ini 文件中对应的超参数名改成 hidden_dim

Comment on lines 266 to 267
opt = torch.optim.Adam([{'params': self.model.parameters(), 'lr': 0.01}, {'params': log.parameters()}], lr=0.001, weight_decay=0.0005)
log.to(device)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在优化器中的学习率使用的是固定参数,这样做不准确。需要将值设置为 config.ini 中的参数值

except:
pass
labels = labels.astype(np.int16)
device=torch.device('cuda')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main.py 中已经通过 --gpu 这个参数来设置tensor的位置了,不需要重复设置

Comment on lines 42 to 52
class TextDataset(Dataset):
def __init__(self, filepath):
self.data = []
with open(filepath, 'r') as f:
for line in f:

split_line = list(map(int, line.strip().split()))
self.data.append(split_line)

def __len__(self):
return len(self.data)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个类在后续代码中并没有用到,可以删除

Comment on lines 8 to 63
class TextDataset(Dataset):
def __init__(self, filepath):
self.data = []
with open(filepath, 'r') as f:
for line in f:

split_line = list(map(int, line.strip().split()))
self.data.append(split_line)

def __len__(self):
return len(self.data)

def __getitem__(self, idx):

data = self.data[idx]
features = torch.tensor(data[:-1], dtype=torch.float32)
labels = torch.tensor(data[-1], dtype=torch.long)
return features, labels

def load_edges(file_path):
edge_data = {
1: [],
2: [],
3: []
}

with open(file_path, 'r') as f:
for line in f:

split_line = list(map(int, line.strip().split()))
edge_type, src_id, dst_id, _ = split_line
edge_data[edge_type].append((src_id, dst_id))

return edge_data

def build_hetero_graph():

edge_data = load_edges('OpenHGNN/openhgnn/dataset/data/test/BPHGNN_dataset/alibaba_small/train.txt')

data_dict = {
('node', 'relation1', 'node'): edge_data[1],
('node', 'relation2', 'node'): edge_data[2],
('node', 'relation3', 'node'): edge_data[3],
}

hg = dgl.heterograph(data_dict)
return hg


train_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/BPHGNN_dataset/train.txt')
valid_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/BPHGNN_dataset/valid.txt')
test_dataset = TextDataset('OpenHGNN/openhgnn/dataset/data/BPHGNN_dataset/test.txt')

train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
valid_loader = DataLoader(valid_dataset, batch_size=32, shuffle=False)
test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataset 文件的内容可以参考其他dataset文件的编写内容,这样写不对

@@ -500,6 +502,7 @@ def __init__(self, dataset_name, *args, **kwargs):
self.train_idx, self.valid_idx, self.test_idx = split_idx["train"][self.category], split_idx["valid"][
self.category], split_idx["test"][self.category]
self.g, self.label_dict = dataset[0]
self.BPHGNN_g = self.mag4mhgcn(dataset)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bphgnn模型为什么要调用self.mag4mhgcn(dataset)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants