google-research / retvec

RETVec is an efficient, multilingual, and adversarially-robust text vectorizer.
Apache License 2.0
284 stars 24 forks source link

ValueError raised upon calling RetVecTokenizer function #48

Open chinsu70802 opened 6 months ago

chinsu70802 commented 6 months ago

Hi!

I am trying to use RetVec as an embedding layer for a email spam classification project. When the RetVecTokenizer function is called, I get a Value Error which is described below:

File format not supported: filepath=/root/.keras/retvec-v1. Keras 3 only supports V3 .keras files and legacy H5 format files (.h5 extension). Note that the legacy SavedModel format is not supported by load_model() in Keras 3. In order to reload a TensorFlow SavedModel as an inference-only layer in Keras 3, use keras.layers.TFSMLayer(/root/.keras/retvec-v1, call_endpoint='serving_default') (note that your call_endpoint might have a different name).

Here is the code I wrote:

inputs = layers.Input(shape=(1, ), name="token", dtype=tf.string)

lstm_1 = tf.keras.layers.LSTM(20, dropout=0.2, return_sequences=True)(x) lstm_2 = tf.keras.layers.LSTM(20, dropout=0.2, return_sequences=True)(lstm_1) flatten = tf.keras.layers.Flatten()(lstm_2) dropout = tf.keras.layers.Dropout(0.2, name="dropout")(flatten) dense = tf.keras.layers.Dense(1, activation="sigmoid")(dropout)

model = tf.keras.Model(inputs=[inputs], outputs=[dense])

How to resolve this?

Jinnrry commented 4 months ago

Same problem, I downgraded tensorflow to 2.7.4 to solve the problem.

Jinnrry commented 4 months ago

Addendum: 2.7.4 can train the model but cannot execute the prediction code, with 2.8.4 you can train as well as execute the prediction.

chinsu70802 commented 4 months ago

Thanks @Jinnrry! It is working now.