# tfrs.layers.loss.HardNegativeMining

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/recommenders/blob/v0.7.7/tensorflow_recommenders/layers/loss.py#L61-L111) |

Transforms logits and labels to return hard negatives.

    tfrs.layers.loss.HardNegativeMining(
        num_hard_negatives: int
    ) -> None

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_hard_negatives` | How many hard negatives to return. |

<br />

## Methods

### `call`

[View source](https://github.com/tensorflow/recommenders/blob/v0.7.7/tensorflow_recommenders/layers/loss.py#L74-L111)

    call(
        logits: tf.Tensor, labels: tf.Tensor
    ) -> Tuple[tf.Tensor, tf.Tensor]

Filters logits and labels with per-query hard negative mining.

The result will include logits and labels for num_hard_negatives
negatives as well as the positive candidate.

<br />

<br />

<br />

| Args ||
|---|---|
| `logits` | \[batch_size, number_of_candidates\] tensor of logits. |
| `labels` | \[batch_size, number_of_candidates\] one-hot tensor of labels. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `logits` | \[batch_size, num_hard_negatives + 1\] tensor of logits. |
| `labels` | \[batch_size, num_hard_negatives + 1\] one-hot tensor of labels. |

<br />