"LookupError: gradient registry has no entry for: shap_TensorListStack" using DeepExplainer for Keras Model

3.2k views Asked by At

I am getting the following error when using the DeepExplainer for the Keras sequential model for Multiclass text classification. Please find the details below:

##KERAS VERSION: 2.4.3.

##MODEL

model = Sequential()
model.add(InputLayer (input_shape= (max_len ,)))
model.add(Embedding (vocab_size +1 , embed_dim , input_length= max_len, weights[embed_matrix]))
model.add(LSTM (LSTM_unit , dropout= dropouts, recurrent_dropout=dropouts,return_sequences=False))
model.add(Dense (6 , activation="softmax"))
##DEEPEXPLAINER

explainer = shap.DeepExplainer(model, X_train[:100], learning_phase_flags = None)
shap_values = explainer.shap_values(X_test[:10])

ERROR

LookupError: gradient registry has no entry for: shap_TensorListStack

Please help me with the solution to this issue. I have tried all the possible solutions provided in the issues mentioned in the repository but couldn't able to solve this error.

Best Regards, Meghna Goyal

1

There are 1 answers

0
MonsieurWave On

This error is due to the "shap" package that you are using. It requires a specific set of packages to work:

  • TensorFlow 1.14
  • Python 3.7
  • Protobuf 3.20
  • h5py 2.10
    import tensorflow as tf
    import sys
    import google.protobuf
    import h5py
    
    assert tf.__version__ == '1.14.0'
    assert sys.version_info[0] == 3 and sys.version_info[1] == 7
    assert google.protobuf.__version__ == '3.20.0'
    assert h5py.__version__ == '2.10.0'

Ref: https://github.com/slundberg/shap/issues/1490#issuecomment-1368185975