Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Explore Google’s enterprise deep learning framework: static computational graphs, high-level Keras Sequential API, and TensorBoard.
model = Sequential() (Create empty network)
2. model.add(Dense(64)) (Add a layer of 64 neurons)
3. model.fit(X, y) (Train on data!)@tf.function) targeting XLA (Accelerated Linear Algebra) compilers. The Keras high-level API encapsulates model compilation, optimizer registration, and lifecycle callback hooks for distributed execution.Assemble layers sequentially using tf.keras.Sequential([Dense(...)]).
Register optimizer ("adam"), loss ("sparse_categorical_crossentropy"), and metrics.
model.fit(X, y, epochs=10, validation_split=0.2) runs training loop.
Problem: Serving sub-millisecond personalized video rankings across 2 billion users.
Solution: Distributed TensorFlow models score billions of candidate video embeddings in parallel.
Interactive activity component
Build, compile, and fit a neural network in TensorFlow.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install tensorflow1 import tensorflow as tf 2 from tensorflow.keras import layers, models 3 import numpy as np
import tensorflow as tf → Import TensorFlow
from tensorflow.keras import layers, models → Import Keras layers
import numpy as np → NumPy for data
1 # Synthetic dataset: 100 samples, 8 features 2 X = np.random.randn(100, 8) 3 y = np.random.randint(0, 2, size=(100, 1)) # Binary targets 4 5 # Build model with Keras Sequential: 6 model = models.Sequential([ 7 layers.Dense(32, activation="relu", input_shape=(8,)), # Layer 1 8 layers.Dense(16, activation="relu"), # Layer 2 9 layers.Dense(1, activation="sigmoid") # Output head 10 ]) 11 12 # Compile model: 13 model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"]) 14 15 # Fit for 3 epochs: 16 history = model.fit(X, y, epochs=3, batch_size=16, verbose=1) 17 print("Training Complete! Final Loss:", round(history.history["loss"][-1], 4))
# Synthetic dataset: 100 samples, 8 features
Dataset
X = np.random.randn(100, 8)
Features
y = np.random.randint(0, 2, size=(100, 1)) # Binary targets
Labels
# Build model with Keras Sequential:
Architecture
model = models.Sequential([
Container
layers.Dense(32, activation="relu", input_shape=(8,)), # Layer 1
Hidden layer
layers.Dense(16, activation="relu"), # Layer 2
Hidden layer
layers.Dense(1, activation="sigmoid") # Output head
Sigmoid output
])
Close model
# Compile model:
Compilation
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
Configure learning
# Fit for 3 epochs:
Training loop
history = model.fit(X, y, epochs=3, batch_size=16, verbose=1)
Run training
print("Training Complete! Final Loss:", round(history.history["loss"][-1], 4))
Print final loss
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Building an MLP in TensorFlow / Keras 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install tensorflow 8 9 # Step 2: Import libraries 10 import tensorflow as tf 11 from tensorflow.keras import layers, models 12 import numpy as np 13 14 # Step 3: Run Demonstration 15 # Synthetic dataset: 100 samples, 8 features 16 X = np.random.randn(100, 8) 17 y = np.random.randint(0, 2, size=(100, 1)) # Binary targets 18 19 # Build model with Keras Sequential: 20 model = models.Sequential([ 21 layers.Dense(32, activation="relu", input_shape=(8,)), # Layer 1 22 layers.Dense(16, activation="relu"), # Layer 2 23 layers.Dense(1, activation="sigmoid") # Output head 24 ]) 25 26 # Compile model: 27 model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"]) 28 29 # Fit for 3 epochs: 30 history = model.fit(X, y, epochs=3, batch_size=16, verbose=1) 31 print("Training Complete! Final Loss:", round(history.history["loss"][-1], 4))
Creates 8 -> 32 -> 16 -> 1 graph.
Attaches Adam optimizer and binary cross-entropy loss.
Trains over 3 epochs, reporting loss and accuracy reduction.
100 samples with 8 features each
Epoch 1/3: loss: 0.712 - accuracy: 0.52 Epoch 2/3: loss: 0.695 - accuracy: 0.55 Epoch 3/3: loss: 0.681 - accuracy: 0.58 Training Complete!
Keras abstracts complex training loops into clean, expressive, readable syntax.
CNN, MNIST dataset, backpropagation, loss functions, and optimization.
Test your understanding with these questions. Remember, this is for learning, not examination!