[Model] Add HGAT#213
Open
martinjingyu wants to merge 3 commits into
Open
Conversation
gyzhou2000
reviewed
Jul 2, 2024
Comment on lines
+51
to
+62
| # out_dict={} | ||
| # for node_type, _ in x_dict.items(): | ||
| # out_dict[node_type]=[] | ||
| # for edge_type, edge_index in edge_index_dict.items(): | ||
| # src_type, _, dst_type = edge_type | ||
| # src = edge_index[0,:] | ||
| # dst = edge_index[1,:] | ||
| # message = unsorted_segment_sum(tlx.gather(x_dict[src_type],src),dst,num_nodes_dict[dst_type]) | ||
| # out_dict[dst_type].append(message) | ||
| # for node_type, outs in out_dict.items(): | ||
| # aggr_out = tlx.reduce_sum(outs,axis=0) | ||
| # out_dict[node_type]=tlx.relu(aggr_out) No newline at end of file |
Comment on lines
+40
to
+79
| data = HeteroGraph() | ||
|
|
||
| node_types = ['documents', 'topics', 'words'] | ||
| for i, node_type in enumerate(node_types): | ||
| x = sp.load_npz(osp.join(self.raw_dir, f'features_{i}.npz')) | ||
| data[node_type].x = tlx.convert_to_tensor(x.todense(), dtype=tlx.float32) | ||
|
|
||
| y = np.load(osp.join(self.raw_dir, 'labels.npy')) | ||
| y = np.argmax(y,axis=1) | ||
| data['documents'].y = tlx.convert_to_tensor(y, dtype=tlx.int64) | ||
|
|
||
| split = np.load(osp.join(self.raw_dir, 'train_val_test_idx.npz')) | ||
| for name in ['train', 'val', 'test']: | ||
| idx = split[f'{name}_idx'] | ||
| mask = np.zeros(data['documents'].num_nodes, dtype=np.bool_) | ||
| mask[idx] = True | ||
| data['documents'][f'{name}_mask'] = tlx.convert_to_tensor(mask, dtype=tlx.bool) | ||
|
|
||
|
|
||
| s = {} | ||
| N_m = data['documents'].num_nodes | ||
| N_d = data['topics'].num_nodes | ||
| N_a = data['words'].num_nodes | ||
| s['documents'] = (0, N_m) | ||
| s['topics'] = (N_m, N_m + N_d) | ||
| s['words'] = (N_m + N_d, N_m + N_d + N_a) | ||
|
|
||
| A = sp.load_npz(osp.join(self.raw_dir, 'adjM.npz')).tocsr() | ||
| for src, dst in product(node_types, node_types): | ||
| A_sub = A[s[src][0]:s[src][1], s[dst][0]:s[dst][1]].tocoo() | ||
| if A_sub.nnz > 0: | ||
| row = tlx.convert_to_tensor(A_sub.row, dtype=tlx.int64) | ||
| col = tlx.convert_to_tensor(A_sub.col, dtype=tlx.int64) | ||
| data[src, dst].edge_index = tlx.stack([row, col], axis=0) | ||
| print(src+"____"+dst) | ||
|
|
||
| if self.pre_transform is not None: | ||
| data = self.pre_transform(data) | ||
|
|
||
| self.save_data(self.collate([data]), self.processed_paths[0]) |
Contributor
There was a problem hiding this comment.
修改成从作者提供的url下载数据集,然后处理成heterograph
| from gammagl.data import (HeteroGraph, InMemoryDataset, download_url, | ||
| extract_zip) | ||
|
|
||
| class OHSUMED(InMemoryDataset): |
Contributor
There was a problem hiding this comment.
写一个test文件,参考gammagl/datasets/路径下的其他测试文件
gyzhou2000
reviewed
Jul 4, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new model: HGAT
corresponding with two conv layer, HINConv and HGATConv
and a new method to convert the Heterogeneous graph dict to homogeneous graph matrix: heter_homo_mutual_convert