RandomLinkSplit不与HeteroData一起使用
在处理我自己的数据时,我在使用torch-geometric
时遇到了一些严重的问题。 我正在尝试构建一个具有 4 个不同节点实体(其中只有 1 个具有某些节点特征,其他是简单节点)和 5 个不同边类型(其中只有一个具有权重)的图。 我成功地通过构建一个 HeteroData() 对象并加载带有标签、属性等的不同矩阵来做到这一点。
当我尝试调用 RandomLinkSplit
时,问题就出现了。这是我的调用的样子:
import torch_geometric.transforms as T
transform = T.RandomLinkSplit(
num_val = 0.1,
num_test = 0.1,
edge_types = [('Patient', 'suffers_from', 'Diagnosis'),
('bla', 'bla', 'bla') #I copy all the edge types here
],
)
但是我得到了空的 AssertionError
条件:
assert is instance(rev_edge_types, list)
所以我认为我需要像教程一样将图转换为无向(出于某种奇怪的原因),然后示例还反转边缘(即使我不需要它们):
import torch_geometric.transforms as T
data = T.ToUndirected()(data)
transform = T.RandomLinkSplit(
num_val = 0.1,
num_test = 0.1,
edge_types = [('Patient', 'suffers_from', 'Diagnosis'),
('bla', 'bla', 'bla') #I copy all the edge types here
],
rev_edge_types = [('Diagnosis', 'rev_suffers_from', 'Patient'),
...
]
)
但这次我收到错误*:'Tensor'和'NoneType'不支持的操作数类型
。
有专家对为什么会发生这种情况有任何想法吗?我只是想进行火车测试分割,从我读到的文档中,异构图应该得到很好的支持,但我不明白为什么这不起作用,而且我已经尝试了很多不同的事情。
任何帮助将不胜感激! 谢谢
I am having some serious trouble with torch-geometric
when dealing with my own data.
I am trying to build a graph that has 4 different node entities (of which only 1 bears some node features, the others are simple nodes), and 5 different edge type (of which only one bears a weight).
I have managed to do so by building a HeteroData()
object and loading the different matrices with labels, attributes and so on.
The problem arises when I try to call RandomLinkSplit
. Here's what my call looks like:
import torch_geometric.transforms as T
transform = T.RandomLinkSplit(
num_val = 0.1,
num_test = 0.1,
edge_types = [('Patient', 'suffers_from', 'Diagnosis'),
('bla', 'bla', 'bla') #I copy all the edge types here
],
)
but I get the empty AssertionError
on the condition:
assert is instance(rev_edge_types, list)
So I thought that I needed to transform the graph to undirected (for some weird reason) like the tutorial does, and then to sample also reverse edges (even though I don't need them):
import torch_geometric.transforms as T
data = T.ToUndirected()(data)
transform = T.RandomLinkSplit(
num_val = 0.1,
num_test = 0.1,
edge_types = [('Patient', 'suffers_from', 'Diagnosis'),
('bla', 'bla', 'bla') #I copy all the edge types here
],
rev_edge_types = [('Diagnosis', 'rev_suffers_from', 'Patient'),
...
]
)
but this time I get the error unsupported operand type(s) for *: 'Tensor' and 'NoneType'
.
Does any expert have any ideas on why this is happening? I am simply trying to do a train test split, and from the docs I read the Heterogeneous graphs should be well supported, but I don't understand why this is not working and I have been trying different things for quite a lot of time.
Any help would be appreciated!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该尝试对每个边缘进行分割,并一次在一种边缘类型上进行训练。
You should try to do split per edge and train on one edge type at a time.
我也遇到了这个问题。
在探索了一些代码之后,我发现有一个变量
size[1]
本来应该是一个 int,但结果是 None。在弄清楚它来自哪里并手动检查
data[edgekey].size()
后,我收到了一个额外的警告,无法推断我的节点类型之一上的num_nodes
.在这种类型上设置 num_nodes 后,一切正常。
确保您使用的边缘键和节点键没有拼写错误。这似乎也导致了这个错误
I ran into this problem as well.
After exploring a bit of code I found that there was a variable
size[1]
which should have been an int, but turned out to be None.After figuring out where it came from, and manually checking
data[edgekey].size()
I got an additional warning thatnum_nodes
on one of my node types could not be inferred.After setting
num_nodes
on this type everything worked well.Make sure that there are no typos in the edge and node keys that you use either. That also seems to lead to this error