ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


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.


linear_model = LinearModel()
dnn_model = keras.Sequential([keras.layers.Dense(units=64),
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.[linear_inputs, dnn_inputs], y, epochs)
# or define a single `` that contains a single tensor or
# separate tensors for dnn_inputs and linear_inputs.
dataset =[linear_inputs, dnn_inputs], y)), epochs)

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


linear_model = LinearModel()
linear_model.compile('adagrad', 'mse'), y, epochs)
dnn_model = keras.Sequential([keras.layers.Dense(units=1)])
dnn_model.compile('rmsprop', 'mse'), y, epochs)
combined_model = WideDeepModel(linear_model, dnn_model)
combined_model.compile(optimizer=['sgd', 'adam'], 'mse', ['mse'])[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.

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

inputs = tf.keras.layers.Input(shape=(3,))