KerasRS / API 文档 / 检索层 / RemoveAccidentalHits 层

RemoveAccidentalHits 层

[源代码]

RemoveAccidentalHits

keras_rs.layers.RemoveAccidentalHits(
    activity_regularizer=None,
    trainable=True,
    dtype=None,
    autocast=True,
    name=None,
    **kwargs
)

将意外负样本的 logits 置零。

将与该行中正样本具有相同 ID 的负样本候选项的 logits 置零。

示例

# Create layer with the configured number of hard negatives to mine.
remove_accidental_hits = keras_rs.layers.RemoveAccidentalHits()

# This will zero the logits of negative candidates that have the same ID as
# the positive candidate from `labels` so as to not negatively impact the
# true positive.
logits = remove_accidental_hits(logits, labels, candidate_ids)

[源代码]

call 方法

RemoveAccidentalHits.call(logits: Any, labels: Any, candidate_ids: Any)

将选定的 logits 置零。

对于批次中的每一行,将与该行中正样本具有相同 ID 的负样本候选项的 logits 置零。

参数

  • logits:logits 张量,通常为 [batch_size, num_candidates],但可以有更多维度或为 [num_candidates] 的一维张量。
  • labels:one-hot 标签张量,必须与 logits 的形状相同。
  • candidate_ids:候选项标识符张量,可以是 [num_candidates][batch_size, num_candidates],或者只要与 labels 的最后维度匹配就可以有更多维度。

返回

修改后的 logits,与输入 logits 的形状相同。