Get startedGet started for free

Summarizing and plotting models

1. Summarizing and plotting models

In this lesson you will take a closer look at your three-input model, using Keras' built-in summary() and plot() methods.

2. Understanding a model summary

Here is the summary for a Keras model. The summary shows you all the layers in the model, as well as how many parameters each layer has. Importantly, Keras models can have non-trainable parameters that are fixed and do not change, as well as trainable parameters, that are learned from the data when the model is fit. Models with more trainable parameters are typically more flexible. This can also make them more prone to overfitting. Models with fewer trainable parameters are less flexible, but therefore less likely to overfit. In this case, the model has three inputs. Since all three of them feed into one Dense layer, the model has four parameters: one per input plus a bias, or intercept. All of these parameters are trainable. A model's trainable parameters are usually in its Dense layers.

3. Understanding a model summary

Here is the summary of a slightly more complicated model. You can see that this model has an embedding layer. Even though the dense layer still only has 4 parameters, the model has many more trainable parameters, because of the embedding layer. It's important to remember that embedding layers often add a very large number of trainable parameters to a model. Recall that embedding layers map integers to floats: each unique value of the embedding input gets a parameter for its output.

4. Understanding a model plot!

Here is the plot for a very complicated model. The box at the bottom of the image represents the model's output. In this case, the model has one output. Note that output layers have arrows coming in, but no arrows going out. The boxes in the middle of the image represent intermediate steps in the model. These boxes have arrows coming in, and arrows going out. Note that this model has a shared model: the team strength model, which is applied to two of the inputs before they are combined in the concatenate layer with the third input. The boxes at the top of the image represent the inputs. These boxes only have one arrow going out and none coming in.

5. Understanding a model plot!

Here's another way of looking at the same model, using the network diagrams I've made for the previous chapter's models. Shared models work exactly the same as shared layers. This is a useful abstraction because you can put together a sequence of layers to define a custom model, and then share the entire model in exactly the same way you'd share a layer. It's a little prettier when you make them by hand, but the auto-plotting function in Keras does a good job representing the actual structure of the model.

6. Let's Practice

Now that I've shown you how to summarize and plot models, you try it for yourself!