Skip to content

TensorFlow Ranking v0.4.0

Compare
Choose a tag to compare
@ramakumar1729 ramakumar1729 released this 25 May 17:36
· 164 commits to master since this release

This release is one of the major releases for TF-Ranking. It provides full support to build and train a native Keras model for ranking problems. It includes necessary Keras layers for a ranking model, a module to construct a model in a flexible manner, and a pipeline to train a model with minimal boilerplate. To get started, please follow the example here. In addition, the new release adds RaggedTensor support in losses and metrics and we provide a handy example to show how to use it in a ranking model.

The new components are listed below:

  • Keras Layers:

    • Use input packing for layer signatures for SavedModel compatibility.
    • create_tower function to create a feedforward neural network with batch normalization and dropout.
    • GAMLayer, a Keras layer which implements the neural generalized additive ranking model.
    • Update build method of DocumentInteractionAttention layer to ensure SavedModel is restored correctly.
  • ModelBuilder to build tf.keras.Model using Functional API:

    • AbstractModelBuilder class for users to inherit.
    • ModelBuilder class that wraps the boilerplate code to build tf.keras.Model for a ranking model.
    • InputCreator abstract class to implement create_inputs in ModelBuilder.
      • FeatureSpecInputCreator class to create inputs from feature_specs.
      • TypeSpecInputCreator class to create inputs from type_specs.
    • Preprocessor abstract class to implement preprocess in ModelBuilder.
      • PreprocessorWithSpec class to do Keras preprocessing or feature transformations with functions specified in Specs.
    • Scorer abstract class to implement score in ModelBuilder.
      • UnivariateScorer class to implement univariate scoring functions.
        • DNNScorer class to implement fully connected DNN univariate scoring.
        • GAMScorer class to implement feature based GAM univariate scoring.
  • Pipeline to wrap the boilerplate codes for training:

    • AbstractDatasetBuilder abstract class to build and serve the dataset for training.
    • BaseDatasetBuilder class to build training and validation datasets and signatures for SavedModel from feature_specs.
      • SimpleDatasetBuilder class to build datasets with a single label feature spec.
      • MultiLabelDatasetBuilder class to build datasets for multi-task learning.
    • DatasetHparams dataclass to specify all hyper-parameters used in BaseDatasetBuilder class.
    • AbstractPipeline abstract class to train and validate the ranking tf.keras.Model.
    • ModelFitPipeline class to train the ranking models using model.fit() compatible with distribution strategies.
      • SimplePipeline class for single-task training.
      • MultiTaskPipeline class for multi-task training.
      • An example client to showcase training a deep neural network model with a distribution strategy using SimplePipeline.
    • PipelineHparams dataclass to specify all hyper-parameters used in ModelFitPipeline class.
    • strategy_utils helper module to support tf.distribute strategies.
  • RaggedTensor support in losses and metrics:

    • Losses in tfr.keras.losses and metrics in tfr.keras.metrics support to act on tf.RaggedTensor inputs. To do so, set argument ragged=True when defining the loss and metric objects:
      • E.g.: loss = tf.keras.losses.SoftmaxLoss(name=’softmax_loss’, ragged=True)
      • Add this argument in get to get the losses and metrics support ragged tensors: loss = tf.keras.losses.get(‘softmax_loss’, ragged=True)
      • An example client to showcase training a deep neural network model using model.fit() with ragged inputs and outputs.

Dependencies: The following packages will be installed as required when installing tensorflow-ranking.
tf-models-official >= 2.5.0
tensorflow-serving-api>= 2.0.0, < 3.0.0
tensorflow==2.5.0.