tfr.keras.model.Scorer

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

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.