-
Hi, I am implementing a GNN model as an exercise to get familiar with Pytorch Geometric and I have a doubt about linear layers when using mini-batches. I've tried to find a solution online and on the other threads, but I couldn't find any. I am using a customised data class for my graphs (which are basically bipartite graphs):
And I load them in mini-batches using dataloader: In my model I have several linear layers that are applied on the feature vectors x_l and x_c (they are updated at different times) contained in my class MLP:
Instances of the class MLP are then used in However, if I am not mistaken, when using batches, the features matrices x_l and x_c get concatenated along the first dimension and for this reason when I forward them on a MLP, the output of a node feature can depend also on the features of nodes belonging to other graphs (unless I've misunderstood how linear layers works). Is there a way to use linear layers in such a way that the output values of each graph's feature matrix depend only on its own initial value, instead of having outputs which mix values coming from different graphs? The graphs can have different numbers of nodes. Moreover, I am also using Pytorch's implementation of LSTM for some layers and I guess that the same problem occurs also in that case. I am happy to provide more information if needed! Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is not a problem. A x = ... # [num_nodes, 256]
lin = Linear(256, 512)
x = self.lin(x) # [num_nodes, 512] You don't have to worry about that (even for LSTMs), as long as the node dimension is used as the batch dimension. |
Beta Was this translation helpful? Give feedback.
This is not a problem. A
linear
layer will transform each node feature vector in isolation - the node feature dimension acts as the batch dimension here:You don't have to worry about that (even for LSTMs), as long as the node dimension is used as the batch dimension.