Tutorial

Build your first neural network in Keras

Here's the end-to-end Keras workflow for a first neural network: define a model, compile it, fit it, and evaluate it.

1. Define the model

import keras
from keras import layers

model = keras.Sequential([
    layers.Dense(128, activation="relu"),
    layers.Dropout(0.2),
    layers.Dense(10, activation="softmax"),
])

2. Compile

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

3. Fit (train)

model.fit(x_train, y_train, epochs=10, validation_split=0.1)

4. Evaluate & predict

model.evaluate(x_test, y_test)
preds = model.predict(x_new)
That's the whole loop — and it's identical on every backend. For datasets, callbacks and GPU training, follow the official documentation.
Want the source? Use the get-it section — it stays on-page and links to the official GitHub repository.

Related guides