From 38c9a52a810bfc65c4592b963d66330e6cfe3355 Mon Sep 17 00:00:00 2001 From: AlexShen-Oguri <176059206+AlexShen-Oguri@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:29:18 -0500 Subject: [PATCH] Pass integer labels to Accuracy in the Keras guide Flatten the sigmoid predictions and cast the rounded values to integers in both the callback and the final evaluation. Co-authored-by: OpenAI Codex --- docs/source/keras_integrations.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/keras_integrations.md b/docs/source/keras_integrations.md index 317078810..31d0b81cc 100644 --- a/docs/source/keras_integrations.md +++ b/docs/source/keras_integrations.md @@ -72,8 +72,8 @@ class MetricsCallback(keras.callbacks.Callback): def on_epoch_end(self, epoch, logs=dict()): m = self.model - # Ensure we get labels of "1" or "0" - training_preds = np.round(m.predict(self.x_data)) + # Accuracy expects one integer label per example. + training_preds = np.round(m.predict(self.x_data)).reshape(-1).astype(np.int32) training_labels = self.y_data # Compute score and save @@ -102,8 +102,8 @@ We can also use the same metric after model training! Here, we show how to check ```python acc = evaluate.load("accuracy") -# Round the predictions to turn them into "0" or "1" labels -test_preds = np.round(model.predict(x_test)) +# Convert the sigmoid outputs from shape (num_examples, 1) into integer labels. +test_preds = np.round(model.predict(x_test)).reshape(-1).astype(np.int32) test_labels = y_test ```