diff --git a/keras_nlp/src/utils/tensor_utils.py b/keras_nlp/src/utils/tensor_utils.py index 46583eed0d..f94295c71f 100644 --- a/keras_nlp/src/utils/tensor_utils.py +++ b/keras_nlp/src/utils/tensor_utils.py @@ -20,6 +20,8 @@ import keras import numpy as np from keras import ops +from collections.abc import Mapping +from collections.abc import Sequence try: import tensorflow as tf @@ -115,13 +117,13 @@ def convert_preprocessing_inputs(x): if not tf.executing_eagerly() or in_no_convert_scope(): return x - if isinstance(x, dict): + if isinstance(x, Mapping): return {k: convert_preprocessing_inputs(x[k]) for k, v in x.items()} if isinstance(x, tuple): return tuple(convert_preprocessing_inputs(v) for v in x) if isinstance(x, (str, bytes)): return tf.constant(x) - if isinstance(x, list): + if isinstance(x, Sequence): try: numpy_x = np.array(x) except ValueError as e: