【发布时间】:2021-11-28 19:58:31
【问题描述】:
每当我想用 SHAP 解释 CNN 分类器进行情感分析时,我都会收到如下错误:
InvalidArgumentError: Incompatible shapes: [100,128] vs. [100,46,128]
[[{{node gradients/global_max_pooling1d/Max_grad/truediv_1}}]]
这是我的 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'])
这是我的 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])
【问题讨论】:
标签: python tensorflow conv-neural-network shap