Keras
Originally by François Chollet, now maintained as part of Google's ML ecosystem
Keras is a high-level Python API for building and training neural networks, designed to make deep learning accessible through simple, readable code. Originally an independent multi-backend library, Keras became TensorFlow's official…
Definition
Keras is a high-level Python API for building and training neural networks, designed to make deep learning accessible through simple, readable code. Originally an independent multi-backend library, Keras became TensorFlow's official high-level API and has since evolved into Keras 3, which supports running the same code on top of TensorFlow, PyTorch, or JAX as an interchangeable backend chosen at runtime.
Overview
Building a neural network directly against a lower-level framework's tensor operations requires writing a fair amount of boilerplate: defining layers, wiring forward passes, and managing training loops by hand. Keras was created to remove that friction by providing a small set of high-level building blocks, layers, models, and a compact `fit`/`evaluate`/`predict` interface, that let a developer assemble and train a common neural network architecture in a handful of lines of readable code. Mechanically, a Keras model is typically built by stacking layer objects, either sequentially or through a more flexible functional API for models with branching or multiple inputs and outputs, then compiling the model with a loss function, optimizer, and metrics before calling `fit` to run the training loop. Keras handles the training loop mechanics, batching, and metric tracking internally, while still allowing custom layers, losses, and training steps for cases that need more control than the default `fit` call provides. Keras occupies the high-level end of the deep learning tooling spectrum, in contrast to writing directly against PyTorch's or TensorFlow's lower-level tensor and autograd APIs, or against JAX's functional transformations. Its distinguishing move with Keras 3 is backend independence: the same Keras model code can run on top of TensorFlow, PyTorch, or JAX, letting a team choose or switch the underlying engine without rewriting the model definition itself, a flexibility earlier Keras versions tied exclusively to TensorFlow did not offer. In practice, Keras is widely used for teaching and learning deep learning given its readable syntax, for rapid prototyping of standard model architectures, and increasingly for production models where a team wants the option to move between backends, for example prototyping in one framework and deploying with the performance characteristics of another entirely. It is also common in tutorials, courses, and documentation examples precisely because its syntax reads closely to the underlying mathematical description of the model, which shortens the distance between a diagram sketched on a whiteboard and a piece of actual working, runnable code. Limitations include that its high-level abstractions can obscure fine-grained control for genuinely novel architectures or training procedures, which sometimes pushes advanced researchers toward writing custom code directly against PyTorch or JAX instead. The multi-backend transition of Keras 3 also introduced some compatibility considerations for code and third-party extensions written against the earlier TensorFlow-only version of Keras, so older tutorials and packages may need updating before they work correctly under the newer release.
Key Features
- Provides a high-level API for building and training neural networks
- Offers both sequential and functional model-building interfaces
- Supports TensorFlow, PyTorch, or JAX as an interchangeable backend in Keras 3
- Includes a compact `fit`/`evaluate`/`predict` training interface
- Allows custom layers, losses, and training steps for advanced needs
- Prioritizes readable, concise code for common architectures
- Is widely used for teaching deep learning fundamentals
Use Cases
Alternatives
Frequently Asked Questions
From the Blog
PyTorch vs TensorFlow: Which to Learn in 2026
PyTorch wins for research and learning; TensorFlow/Keras wins for mobile and production deployment. Most beginners should start with PyTorch.
Read More Data ScienceTensorFlow and Keras: How the Two Fit Together
Keras is the model-building API and TensorFlow is the tensor runtime beneath it. Learn which layer each task belongs in — models and callbacks in Keras, data pipelines and graph compilation in TensorFlow — so shape errors, retracing surprises and deployment questions stop being confusing.
Read More Data ScienceKeras Sequential vs Functional vs subclassing: which API to use
Pick the API from the shape of your model's graph, not from style preference. Sequential handles a single chain, Functional handles multiple inputs, shared layers and merges while staying inspectable and easy to save, and subclassing is for genuinely dynamic forward logic.
Read More Data ScienceWhy your Keras model predicts one class for everything
A model that outputs the majority class for every input has collapsed to the prior, and there are five likely causes. Check the confusion matrix first, then class balance, the activation and loss pairing, input scaling, the learning rate, and label alignment — in that order.
Read More