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

How to obtain the categorical node features for GIN and GNNOGB? #220

Open
Wang-Lin-boop opened this issue Jul 26, 2023 · 3 comments
Open

Comments

@Wang-Lin-boop
Copy link

When calling the GIN or GNNOGB modules, the forward function requires a LongTensor storing the node categorical features, which looks like it may be an attributes of DGLGraph, but I can't find a way to get it in the DGL documentation.

If I can get a dictionary from BaseAtomFeaturizer to store node categorical ID and its features, a function that seems easy to implement manually as well, does BaseAtomFeaturizer support getting a dictionary of a node's categorical features?

Progressively refining this dictionary by analyzing the nodes of each batch seems like a viable option, but it doesn't seem elegant enough that I can't believe it's the right one. Can anyone tell me how you solved this problem? I'am looking forward to you reply.

Thanks!

@mufeili
Copy link
Contributor

mufeili commented Jul 26, 2023

When calling the GIN or GNNOGB modules, the forward function requires a LongTensor storing the node categorical features, which looks like it may be an attributes of DGLGraph, but I can't find a way to get it in the DGL documentation.

In the context of molecules, most likely they are atom types. It depends on if your graph already has atom types extracted and stored.

If I can get a dictionary from BaseAtomFeaturizer to store node categorical ID and its features, a function that seems easy to implement manually as well, does BaseAtomFeaturizer support getting a dictionary of a node's categorical features?

Yes, it returns a dictionary of node features, as can be found in the example here: https://github.com/awslabs/dgl-lifesci/blob/master/python/dgllife/utils/featurizers.py#L858

Progressively refining this dictionary by analyzing the nodes of each batch seems like a viable option, but it doesn't seem elegant enough that I can't believe it's the right one. Can anyone tell me how you solved this problem? I'am looking forward to you reply.

It's generally recommended to first extract node features for each molecule and then save them in the corresponding DGLGraph. When you batch multiple graphs corresponding to molecules, their features will be also batched.

@Wang-Lin-boop
Copy link
Author

In the context of molecules, most likely they are atom types. It depends on if your graph already has atom types extracted and stored.

For my featurizer BaseAtomFeaturizer({'atom_type':ConcatFeaturizer([atom_type_one_hot, atom_hybridization_one_hot, atom_formal_charge, atom_chiral_tag_one_hot, atom_is_in_ring, atom_is_aromatic])}), the node features is a long vector, look like (for OCCOCC) :

tensor([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.],
        [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.],
        [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.],
        [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.],
        [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.],
        [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0., 0.,
         0.]])

It looks like I can't get node categorical features directly using the existing API.

@mufeili
Copy link
Contributor

mufeili commented Jul 26, 2023

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

No branches or pull requests

2 participants