I am running a simple fine tuning using Cosine Similiarity loss code and getting following error. Can you please help me to understand the issue and resolve.
Tensorflow Version: 2.0
Error:
ValueError: Failed to find data adapter that can handle input: (class 'list' containing values of types {"class 'str'"}), class 'numpy.ndarray'>
Code
import tensorflow as tf
import tensorflow_hub as hub
from tensorflow import keras
huburl='https://tfhub.dev/google/universal-sentence-encoder-large/5'
left_loaded_module_obj = hub.load(huburl)
left_input = keras.Input(shape=(), dtype=tf.string)
# left_trainable_embedding_layer = hub.KerasLayer(huburl,trainable=True)
left_trainable_embedding_layer = hub.KerasLayer(left_loaded_module_obj,trainable=True)
embedding_left_output= left_trainable_embedding_layer(left_input)
model = tf.keras.Model(left_input, embedding_left_output)
model.compile('sgd', loss=tf.keras.losses.CosineSimilarity(axis=-1))
model.summary()
import tensorflow_hub as hub
import tensorflow as tf
tf.enable_eager_execution()
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder-large/5")
text_list=["The quick brown fox jumps over the lazy dog.",
"I am a sentence for which I would like to get its embedding"]
embeddings = embed(text_list)
print (embeddings.numpy())
embed_target=embeddings.numpy()
print (type(embed_target),embed_target.shape)
model.fit(x=text_list,y=embed_target)
Simply convert the list y into a numpy array, and it should do the trick. Something like this:
y = np.array(y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With