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.



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.

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

A tensor or list/tuple of tensors.


View source

Resets the metrics.


View source

Returns a list of metric results.


View source

Updates the metrics.

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.

Update op. Only used in graph mode.