clabrugere / multitask-learning

Tensorflow implementation of three architectures for multi-task learning, a paradigm to learn different prediction tasks jointly using one model
MIT License
8 stars 0 forks source link

Troubleshooting Concatenation in MultiGateMixtureOfExperts Model Training #2

Open SEHABI-YOUSSOUF opened 4 months ago

SEHABI-YOUSSOUF commented 4 months ago

hi sir i keep getting this error can you help me for instance give me exemple in collab of runing code please and thank you

----> 1 history =model.fit(x=sample_dataset, epochs=1)

2 frames /tmp/__autograph_generated_filedpw8h24k.py in tfcall(self, inputs) 10 (cat_inputs, cont_inputs) = ag.ld(inputs) 11 cat_embed = ag.converted_call(ag__.ld(self).embedding_layer, (ag.ld(cat_inputs),), None, fscope) ---> 12 combined_inputs = ag.converted_call(ag.ld(tf).concat, ([ag.ld(cat_embed), ag.ld(cont_inputs)],), dict(axis=-1), fscope) 13 out = ag__.converted_call(ag.ld(self).mlp, (ag.ld(combined_inputs),), None, fscope) 14 try:

ValueError: in user code:

File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1401, in train_function  *
    return step_function(self, iterator)
File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1384, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1373, in run_step  **
    outputs = model.train_step(data)
File "/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py", line 1150, in train_step
    y_pred = self(x, training=True)
File "/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
File "/tmp/__autograph_generated_filedpw8h24k.py", line 12, in tf__call
    combined_inputs = ag__.converted_call(ag__.ld(tf).concat, ([ag__.ld(cat_embed), ag__.ld(cont_inputs)],), dict(axis=-1), fscope)

ValueError: Exception encountered when calling layer 'multi_gate_mixture_of_experts_23' (type MultiGateMixtureOfExperts).

in user code:

    File "<ipython-input-46-fb5e519901c9>", line 50, in call  *
        combined_inputs = tf.concat([cat_embed, cont_inputs], axis=-1)

    ValueError: Shape must be rank 3 but is rank 2 for '{{node multi_gate_mixture_of_experts_23/concat}} = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32](multi_gate_mixture_of_experts_23/embedding_25/embedding_lookup/Identity, IteratorGetNext:1, multi_gate_mixture_of_experts_23/concat/axis)' with input shapes: [?,2,64], [?,10], [].

Call arguments received by layer 'multi_gate_mixture_of_experts_23' (type MultiGateMixtureOfExperts):
  • inputs=('tf.Tensor(shape=(None, 2), dtype=int32)', 'tf.Tensor(shape=(None, 10), dtype=float32)')
clabrugere commented 4 months ago

Hello, the inputs are supposed to be a list/tuple of 2D tensors of shapes (batch size, num sparse features), (batch size, num dense features) and labels a 2D tensor of shape (batch size, num tasks). If you have only sparse or dense features you need to adapt the model accordingly.

I added this example notebook with random data. I hope that helps.