RGCNLoss¶
- class pybind11_ke.module.loss.RGCNLoss(*args: Any, **kwargs: Any)[源代码]¶
R-GCN[SKB+18] 原论文中应用这种损失函数完成模型训练。备注
forward()中的正样本评分函数的得分应大于负样本评分函数的得分。例子:
from pybind11_ke.module.loss import RGCNLoss from pybind11_ke.module.strategy import RGCNSampling
# define the loss function model = RGCNSampling(
model = rgcn, loss = RGCNLoss(model = rgcn, regularization = 1e-5)
)
- __weakref__¶
list of weak references to the object (if defined)
- forward(score: torch.Tensor, labels: torch.Tensor) torch.Tensor[源代码]¶
计算 RGCNLoss 损失函数。定义每次调用时执行的计算。
torch.nn.Module子类必须重写torch.nn.Module.forward()。- 参数:
score (torch.Tensor) – 模型的得分。
labels (torch.Tensor) – 标签
- 返回:
损失值
- 返回类型:
- get_parameters(mode: str = 'numpy', param_dict: dict[str, Any] | None = None) dict[str, numpy.ndarray] | dict[str, list] | dict[str, torch.Tensor]¶
获得模型权重。
- pi_const: torch.nn.parameter.Parameter¶
常数 pi
- reg_loss() torch.Tensor[源代码]¶
获得正则部分的损失。
- 返回:
损失值
- 返回类型:
- zero_const: torch.nn.parameter.Parameter¶
常数 0