LinkPredictAdvBCELossFunc

class graphstorm.model.LinkPredictAdvBCELossFunc(adversarial_temperature)

Bases: LinkPredictBCELossFunc

Binary cross entropy loss function for link prediction tasks with adversarial loss for negative samples.

The loss of positive edges is defined as:

\[loss_{pos} = - \log score\]

where score is the score value of the positive edges computed by the score function.

The loss of negative edges is defined as:

\[\begin{split}loss_{neg} = \log (1 - score) \\ loss_{neg} = \mathrm{softmax}(score * adversarial\_temperature) * loss_{neg}\end{split}\]

where score is the score value of the negative edges computed by the score function and adversarial_temperature is a hyper-parameter.

The final loss is defined as:

\[loss = \dfrac{\mathrm{avg}(loss_{pos}) + \mathrm{avg}(loss_{neg})}{2}\]

Parameters

adversarial_temperature: float

Temperature value for adversarial loss.

forward(pos_score, neg_score)

The forward function.

Parameters

pos_score: dict of Tensor

The scores for positive edges of each edge type.

neg_score: dict of Tensor

The scores for negative edges of each edge type.

Returns

loss: Tensor

The loss value.