antoniolonga / pytorchgeometrictutorial Goto Github PK
View Code? Open in Web Editor NEWPytorch Geometric Tutorials
Pytorch Geometric Tutorials
Reading the loss function of Node2Vec class (https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/nn/models/node2vec.html) , i feel the return value of "pos_loss + neg_loss" does not seem to take into account of 'num_negative_samples'. Shouldn't the loss function return "pos_loss + neg_loss * self.num_ negative_samples" instead?
[Tutorial16] Report an error,There is an error in BatchNorm1d part
Hi
In the final GAT implementation:
We use two imported GATConv layers.
In the constructor, we initialize each one of them with a dropout of 0.6.
In the forward method, we apply additional dropout before each one of them.
What's the point in doing additional dropout?
Thank you for making the videos and notebooks available! They are very nice and helpful.
I saw that the DiffPool model still does not work for the version that is uploaded here.
I was wondering if you already have the working model available?
Thank you in advance!
Tutorial 14 and 15 both no longer work with colab and give this error after the second cell
OSError Traceback (most recent call last)
in ()
2 import os
3 import pandas as pd
----> 4 from torch_geometric.data import InMemoryDataset, Data, download_url, extract_zip
5 from torch_geometric.utils.convert import to_networkx
6 import networkx as nx
6 frames
/usr/lib/python3.7/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: /usr/local/lib/python3.7/dist-packages/torch_sparse/_convert_cpu.so: undefined symbol: _ZNK2at6Tensor5zero_Ev
https://github.com/AntonioLonga/PytorchGeometricTutorial/blob/main/Tutorial1/Tutorial1.ipynb
I think this example could be modified for the better. In fact, the nums_layer = 1 parameter should be defined in Net, and a layer of GNNStack should be defined according to this parameter in the forward method. This would solve the problem raised by YouTube video 43:29.
Hi,
Thanks for this great tutorials and videos. Really nice work.
I was wondering about the GATLayer class in the code of tutorial 3. Once the class is made, it is no longer used after the 'Use it' heading in the notebook. Instead, the GATConv from torch geometric is used directly. Then why was the GATLayer class made?
Thanks,
VR
Hi,
My background is in Knowledge Representation and Reasoning and I'm just a beginner in Deep Learning on Graphs, so apologies in advance if I say something against the (coding) conventions in this domain.
I started to go through the tutorials, converting each into a torch/geometric script (to get familiar with the engineering aspect), as well as a torch/geometric/lightning script.
I've noticed that the methods from the class "Net" of Tutorial 1 are missing all the parameters required to function.
Specifically, they are missing "dataset" (in __init__()
) and "data" (in forward()
).
The notebook works fine because "dataset" and "data" are defined in a cell above Net
, therefore they are hardcoded.
I'm not sure sure if this was intended, since it might mislead learners.
As a result, I've changed your code as follows (including the changes discussed above and some cosmetic changes for readability):
import torch.nn as nn
import torch_geometric.nn as gnn
class Net(nn.Module):
def __init__(self, num_features: int, num_classes: int):
super(Net, self).__init__()
assert num_features > 0, f"At least 1 feature required, {num_features} were given"
assert num_classes > 0, f"At least 1 class required, {num_classes} were given"
self.conv = gnn.SAGEConv(
num_features,
num_classes,
aggr="max", # max, mean, add ...
)
def forward(self, x, edge_index):
x = self.conv(x, edge_index)
x = F.log_softmax(x, dim=1)
return x
Consequently, the model is instantiated as follows:
device = torch.device('cuda' if torch.cuda.is_available() and use_cuda_if_available else 'cpu')
model, data = Net(
num_features=dataset.num_features,
num_classes=dataset.num_classes,
).to(device), data.to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)
And the train()
and test()
methods become as follows:
def train():
model.train()
optimizer.zero_grad()
logits = model(data.x, data.edge_index)
F.nll_loss(logits[data.train_mask], data.y[data.train_mask]).backward()
optimizer.step()
def test():
model.eval()
logits, accs = model(data.x, data.edge_index), []
for _, mask in data('train_mask', 'val_mask', 'test_mask'):
pred = logits[mask].max(1)[1]
acc = pred.eq(data.y[mask]).sum().item() / mask.sum().item()
accs.append(acc)
return accs
Let me know if I stand correct in my thoughts, or if I'm missing some crucial point because I'm not familiar with this domain.
Also please let me know if you find this feedback helpful, and I'll keep reporting other things that I notice in the tutorials.
Also please let me know if you'd be interested in the Torch Lightning examples as well (so far I've managed to do it, at least!).
Last but not least, please send my greetings to Trento and Val di Non that I miss deeply! 🥹 Ciao!
Hi, this is a nice tutorial. However, I find that there are some minor problems with the materials.
Hi Antonio or anyone else,
I am trying to see what do the counts 140, 500, 1000 mean for train, val and test masks respectively.
torch.sum(data.train_mask), torch.sum(data.val_mask), torch.sum(data.test_mask), data
Gives me this result:
(tensor(140, device='cuda:0'),
tensor(500, device='cuda:0'),
tensor(1000, device='cuda:0'),
Data(x=[2708, 1433], edge_index=[2, 10556], y=[2708], train_mask=[2708], val_mask=[2708], test_mask=[2708]))
Question 1: Does this imply, for train only 140 nodes are available whereas for val and test a lot more as per the split in this data? I am coming from non-GNN background therefore this caught my eye.
Question 2: The addition of 140+500+1000 = 1640, does not add upto 2708, should it not?
In tutorial 6 if we use the randomlinksplit how does train_pos_edge_index get handled later in the code?
Does this line become:
train_pos_edge_index = train_data.edge_index.to(device)
?
And how is the test function redefined? If we don't have pos edges nor neg edges, then can you describe what happens to the test function?
Hello, Thank you for the nice tutorial, it helps a lot to get started! I have a few questions concerning Tutorial16.ipynb: 1/ what is the effect of the parameter lin=True? 2/ what's the effect of changing the number of hidden and output channels? 3/ what is the purpose of l1, e1, l2, e2? Best, Claire
Thanks for your effort and great work!
I think, In order to make the tutorials more convenient for a wide audience it would be helpful to add a colab
version of the notebooks with the special button, that redirects to the http://colab.research.google.com/.
All tutorials can be run in colab
via adding the notebook from GitHub and adding the cell with the installation of the pytorch-geometric
and all dependencies. But the version with native support would make it more convenient.
while running from torch_geometric.nn import Node2Vec in google colab an error occur
OSError: /usr/local/lib/python3.7/dist-packages/torch_sparse/_convert_cpu.so: undefined symbol: _ZNK2at6Tensor5zero_Ev
what should I do?
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.