IndexError: index out of range in SMS Text Classifier test cell

Hi, I’m stuck on the SMS Text Classifier project. My model seems to work fine, but the testing cell throws an IndexError: index out of range.

​I suspect it’s happening when the test cell tries to access the result from my predict_message function.

​Here is my predict_message function:

def predict_message(pred_text):
prediksi = Final_model.predict(pred_text)
prediction = [prediksi]
if prediksi > 0.5:
prediction.append(“spam”)
else:
prediction.append(“ham”)

return prediction

pred_text = np.array([“big prize! £1000 cash! sale only today! call no 19282727 to stop this message”])
final = Tokenin(pred_text)
Versi_np = final.numpy().astype(np.int64)
layer_0 = Versi_np[0]
expand = np.expand_dims(layer_0, axis=0)

prediction = predict_message(expand)
print(prediction)

​And here is the full error trace:

1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 56ms/step

---------------------------------------------------------------------------

IndexError                                Traceback (most recent call last)

/tmp/ipython-input-3870904172.py in <cell line: 0>()
     29   return (tensor, y_final)
     30 
---> 31 test_predictions()



3 frames


/tmp/ipython-input-3870904172.py in test_predictions()
     18 
     19   for msg, ans in zip(test_messages, test_answers):
---> 20     prediction = predict_message(msg)
     21     if prediction[1] != ans:
     22       passed = False


/tmp/ipython-input-1103236006.py in predict_message(pred_text)
      3 
      4 def predict_message(pred_text):
----> 5   prediksi = Final_model.predict(pred_text)
      6   prediction = [prediksi]
      7   if prediksi > 0.5:


/usr/local/lib/python3.12/dist-packages/keras/src/utils/traceback_utils.py in error_handler(*args, **kwargs)
    120             # To get the full stack trace, call:
    121             # `keras.config.disable_traceback_filtering()`
--> 122             raise e.with_traceback(filtered_tb) from None
    123         finally:
    124             del filtered_tb


/usr/local/lib/python3.12/dist-packages/keras/src/trainers/data_adapters/data_adapter_utils.py in <genexpr>(.0)
    103 def check_data_cardinality(data):
    104     num_samples = set(
--> 105         int(i.shape[0]) for i in tree.flatten(data) if i is not None
    106     )
    107     if len(num_samples) > 1:


IndexError: tuple index out of range

​Can anyone help me see if I’m returning the wrong format or if it’s a shape mismatch?

using “tree.flatten(data)” already flattened the data to a 1D data.. assuming the original array data is [[0.1,0.2,0.3], [0.4,0.5,0.6]] which is 2D, flattening it would result it to become 1D: [0.1,0.2,0.3,0.4,0.5,0.6],
Then you now tried to access it each element in the array and gettting their shape, which would result in an error.. if i can see how the original array looks like before flattening that would help better