KerasRS / API documentation / Retrieval Layers / RemoveAccidentalHits layer

RemoveAccidentalHits layer

[source]

RemoveAccidentalHits class

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

Zeroes the logits of accidental negatives.

Zeroes the logits of negative candidates that have the same ID as the positive candidate in that row.

Example

# 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)

[source]

call method

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

Zeroes selected logits.

For each row in the batch, zeroes the logits of negative candidates that have the same ID as the positive candidate in that row.

Arguments

  • logits: The logits tensor, typically [batch_size, num_candidates] but can have more dimensions or be 1D as [num_candidates].
  • labels: The one-hot labels tensor, must be the same shape as logits.
  • candidate_ids: The candidate identifiers tensor, can be [num_candidates] or [batch_size, num_candidates] or have more dimensions as long as they match the last dimensions of labels.

Returns

The modified logits with the same shape as the input logits.