node2vec需要火炬集群



我正在尝试使用PyG的Node2Vec,我遇到以下错误:

ImportError                               Traceback (most recent call last)
<ipython-input-58-27749832cd17> in <module>()
----> 1 model = Node2Vec(pygraph.edge_index, embedding_dim=128, walk_length=20,context_size=10, walks_per_node=10, num_negative_samples=1, p=1, q=1, sparse=True).to(device)
/usr/local/lib/python3.7/dist-packages/torch_geometric/nn/models/node2vec.py in __init__(self, edge_index, embedding_dim, walk_length, context_size, walks_per_node, p, q, num_negative_samples, num_nodes, sparse)
53 
54         if random_walk is None:
---> 55             raise ImportError('`Node2Vec` requires `torch-cluster`.')
56 
57         N = maybe_num_nodes(edge_index, num_nodes)
ImportError: `Node2Vec` requires `torch-cluster`.
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

我已经浏览了这里列出的PyTorch Geo文档

在以下代码行中抛出错误:

if random_walk is None:
raise ImportError('`Node2Vec` requires `torch-cluster`.')

为了解决这个问题,我导入了random_walk,与文档

中的方法类似。下面是我的代码:
import os
import torch
os.environ['TORCH'] = torch.__version__
print(torch.__version__)
!pip install -q torch-scatter -f https://data.pyg.org/whl/torch-${TORCH}.html
!pip install -q torch-sparse -f https://data.pyg.org/whl/torch-${TORCH}.html
!pip install -q git+https://github.com/pyg-team/pytorch_geometric.git
from torch_geometric.nn import Node2Vec
!pip install torch-cluster -f https://data.pyg.org/whl/torch-${TORCH}.html
import torch_cluster
random_walk = torch.ops.torch_cluster.random_walk
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = Node2Vec(pygraph.edge_index, embedding_dim=128, walk_length=20,context_size=10, walks_per_node=10, num_negative_samples=1, p=1, q=1, sparse=True).to(device)

注意:在Google Colab上运行

Node2Vec模型需要torch-cluster库,它是PyTorch Geometric (PyG)的一部分。

安装火炬集群:

pip install torch-cluster

但是由于它依赖于特定版本的PyTorch和CUDA,使用提供的安装命令安装PyTorch Geometric及其所有组件可能更容易。

pip安装火炬-分散火炬-稀疏火炬-簇火炬-样条-转换火炬-几何

相关内容

  • 没有找到相关文章

最新更新