TensorFlow Ranking v0.4.0
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_towerfunction 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
DocumentInteractionAttentionlayer to ensure SavedModel is restored correctly.
-
ModelBuilder to build
tf.keras.Modelusing Functional API:AbstractModelBuilderclass for users to inherit.ModelBuilderclass that wraps the boilerplate code to buildtf.keras.Modelfor a ranking model.InputCreatorabstract class to implementcreate_inputsinModelBuilder.FeatureSpecInputCreatorclass to create inputs fromfeature_specs.TypeSpecInputCreatorclass to create inputs fromtype_specs.
Preprocessorabstract class to implementpreprocessinModelBuilder.PreprocessorWithSpecclass to do Keras preprocessing or feature transformations with functions specified in Specs.
Scorerabstract class to implementscoreinModelBuilder.UnivariateScorerclass to implement univariate scoring functions.DNNScorerclass to implement fully connected DNN univariate scoring.GAMScorerclass to implement feature based GAM univariate scoring.
-
Pipeline to wrap the boilerplate codes for training:
AbstractDatasetBuilderabstract class to build and serve the dataset for training.BaseDatasetBuilderclass to build training and validation datasets and signatures for SavedModel fromfeature_specs.SimpleDatasetBuilderclass to build datasets with a single label feature spec.MultiLabelDatasetBuilderclass to build datasets for multi-task learning.
DatasetHparamsdataclass to specify all hyper-parameters used inBaseDatasetBuilderclass.AbstractPipelineabstract class to train and validate the rankingtf.keras.Model.ModelFitPipelineclass to train the ranking models usingmodel.fit()compatible with distribution strategies.SimplePipelineclass for single-task training.MultiTaskPipelineclass for multi-task training.- An example client to showcase training a deep neural network model with a distribution strategy using
SimplePipeline.
PipelineHparamsdataclass to specify all hyper-parameters used inModelFitPipelineclass.strategy_utilshelper module to supporttf.distributestrategies.
-
RaggedTensor support in losses and metrics:
- Losses in
tfr.keras.lossesand metrics intfr.keras.metricssupport to act ontf.RaggedTensorinputs. To do so, set argumentragged=Truewhen defining the loss and metric objects:- E.g.:
loss = tf.keras.losses.SoftmaxLoss(name=’softmax_loss’, ragged=True) - Add this argument in
getto 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.
- E.g.:
- Losses in
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.