Quantcast
Viewing all articles
Browse latest Browse all 14069

Python Bert is failing at preprocessed_inputs = preprocessor(text_input). A KerasTensor is symbolic: it's a placeholder for a shape an dtype

I'm tying to load bert model and text_input is printing<KerasTensor shape=(None,), dtype=string, sparse=None, name=keras_tensor_54>and preprocessor is also loading but still getting this error.ValueError: A KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to a NumPy array.

Code

text_input = tf.keras.layers.Input(shape=(), dtype=tf.string)print(text_input)# Load the BERT preprocessing model from TensorFlow Hubpreprocessor_url = "https://kaggle.com/models/tensorflow/bert/TensorFlow2/en-uncased-preprocess/3"try:    preprocessor = hub.KerasLayer(preprocessor_url)except Exception as e:    print("Error loading the BERT preprocessing model:", e)# Check if the preprocessor is Noneif preprocessor is None:    print("Preprocessor is None. There was an error loading the model.")else:    # Preprocess the text inputs using the BERT preprocessing layer    preprocessed_inputs = preprocessor(text_input)

Stack trace

Traceback (most recent call last):  File "/home/ayazbism/PycharmProjects/hate-speech-detection/hate_speech_detection.py", line 394, in <module>    preprocessed_inputs = preprocessor(text_input)  File "/home/ayazbism/.local/lib/python3.10/site-packages/tf_keras/src/engine/base_layer_v1.py", line 899, in __call__    outputs = self.call(cast_inputs, *args, **kwargs)  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow_hub/keras_layer.py", line 250, in call    result = smart_cond.smart_cond(training,  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/python/framework/smart_cond.py", line 55, in smart_cond    return false_fn()  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow_hub/keras_layer.py", line 252, in <lambda>    lambda: f(training=False))  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py", line 817, in _call_attribute    return instance.__call__(*args, **kwargs)  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler    raise e.with_traceback(filtered_tb) from None  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 583, in canonicalize_to_monomorphic    _make_validated_mono_param(name, arg, poly_parameter.kind,  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 522, in _make_validated_mono_param    mono_type = trace_type.from_value(value, type_context)  File "/home/ayazbism/.local/lib/python3.10/site-packages/tensorflow/core/function/trace_type/trace_type_builder.py", line 185, in from_value    ndarray = value.__array__()  File "/home/ayazbism/.local/lib/python3.10/site-packages/keras/src/backend/common/keras_tensor.py", line 61, in __array__    raise ValueError(ValueError: A KerasTensor is symbolic: it's a placeholder for a shape an a dtype. It doesn't have any actual numerical value. You cannot convert it to a NumPy array.

Please share the reason. why I'm getting this error. is it due to python version because bert code is same at all places.


Viewing all articles
Browse latest Browse all 14069

Trending Articles