Cartus / AGGCN

Attention Guided Graph Convolutional Networks for Relation Extraction (authors' PyTorch implementation for the ACL19 paper)
MIT License
433 stars 88 forks source link

What is the function of tensor "denom" ? #38

Closed qwe1997 closed 2 years ago

qwe1997 commented 2 years ago

In the Class of GraphConvLayer and MultiGraphConvLayer, there is a tensor called denom. I have tried to understand its meaning,however I failed.So please tell me this tensor's meaning.thanks!

` def forward(self, adj, gcn_inputs):

gcn layer

    denom = adj.sum(2).unsqueeze(2) + 1  
    outputs = gcn_inputs
    cache_list = [outputs]
    output_list = []

    for l in range(self.layers):  # 0, 1
        Ax = adj.bmm(outputs)
        AxW = self.weight_list[l](Ax)
        AxW = AxW + self.weight_list[l](outputs)  # self loop
        AxW = AxW / denom 
        gAxW = F.relu(AxW)
        cache_list.append(gAxW)
        outputs = torch.cat(cache_list, dim=2) 
        output_list.append(self.gcn_drop(gAxW))`
Cartus commented 2 years ago

As I remember, denom is the diagonal node degree matrix used in GCN, please refer to the original GCN paper: https://arxiv.org/pdf/1609.02907.pdf

qwe1997 commented 2 years ago

Thank you very much! "denom" is the diagonal node degree matrix, "adj.sum(2)" means getting graph nodes degrees and unsqueeze(2) means generating two dimensional matrix for graph convolution calculation and +1 means adding self-loop nodes degrees!

Cartus commented 2 years ago

Exactly! I am closing this issue, if you have further questions, feel free to re-open it.