Three ways to build the same network
Keras started as an independent library in 2015 — François Chollet wrote it on top of Theano with a clear philosophy: neural network code should be readable, modular, minimal. Google integrated Keras into TensorFlow as tf.keras in TF 2.0. From TF 2.16, tf.keras uses Keras 3 underneath — the multi-backend rewrite that runs on TF, PyTorch, or JAX.
Today both from tensorflow import keras and import keras refer to the same Keras 3. Use the latter for code you might want to run on a non-TF backend later.
Keras gives you three model-building APIs, each suited to different complexity levels:
| API | Best for | Limitation |
|---|---|---|
| Sequential | Linear stacks, one input → one output | No branches, no shared layers, no multi-I/O |
| Functional | DAGs, residual connections, multi-I/O | Requires explicit Input declaration |
| Subclassing | Custom forward-pass logic, research | Less introspectable, harder to serialize |