Multi class node classification

Greetings!

I am trying to code a GCN model to perform multi-class classification. The problem setup is as follows with each node (node feature) having multiple classes (one-hot encoding fashion),

node1_features–>[1, 0, 0]
node2_features–>[0, 1, 0]

I am having issues when dealing with the data loader and the collate function. I have the following setup for the collate function,

    def collate(samples):
        multi_labels = []
        graphs, node_labels = map(list, zip(*samples))
        batch_graph = dgl.batch(graphs)
        for i in range(len(node_labels)):
            for j in range(len(node_labels[i])):
                labels.append(node_labels[i][j])
        return batch_graph, th.tensor(labels)

The “node_labels” in the above code represent one vector of one-hot encoding ([0, 1, 0])

Also, I am curious what will be the setup for the loss function. Any help would be appreciated!

I don’t think you need the nested for loop. It suffices to use th.tensor(labels). Also, you don’t need to use one-hot encoding of the labels for multiclass classification. The pipeline for graph classification is similar to that for node classification. See the example here.

Thank you for the response. I am able to make node classification work for nodes having a single label, such as binary classification. However, in my current setup, I have each node labeled with multiple classes. For example, a node may refer to multiple objects A, B, C, D, etc. If a node belongs to both A and B then the first two positions will be 1 and the rest of the positions will be 0, so the label for that node will be [1 1 0 0]. I was curious if there is any example where a node is labeled with a vector rather than just one value (or binary classification).

I see your point. Then you are actually referring to multi-label binary classification. For an example, see dgl-lifesci/examples/property_prediction/csv_data_configuration/classification_train.py at master · awslabs/dgl-lifesci · GitHub

Thanks a lot! It will help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.