BinaryCrossEntropyLoss
- class KGE.loss.BinaryCrossEntropyLoss[source]
Bases:
KGE.loss.LossAn implementation of Binary Cross Entropy Loss.
Binary Cross Entropy Loss is commonly used in binary classification problem. In KGE, we can also turn the problem into a binary classification problem that classifies triplet into positive or negative \(y_i = 1~or~0\) with the triplet score as logit: \(logit_i = f\left( (h,r,t)_i \right)\)
\[ \begin{align}\begin{aligned}\begin{aligned} \mathscr{L} &= - \sum_i y_i log(\hat{y}_i) + (1-y_i) log(1-\hat{y}_i)\\ &= - \sum_i log\left[\sigma(f((h,r,t)_i^+))\right] - \sum_i log\left[1-\sigma(f((h,r,t)_i^-))\right]\\ &= - \sum_i log\left[\sigma(f((h,r,t)_i^+))\right] - \sum_i log\left[\sigma(-f((h,r,t)_i^-))\right] \end{aligned}\end{aligned}\end{align} \]Methods Summary
__call__(pos_score, neg_score)Calculate loss.
Methods Documentation
- __call__(pos_score, neg_score)[source]
Calculate loss.
- Parameters
pos_score (
tf.Tensor) – score of postive triplets, with shape(n,)neg_score (
tf.Tensor) – score of negative triplets, with shape(n,)
- __new__(*args, **kwargs)