tensorflow / neural-structured-learning

Training neural models with structured signals.
https://www.tensorflow.org/neural_structured_learning
Apache License 2.0
980 stars 189 forks source link

ValueError in the tutorial on Colab environment #41

Closed yenhao closed 4 years ago

yenhao commented 4 years ago

Hello

The ValueError error Insufficient elements in branch_graphs[0].outputs. is found in both Neural Graph Learning tutorials (sentiment and document classification).

Both happen during the training of graph_reg_model.fit() process. The error messages are shown below, I think it is due to the same issue.

Epoch 1/100
      1/Unknown - 0s 303ms/step

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-20-0c7d19de6181> in <module>()
     10     loss='sparse_categorical_crossentropy',
     11     metrics=['accuracy'])
---> 12 graph_reg_model.fit(train_dataset, epochs=HPARAMS.train_epochs, verbose=1)

25 frames

/tensorflow-2.1.0/python3.6/tensorflow_core/python/ops/cond_v2.py in _make_indexed_slices_indices_types_match(op_type, branch_graphs)
    650                      "Expected: %i\n"
    651                      "Actual: %i" %
--> 652                      (current_index, len(branch_graphs[0].outputs)))
    653 
    654   # Cast indices with mismatching types to int64.

ValueError: Insufficient elements in branch_graphs[0].outputs.
Expected: 11
Actual: 10
Epoch 1/10
      1/Unknown - 2s 2s/step

---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-30-e49eed0ffe51> in <module>()
      3     validation_data=validation_dataset,
      4     epochs=HPARAMS.train_epochs,
----> 5     verbose=1)

25 frames

/tensorflow-2.1.0/python3.6/tensorflow_core/python/ops/cond_v2.py in _make_indexed_slices_indices_types_match(op_type, branch_graphs)
    650                      "Expected: %i\n"
    651                      "Actual: %i" %
--> 652                      (current_index, len(branch_graphs[0].outputs)))
    653 
    654   # Cast indices with mismatching types to int64.

ValueError: Insufficient elements in branch_graphs[0].outputs.
Expected: 18
Actual: 17

Thanks

arjung commented 4 years ago

Thanks for raising the issue! This is caused by an underlying bug in TensorFlow, the fix for which is on master but not in TensorFlow 2.1.0-rc1/2.1.0-rc2. Since the NSL tutorials currently seem to be using TF 2.1.0-rc1, they are impacted by this bug.

We have reached out to the TensorFlow team on how to work around this and will get back to you once we hear from them.

arjung commented 4 years ago

Hi @yenhao, thanks for your patience. We are going to update the NSL graph tutorials to use TF 2.2.x instead to work around the TF bug in v2.1.

arjung commented 4 years ago

Fixed by https://github.com/tensorflow/neural-structured-learning/commit/de5989351d3347c217ee02b8032b1c13be6dc968

iuria21 commented 4 years ago

Hi, I'm having the same problem in Colab, and I can't install the 2.2.x version. Do you know how can I do it in colab? the latest version available with pip is 2.1...

arjung commented 4 years ago

Hi @basque21, both the NSL graph tutorials should be working and use a nightly build of TF 2.2.x. In particular, they use the following command:

pip install --quiet tf-nightly==2.2.0.dev20200119

Hope this helps.

vinayprabhu commented 4 years ago

@arjung Can you please reconfirm the version # ? ERROR: No matching distribution found for tf-nightly==2.2.0.dev20200119

arjung commented 4 years ago

@vinayprabhu , thanks for your comment. Unfortunately that version no longer exists on PyPi. Our tutorials for graph regularization are currently using the following nightly build version: 2.2.0.dev20200218.

This version will be subject to change until the underlying TensorFlow bug is fixed in TF 2.2.0.

basirshariat commented 4 years ago

I upgraded to 2.2.0rc1 and i get this error when the fit of the base model is called:

/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py:216 assert_input_compatibility ' but received input with shape ' + str(shape))

ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 1433 but received input with shape [None, 1]
aczw900 commented 4 years ago

Which nightly version is currently being used for your tutorials for graph regularization? ERROR: No matching distribution found for tf-nightly==2.2.0.dev20200218

arjung commented 4 years ago

Thanks @basirshariat and @aczw900! We updated our graph regularization tutorials in https://github.com/tensorflow/neural-structured-learning/commit/f4b302c0e00c9f90ee93393b5c7bfbb715bc929d to use TF 2.0.1, which is a stable version.

We are actively looking into getting this addressed soon for TF 2.2, which is still undergoing development.

arjung commented 4 years ago

This should no longer be an issue since TF 2.2.0 has been released. Sorry about the version complications, things will be much simpler now.

https://github.com/tensorflow/neural-structured-learning/commit/edead04aa3be59f07baea52fc2cf22c320cdaff5 updates the neural graph learning tutorials to use the default TF version in colab.