LinkPredictContrastiveLossFunc

class graphstorm.model.LinkPredictContrastiveLossFunc(temp=1.0)

Bases: GSLayer

Contrastive Loss function for link prediction tasks.

The positive and negative scores are computed through a score function as:

\[score = f(<src, rel, dst>)\]

And we treat a score as the distance between src and dst nodes under relation rel.

In contrastive loss, we assume one positive pair <src, dst> has K corresponding negative pairs <src, neg_dst1>, <src, neg_dst2> …. <src, neg_dstk>. When we compute the loss of <src, dst>, we follow the following equation:

\[loss = -log(exp(pos\_score)/\sum_{i=0}^K exp(score_i))\]

where score includes both positive score of <src, dst> and negative scores of <src, neg_dst0>, … <src, neg_dstk>.

Parameters

temp: float

Temperature value.

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.

property in_dims

The number of input dimensions.

Returns

int : the number of input dimensions.

property out_dims

The number of output dimensions.

Returns

int : the number of output dimensions.