Help protect the Great Barrier Reef with TensorFlow on Kaggle Join Challenge


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,))
outputs = tf.keras.layers.Dense(2)(inputs)
model = tf.keras.models.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer="Adam", loss="mse", metrics=["mae"])
x = np.random.random((2, 3))
y = np.random.randint(0, 2, (2, 2)), y)
['loss', 'mae']
inputs = tf.keras.layers.Input(shape=(3,))
d = tf.keras.layers.Dense(2, name='out')
output_1 = d(inputs)
output_2 = d(inputs)
model = tf.keras.models.Model(
   inputs=inputs, outputs=[output_1, output_2])
model.compile(optimizer="Adam", loss="mse", metrics=["mae", "acc"]), (y, y))
['loss', 'out_loss', 'out_1_loss', 'out_mae', 'out_acc', '