Concepts / Keras Model Architecture

Keras Model Architecture

TensorBoard is a browser-based visualization tool packaged with TensorFlow for inspecting Keras models using the TensorFlow backend.

  • Programming

From Training Run to Insight

A training run produces measurements and internal values, but a final score gives only a compressed view of what happened. TensorBoard helps you inspect that run through browser-based visualizations. It is packaged with TensorFlow and is available for Keras models when Keras uses the TensorFlow backend.

Training runmodel and dataLog eventsrecorded measurementsTensorBoardbrowser viewsObservationmetrics and internalsNext experimentmodel refinementproducesread bypresentsinforms
What information flows from repeated training runs into TensorBoard, and how can that information guide the next model change?

The important handoff is between training and inspection. Training produces log events in a directory. After training begins, the TensorBoard command-line utility reads those events and presents visual views in a browser. TensorBoard does not replace the experiment; it makes the experiment easier to examine while it is running or after its events have been written.

A Source-Grounded Run

Worked example

Following an IMDB Sentiment Model

Trace what becomes inspectable when the source example trains a one-dimensional convolutional network for IMDB sentiment analysis.

  1. 1
    Prepare the inputs

    The example limits the vocabulary to the top 2,000 words and pads texts to a maximum length of 500.

  2. 2
    Define the model

    The model begins with an embedding layer, continues through convolution and pooling layers, and ends with a dense output layer.

  3. 3
    Record the run

    A TensorBoard callback writes log events to a directory during training.

  4. 4
    Inspect the events

    The TensorBoard command-line utility reads the log events, and the source example opens TensorBoard at http://localhost:6006.

Result

The training run becomes available through several visual views rather than only through its final score.

This sequence illustrates why logging matters during iterative development. Before logging, the experiment has produced information, but that information is not yet organized into TensorBoard's inspection views. After the events are written and TensorBoard reads them, you can examine the trajectory of measurements and selected internal behavior.

What the Dashboard Reveals

Training runrecorded eventsMetricstraining and validationHistogramsactivations and gradientsEmbeddings2D or 3D relationshipsGraphsTensorFlow operationsshowsshowsshowsshows
What kinds of training information can TensorBoard display, and how do those views complement one another?
ViewWhat it displaysQuestion it helps answer
MetricsTraining and validation measurements over timeHow does the run develop rather than finish?
HistogramsActivation values and gradients taken by layersWhat internal numerical behavior occurs during training?
EmbeddingsSpatial relationships after reducing an embedding space to 2D or 3DWhich learned representations appear near one another?
GraphsLow-level TensorFlow operations underlying the Keras modelWhat operations are involved beneath the layer definition?

TensorBoard views answer different questions about the same training run.

The metrics view is usually the starting point for following learning over time. It provides live graphs of training and validation metrics, so you can inspect a trajectory instead of relying on one final value. The other views add information that a metric cannot contain: distributions of internal values, spatial relationships among learned representations, and the operations underlying the model.

Two Ways to View Architecture

TensorFlow operationslow-level graphKeras layerslayer-level graphGradient descenttraining structuresShape informationoptional displayDetailed operationgraphoften more complicatedLayer graphcleaner model pictureformadds structures toformcan annotate
How do TensorFlow's low-level operation graph and Keras's layer-graph plot differ in the entities and connections they show?
QuestionTensorBoard Graphs tabKeras plot_model
What is represented?Low-level TensorFlow operations underlying the Keras modelThe model's layers and their connections
How detailed is the view?It can be much more complicated than the short layer sequenceIt provides a cleaner layer-level picture
What may add complexity?Structures associated with gradient descentThe layer definition remains the focus
Can shapes be shown?Not the distinction emphasized by the sourcePassing show_shapes=True adds shape information

Use the operation graph to inspect underlying TensorFlow computation and plot_model to inspect the cleaner Keras layer structure.

Reading Activation Histograms

Early trainingactivation distributionLater trainingactivation distributionLayer comparisoninternal behaviorcompare across stepsinspect across layers
How can activation-value distributions change across training steps or layers, and what can that reveal beyond a final loss?

A metric reduces a training run to a small number of measurements. A histogram preserves distributional information about values inside the model. TensorBoard can show distributions of activation values taken by layers, and the source also identifies histograms of gradients as part of its feature set. Comparing these views across training steps or layers lets you inspect internal numerical behavior instead of treating the model as a black box that produces only an output score.

In the real world

Suppose two experiments finish with similar final scores. Their activation histograms can still provide different internal views because the histograms show how activation values and gradients are distributed through layers during training. The useful conclusion is not that a histogram automatically identifies the best model, but that it exposes evidence unavailable in the final score alone.

Exploring Learned Embeddings

Input wordsvocabulary items128-dimensional spacelearned representationsPCA or t-SNEdimensionality reduction2D or 3D viewspatial relationshipsPositive wordsvisible clusterNegative wordsvisible clusterrepresented inreduced bymaps tocan revealcan reveal
How are high-dimensional learned embeddings mapped into a visual space, and what relationships can the result reveal?

The Embeddings view focuses on the locations and spatial relationships learned by an embedding layer. In the source example, the initial embedding layer learns representations for words in the input vocabulary. Its embedding space has 128 dimensions, so TensorBoard reduces that space to 2D or 3D for inspection using a selected method: PCA or t-SNE.

In the real world

In the source visualization, words with positive connotations and words with negative connotations form two visible clusters. This gives information about relationships among learned representations that a final training metric does not show directly.

Mistakes in Interpretation

  • Common mistake

    Treating the final metric as the complete explanation of training.

    What it looks like

    Looking only at the last training or validation value.

    Why it fails

    A final value does not show the trajectory of the run, internal activation distributions, gradients, or learned embedding relationships.

    Do this instead

    Use the metrics view for the trajectory and inspect histograms or embeddings when internal behavior matters.

  • Common mistake

    Assuming the Graphs tab is the same as a Keras layer plot.

    What it looks like

    Expecting the TensorBoard graph to contain only the short sequence of layers used to define the model.

    Why it fails

    TensorBoard shows low-level TensorFlow operations, and the graph can include structures associated with gradient descent.

    Do this instead

    Use keras.utils.plot_model for a cleaner layer-level picture, optionally with shape information.

  • Common mistake

    Reading an embedding cluster as a universal meaning.

    What it looks like

    Assuming a cluster learned for one objective will behave the same way for another objective.

    Why it fails

    The source states that embeddings learned jointly with a particular objective are shaped by that task.

    Do this instead

    Interpret the spatial relationships in relation to the objective that produced the embeddings.

  • Common mistake

    Expecting TensorBoard to replace the training experiment.

    What it looks like

    Treating a visualization as if it created the measurements itself.

    Why it fails

    Training produces log events first; TensorBoard reads those events and presents them as visual views.

    Do this instead

    Think of TensorBoard as an inspection tool in the experiment, observation, and refinement cycle.

A Practical Inspection Sequence

  1. 1
    Start with the training and validation metric graphs to follow how the run develops over time.
  2. 2
    Inspect activation and gradient histograms when you need evidence about internal numerical behavior rather than only output measurements.
  3. 3
    Open the Embeddings view when the model contains learned embeddings and you want to examine spatial relationships in the learned representation.
  4. 4
    Use the TensorBoard Graphs tab when your question concerns low-level TensorFlow operations or training-related structures.
  5. 5
    Use keras.utils.plot_model when you need a cleaner layer-level picture of the Keras model, with shape information available through show_shapes=True.
  6. 6
    Use the observations from these views to shape the next experiment.
EASY

A learner says, “The final metric looks acceptable, so the TensorBoard histograms and Embeddings view are unnecessary.” Explain two different kinds of information those views can add beyond the final metric.

Hints
  • One view concerns distributions inside layers.
  • The other concerns spatial relationships among learned representations.
EASY

You want to communicate the short sequence of Keras layers to a learner, not the detailed TensorFlow computation used during training. Which visualization should you choose, and what optional information can it add?

Hints
  • Choose the layer-level alternative rather than the TensorBoard Graphs tab.
  • The source names an option that adds shape information.

The Inspection Cycle

  1. 1
    TensorBoard turns information recorded during TensorFlow training into browser-based visualizations for Keras models using the TensorFlow backend.
  2. 2
    Metrics show training and validation trajectories, while histograms expose activation values and gradients.
  3. 3
    Embedding visualizations reduce a high-dimensional learned space to 2D or 3D so spatial relationships can be inspected.
  4. 4
    The TensorBoard Graphs tab shows low-level TensorFlow operations, whereas keras.utils.plot_model provides a cleaner Keras layer graph and can show shapes.
  5. 5
    Together, these views support an iterative cycle of experiment, observation, and refinement rather than reliance on a final score alone.

Key Takeaways

  • TensorBoard makes recorded training information inspectable through browser-based views.
  • Metrics, histograms, embeddings, and graphs reveal different aspects of a Keras training run.
  • Activation and gradient histograms expose internal numerical behavior beyond final metrics.
  • Embedding visualizations reveal learned spatial relationships, but those relationships are shaped by the training objective.
  • TensorBoard's operation graph and Keras's plot_model serve different architectural inspection purposes.

Related concepts

More concepts starting with K