交叉熵损失
- class CrossEntropyLoss(reduction: str = 'mean')[source]
基础:
SetwiseLoss评估softmax输出后的交叉熵的交叉熵损失。
注意
相关的
torch模块是torch.nn.CrossEntropyLoss,但由于 PyKEEN 的损失函数中实现了扩展功能,因此不能互换使用。初始化损失。
- Parameters:
reduction (str) – 减少方式,参见
pykeen.nn.modules._Loss
方法总结
process_lcwa_scores(predictions, labels[, ...])处理来自LCWA训练循环的分数。
process_slcwa_scores(positive_scores, ...[, ...])处理来自sLCWA训练循环的分数。
方法文档
- process_lcwa_scores(predictions: Tensor, labels: Tensor, label_smoothing: float | None = None, num_entities: int | None = None) Tensor[source]
处理来自LCWA训练循环的分数。
- process_slcwa_scores(positive_scores: Tensor, negative_scores: Tensor, label_smoothing: float | None = None, batch_filter: Tensor | None = None, num_entities: int | None = None) Tensor[来源]
处理来自sLCWA训练循环的分数。
- Parameters:
positive_scores (Tensor) – 形状: (batch_size, 1) 正三元组的分数。
negative_scores (Tensor) – 形状: (batch_size, num_neg_per_pos) 或 (num_unfiltered_negatives,) 负三元组的分数,可以是密集的2D形状,或者如果它们已经被过滤,可以是稀疏形状。如果它们以稀疏形状给出,还需要提供batch_filter。
label_smoothing (float | None) – 一个可选的标签平滑参数。
batch_filter (Tensor | None) – 形状: (batch_size, num_neg_per_pos) 一个可选的负分数过滤器,用于保留哪些负分数。仅在负分数已被预过滤时提供。
num_entities (int | None) – 实体的数量。仅在启用标签平滑时需要。
- Returns:
一个标量损失项。
- Return type: