SoftplusLoss¶
- class pybind11_ke.module.loss.SoftplusLoss(*args: Any, **kwargs: Any)[源代码]¶
ComplEx[TWR+16] 原论文中应用这种损失函数完成模型训练。备注
forward()中的正样本评分函数的得分应大于负样本评分函数的得分。例子:
from pybind11_ke.module.loss import SoftplusLoss from pybind11_ke.module.strategy import NegativeSampling # define the loss function model = NegativeSampling( model = distmult, loss = SoftplusLoss(), batch_size = train_dataloader.get_batch_size(), regul_rate = 1.0 )
- __init__(adv_temperature: float | None = None)[源代码]¶
创建 SoftplusLoss 对象。
- 参数:
adv_temperature (float) – RotatE 提出的自我对抗负采样中的温度。
- __weakref__¶
list of weak references to the object (if defined)
- adv_temperature: torch.nn.parameter.Parameter¶
RotatE 提出的自我对抗负采样中的温度。
- criterion: torch.nn.Softplus¶
用于代替逻辑函数,类型为
torch.nn.Softplus,它是 ReLU 函数的平滑近似。
- forward(p_score: torch.Tensor, n_score: torch.Tensor) torch.Tensor[源代码]¶
计算 SoftplusLoss 损失函数。定义每次调用时执行的计算。
torch.nn.Module子类必须重写torch.nn.Module.forward()。- 参数:
p_score (torch.Tensor) – 正样本评分函数的得分。
n_score (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]¶
获得模型权重。
- get_weights(n_score: torch.Tensor) torch.Tensor[源代码]¶
计算 RotatE 提出的自我对抗负采样中的负样本的分布概率。
- 参数:
n_score (torch.Tensor) – 负样本评分函数的得分。
- 返回:
自我对抗负采样中的负样本的分布概率
- 返回类型:
- pi_const: torch.nn.parameter.Parameter¶
常数 pi
- predict(p_score: torch.Tensor, n_score: torch.Tensor) numpy.ndarray[源代码]¶
SoftplusLoss 的推理方法。
- 参数:
p_score (torch.Tensor) – 正样本评分函数的得分。
n_score (torch.Tensor) – 负样本评分函数的得分。
- 返回:
损失值
- 返回类型:
- zero_const: torch.nn.parameter.Parameter¶
常数 0