shap.DeepExplainer gives an error related to GlobalMaxPooling1D layer of CNN

86
November 29, 2021, at 07:00 AM

I am getting an error as below whenever I want to explain CNN classifier with SHAP for sentiment analysis:

InvalidArgumentError: Incompatible shapes: [100,128] vs. [100,46,128]
     [[{{node gradients/global_max_pooling1d/Max_grad/truediv_1}}]]

This is my code for CNN:

inputs = Input(shape=(max_length,), dtype=tf.int32)
embedded_sequences = Embedding(max_features, embedding_dims)(inputs)
out = Conv1D(filters,
             kernel_size,
             padding='valid',
             activation='relu',
             strides=1)(embedded_sequences)
out = Dropout(0.4)(out)
out = GlobalMaxPooling1D()(out)
out = Dense(hidden_dims, activation='relu')(out)
out = Dropout(0.4)(out)
outputs = Dense(1, activation='sigmoid')(out)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

And this is my code for SHAP:

shap.explainers._deep.deep_tf.op_handlers["AddV2"] = shap.explainers._deep.deep_tf.passthrough
explainer = shap.DeepExplainer(model_lstm, train_padded[:100])
# error appears at this line:
shap_values = explainer.shap_values(test_padded[:20]) 
Answer 1

You need to make sure your batches are of equal size and divisible by 4.

Rent Charter Buses Company
READ ALSO
How can I make a constraint so that the appointment cannot be repeated?

How can I make a constraint so that the appointment cannot be repeated?

I want to make a constraint so that the appointment with a certain doctor cannot be repeated more than onceFor example, if a person chooses an appointment on 11/09/2021 from 15:00 until 15:30, the same appointment cannot be booked again at the same doctor

93
How can I add individual html links into folium's popup window

How can I add individual html links into folium's popup window

I want to add individual html links of google search to the popups on a folium map according to the name of the street the icon is placed

40
Conditional link styling React

Conditional link styling React

I want my nav bar to style the page title I'm in, im using React and Tailwind CSS, for example, just make the title yellow when im on the selected path

75
How to mock async method with axios.post using sinon?

How to mock async method with axios.post using sinon?

I am trying to mock an async function which internally calls n async method in another js fileWhen i mock the the async function, it says 'expected post to be caaled atleast once'

81