massquantity / LibRecommender

Versatile End-to-End Recommender System
https://librecommender.readthedocs.io/
MIT License
384 stars 67 forks source link

Failed to convert elements of (Dimension(None), Dimension(32)) to Tensor - model.fit() #479

Closed BhaveshBhansali closed 5 months ago

BhaveshBhansali commented 5 months ago

While calling

model = DeepFM( task="ranking", data_info=data_info, embed_size=16, n_epochs=3, lr=0.004, batch_size=512, use_bn=True, hidden_units=(128, 64, 32), ) model.fit( train_data, neg_sampling=True, verbose=2, shuffle=True, eval_data=test_data, metrics=["loss"], ),

throws following error:

TypeError: Exception encountered when calling Flatten.call().

Failed to convert elements of (Dimension(None), Dimension(32)) to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

Arguments received by Flatten.call(): • inputs=tf.Tensor(shape=(?, 2, 16), dtype=float32)

I am using LibRecommender==1.4.0 with following dependencies:

  1. python == 3.10.0
  2. tensorflow==2.16.1
  3. torch==2.3.0
Screenshot 2024-06-06 at 11 46 52
massquantity commented 5 months ago

Tensorflow 2.16 starts using Keras 3.0, so tf1 syntax is no longer supported and is used in this library. See https://github.com/massquantity/LibRecommender?tab=readme-ov-file#basic-dependencies-for-libreco

BhaveshBhansali commented 5 months ago

Thank you, I missed the specifiction. Setting Tensorflow to 2.10 worked!

BhaveshBhansali commented 5 months ago

Resolved!