tfrs.tasks.Ranking
Stay organized with collections
Save and categorize content based on your preferences.
A ranking task.
Inherits From: Task
tfrs.tasks.Ranking(
loss: Optional[tf.keras.losses.Loss] = None,
metrics: Optional[List[tf.keras.metrics.Metric]] = None,
prediction_metrics: Optional[List[tf.keras.metrics.Metric]] = None,
label_metrics: Optional[List[tf.keras.metrics.Metric]] = None,
loss_metrics: Optional[List[tf.keras.metrics.Metric]] = None,
name: Optional[Text] = None
) -> None
Used in the notebooks
Recommender systems are often composed of two components:
- a retrieval model, retrieving O(thousands) candidates from a corpus of
O(millions) candidates.
- a ranker model, scoring the candidates retrieved by the retrieval model to
return a ranked shortlist of a few dozen candidates.
This task helps with building ranker models. Usually, these will involve
predicting signals such as clicks, cart additions, likes, ratings, and
purchases.
Args |
loss
|
Loss function. Defaults to BinaryCrossentropy.
|
metrics
|
List of Keras metrics to be evaluated.
|
prediction_metrics
|
List of Keras metrics used to summarize the
predictions.
|
label_metrics
|
List of Keras metrics used to summarize the labels.
|
loss_metrics
|
List of Keras metrics used to summarize the loss.
|
name
|
Optional task name.
|
Methods
call
View source
call(
labels: tf.Tensor,
predictions: tf.Tensor,
sample_weight: Optional[tf.Tensor] = None,
training: bool = False,
compute_metrics: bool = True
) -> tf.Tensor
Computes the task loss and metrics.
Args |
labels
|
Tensor of labels.
|
predictions
|
Tensor of predictions.
|
sample_weight
|
Tensor of sample weights.
|
training
|
Indicator whether training or test loss is being computed.
|
compute_metrics
|
Whether to compute metrics. Set this to False
during training for faster training.
|
Returns |
loss
|
Tensor of loss values.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tfrs.tasks.Ranking\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/recommenders/blob/v0.7.3/tensorflow_recommenders/tasks/ranking.py#L26-L118) |\n\nA ranking task.\n\nInherits From: [`Task`](../../tfrs/tasks/Task) \n\n tfrs.tasks.Ranking(\n loss: Optional[tf.keras.losses.Loss] = None,\n metrics: Optional[List[tf.keras.metrics.Metric]] = None,\n prediction_metrics: Optional[List[tf.keras.metrics.Metric]] = None,\n label_metrics: Optional[List[tf.keras.metrics.Metric]] = None,\n loss_metrics: Optional[List[tf.keras.metrics.Metric]] = None,\n name: Optional[Text] = None\n ) -\u003e None\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Recommending movies: ranking](https://www.tensorflow.org/recommenders/examples/basic_ranking) - [Deep \\& Cross Network (DCN)](https://www.tensorflow.org/recommenders/examples/dcn) - [Listwise ranking](https://www.tensorflow.org/recommenders/examples/listwise_ranking) - [Multi-task recommenders](https://www.tensorflow.org/recommenders/examples/multitask) - [Using TensorFlow Recommenders with TFX](https://www.tensorflow.org/recommenders/examples/ranking_tfx) |\n\nRecommender systems are often composed of two components:\n\n- a retrieval model, retrieving O(thousands) candidates from a corpus of O(millions) candidates.\n- a ranker model, scoring the candidates retrieved by the retrieval model to return a ranked shortlist of a few dozen candidates.\n\nThis task helps with building ranker models. Usually, these will involve\npredicting signals such as clicks, cart additions, likes, ratings, and\npurchases.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|----------------------------------------------------------|\n| `loss` | Loss function. Defaults to BinaryCrossentropy. |\n| `metrics` | List of Keras metrics to be evaluated. |\n| `prediction_metrics` | List of Keras metrics used to summarize the predictions. |\n| `label_metrics` | List of Keras metrics used to summarize the labels. |\n| `loss_metrics` | List of Keras metrics used to summarize the loss. |\n| `name` | Optional task name. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `call`\n\n[View source](https://github.com/tensorflow/recommenders/blob/v0.7.3/tensorflow_recommenders/tasks/ranking.py#L69-L118) \n\n call(\n labels: tf.Tensor,\n predictions: tf.Tensor,\n sample_weight: Optional[tf.Tensor] = None,\n training: bool = False,\n compute_metrics: bool = True\n ) -\u003e tf.Tensor\n\nComputes the task loss and metrics.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|------------------------------------------------------------------------------------|\n| `labels` | Tensor of labels. |\n| `predictions` | Tensor of predictions. |\n| `sample_weight` | Tensor of sample weights. |\n| `training` | Indicator whether training or test loss is being computed. |\n| `compute_metrics` | Whether to compute metrics. Set this to False during training for faster training. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------|------------------------|\n| `loss` | Tensor of loss values. |\n\n\u003cbr /\u003e"]]