tfr.keras.model.Scorer
Stay organized with collections
Save and categorize content based on your preferences.
Interface for scorer.
The Scorer
class is an abstract class to implement score
in ModelBuilder
in tfr.keras.
To be implemented by subclasses:
__call__()
: Contains the logic to score based on the context and example
features.
Example subclass implementation:
class SimpleScorer(Scorer):
def __call__(self, context_features, example_features, mask):
x = tf.concat([tensor for tensor in example_features.values()], -1)
return tf.keras.layers.Dense(1)(x)
Methods
__call__
View source
@abc.abstractmethod
__call__(
context_features: tfr.keras.model.TensorDict
,
example_features: tfr.keras.model.TensorDict
,
mask: tf.Tensor
) -> Union[TensorLike, TensorDict]
Scores all examples given context and returns logits.
Args |
context_features
|
maps from context feature keys to [batch_size,
feature_dims]-tensors of preprocessed context features.
|
example_features
|
maps from example feature keys to [batch_size,
list_size, feature_dims]-tensors of preprocessed example features.
|
mask
|
[batch_size, list_size]-tensor of mask for valid examples.
|
Returns |
A [batch_size, list_size]-tensor of logits or a dict mapping task name to
logits in the multi-task setting.
|
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 2023-08-18 UTC.
[null,null,["Last updated 2023-08-18 UTC."],[],[],null,["# tfr.keras.model.Scorer\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L668-L710) |\n\nInterface for scorer.\n\nThe `Scorer` class is an abstract class to implement `score` in `ModelBuilder`\nin tfr.keras.\n\nTo be implemented by subclasses:\n\n- `__call__()`: Contains the logic to score based on the context and example features.\n\nExample subclass implementation: \n\n class SimpleScorer(Scorer):\n\n def __call__(self, context_features, example_features, mask):\n x = tf.concat([tensor for tensor in example_features.values()], -1)\n return tf.keras.layers.Dense(1)(x)\n\nMethods\n-------\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/model.py#L690-L710) \n\n @abc.abstractmethod\n __call__(\n context_features: ../../../tfr/keras/model/TensorDict,\n example_features: ../../../tfr/keras/model/TensorDict,\n mask: tf.Tensor\n ) -\u003e Union[TensorLike, TensorDict]\n\nScores all examples given context and returns logits.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------|---------------------------------------------------------------------------------------------------------------------|\n| `context_features` | maps from context feature keys to \\[batch_size, feature_dims\\]-tensors of preprocessed context features. |\n| `example_features` | maps from example feature keys to \\[batch_size, list_size, feature_dims\\]-tensors of preprocessed example features. |\n| `mask` | \\[batch_size, list_size\\]-tensor of mask for valid examples. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A \\[batch_size, list_size\\]-tensor of logits or a dict mapping task name to logits in the multi-task setting. ||\n\n\u003cbr /\u003e"]]