mberr / torch-ppr Goto Github PK
View Code? Open in Web Editor NEW(Personalized) Page-Rank computation using PyTorch
License: MIT License
(Personalized) Page-Rank computation using PyTorch
License: MIT License
can u provide one simple example , how to use it for bipartite graph for recommending items to for users using this PPR code.
thanks
Dear torch-ppr
I installed torch-ppr on my Mac with python 3.9 and run the example code
>>> import torch
>>> edge_index = torch.as_tensor(data=[(0, 1), (1, 2), (1, 3), (2, 4)]).t()
>>> from torch_ppr import page_rank
>>> page_rank(edge_index)
I got a runtimeerror as
x = torch.sparse.addmm(input=x0, sparse=adj, dense=x, beta=alpha, alpha=beta)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (2x4 and 2x1)
I printed the shape of x0, adj and x
torch.Size([2, 1])
torch.Size([2, 4])
torch.Size([2, 1])
I believe that the shape of adj should be 2x2 or I might be wrong.
I find the define process of adj.
# convert to sparse matrix, shape: (n, n)
adj = edge_index_to_sparse_matrix(edge_index=edge_index, num_nodes=num_nodes)
adj = adj + adj.t()
The adj is symmect.
I wonder how to fix the runtimeError or any suggestions?
Thanks in advanced
meatball1982
12-May-2022 09:54:50
Thank you for this repo!
The reason to request a 'layer' fomulation is to convert the function page_rank
to an onnx graph with torch.onnx
(only accepts models).
Once I have the onnx model, I can compile it different hardware (other than cuda).
Maybe need just the forward pass, no need for a backward pass although I think the compute will be differentiable.
Thanks.
related to #18
Suddenly, everything stopped working ๐ฑ presumably because of the changes to torch.sparse.
Particularly, I am on PyTorch 1.10, master branch of PyKEEN and torch-ppr 0.0.5.
Problem 1: the allclose()
check does not pass now:
torch-ppr/src/torch_ppr/utils.py
Lines 221 to 222 in 921898f
MWE:
import torch
from torch_ppr import page_rank
from pykeen.datasets import FB15k237
dataset = FB15k237(create_inverse_triples=False)
edges = dataset.training.mapped_triples[:, [0, 2]].t()
pr = page_rank(edge_index=torch.cat([edges, edges.flip(0)], dim=-1), num_nodes=dataset.num_entities)
>> ValueError: Invalid column sum: tensor([1.0000, 1.0000, 1.0000, ..., 1.0000, 1.0000, 1.0000]). expected 1.0
Looking into the debugger:
adj_sum
does sum up to the number of nodesrtol=1e-4
or atol=1e-4
- the check passesProblem 2: the signature of torch.sparse.addmm
has changed from the one used in power_iteration
so the API call fails with the unknown kwarg error.
torch-ppr/src/torch_ppr/utils.py
Line 310 in 921898f
In fact, I can't find where those kwargs input, sparse, dense
come from because the current signature has less readable mat, mat1, mat2
. I traced to the very Torch 1.3.0 and still can't find where those originated from. Where does this signature come from? ๐
My test env
torch 1.10.0
torch-ppr 0.0.5
Hello,
Thank you for this great repository; it is a great, handy package that performs very well! I was wondering however; is it possible to incorporate edge weights into the personalized pagerank method?
Best
Filip
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.