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 & Dataset] facebook & sp2gcl #201

Merged
merged 19 commits into from
Jul 5, 2024
Merged

Conversation

777sssa
Copy link
Contributor

@777sssa 777sssa commented Apr 23, 2024

Description

Checklist

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • Code is well-documented
  • To the best of my knowledge, examples are either not affected by this change,
    or have been fixed to be compatible with this change
  • Related issue is referred in this PR

Changes

@gyzhou2000 gyzhou2000 changed the title Create facebook.py [Model & Dataset] facebook & sp2gcl May 17, 2024
x = tlx.convert_to_tensor(data['features'], dtype=tlx.float32)
y = tlx.convert_to_tensor(data['target'], dtype=tlx.int64)
edge_index = tlx.convert_to_tensor(data['edges'], dtype=tlx.int64)
edge_index = edge_index.T
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried if this can work in the other backend like 'mindspore'?


def __init__(
self,
root: str,
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, this argument can be optional, as we have a cached mechanism compared to PyG.

loss = 0.5 * tlx.losses.softmax_cross_entropy_with_logits(logits, labels) + 0.5 * tlx.losses.softmax_cross_entropy_with_logits(logits.transpose(-2, -1), labels)
return loss
def main(args):
global edge, e, u, test_idx
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this line doing?

val_idx = tlx.where(data.val_mask)[0]
test_idx = tlx.where(data.test_mask)[0]
else:
train_idx, val_idx, test_idx = split(y)
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think this is useful. Usually, the train, valid, test split should be done in the dataset. You may directly use data.train_mask .etc to get the idx instead of add a new function in the util.

import tensorlayerx as tlx
import tensorlayerx.nn as nn
from gammagl.layers.conv import GCNConv
class Encoder(nn.Module):
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember there are many Encoder in the gammagl. I do not recommend you to place this function here.

return x


class MLP(nn.Module):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.




class EigenMLP(nn.Module):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

import tensorlayerx as tlx
import numpy as np

def split(y):
Copy link
Contributor

Choose a reason for hiding this comment

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

This util is useless, remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

from sklearn.model_selection import train_test_split

@ -0,0 +1,40 @@
# Graph Contrastive Learning with Stable and Scalable

- Paper link: [https://proceedings.neurips.cc/paper_files/paper/2023/file/8e9a6582caa59fda0302349702965171-Paper-Conference.pdf](https://arxiv.org/abs/2201.11349)
Copy link
Contributor

Choose a reason for hiding this comment

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

链接不对

Comment on lines 39 to 42
period_e = e.unsqueeze(1) * tlx.pow(2, period_term)
# period_e = period_e.to(u.device)
fourier_e = tlx.concat([tlx.sin(period_e), tlx.cos(period_e)], axis=-1)
h = u @ fourier_e
Copy link
Contributor

Choose a reason for hiding this comment

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

tlx.unsqueeze,矩阵乘用tlx.matmul

Comment on lines 32 to 34
| PubMed | 82.3±0.3 | OOM |
| Wiki-CS | 79.42±0.19 | 76.79 ± 0.61 |
| Facebook | 90.43±0.13 | 85.35±0.26 |
Copy link
Contributor

Choose a reason for hiding this comment

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

调参

Comment on lines 29 to 30
self.phi = nn.Sequential(nn.Linear(1, 16), nn.ReLU(), nn.Linear(16, 16))
self.psi = nn.Sequential(nn.Linear(16, 16), nn.ReLU(), nn.Linear(16, 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

Comment on lines 5 to 7
dataset = FacebookPagePage(root='data/facebook')
g = dataset[0]
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

节点数量,边数量,节点特征维度,类别数量都判断一下

Comment on lines 133 to 134
parser.add_argument('--seed', type=int, default=0)
parser.add_argument('--cuda', type=int, default=3)
Copy link
Contributor

Choose a reason for hiding this comment

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

seed去点,设置device参考其他trainer写法

Comment on lines 42 to 58
def compute_laplacian(data):

edge_index = data.edge_index
num_nodes = data.num_nodes
row, col = edge_index
data_adj = csr_matrix((np.ones(len(row)), (row, col)), shape=(num_nodes, num_nodes))
degree = np.array(data_adj.sum(axis=1)).flatten()
deg_inv_sqrt = 1.0 / np.sqrt(degree)
deg_inv_sqrt[np.isinf(deg_inv_sqrt)] = 0
I = csr_matrix(np.eye(num_nodes))
D_inv_sqrt = csr_matrix((deg_inv_sqrt, (np.arange(num_nodes), np.arange(num_nodes))))
L = I - D_inv_sqrt.dot(data_adj).dot(D_inv_sqrt)
e, u = scipy.sparse.linalg.eigsh(L, k=100, which='SM', tol=1e-3)
data.e = tlx.convert_to_tensor(e, dtype=tlx.float32)
data.u = tlx.convert_to_tensor(u, dtype=tlx.float32)

return data
Copy link
Contributor

Choose a reason for hiding this comment

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

试试用 get_laplacian 接口替换

@gyzhou2000 gyzhou2000 merged commit e276485 into BUPT-GAMMA:main Jul 5, 2024
1 check passed
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.

3 participants