tfrs.metrics.FactorizedTopK

Computes metrics for across top K candidates surfaced by a retrieval model.

Used in the notebooks

Used in the tutorials

The default metric is top K categorical accuracy: how often the true candidate is in the top K candidates for a given query.

candidates A layer for retrieving top candidates in response to a query, or a dataset of candidate embeddings from which candidates should be retrieved.
metrics The metrics to compute. If not supplied, will compute top-K categorical accuracy metrics.
k The number of top scoring candidates to retrieve for metric evaluation.
name Optional name.

Methods

call

This is where the layer's logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Arguments
inputs Input tensor, or list/tuple of input tensors.
**kwargs Additional keyword arguments. Currently unused.

Returns
A tensor or list/tuple of tensors.

reset_states

View source

Resets the metrics.

result

View source

Returns a list of metric results.

update_state

View source

Updates the metrics.

Args
query_embeddings [num_queries, embedding_dim] tensor of query embeddings.
true_candidate_embeddings [num_queries, embedding_dim] tensor of embeddings for candidates that were selected for the query.

Returns
Update op. Only used in graph mode.