kundajelab / deeplift

Public facing deeplift repo
MIT License
826 stars 164 forks source link

Support for Keras "Add" layer #112

Open yynst2 opened 4 years ago

yynst2 commented 4 years ago

Hi,

My network involves simple residual connection structures that use keras Add layer, it seems this type of structure is supported according to your latest work with "BPnet" paper. Do you have an updated version of deeplift that actually supports it?

The current version reports the Add layer is not supported (not in the conversion mapping), and gives the following error.

/usr/local/lib/python3.6/dist-packages/deeplift/conversion/kerasapi_conversion.py in layer_name_to_conversion_function(layer_name) 338 # lowercase to create resistance to capitalization changes 339 # was a problem with previous Keras versions --> 340 return name_dict[layer_name.lower()] 341 342

KeyError: 'add'

Thanks a lot!

AvantiShri commented 4 years ago

Hi @yynst2, the BPNet paper actually used the implementation of DeepLIFT from the DeepExplain repository (our branch is forked from marcoancona/DeepExplain): https://github.com/kundajelab/DeepExplain. We used this implementation precisely because it is more flexible as it is built by overriding tensorflow gradient operators. As I recall, the difference between our fork of DeepExplain and the original DeepExplain repository is a few modifications that facilitate calculation of the hypothetical importance scores.

It is also possible to use DeepSHAP’s implementation of DeepLIFT to compute the importance scores. This is what we have been moving towards for BPNet, as DeepSHAP allows the use of multiple references per sequence (DeepExplain only supports one reference per sequence; this is discussed in the FAQ). For convolutional architectures, DeepSHAP is similar to DeepLIFT with the Rescale rule (this is also discussed in the FAQ). In benchmarking, I have found that the Rescale rule performs equivalently to the combination of Rescale & RevealCancel when used with shuffled sequences as the reference. Here are some slides that cover how to use DeepSHAP to get explanations from models trained on genomic data (including BPNet-style models): https://docs.google.com/presentation/d/1JCLMTW7ppA3Oaz9YA2ldDgx8ItW9XHASXM1B3regxPw/edit

Let me know if you have additional questions.

yynst2 commented 4 years ago

Thanks a lot, that's very helpful.