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_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 buildtf.keras.Model
for a ranking model.InputCreator
abstract class to implementcreate_inputs
inModelBuilder
.FeatureSpecInputCreator
class to create inputs fromfeature_spec
s.TypeSpecInputCreator
class to create inputs fromtype_spec
s.
Preprocessor
abstract class to implementpreprocess
inModelBuilder
.PreprocessorWithSpec
class to do Keras preprocessing or feature transformations with functions specified in Specs.
Scorer
abstract class to implementscore
inModelBuilder
.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 fromfeature_spec
s.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 inBaseDatasetBuilder
class.AbstractPipeline
abstract class to train and validate the rankingtf.keras.Model
.ModelFitPipeline
class to train the ranking models usingmodel.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 inModelFitPipeline
class.strategy_utils
helper module to supporttf.distribute
strategies.
-
RaggedTensor support in losses and metrics:
- Losses in
tfr.keras.losses
and metrics intfr.keras.metrics
support to act ontf.RaggedTensor
inputs. To do so, set argumentragged=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.
- 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
.