Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 40 ยท Getting Started

What Are TensorFlow and Keras?

Learn what TensorFlow and Keras are, how Keras 3 fits in, what you can build with them, and how this course teaches them with runnable NumPy stand-ins.

TensorFlow is an open-source library for numerical computing that is built around one idea: describe a calculation on multi-dimensional arrays called tensors, and let the library run it fast (on a CPU, a GPU or a TPU) and differentiate it automatically. Keras is the friendly, high-level interface on top: layers, models, losses, optimizers and a fit() loop that hides the plumbing. Together they are one of the most widely used ways to build neural networks for images, text, audio, tables and time series.

This first lesson draws the map: what each piece does, how they relate in the modern Keras 3 world, what a typical project looks like, and, just as important, how this course lets you practice in the browser even though TensorFlow itself cannot run there.

What is real and what is a stand-in

Please read this part carefully, because the rest of the course follows one rule.

  • Real TensorFlow and Keras code appears in read-only ```python blocks. It is correct code for TensorFlow 2.x and Keras 3, written to run on your own computer or in a notebook service. Outputs are shown only when the result is certain (shapes, parameter counts); anything that depends on random initialization is described, not printed.
  • The Run buttons execute plain NumPy in Pyodide inside your browser. TensorFlow does not ship for Pyodide, so we cannot run it here. Every runnable example is a clearly labelled stand-in: it re-implements the idea underneath (tensors and broadcasting, automatic differentiation, gradient descent, a dense layer, a loss, an optimizer) in a few lines you can read and change.

The stand-ins are not a trick or a shortcut. Once you can write a dense layer's forward and backward pass in NumPy, keras.layers.Dense stops being magic. When the lesson shows the real API next to it, you will recognize every piece.

If you want to run the real code, create a free notebook in Google Colab. TensorFlow and Keras 3 are preinstalled there. Installing and Your First Model shows the local setup.

How the pieces relate

The stack in four layers

Keras Layers, models, fit and evaluate.
TensorFlow Tensors, autodiff, tf.data, saving.
Kernels Fast C++ and CUDA operations.
Hardware CPU, GPU or TPU.

You write the top layer. Everything below works for you.

1 / 2

Keras started in 2015 as an independent library. It was merged into TensorFlow as tf.keras in TensorFlow 2.0 (2019). Since Keras 3 (late 2023) it is again a standalone package, keras, that can run on top of TensorFlow, JAX or PyTorch. TensorFlow 2.16 and newer ship with Keras 3 as the default. In this course we import Keras as import keras and TensorFlow as import tensorflow as tf, and we use the TensorFlow backend.

flowchart TB
    A["Your code: import keras"] --> B["Keras 3 API<br/>layers, models, losses"]
    B --> C["TensorFlow backend"]
    B --> D["JAX backend"]
    B --> E["PyTorch backend"]
    C --> F["CPU / GPU / TPU"]

Keras is the interface; the backend does the heavy numerical work.

What TensorFlow gives you

Even if you only ever call Keras, TensorFlow is doing four jobs underneath, and later chapters use them directly.

  1. Tensors. tf.constant, tf.Variable and a large library of operations (tf.matmul, tf.reduce_sum, ...). See Tensors and Shapes.
  2. Automatic differentiation. tf.GradientTape records operations and computes gradients. See Automatic Differentiation.
  3. Graph compilation. tf.function turns Python code into an optimized graph for speed and for deployment.
  4. Data and deployment. tf.data input pipelines, SavedModel export, TensorFlow Lite for phones, TensorFlow.js for browsers and TensorFlow Serving for servers.

What a Keras project looks like

Almost every Keras project follows the same five steps. Here is the real code for a tiny classifier; read it as a map, not as something to run here.

Python
import keras
from keras import layers

model = keras.Sequential([
    keras.Input(shape=(20,)),             # 20 input features
    layers.Dense(32, activation="relu"),  # hidden layer
    layers.Dense(1, activation="sigmoid") # probability output
])

model.compile(optimizer="adam",
              loss="binary_crossentropy",
              metrics=["accuracy"])

model.fit(x_train, y_train, epochs=10, validation_split=0.2)
model.evaluate(x_test, y_test)
model.predict(x_new)

The five steps are: prepare data, define the model, compile (choose loss, optimizer, metrics), fit (train) and evaluate/predict. Chapters 3 and 4 of this course take these apart one by one.

A first stand-in: what a model really is

At its core, a model is a function with adjustable numbers (weights). Training adjusts the numbers so the function matches examples. Here is the smallest possible model written in NumPy: a single "neuron" with two weights and a bias, the same math that Dense(1) performs.

Python Stand-in: a Dense(1) layer by hand (NumPy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

x @ w + b is matrix multiplication followed by adding a bias to every row. That one line is the heart of most neural networks. Everything else, including activations, extra layers and convolutions, builds on it.

A second stand-in: what "learning" means

Learning is trial and error guided by a number: the loss, which says how wrong the predictions are. We nudge the weights in the direction that lowers it. This tiny loop fits the line y = 2x + 1 from five points.

Python Stand-in: learning two numbers by gradient descent (NumPy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You will see the loss fall and w and b approach 2 and 1. Keras does the same thing, with millions of weights instead of two, gradients computed automatically instead of by hand, and clever optimizers on top.

What can you build?

  • Tabular models: predict prices, churn or risk from spreadsheet-like data.
  • Image models: classify photos, detect objects, segment medical scans (Chapter 5).
  • Text and sequence models: sentiment analysis, translation, time-series forecasting (Chapter 6).
  • Generative models: autoencoders, GANs and transformers (Chapter 8).
  • Deployed models: export to a server, a phone or a web page (Chapter 7).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Keras?

    Keras is the high-level interface (layers, models, compile, fit). It runs on a backend such as TensorFlow.
  2. 2. Which statement about Keras 3 is true?

    Keras 3 is multi-backend. This course uses the TensorFlow backend.
  3. 3. Why do the Run buttons in this course use NumPy instead of TensorFlow?

    Pyodide has no TensorFlow build. Stand-ins re-implement the underlying ideas so you can run and edit them.
  4. 4. What does x @ w + b compute in the stand-in?

    @ is matrix multiplication. Adding the bias gives the same math as a Dense layer without an activation.

Summary

  • TensorFlow provides tensors, automatic differentiation, graph compilation and deployment tools; Keras provides layers, models and the training loop.
  • Keras 3 is a standalone, multi-backend package; this course uses it with the TensorFlow backend.
  • A Keras project has five steps: data, model, compile, fit, evaluate/predict.
  • Real TensorFlow code is read-only here; the runnable examples are NumPy stand-ins that teach the same ideas.

Next: Installing and Your First Model