Adding edge features to hetero-graphs HeteroData
#8119
-
For some reason I'm not being able to assign features to edges using Given the following code snippet import torch
from torch_geometric.data import HeteroData
data = HeteroData()
# Params
num_papers, num_paper_features = 5, 7
num_authors, num_author_features = 4, 10
num_edges = torch.randint(5, num_papers*num_authors, [1]).item()
author_writes_paper_num_features = 4
# Adding features to nodes
data['paper'].x = torch.randn(num_papers, num_paper_features)
data['author'].x = torch.randn(num_authors, num_author_features)
# Creating some random edges
author_edge_index = torch.randint(0, num_authors, [num_edges])
paper_edge_index = torch.randint(0, num_papers, [num_edges])
edge_index = torch.stack((author_edge_index, paper_edge_index))
data['author', 'writes', 'paper'].edge_index = edge_index
# Remove repeated edges and sort
data = data.coalesce()
# Adding features to edges
data['author', 'writes', 'paper'].x = torch.randn(author_writes_paper_num_features, data.num_edges)
# Also tried using the transpose edge feature matrix
# data['author', 'writes', 'paper'].x = torch.randn(data.num_edges, author_writes_paper_num_features) But, while I can correctly fetch node features
The same does not happens with edge features
Is ZERO. Even with a
We can see that no feature attribute data.edge_attrs()
# ['edge_index'] Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For edge features, you should use the |
Beta Was this translation helpful? Give feedback.
Citing Jintang Li:
For edge features, you should use the
edge_attr
rather thanx
.