marcoancona / DeepExplain

A unified framework of perturbation and gradient-based attribution methods for Deep Neural Networks interpretability. DeepExplain also includes support for Shapley Values sampling. (ICLR 2018)
https://arxiv.org/abs/1711.06104
MIT License
729 stars 133 forks source link

Error while using DeepLift: You must feed a value for placeholder tensor 'input_1' #65

Closed dlacorte closed 3 years ago

dlacorte commented 3 years ago

Hi,

I am working on a TextCNN Model with Keras.

With the section NLP / Embedding lookups I was able to make use of all attribution methos beside deeplift.

attributions_dl = de.explain('deeplift', pre_sigmoid * ys, embedding, embedding_out)

I get the following error message: "tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,100]"

Any tips on that matter would be appreciated

Best Daniel

AvantiShri commented 3 years ago

I'm not a creator of deepexplain, but my guess is that the computation graph is wired in such a way that the "embedding" tensor is insufficient to compute "pre_sigmoid" (rather, calculating "pre_sigmoid" relies on a tensor called "input_1"). Can you post the code for how the tensors "pre_sigmoid" and "embedding" were obtained, as well as the model architecture?

dlacorte commented 3 years ago

@AvantiShri Thanks for your comment.

The model:

model = Sequential() model.add(InputLayer(input_shape=(maxlen,))) model.add(layers.Embedding(vocab_size, embedding_dim, input_length=maxlen, trainable=True)) model.add(layers.Conv1D(128, 3, activation='relu', padding='same')) model.add(layers.Flatten()) model.add(layers.Dropout(0.5)) model.add(layers.Dense(128, activation='relu')) model.add(layers.Dense(20)) model.add(Activation('sigmoid'))

Tensors:

embedding = model.layers[0].output input_tensor = model.inputs[0] embedding_out = current_session.run(embedding, {input_tensor: x_test}) pre_sigmoid = model.layers[-2].output

dlacorte commented 3 years ago

I found out that when I create and train the model in the deep explain context, the errors is gone. Also deeplift works now,

However, If train the model outside the context and reinitiate it inside the context that causes the described behaviour:

What I am doing inside the context is the following: new_model = load_model('model/text_cnn_simple.h5')

It looks like I can not train a model outside the deep explain context and load it after the training into the context

AvantiShri commented 3 years ago

Potential workaround: define the model architecture with the context and then (still within the context) call model.load_weights(...) using the weights from the hdf5 file - that way, maybe you can train the model outside the context?

dlacorte commented 3 years ago

@AvantiShri Thanks for the suggestion. I have tried it out. The problem stays the same.

I am currently trying to recreate the graph inside the context: From the examples of the author: fModel = Model(inputs=input_tensor, outputs = model.layers[-2].output) target_tensor = fModel(input_tensor)

At the moment I am not able to adapt this example to my scenario which makes use of embeddings.