Tune in to the first Women in ML Symposium this Tuesday, October 19 at 9am PST Register now

tf.keras.experimental.WideDeepModel

Wide & Deep Model for regression and classification problems.

Inherits From: Model, Layer, Module

Used in the notebooks

Used in the guide

This model jointly train a linear and a dnn model.

Example:

linear_model = LinearModel()
dnn_model = keras.Sequential([keras.layers.Dense(units=64),
                             keras.layers.Dense(units=1)])
combined_model = WideDeepModel(linear_model, dnn_model)
combined_model.compile(optimizer=['sgd', 'adam'], 'mse', ['mse'])
# define dnn_inputs and linear_inputs as separate numpy arrays or
# a single numpy array if dnn_inputs is same as linear_inputs.
combined_model.fit([linear_inputs, dnn_inputs], y, epochs)
# or define a single `tf.data.Dataset` that contains a single tensor or
# separate tensors for dnn_inputs and linear_inputs.
dataset = tf.data.Dataset.from_tensors(([linear_inputs, dnn_inputs], y))
combined_model.fit(dataset, epochs)

Both linear and dnn model can be pre-compiled and trained separately before jointly training:

Example:

linear_model = LinearModel()
linear_model.compile('adagrad', 'mse')
linear_model.fit(linear_inputs, y, epochs)
dnn_model = keras.Sequential([keras.layers.Dense(units=1)])
dnn_model.compile('rmsprop', 'mse')
dnn_model.fit(dnn_inputs, y, epochs)
combined_model = WideDeepModel(linear_model, dnn_model)
combined_model.compile(optimizer=['sgd', 'adam'], 'mse', ['mse'])
combined_model.fit([linear_inputs, dnn_inputs], y, epochs)

linear_model a premade LinearModel, its output must match the output of the dnn model.
dnn_model a tf.keras.Model, its output must match the output of the linear model.
activation Activation function. Set it to None to maintain a linear activation.
**kwargs The keyword arguments that are passed on to BaseLayer.init. Allowed keyword arguments include name.

distribute_strategy The tf.distribute.Strategy this model was created under.
layers

metrics_names Returns the model's display labels for all outputs.

inputs = tf.keras.layers.Input(shape=(3,))
outputs = tf.keras.layers.Dense(2)(inputs)
model = tf.keras.models.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer="Adam", loss="mse", metrics=["mae"])
model.metrics_names