AICPS / hw2vec

MIT License
35 stars 20 forks source link

why use both log_softmax and CrossEntropyLoss ? #23

Closed Lzrony3 closed 7 months ago

Lzrony3 commented 7 months ago
def train_epoch_tj(self, data):
    output, _ = self.model.embed_graph(data.x, data.edge_index, data.batch)
    output = self.model.mlp(output)
    output = F.log_softmax(output, dim=1)

    loss_train = self.loss_func(output, data.label)
    return loss_train

def __init__(self, cfg, class_weights=None):
    super().__init__(cfg)
    self.task = "TJ"
    if class_weights.shape[0] < 2:
        self.loss_func = nn.CrossEntropyLoss()
    else:    
        self.loss_func = nn.CrossEntropyLoss(weight=class_weights.float().to(cfg.device))

That means using double logsoftmax, which might introduce some negative effects.