[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-kundajelab--deeplift":3,"tool-kundajelab--deeplift":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":80,"owner_email":80,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":92,"env_os":93,"env_gpu":93,"env_ram":93,"env_deps":94,"category_tags":100,"github_topics":101,"view_count":23,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":108,"updated_at":109,"faqs":110,"releases":140},2894,"kundajelab\u002Fdeeplift","deeplift","Public facing deeplift repo","DeepLIFT（Deep Learning Important FeaTures）是一款专为深度学习模型设计的可解释性分析工具，旨在帮助用户理解神经网络是如何做出预测的。它通过“传播激活差异”的核心算法，将模型的输出归因到各个输入特征上，从而量化每个输入对最终结果的贡献程度。\n\n该工具主要解决了深度学习模型“黑盒”难题，让开发者能够清晰地看到哪些输入特征（如图像中的像素或文本中的词语）推动了模型的决策，以及哪些特征起到了抑制作用。除了核心的 DeepLIFT 算法外，它还集成了梯度、引导反向传播（Guided Backprop）和积分梯度（Integrated Gradients）等多种主流归因方法，方便进行对比分析。\n\nDeepLIFT 特别适合 AI 研究人员、数据科学家以及需要调试和优化模型的深度学习开发者使用。其独特的技术亮点在于引入了“参考值”概念，通过比较当前输入与参考状态的差异来计算贡献分数，这比单纯的梯度方法能提供更丰富的信息（包括负向贡献）。虽然目前官方版本主要支持基于 Keras 和 TensorFlow 的模型，但其提供的理论思路和代码实现对于探索模型内部机制具","DeepLIFT（Deep Learning Important FeaTures）是一款专为深度学习模型设计的可解释性分析工具，旨在帮助用户理解神经网络是如何做出预测的。它通过“传播激活差异”的核心算法，将模型的输出归因到各个输入特征上，从而量化每个输入对最终结果的贡献程度。\n\n该工具主要解决了深度学习模型“黑盒”难题，让开发者能够清晰地看到哪些输入特征（如图像中的像素或文本中的词语）推动了模型的决策，以及哪些特征起到了抑制作用。除了核心的 DeepLIFT 算法外，它还集成了梯度、引导反向传播（Guided Backprop）和积分梯度（Integrated Gradients）等多种主流归因方法，方便进行对比分析。\n\nDeepLIFT 特别适合 AI 研究人员、数据科学家以及需要调试和优化模型的深度学习开发者使用。其独特的技术亮点在于引入了“参考值”概念，通过比较当前输入与参考状态的差异来计算贡献分数，这比单纯的梯度方法能提供更丰富的信息（包括负向贡献）。虽然目前官方版本主要支持基于 Keras 和 TensorFlow 的模型，但其提供的理论思路和代码实现对于探索模型内部机制具有极高的参考价值，是提升模型透明度和可信度的得力助手。","DeepLIFT: Deep Learning Important FeaTures\n===\n[![Build Status](https:\u002F\u002Fapi.travis-ci.org\u002Fkundajelab\u002Fdeeplift.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Fkundajelab\u002Fdeeplift)\n[![license](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmashape\u002Fapistatus.svg?maxAge=2592000)](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FLICENSE)\n\n**This version of DeepLIFT has been tested with Keras 2.2.4 & tensorflow 1.14.0**. See [this FAQ question](#my-model-architecture-is-not-supported-by-this-deeplift-implementation-what-should-i-do) for information on other implementations of DeepLIFT that may work with different versions of tensorflow\u002Fpytorch, as well as a wider range of architectures. See the tags for older versions.\n\nThis repository implements the methods in [\"Learning Important Features Through Propagating Activation Differences\"](https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.02685) by Shrikumar, Greenside & Kundaje, as well as other commonly-used methods such as gradients, gradient-times-input (equivalent to a version of Layerwise Relevance Propagation for ReLU networks), [guided backprop](https:\u002F\u002Farxiv.org\u002Fabs\u002F1412.6806) and [integrated gradients](https:\u002F\u002Farxiv.org\u002Fabs\u002F1611.02639).\n\nHere is a link to the [slides](https:\u002F\u002Fdocs.google.com\u002Ffile\u002Fd\u002F0B15F_QN41VQXSXRFMzgtS01UOU0\u002Fedit?usp=docslist_api&filetype=mspresentation) and the [video](https:\u002F\u002Fvimeo.com\u002F238275076) of the 15-minute talk given at ICML. [Here](https:\u002F\u002Fwww.youtube.com\u002Fplaylist?list=PLJLjQOkqSRTP3cLB2cOOi_bQFw6KPGKML) is a link to a longer series of video tutorials. Please see the [FAQ](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FREADME.md#faq) and file a github issue if you have questions.\n\nNote: when running DeepLIFT for certain computer vision tasks **you may get better results if you compute contribution scores of some higher convolutional layer rather than the input pixels**. Use the argument `find_scores_layer_idx` to specify which layer to compute the scores for.\n\n**Please be aware that figuring out optimal references is still an open problem. Suggestions on good heuristics for different applications are welcome.** In the meantime, feel free to look at this github issue for general ideas: https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F104\n\nPlease feel free to follow this repository to stay abreast of updates.\n\n## Table of contents\n\n  * [Installation](#installation)\n  * [Quickstart](#quickstart)\n  * [Examples](#examples)\n  * [FAQ](#faq)\n    * [Can you provide a brief intuition for how DeepLIFT works?](#can-you-provide-a-brief-intuition-for-how-deeplift-works)\n    * [My model architecture is not supported by this DeepLIFT implementation. What should I do?](#my-model-architecture-is-not-supported-by-this-deeplift-implementation-what-should-i-do)\n    * [What are the similarities and differences between the DeepLIFT-like implementations in DeepExplain from Ancona et al. (ICLR 2018) and DeepSHAP\u002FDeepExplainer from the SHAP repository?](#what-are-the-similarities-and-differences-between-the-deeplift-like-implementations-in-deepexplain-from-ancona-et-al-iclr-2018-and-deepshapdeepexplainer-from-the-shap-repository)\n    * [How does DeepLIFT compare to integrated gradients?](#how-does-deeplift-compare-to-integrated-gradients)\n    * [How does the implementation in this repository compare with the DeepLIFT implementation in Poerner et al. (ACL 2018)?](#how-does-the-implementation-in-this-repository-compare-with-the-deeplift-implementation-in-poerner-et-al-acl-2018)\n    * [Do you have support for non-keras models?](#do-you-have-support-for-non-keras-models)\n    * [What do negative scores mean?](#what-do-negative-scores-mean)\n    * [How do I provide a reference argument?](#how-do-i-provide-a-reference-argument)\n    * [What should I use as my reference?](#what-should-i-use-as-my-reference)\n    * [How can I get a sense of how much an input contributes across all examples?](#how-can-i-get-a-sense-of-how-much-an-input-contributes-across-all-examples)\n    * [Can I have multiple input modes?](#can-i-have-multiple-input-modes)\n    * [Can I get the contribution scores on multiple input layers at once?](#can-i-get-the-contribution-scores-on-multiple-input-layers-at-once)\n    * [What's the license?](#whats-the-license)\n    * [I have heard DeepLIFT can do pattern discovery - is that right?](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FREADME.md#i-have-heard-deeplift-can-do-pattern-discovery---is-that-right)\n  * [Contact](#contact)\n  * [Under The Hood](#under-the-hood)\n    * [Layers](#layers)\n    * [The Forward Pass](#the-forward-pass)\n    * [The Backward Pass](#the-backward-pass)\n\n## Installation\n\nDeepLIFT is on pypi, so it can be installed using pip:\n```unix\npip install deeplift\n```\n\nIf you want to be able to make edits to the code, it is recommended that you clone the repository and install using the `--editable` flag.\n```unix\ngit clone https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift.git #will clone the deeplift repository\npip install --editable deeplift\u002F #install deeplift from the cloned repository. The \"editable\" flag means changes to the code will be picked up automatically.\n```\n\nWhile DeepLIFT does not require your models to be trained with any particular library, we have provided autoconversion functions to convert models trained using Keras into the DeepLIFT format. If you used a different library to train your models, you can still use DeepLIFT if you recreate the model using DeepLIFT layers.\n\nThis implementation of DeepLIFT was tested with tensorflow 1.7, and autoconversion was tested using keras 2.0.\n\n## Quickstart\n\nThese examples show how to autoconvert a keras model and obtain importance scores. Non-keras models can be converted to DeepLIFT if they are saved in the keras 2.0 format \n\n```python\n#Convert a keras sequential model\nimport deeplift\nfrom deeplift.conversion import kerasapi_conversion as kc\n#NonlinearMxtsMode defines the method for computing importance scores.\n#NonlinearMxtsMode.DeepLIFT_GenomicsDefault uses the RevealCancel rule on Dense layers\n#and the Rescale rule on conv layers (see paper for rationale)\n#Other supported values are:\n#NonlinearMxtsMode.RevealCancel - DeepLIFT-RevealCancel at all layers (used for the MNIST example)\n#NonlinearMxtsMode.Rescale - DeepLIFT-rescale at all layers\n#NonlinearMxtsMode.Gradient - the 'multipliers' will be the same as the gradients\n#NonlinearMxtsMode.GuidedBackprop - the 'multipliers' will be what you get from guided backprop\n#Use deeplift.util.get_integrated_gradients_function to compute integrated gradients\n#Feel free to email avanti [dot] shrikumar@gmail.com if anything is unclear\ndeeplift_model =\\\n    kc.convert_model_from_saved_files(\n        saved_hdf5_file_path,\n        nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault) \n\n#Specify the index of the layer to compute the importance scores of.\n#In the example below, we find scores for the input layer, which is idx 0 in deeplift_model.get_layers()\nfind_scores_layer_idx = 0\n\n#Compile the function that computes the contribution scores\n#For sigmoid or softmax outputs, target_layer_idx should be -2 (the default). This computes explanations\n# w.r.t. the logits. (See \"3.6 Choice of target layer\" in https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.02685 for justification)\n#For regression tasks with a linear output, target_layer_idx should be -1 (which simply refers to the last layer)\n#Note that in the case of softmax outputs, it may be a good idea to normalize the softmax logits so\n# that they sum to zero across all tasks. This ensures that if a feature is contributing equally to\n# to all the softmax logits, it will effectly be seen as contributing to none of the tasks (adding\n# a constant to all logits of a softmax does not change the output). This is discussed in\n# https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F116. One way to efficiently acheive this\n# normalization is to mean-normalize the weights going into the Softmax layer as\n# discussed in eqn. 21 in Section 2.5 of https:\u002F\u002Farxiv.org\u002Fpdf\u002F1605.01713.pdf (\"A note on Softmax Activation\")\n#If you want the DeepLIFT multipliers instead of the contribution scores, you can use get_target_multipliers_func\ndeeplift_contribs_func = deeplift_model.get_target_contribs_func(\n                            find_scores_layer_idx=find_scores_layer_idx,\n                            target_layer_idx=-1)\n#You can also provide an array of indices to find_scores_layer_idx to get scores for multiple layers at once\n\n#compute scores on inputs\n#input_data_list is a list containing the data for different input layers\n#eg: for MNIST, there is one input layer with with dimensions 1 x 28 x 28\n#In the example below, let X be an array with dimension n x 1 x 28 x 28 where n is the number of examples\n#task_idx represents the index of the node in the output layer that we wish to compute scores.\n#Eg: if the output is a 10-way softmax, and task_idx is 0, we will compute scores for the first softmax class\nscores = np.array(deeplift_contribs_func(task_idx=0,\n                                         input_data_list=[X],\n                                         batch_size=10,\n                                         progress_update=1000))\n```\n\nThis will work for sequential models involving dense and\u002For conv1d\u002Fconv2d layers and linear\u002Frelu\u002Fsigmoid\u002Fsoftmax or prelu activations. Please create a github issue or email avanti [dot] shrikumar@gmail.com readme if you are interested in support for other layer types.\n\nThe syntax for using functional models is similar; you can use `deeplift_model.get_name_to_layer().keys()` to get a list of layer names when figuring out how to specify `find_scores_layer_name` and `pre_activation_target_layer_name`:\n\n```python\ndeeplift_model =\\\n    kc.convert_model_from_saved_files(\n        saved_hdf5_file_path,\n        nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault) \n#The syntax below for obtaining scores is similar to that of a converted graph model\n#See deeplift_model.get_name_to_layer().keys() to see all the layer names\n#As before, you can provide an array of names to find_scores_layer_name\n#to get the scores for multiple layers at once\ndeeplift_contribs_func = deeplift_model.get_target_contribs_func(\n    find_scores_layer_name=\"name_of_input_layer\",\n    pre_activation_target_layer_name=\"name_goes_here\")\n```\n\n## Examples\nA notebook replicating the results in the paper on MNIST is at `examples\u002Fmnist\u002FMNIST_replicate_figures.ipynb`, and a notebook demonstrating use on a genomics model with 1d convolutions is at `examples\u002Fgenomics\u002Fgenomics_simulation.ipynb`.\n\n## FAQ\n\n#### Can you provide a brief intuition for how DeepLIFT works?\nThe 15-minute talk from ICML gives an intuition for the method. Here are links to the [slides](https:\u002F\u002Fdocs.google.com\u002Ffile\u002Fd\u002F0B15F_QN41VQXSXRFMzgtS01UOU0\u002Fedit?usp=docslist_api&filetype=mspresentation) and the [video](https:\u002F\u002Fvimeo.com\u002F238275076) (the video truncates the slides, which is why the slides are linked separately). Please file a github issue if you have questions.\n\n#### My model architecture is not supported by this DeepLIFT implementation. What should I do?\nMy first suggestion would be to look at [DeepSHAP\u002FDeepExplainer (Lundberg & Lee)](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Ftree\u002Fmaster\u002Fshap\u002Fexplainers\u002Fdeep), [DeepExplain (Ancona et al.)](https:\u002F\u002Fgithub.com\u002Fmarcoancona\u002FDeepExplain) or [Captum](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fcaptum) (if you are using pytorch) to see if any of them satisfy your needs. They are implemented by overriding gradient operators and thus support a wider variety of architectures. However, none of these implementations support the RevealCancel rule (which deals with failure modes such as the min function). The pros and cons of DeepSHAP vs DeepExplain are discussed in more detail below. If you would really like to have the RevealCancel rule, go ahead and post a github issue, although my energies are currently focused on other projects and I may not be able to get to it for some time.\n\nNote for people in genomics planning to use TF-MoDISco: for DeepSHAP, I have a custom branch of the DeepSHAP repository that has functionality for computing hypothetical importance scores. A colab notebook demonstrating the use of that repository is [here](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002FAvantiShri\u002Fshap\u002Fblob\u002F5fdad0651176cdbf1acd6c697604a71529695211\u002Fnotebooks\u002Fdeep_explainer\u002FTensorflow%20DeepExplainer%20Genomics%20Example%20With%20Hypothetical%20Importance%20Scores.ipynb), and a tutorial I made on DeepSHAP for genomics is [here](https:\u002F\u002Fdocs.google.com\u002Fpresentation\u002Fd\u002F1JCLMTW7ppA3Oaz9YA2ldDgx8ItW9XHASXM1B3regxPw\u002Fedit?usp=sharing).\n\n#### What are the similarities and differences between the DeepLIFT-like implementations in [DeepExplain from Ancona et al. (ICLR 2018)](https:\u002F\u002Fgithub.com\u002Fmarcoancona\u002FDeepExplain) and [DeepSHAP\u002FDeepExplainer from the SHAP repository](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap)?\nBoth DeepExplain (Ancona et al.) and DeepSHAP\u002FDeepExplainer work by overriding gradient operators, and can thus support a wider variety of architectures than those that are covered in the DeepLIFT repo (in fact, the DeepSHAP\u002FDeepExplainer implementation was inspired by Ancona et al.'s work and builds on a connection between DeepLIFT and SHAP, described in the [SHAP paper](https:\u002F\u002Fpapers.nips.cc\u002Fpaper\u002F7062-a-unified-approach-to-interpreting-model-predictions)). For the set of architectures described in the DeepLIFT paper, i.e. linear matrix multiplications, convolutions, and single-input nonlinearities (like ReLUs), both these implementations are identical to DeepLIFT with the Rescale rule. However, neither implementation supports DeepLIFT with the RevealCancel rule (a rule that was developed to deal with failure cases such as the min function, and which unfortunately is not easily implemented by overriding gradient operators). The key differences are as follows:\n\n(1) DeepExplain uses standard gradient backpropagation for elementwise operations (such as those present in LSTMs\u002FGRUs\u002FAttention). This will likely violate the summation-to-delta property (i.e. the property that the sum of the attributions over the input is equal to the difference-from-reference of the output). If you have elementwise operations, I recommend you use DeepSHAP\u002FDeepExplainer, which employs a summation-to-delta-preserving backprop rule. The same is technically true for Maxpooling operations when a non-uniform reference is used (though this has not been a salient problem for us in practice); the DeepSHAP\u002FDeepExplainer implementation guarantees summation-to-delta is satisfied for Maxpooling by assigning credit\u002Fblame to either the neuron that is the max in the actual input or the neuron that was the max in the reference (this is different from the 'Max' attribution rule proposed in the SHAP paper; that attribution rule does not scale well).\n\n(2) DeepExplain (by Ancona et al.) does not support the dynamic reference that is demonstrated in the DeepLIFT repo (i.e. the case where a different reference is generated according to the properties of the input example, such as the 'dinucleotide shuffled' references used in genomics). [I've implemented the dynamic reference feature for DeepSHAP\u002FDeepExplainer (click for a link to the PR)](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Fpull\u002F322). Also, if you are planning to use DeepSHAP for genomics with TF-MoDISco, please see the note above on my custom implementation of DeepSHAP for computing hypothetical importance scores + a link to the slides for a tutorial.\n\n(3) DeepSHAP\u002FDeepExplainer is implemented such that multiple references can be used for a single example, and the final attributions are averaged over each reference. However, the way this is implemented, each GPU batch calculates attributions for [a single example, for all references](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Fblob\u002F98bf721cc063222feb2456504d20396eeba6a6aa\u002Fshap\u002Fexplainers\u002Fdeep\u002Fdeep_tf.py#L257-L262). This means that the DeepSHAP\u002FDeepExplainer implementation might be slow in cases where you have a large number of samples and only one reference. By contrast, DeepExplain (Ancona et al.) is structured such that the user provides a single reference, and this reference is used for all the examples. Thus, DeepExplain (Ancona et al.) allows GPU batching across examples, but does not allow for GPU batching across different references.\n\nIn summary, my recommendations are: use DeepSHAP if you have elementwise operations (e.g. GRUs\u002FLSTMs\u002FAttention), a need for dynamic references, or a large number of references compared to samples. Use DeepExplain when you have a large number of samples compared to references.\n\n#### How does the implementation in this repository compare with the DeepLIFT implementation in [Poerner et al. (ACL 2018)](http:\u002F\u002Fwww.aclweb.org\u002Fanthology\u002FP18-1032)?\nPoerner et al. conducted a series of benchmarks comparing DeepLIFT to other explanation methods on NLP tasks. Their implementation differs from the canonical DeepLIFT implementation in two main ways. First, they considered only the Rescale rule of DeepLIFT (according to the implementation [here](https:\u002F\u002Fgithub.com\u002FNPoe\u002Fneural-nlp-explanation-experiment\u002Fblob\u002Fmaster\u002FHybridDocuments\u002FThirdParty\u002FLRP_and_DeepLIFT\u002Fcode\u002Flayers.py)). Second, to handle operations that involve multiplications with gating units (which DeepLIFT was not designed for), they treat the gating neuron as a weight (similar to the approach in [Arras et al.](https:\u002F\u002Fgithub.com\u002FArrasL\u002FLRP_for_LSTM)) and assign all importance to the non-gating neuron. Note that this differs from the implementation in [DeepSHAP\u002FDeepExplainer](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Ftree\u002Fmaster\u002Fshap\u002Fexplainers\u002Fdeep), which handles elementwise multiplications using a backprop rule base on SHAP and would assign importance to the gating neuron. We have not studied the appropriateness of Arras et al.'s approach, but the authors did find that \"LIMSSE, LRP (Bach et al., 2015) and DeepLIFT (Shrikumar et al., 2017) are the most effective explanation methods (§4): LRP and DeepLIFT are the most consistent methods, while LIMSSE wins the hybrid document experiment.\" (They did not compare with the DeepSHAP\u002FDeepExplainer implementation)\n\n#### How does DeepLIFT compare to integrated gradients?\n\nAs illustrated in the DeepLIFT paper, the RevealCancel rule of DeepLIFT can allow DeepLIFT to properly handle cases where integrated gradients may give misleading results. [Independent researchers](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1711.06104.pdf) have found that DeepLIFT with just the Rescale rule performs comparably to Integrated Gradients (they write: “Integrated Gradients and DeepLIFT have very high correlation, suggesting that the latter is a good (and faster) approximation of the former in practice”). Their finding was consistent with our own personal experience. The speed improvement of DeepLIFT relative to Integrated Gradients becomes particularly useful when using a collection of references (since having a collection of references per example increases runtime).\n\n#### Do you have support for non-keras models?\nAt the moment, we do not. However, if you are able to convert your model into the saved file format used by the Keras 2 API, then you can use this branch to load it into the DeepLIFT format. For inspiration on how to achieve this, you can look at `examples\u002Fconvert_models\u002Fkeras1.2to2` for a notebook demonstrating how to convert models saved in the keras1.2 format to keras 2. DeepLIFT conversion works directly from keras saved files without ever actually loading the models into keras. If you have a pytorch model, you may also be interested in the [Captum implementation](#my-model-architecture-is-not-supported-by-this-deeplift-implementation-what-should-i-do).\n\n#### What do negative scores mean?\nA negative contribution score on an input means that the input contributed to moving the output below its reference value, where the reference value of the output is the value that it has when provided the reference input. A negative contribution does not mean that the input is \"unimportant\". If you want to find inputs that DeepLIFT considers \"unimportant\" (i.e. DeepLIFT thinks they don't influence the output of the model much), these would be the inputs that have contribution scores near 0.\n\n#### How do I provide a reference argument?\n\nJust as you supply `input_data_list` as an argument to the scoring function, you can also supply `input_references_list`. It would have the same dimensions as `input_data_list`, but would contain reference images for each input.\n\n#### What should I use as my reference?\n\nThe choice of reference depends on the question you wish to ask of the data. Generally speaking, the reference should retain the properties you don't care about and scramble the properties you do care about. In the [supplement of the DeepLIFT paper](http:\u002F\u002Fproceedings.mlr.press\u002Fv70\u002Fshrikumar17a\u002Fshrikumar17a-supp.pdf), Appendix L looks at the results on a CIFAR10 model with two different choices of the reference. You'll notice that when a blurred version of the input is used as a reference, the outlines of objects stand out. When a black reference is used, the results are more confusing, possibly because the net is also highlighting color. If you have a particular reference in mind, it is a good idea to check that the output of the model on that reference is consistent with what you expect. Another idea to consider is using multiple different references to interpret a single image and averaging the results over all the different references. We use this approach in genomics; we generate a collection of references per input sequence by shuffling the sequence (this is demonstrated in the genomics example notebook).\n\n#### How can I get a sense of how much an input contributes across all examples?\n\nIt is fine to average the DeepLIFT contribution scores across examples. Be aware that there might be considerable heterogeneity in your data (i.e. some inputs may be very important for some subset of examples but not others, some inputs may contribute positively on some examples and negatively on others) so clustering may prove more insightful than averaging. For the purpose of feature selection, a reasonable heuristic would be to rank inputs in descending order of the average magnitude of the DeepLIFT contribution scores.\n\n#### Can I have multiple input modes?\n\nYes. Rather than providing a single numpy array to input_data_list, provide a list of numpy arrays containing the input to each mode. You can also provide a dictionary to input_data_list where the key is the mode name and the value is the numpy array. Each numpy array should have the first axis be the sample axis.\n\n#### Can I get the contribution scores on multiple input layers at once?\n\nAlso yes. Just provide a list to `find_scores_layer_name` rather than a single argument.\n\n#### What's the license?\nMIT License. While we had originally filed a patent on some of our interpretability work, we have since disbanded the patent as it appears this project has enough interest from the community to be best distributed in open-source format.\n\n#### I have heard DeepLIFT can do pattern discovery - is that right?\nYou are likely thinking of TF-MoDISco. [Here](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Ftfmodisco) is a link to that code.\n\n## Contact\nPlease email avanti [dot] shrikumar [at] gmail.com with questions, ideas, feature requests, etc. If I don't respond, keep emailing me until I feel guilty and respond. Also feel free to email my adviser (anshul [at] kundaje [dot] net), who can further guilt me into responding. I promise I do actually want to respond; I'm just busy with other things because the incentive structure of academia doesn't reward maintenance of projects.\n\n## Under the hood\nThis section explains finer aspects of the deeplift implementation\n\n### Layers\nThe layer (`deeplift.layers.core.Layer`) is the basic unit. `deeplift.layers.core.Dense` and `deeplift.layers.convolution.Conv2D` are both examples of layers.\n\nLayers implement the following key methods:\n#### get_activation_vars()\nReturns symbolic variables representing the activations of the layer. For an understanding of symbolic variables, refer to the documentation of symbolic computation packages like theano or tensorflow.\n\n#### get_pos_mxts() and get_neg_mxts()\nReturns symbolic variables representing the positive\u002Fnegative multipliers on this layer (for the selected output). See paper for details.\n\n#### get_target_contrib_vars()\nReturns symbolic variables representing the importance scores. This is a convenience function that returns `self.get_pos_mxts()*self._pos_contribs() + self.get_neg_mxts()*self._neg_contribs()`. See paper for details.\n\n### The Forward Pass\nHere are the steps necessary to implement a forward pass. If executed correctly, the results should be identical (within numerical precision) to a forward pass of your original model, so this is definitely worth doing as a sanity check. Note that if autoconversion (as described in the quickstart) is an option, you can skip steps (1) and (2).\n\n1. Create a layer object for every layer in the network\n2. Tell each layer what its inputs are via the `set_inputs` function. The argument to `set_inputs` depends on what the layer expects\n  - If the layer has a single layer as its input (eg: Dense layers), then the argument is simply the layer that is the input\n  - If the layer takes multiple layers as its input, the argument depends on the specific implementation - for example, in the case of a Concat layer, the argument is a list of layers \n3. Once every layer is linked to its inputs, you may compile the forward propagation function with `deeplift.backend.function([input_layer.get_activation_vars()...], output_layer.get_activation_vars())`\n  - If you are working with a model produced by autoconversion, you can access individual layers via `model.get_layers()` for sequential models (where this function would return a list of layers) or `model.get_name_to_layer()` for Graph models (where this function would return a dictionary mapping layer names to layers) \n  - The first argument is a list of symbolic tensors representing the inputs to the net. If the net has only one input layer, then this will be a list containing only one tensor\n  - The second argument is the output of the function. In the example above, it is a single tensor, but it can also be a list of tensors if you want the outputs of more than one layer\n4. Once the function is compiled, you can use `deeplift.util.run_function_in_batches(func, input_data_list)` to run the function in batches (which would be advisable if you want to call the function on a large number of inputs that wont fit in memory)\n  - `func` is simply the compiled function returned by `deeplift.backend.function`\n  - `input_data_list` is a list of numpy arrays containing data for the different input layers of the network. In the case of a network with one input, this will be a list containing one numpy array\n  - Optional arguments to `run_function_in_batches` are `batch_size` and `progress_update`\n\n### The Backward Pass\nHere are the steps necessary to implement the backward pass, which is where the importance scores are calculated. Ideally, you should create a model through autoconversion (described in the quickstart) and then use `model.get_target_contribs_func` or `model.get_target_multipliers_func`. Howver, if that is not an option, read on (please also consider sending us a message to let us know, as if there is enough demand for a feature we will consider adding it). Note the instructions below assume you have done steps (1) and (2) under the forward pass section.\n\n1. For the layer(s) that you wish to compute the importance scores for, call `reset_mxts_updated()`. This resets the symbolic variables for computing the multipliers. If this is the first time you are compiling the backward pass, this step is not strictly necessary.\n2. For the output layer(s) containing the neuron(s) that the importance scores will be calculated with respect to, call `set_scoring_mode(deeplift.layers.ScoringMode.OneAndZeros)`.\n    - Briefly, this is the scoring mode that is used when we want to find scores with respect to a single target neuron. Other kinds of scoring modes may be added later (eg: differences between neurons).\n    - A point of clarification: when we eventually compile the function, it will be a function which computes scores for only a single output neuron in a single layer every time it is called. The specific neuron and layer can be toggled later, at runtime. Right now, at this step, you should call `set_scoring_mode` on all the target layers that you might conceivably want to find the scores with respect to. This will save you from having to recompile the function to allow a different target layer later.\n    - For Sigmoid\u002FSoftmax output layers, the output layer that you use should be the linear layer (usually a Dense layer) that comes before the final nonlinear activation. See \"3.6 Choice of target layer\" in the paper for justification. If there is no final nonlinearity (eg: in the case of many regression tasks), then the output layer should just be the last linear layer. \n    - For Softmax outputs, you should may want to subtract the average contribution to all softmax classes as described in \"Adjustments for softmax layers\" in the paper (section 3.6). If your number of softmax classes is very large and you don't want to calculate contributions to each class separately for each example, contact me (avanti [dot] shrikumar@gmail.com) and I can implement a more efficient way to do the calculation (there is a way but I haven't coded it up yet).\n3. For the layer(s) that you wish to compute the importance scores for, call `update_mxts()`. This will create the symbolic variables that compute the multipliers with respect to the layer specified in step 2.\n4. Compile the importance score computation function with\n\n    ```python\n    deeplift.backend.function([input_layer.get_activation_vars()...,\n                               input_layer.get_reference_vars()...],\n                              layer_to_find_scores_for.get_target_contrib_vars())\n    ```\n    - The first argument represents the inputs to the function and should be a list of one symbolic tensor for the activations of each input layer (as for the forward pass), followed by a list of one symbolic tensor for the references of each input layer\n    - The second argument represents the output of the function. In the example above, it is a single tensor containing the importance scores of a single layer, but it can also be a list of tensors if you wish to compute the scores for multiple layers at once.\n    - Instead of `get_target_contrib_vars()` which returns the importance scores (in the case of `NonlinearMxtsMode.DeepLIFT`, these are called \"contribution scores\"), you can use `get_pos_mxts()` or `get_neg_mxts()` to get the multipliers.\n5. Now you are ready to call the function to find the importance scores.\n    - Select a specific output layer to compute importance scores with respect to by calling `set_active()` on the layer.\n    - Select a specific target neuron within the layer by calling `update_task_index(task_idx)` on the layer. Here `task_idx` is the index of a neuron within the layer.\n    - Call the function compiled in step 4 to find the importance scores for the target neuron. Refer to step 4 in the forward pass section for tips on using `deeplift.util.run_function_in_batches` to do this.\n    - Deselect the output layer by calling `set_inactive()` on the layer. Don't forget this!\n    - (Yes, I will bundle all of these into a single function at some point)\n\n","DeepLIFT：深度学习重要特征\n===\n[![构建状态](https:\u002F\u002Fapi.travis-ci.org\u002Fkundajelab\u002Fdeeplift.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Fkundajelab\u002Fdeeplift)\n[![许可证](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmashape\u002Fapistatus.svg?maxAge=2592000)](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FLICENSE)\n\n**此版本的DeepLIFT已使用Keras 2.2.4和TensorFlow 1.14.0进行测试**。有关其他可能适用于不同版本的TensorFlow\u002FPyTorch以及更广泛架构的DeepLIFT实现，请参阅[此常见问题解答](#my-model-architecture-is-not-supported-by-this-deeplift-implementation-what-should-i-do)。旧版本请查看标签。\n\n本仓库实现了Shrikumar、Greenside和Kundaje在《通过传播激活差异学习重要特征》（arXiv:1704.02685）中提出的方法，以及其他常用方法，如梯度、梯度乘以输入（等价于ReLU网络的逐层相关性传播的一种形式）、[引导反向传播](https:\u002F\u002Farxiv.org\u002Fabs\u002F1412.6806)和[积分梯度](https:\u002F\u002Farxiv.org\u002Fabs\u002F1611.02639)。\n\n以下是ICML会议上15分钟演讲的[幻灯片](https:\u002F\u002Fdocs.google.com\u002Ffile\u002Fd\u002F0B15F_QN41VQXSXRFMzgtS01UOU0\u002Fedit?usp=docslist_api&filetype=mspresentation)和[视频](https:\u002F\u002Fvimeo.com\u002F238275076)链接。[这里](https:\u002F\u002Fwww.youtube.com\u002Fplaylist?list=PLJLjQOkqSRTP3cLB2cOOi_bQFw6KPGKML)是更长系列视频教程的链接。如有疑问，请参阅[常见问题解答](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FREADME.md#faq)，并提交GitHub问题。\n\n注意：在运行DeepLIFT处理某些计算机视觉任务时，**如果您计算的是较高卷积层的贡献分数，而不是输入像素的贡献分数，可能会获得更好的结果**。请使用参数`find_scores_layer_idx`来指定要计算分数的层。\n\n**请注意，确定最佳参考仍然是一个开放问题。欢迎提供针对不同应用的良好启发式方法建议。** 同时，您可以查看此GitHub问题以获取一般性思路：https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F104\n\n请随时关注本仓库，以了解最新更新。\n\n## 目录\n\n  * [安装](#installation)\n  * [快速入门](#quickstart)\n  * [示例](#examples)\n  * [常见问题解答](#faq)\n    * [能否简要解释一下DeepLIFT的工作原理？](#can-you-provide-a-brief-intuition-for-how-deeplift-works)\n    * [我的模型架构不被此DeepLIFT实现支持。我该怎么办？](#my-model-architecture-is-not-supported-by-this-deeplift-implementation-what-should-i-do)\n    * [Ancona等人在ICLR 2018提出的DeepExplain中的DeepLIFT类似实现与SHAP库中的DeepSHAP\u002FDeepExplainer之间有哪些异同？](#what-are-the-similarities-and-differences-between-the-deeplift-like-implementations-in-deepexplain-from-ancona-et-al-iclr-2018-and-deepshapdeepexplainer-from-the-shap-repository)\n    * [DeepLIFT与积分梯度相比如何？](#how-does-deeplift-compare-to-integrated-gradients)\n    * [本仓库中的实现与Poerner等人在ACL 2018中提出的DeepLIFT实现有何不同？](#how-does-the-implementation-in-this-repository-compare-with-the-deeplift-implementation-in-poerner-et-al-acl-2018)\n    * [您是否支持非Keras模型？](#do-you-have-support-for-non-keras-models)\n    * [负分意味着什么？](#what-do-negative-scores-mean)\n    * [如何提供参考参数？](#how-do-i-provide-a-reference-argument)\n    * [我应该使用什么作为参考？](#what-should-i-use-as-my-reference)\n    * [如何了解某个输入在整个数据集中的总体贡献程度？](#how-can-i-get-a-sense-of-how-much-an-input-contributes-across-all-examples)\n    * [我可以有多个输入模式吗？](#can-i-have-multiple-input-modes)\n    * [我可以同时获取多个输入层的贡献分数吗？](#can-i-get-the-contribution-scores-on-multiple-input-layers-at-once)\n    * [许可证是什么？](#whats-the-license)\n    * [我听说DeepLIFT可以进行模式发现——这是真的吗？](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fblob\u002Fmaster\u002FREADME.md#i-have-heard-deeplift-can-do-pattern-discovery---is-that-right)\n  * [联系方式](#contact)\n  * [内部机制](#under-the-hood)\n    * [层](#layers)\n    * [前向传播](#the-forward-pass)\n    * [反向传播](#the-backward-pass)\n\n## 安装\n\nDeepLIFT已在PyPI上发布，因此可以使用pip进行安装：\n```unix\npip install deeplift\n```\n\n如果您希望对代码进行修改，建议克隆仓库并使用`--editable`标志进行安装。\n```unix\ngit clone https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift.git #克隆deeplift仓库\npip install --editable deeplift\u002F #从克隆的仓库中安装deeplift。“editable”标志表示对代码的更改会自动生效。\n```\n\n虽然DeepLIFT不要求您的模型必须使用特定的深度学习框架训练，但我们提供了自动转换函数，可将使用Keras训练的模型转换为DeepLIFT格式。如果您使用了其他框架训练模型，仍可通过使用DeepLIFT层重新构建模型来使用DeepLIFT。\n\n此版本的DeepLIFT已在TensorFlow 1.7上进行了测试，自动转换功能则使用Keras 2.0进行了测试。\n\n## 快速入门\n\n这些示例展示了如何自动转换 Keras 模型并获取重要性得分。如果非 Keras 模型以 Keras 2.0 格式保存，也可以将其转换为 DeepLIFT 格式。\n\n```python\n# 转换一个 Keras 顺序模型\nimport deeplift\nfrom deeplift.conversion import kerasapi_conversion as kc\n# NonlinearMxtsMode 定义了计算重要性得分的方法。\n# NonlinearMxtsMode.DeepLIFT_GenomicsDefault 在 Dense 层使用 RevealCancel 规则，\n# 在卷积层使用 Rescale 规则（具体原因请参阅论文）。\n# 其他支持的值包括：\n# NonlinearMxtsMode.RevealCancel - 所有层都使用 DeepLIFT-RevealCancel（用于 MNIST 示例）\n# NonlinearMxtsMode.Rescale - 所有层都使用 DeepLIFT-rescale\n# NonlinearMxtsMode.Gradient - “乘数”将与梯度相同\n# NonlinearMxtsMode.GuidedBackprop - “乘数”将是引导反向传播的结果\n# 使用 deeplift.util.get_integrated_gradients_function 计算积分梯度\n# 如有任何疑问，请随时发送邮件至 avanti [dot] shrikumar@gmail.com\ndeeplift_model =\\\n    kc.convert_model_from_saved_files(\n        saved_hdf5_file_path,\n        nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault) \n\n# 指定要计算重要性得分的层的索引。\n# 在下面的示例中，我们为输入层计算得分，该层在 deeplift_model.get_layers() 中的索引为 0。\nfind_scores_layer_idx = 0\n\n# 编译计算贡献得分的函数\n# 对于 sigmoid 或 softmax 输出，target_layer_idx 应设置为 -2（默认值）。这会计算关于 logits 的解释。（理由请参阅 https:\u002F\u002Farxiv.org\u002Fabs\u002F1704.02685 中的“3.6 目标层的选择”）\n# 对于具有线性输出的回归任务，target_layer_idx 应设置为 -1（即最后一层）。\n# 注意，在 softmax 输出的情况下，最好对 softmax logits 进行归一化，使其在所有任务上之和为零。这样可以确保如果某个特征对所有 softmax logits 的贡献相等，它实际上不会对任何任务产生影响（向 softmax 的所有 logits 加上一个常数并不会改变输出）。这一点在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F116 中有所讨论。一种高效实现这种归一化的办法是按照 https:\u002F\u002Farxiv.org\u002Fpdf\u002F1605.01713.pdf (“关于 Softmax 激活的一点说明”) 第 2.5 节公式 21 的方法，对进入 Softmax 层的权重进行均值归一化。\n# 如果您想要的是 DeepLIFT 乘数而不是贡献得分，可以使用 get_target_multipliers_func。\ndeeplift_contribs_func = deeplift_model.get_target_contribs_func(\n                            find_scores_layer_idx=find_scores_layer_idx,\n                            target_layer_idx=-1)\n# 您还可以为 find_scores_layer_idx 提供一个索引数组，以便一次性获取多个层的得分。\n\n# 在输入数据上计算得分\n# input_data_list 是一个包含不同输入层数据的列表。\n# 例如：对于 MNIST，只有一个输入层，其维度为 1 x 28 x 28。\n# 在下面的示例中，假设 X 是一个维度为 n x 1 x 28 x 28 的数组，其中 n 是样本数量。\n# task_idx 表示我们希望计算得分的输出层节点的索引。\n# 例如：如果输出是一个 10 类的 softmax，且 task_idx 为 0，则我们将计算第一个 softmax 类别的得分。\nscores = np.array(deeplift_contribs_func(task_idx=0,\n                                         input_data_list=[X],\n                                         batch_size=10,\n                                         progress_update=1000))\n```\n\n此方法适用于包含密集层和\u002F或 conv1d\u002Fconv2d 层以及线性\u002FReLU\u002Fsigmoid\u002Fsoftmax 或 prelu 激活函数的顺序模型。如果您希望支持其他类型的层，请创建一个 GitHub 问题或发送电子邮件至 avanti [dot] shrikumar@gmail.com 阅读自述文件。\n\n使用函数式模型的语法类似；您可以使用 `deeplift_model.get_name_to_layer().keys()` 来获取层名称列表，从而确定如何指定 `find_scores_layer_name` 和 `pre_activation_target_layer_name`：\n\n```python\ndeeplift_model =\\\n    kc.convert_model_from_saved_files(\n        saved_hdf5_file_path,\n        nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault) \n# 下面获取得分的语法与转换后的图模型类似。\n# 请查看 deeplift_model.get_name_to_layer().keys() 以了解所有层名。\n# 同样，您可以为 find_scores_layer_name 提供一个名称数组，\n# 以同时获取多个层的得分。\ndeeplift_contribs_func = deeplift_model.get_target_contribs_func(\n    find_scores_layer_name=\"name_of_input_layer\",\n    pre_activation_target_layer_name=\"name_goes_here\")\n```\n\n## 示例\n复现论文中 MNIST 结果的笔记本位于 `examples\u002Fmnist\u002FMNIST_replicate_figures.ipynb`，而演示如何在具有 1D 卷积的基因组学模型上使用的笔记本位于 `examples\u002Fgenomics\u002Fgenomics_simulation.ipynb`。\n\n## 常见问题解答\n\n#### 您能否简要介绍一下 DeepLIFT 的工作原理？\nICML 上的 15 分钟演讲提供了该方法的直观理解。以下是[幻灯片](https:\u002F\u002Fdocs.google.com\u002Ffile\u002Fd\u002F0B15F_QN41VQXSXRFMzgtS01UOU0\u002Fedit?usp=docslist_api&filetype=mspresentation)和[视频](https:\u002F\u002Fvimeo.com\u002F238275076)的链接（视频截取了部分幻灯片，因此幻灯片单独列出）。如有疑问，请提交 GitHub 问题。\n\n#### 我的模型架构不受此 DeepLIFT 实现的支持。我该怎么办？\n我的第一个建议是查看 [DeepSHAP\u002FDeepExplainer (Lundberg & Lee)](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Ftree\u002Fmaster\u002Fshap\u002Fexplainers\u002Fdeep)、[DeepExplain (Ancona 等人)](https:\u002F\u002Fgithub.com\u002Fmarcoancona\u002FDeepExplain) 或 [Captum](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fcaptum)（如果您使用 PyTorch），看看它们是否能满足您的需求。这些工具通过重写梯度运算符来实现，因此支持更广泛的架构。然而，这些实现都不支持 RevealCancel 规则（该规则处理诸如 min 函数之类的失败模式）。DeepSHAP 与 DeepExplain 的优缺点将在下文进一步讨论。如果您确实需要 RevealCancel 规则，请提交一个 GitHub 问题，尽管我目前的精力主要集中在其他项目上，可能暂时无法处理此事。\n\n关于计划使用TF-MoDISco进行基因组学研究的人员请注意：对于DeepSHAP，我维护了一个自定义分支，其中包含了计算假设重要性得分的功能。演示该仓库使用的Colab笔记本位于[这里](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002FAvantiShri\u002Fshap\u002Fblob\u002F5fdad0651176cdbf1acd6c697604a71529695211\u002Fnotebooks\u002Fdeep_explainer\u002FTensorflow%20DeepExplainer%20Genomics%20Example%20With%20Hypothetical%20Importance%20Scores.ipynb)，而我为基因组学编写的DeepSHAP教程则在此[链接](https:\u002F\u002Fdocs.google.com\u002Fpresentation\u002Fd\u002F1JCLMTW7ppA3Oaz9YA2ldDgx8ItW9XHASXM1B3regxPw\u002Fedit?usp=sharing)。\n\n#### Ancona等人在ICLR 2018提出的DeepExplain与SHAP仓库中的DeepSHAP\u002FDeepExplainer，在类似DeepLIFT的实现上有哪些异同？\nDeepExplain（Ancona等）和DeepSHAP\u002FDeepExplainer都通过重写梯度算子来工作，因此能够支持比DeepLIFT仓库涵盖的更广泛架构。事实上，DeepSHAP\u002FDeepExplainer的实现正是受到Ancona等工作的启发，并基于DeepLIFT与SHAP之间的联系——这一联系在SHAP论文中有所描述。对于DeepLIFT论文中提到的一系列架构，即线性矩阵乘法、卷积以及单输入非线性操作（如ReLU），这两种实现与采用Rescale规则的DeepLIFT完全一致。然而，两者都不支持采用RevealCancel规则的DeepLIFT（该规则旨在处理诸如min函数之类的特殊情况，但不幸的是，很难通过重写梯度算子来实现）。其关键区别如下：\n\n(1) DeepExplain对逐元素操作（例如LSTM\u002FGRU\u002F注意力机制中常见的操作）使用标准的梯度反向传播。这可能会破坏“求和等于输出变化量”的属性（即输入特征的重要性之和应等于模型输出相对于参考值的变化量）。如果你的数据包含逐元素操作，建议使用DeepSHAP\u002FDeepExplainer，因为它采用了能保持这一属性的反向传播规则。同样地，当使用非均匀参考时，MaxPooling操作也会面临类似问题（尽管我们在实践中并未遇到显著问题）。DeepSHAP\u002FDeepExplainer通过将信用或责任分配给实际输入中最大值所在的神经元，或者分配给参考值中最大值所在的神经元，从而确保MaxPooling操作满足“求和等于输出变化量”的要求。这与SHAP论文中提出的“Max”归因规则不同；后者在大规模应用时表现不佳。\n\n(2) DeepExplain（Ancona等）不支持DeepLIFT仓库中展示的动态参考机制（即根据输入样本特性生成不同参考的情况，例如基因组学中常用的“二核苷酸随机化”参考）。我已经为DeepSHAP\u002FDeepExplainer实现了动态参考功能（点击[此处查看PR链接](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Fpull\u002F322)）。此外，如果你计划将DeepSHAP与TF-MoDISco结合用于基因组学研究，请参阅上述关于我自定义DeepSHAP实现的说明，该实现可用于计算假设重要性得分，并附有教程幻灯片的链接。\n\n(3) DeepSHAP\u002FDeepExplainer的设计允许为单个样本使用多个参考，并对每个参考的重要性得分取平均。然而，目前的实现方式是：每个GPU批次仅针对一个样本计算所有参考的重要性得分（见[此处代码段](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Fblob\u002F98bf721cc063222feb2456504d20396eeba6a6aa\u002Fshap\u002Fexplainers\u002Fdeep\u002Fdeep_tf.py#L257-L262)）。这意味着，当样本数量较多而参考较少时，DeepSHAP\u002FDeepExplainer的运行速度可能会较慢。相比之下，DeepExplain（Ancona等）的设计则是用户只需提供一个参考，该参考会被应用于所有样本。因此，DeepExplain允许在不同样本之间进行GPU批处理，但无法在不同参考之间进行GPU批处理。\n\n综上所述，我的建议是：如果你的数据包含逐元素操作（如GRU\u002FLSTM\u002F注意力机制）、需要动态参考，或者参考数量远多于样本数量，则应选择DeepSHAP；而当样本数量远大于参考数量时，则可选用DeepExplain。\n\n#### 本仓库中的实现与Poerner等人在ACL 2018中提出的DeepLIFT实现相比如何？\nPoerner等人进行了一系列基准测试，比较了DeepLIFT与其他解释方法在自然语言处理任务上的表现。他们的实现与经典的DeepLIFT实现主要有两点不同。首先，他们只考虑了DeepLIFT的Rescale规则（具体实现见[此处](https:\u002F\u002Fgithub.com\u002FNPoe\u002Fneural-nlp-explanation-experiment\u002Fblob\u002Fmaster\u002FHybridDocuments\u002FThirdParty\u002FLRP_and_DeepLIFT\u002Fcode\u002Flayers.py)）。其次，为了处理涉及门控单元的乘法运算（这是DeepLIFT原本未设计应对的情形），他们将门控神经元视为权重（类似于Arras等人的做法），并将全部重要性归于非门控神经元。需要注意的是，这与[DeepSHAP\u002FDeepExplainer](https:\u002F\u002Fgithub.com\u002Fslundberg\u002Fshap\u002Ftree\u002Fmaster\u002Fshap\u002Fexplainers\u002Fdeep)的实现不同；后者采用基于SHAP的反向传播规则来处理逐元素乘法，并会将重要性分配给门控神经元。我们尚未深入研究Arras等人的方法是否合适，但作者们发现：“LIMSSE、LRP（Bach等人，2015年）和DeepLIFT（Shrikumar等人，2017年）是最有效的解释方法（第4节）；其中LRP和DeepLIFT最为稳定，而LIMSSE则在混合文档实验中胜出。”（他们并未将DeepSHAP\u002FDeepExplainer纳入比较）\n\n#### DeepLIFT与积分梯度相比如何？\n\n正如 DeepLIFT 论文中所展示的那样，DeepLIFT 的 RevealCancel 规则能够使 DeepLIFT 正确处理积分梯度可能给出误导性结果的情况。[独立研究人员](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1711.06104.pdf)发现，仅使用 Rescale 规则的 DeepLIFT 表现与积分梯度相当（他们写道：“积分梯度和 DeepLIFT 之间具有非常高的相关性，这表明后者在实践中是前者的良好（且更快）近似”）。他们的发现与我们自身的经验一致。当使用一组参考输入时，DeepLIFT 相对于积分梯度的速度优势尤为明显，因为每个样本都有一组参考输入会显著增加运行时间。\n\n#### 您是否支持非 Keras 模型？\n目前我们还不支持。不过，如果您能将模型转换为 Keras 2 API 使用的保存文件格式，那么您可以使用本分支将其加载到 DeepLIFT 格式中。有关如何实现这一点的灵感，可以查看 `examples\u002Fconvert_models\u002Fkeras1.2to2` 中的笔记本，它演示了如何将以 keras1.2 格式保存的模型转换为 Keras 2 格式。DeepLIFT 的转换可以直接从 Keras 保存的文件进行，而无需实际将模型加载到 Keras 中。如果您有一个 PyTorch 模型，您可能也会对 [Captum 实现](#我的模型架构不被此 DeepLIFT 实现支持，我该怎么做)感兴趣。\n\n#### 负分值意味着什么？\n输入的负贡献分数表示该输入促使输出低于其参考值，这里的参考值是指在提供参考输入时输出所具有的值。负贡献并不意味着该输入“不重要”。如果您想找出 DeepLIFT 认为“不重要”的输入（即 DeepLIFT 认为它们对模型输出影响不大），那么这些输入的贡献分数应该接近于零。\n\n#### 如何提供参考参数？\n\n就像您向评分函数提供 `input_data_list` 参数一样，您也可以提供 `input_references_list`。它的维度应与 `input_data_list` 相同，但其中包含每个输入对应的参考图像。\n\n#### 我应该使用什么作为参考？\n\n参考的选择取决于您希望从数据中解答的问题。一般来说，参考应保留您不关心的属性，并打乱您关心的属性。在 [DeepLIFT 论文的补充材料](http:\u002F\u002Fproceedings.mlr.press\u002Fv70\u002Fshrikumar17a\u002Fshrikumar17a-supp.pdf)中，附录 L 探讨了使用两种不同参考对 CIFAR10 模型的结果。您会注意到，当使用模糊版本的输入作为参考时，物体的轮廓会更加突出；而当使用黑色参考时，结果则显得更加混乱，这可能是由于网络也在强调颜色信息所致。如果您心中已有特定的参考，最好检查一下模型在该参考上的输出是否符合您的预期。另一个可以考虑的做法是使用多个不同的参考来解释同一张图片，并对所有参考的结果取平均值。我们在基因组学研究中就采用了这种方法：我们通过随机打乱输入序列来为每个序列生成一组参考（这在基因组学示例笔记本中有所演示）。\n\n#### 我如何了解某个输入在所有样本中的总体贡献程度？\n\n对各个样本的 DeepLIFT贡献分数求平均是可行的。需要注意的是，您的数据可能存在较大的异质性（即某些输入可能只对部分样本非常重要，而对其他样本则不然；有些输入可能在某些样本上产生正向贡献，而在另一些样本上则产生负向贡献），因此聚类分析可能会比简单求平均更有启发性。对于特征选择而言，一个合理的启发式方法是按照 DeepLIFT贡献分数的平均绝对值大小对输入进行降序排序。\n\n#### 我可以有多个输入模式吗？\n是的。您可以不再向 `input_data_list` 提供单个 NumPy 数组，而是提供一个包含各模式输入的 NumPy 数组列表。您也可以向 `input_data_list` 提供一个字典，其中键为模式名称，值为相应的 NumPy 数组。每个 NumPy 数组的第一个轴应为样本轴。\n\n#### 我能否同时获取多个输入层的贡献分数？\n也可以。只需向 `find_scores_layer_name` 提供一个列表，而不是单个参数。\n\n#### 该软件的许可证是什么？\nMIT 许可证。尽管我们最初曾为我们的一些可解释性工作申请过专利，但我们后来已放弃该专利，因为该项目似乎已经引起了社区的足够兴趣，以开源形式发布更为合适。\n\n#### 我听说 DeepLIFT 可以进行模式发现——这是真的吗？\n您可能指的是 TF-MoDISco。[这里](https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Ftfmodisco)是该代码的链接。\n\n\n\n## 联系方式\n如有任何问题、想法、功能请求等，请发送邮件至 avanti [dot] shrikumar [at] gmail.com。如果我没有回复，请继续给我发邮件，直到我感到不好意思并作出回应为止。您也可以随时联系我的导师（anshul [at] kundaje [dot] net），他可以帮助督促我尽快回复。我保证我确实愿意回复，只是目前忙于其他事务，因为学术界的激励机制并不鼓励维护项目。\n\n## 内部原理\n本节将解释 DeepLift 实现中的一些更细致的方面。\n\n### 层\n层（`deeplift.layers.core.Layer`）是基本单元。`deeplift.layers.core.Dense` 和 `deeplift.layers.convolution.Conv2D` 都是层的实例。\n\n层实现了以下关键方法：\n#### get_activation_vars()\n返回表示该层激活值的符号变量。关于符号变量的详细信息，请参阅 Theano 或 TensorFlow 等符号计算库的文档。\n\n#### get_pos_mxts() 和 get_neg_mxts()\n返回表示该层上正\u002F负乘数的符号变量（针对选定的输出）。详情请参阅论文。\n\n#### get_target_contrib_vars()\n返回表示重要性分数的符号变量。这是一个便捷函数，其结果为 `self.get_pos_mxts()*self._pos_contribs() + self.get_neg_mxts()*self._neg_contribs()`。详情请参阅论文。\n\n### 前向传播\n以下是实现前向传播所需的步骤。如果操作正确，结果应与原始模型的前向传播结果在数值精度范围内完全一致，因此务必将其作为一项合理性检查来执行。请注意，如果自动转换（如快速入门中所述）可用，则可以跳过步骤 (1) 和 (2)。\n\n1. 为网络中的每一层创建一个层对象。\n2. 通过 `set_inputs` 函数告知每层其输入。`set_inputs` 的参数取决于该层的期望：\n   - 如果该层只有一个输入层（例如全连接层），则参数就是该输入层。\n   - 如果该层有多个输入层，则参数取决于具体实现；例如，对于拼接层，参数是一个包含多个层的列表。\n3. 当所有层都与其输入连接后，即可使用 `deeplift.backend.function([input_layer.get_activation_vars()...], output_layer.get_activation_vars())` 编译前向传播函数。\n   - 如果您正在使用自动转换生成的模型，可以通过 `model.get_layers()` 访问顺序模型中的各个层（该函数将返回一个层列表），或通过 `model.get_name_to_layer()` 访问图模型中的各个层（该函数将返回一个字典，将层名称映射到层对象）。\n   - 第一个参数是表示网络输入的符号张量列表。如果网络只有一个输入层，则此列表仅包含一个张量。\n   - 第二个参数是函数的输出。在上述示例中，它是一个张量，但如果需要获取多个层的输出，也可以是一个张量列表。\n4. 函数编译完成后，可以使用 `deeplift.util.run_function_in_batches(func, input_data_list)` 以批处理方式运行该函数（如果您要对大量无法一次性加载到内存中的输入调用该函数，建议采用此方法）。\n   - `func` 即由 `deeplift.backend.function` 返回的已编译函数。\n   - `input_data_list` 是一个包含网络不同输入层数据的 NumPy 数组列表。对于只有一个输入的网络，此列表将只包含一个 NumPy 数组。\n   - `run_function_in_batches` 的可选参数包括 `batch_size` 和 `progress_update`。\n\n### 反向传播\n以下是实现反向传播所需的步骤，反向传播是计算重要性分数的地方。理想情况下，您应该通过快速入门中描述的自动转换创建模型，然后使用 `model.get_target_contribs_func` 或 `model.get_target_multipliers_func`。然而，如果这不可行，请继续阅读（也请考虑向我们发送消息告知我们，因为如果有足够的需求，我们会考虑添加此功能）。请注意，以下说明假定您已完成前向传播部分中的步骤 (1) 和 (2)。\n\n1. 对于您希望计算重要性分数的层，请调用 `reset_mxts_updated()`。这会重置用于计算乘数的符号变量。如果这是您首次编译反向传播函数，则此步骤并非严格必要。\n2. 对于包含将用于计算重要性分数的神经元的输出层，请调用 `set_scoring_mode(deeplift.layers.ScoringMode.OneAndZeros)`。\n   - 简而言之，此评分模式用于当我们希望针对单个目标神经元计算分数时。未来可能会添加其他类型的评分模式（例如神经元之间的差异）。\n   - 需要澄清的是：当我们最终编译函数时，每次调用该函数都将只为单个层中的单个输出神经元计算分数。具体的神经元和层可以在稍后运行时切换。目前，在此步骤中，您应对所有可能希望计算分数的目标层调用 `set_scoring_mode`，这样可以避免日后为了允许不同的目标层而重新编译函数。\n   - 对于 Sigmoid\u002FSoftmax 输出层，您应使用的输出层是位于最终非线性激活之前的线性层（通常是全连接层）。有关理由，请参阅论文中的“3.6 目标层的选择”。如果不存在最终非线性层（例如在许多回归任务中），则输出层应为最后一个线性层。\n   - 对于 Softmax 输出，您可能需要按照论文第 3.6 节“针对 Softmax 层的调整”中所述，减去对所有 Softmax 类别的平均贡献。如果您的 Softmax 类别数量非常大，并且您不想为每个示例单独计算每个类别的贡献，请联系我（avanti [dot] shrikumar@gmail.com），我可以实现一种更高效的计算方法（目前已有方案，但尚未编码）。\n3. 对于您希望计算重要性分数的层，请调用 `update_mxts()`。这将创建用于计算与步骤 2 中指定层相关乘数的符号变量。\n4. 使用以下代码编译重要性分数计算函数：\n\n    ```python\n    deeplift.backend.function([input_layer.get_activation_vars()...,\n                               input_layer.get_reference_vars()...],\n                              layer_to_find_scores_for.get_target_contrib_vars())\n    ```\n   - 第一个参数代表函数的输入，应为每个输入层激活的单个符号张量列表（与前向传播相同），后接每个输入层参考值的单个符号张量列表。\n   - 第二个参数代表函数的输出。在上述示例中，它是一个包含单个层重要性分数的张量，但如果您希望一次计算多个层的分数，也可以使用张量列表。\n   - 除了返回重要性分数的 `get_target_contrib_vars()`（在 `NonlinearMxtsMode.DeepLIFT` 情况下称为“贡献分数”）之外，您还可以使用 `get_pos_mxts()` 或 `get_neg_mxts()` 来获取乘数。\n5. 现在您可以调用函数来计算重要性分数了。\n   - 通过调用层上的 `set_active()` 来选择特定的输出层，以计算其重要性分数。\n   - 通过调用层上的 `update_task_index(task_idx)` 来选择层内的特定目标神经元。其中 `task_idx` 是该神经元在层中的索引。\n   - 调用步骤 4 中编译的函数，以计算目标神经元的重要性分数。有关如何使用 `deeplift.util.run_function_in_batches` 的提示，请参阅前向传播部分的步骤 4。\n   - 通过调用层上的 `set_inactive()` 来取消选择该输出层。切勿忘记！\n   - （是的，我将在某个时候将所有这些步骤整合到一个函数中）","# DeepLIFT 快速上手指南\n\nDeepLIFT (Deep Learning Important FeaTures) 是一个用于解释深度学习模型预测结果的 Python 库。它通过传播激活差异来计算输入特征的重要性分数，支持梯度、引导反向传播（Guided Backprop）和积分梯度（Integrated Gradients）等多种方法。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux, macOS 或 Windows\n*   **Python 版本**: 推荐 Python 3.6+\n*   **核心依赖**:\n    *   `tensorflow` == 1.14.0 (此版本经过充分测试)\n    *   `keras` == 2.2.4\n    *   `numpy`, `h5py` 等科学计算库\n\n> **注意**：虽然 DeepLIFT 不强制要求模型必须用特定库训练，但本工具提供了将 **Keras** 模型自动转换为 DeepLIFT 格式的功能。如果您使用其他框架（如 PyTorch），需要手动用 DeepLIFT 层重建模型结构。\n\n## 安装步骤\n\n### 方式一：通过 Pip 安装（推荐）\n\n直接使用 pip 从 PyPI 安装稳定版：\n\n```bash\npip install deeplift\n```\n\n**国内加速建议**：\n如果您在中国大陆，建议使用清华或阿里镜像源以加快下载速度：\n\n```bash\npip install deeplift -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 方式二：源码安装（可编辑模式）\n\n如果您需要修改源代码或体验最新功能，建议克隆仓库并使用 `--editable` 标志安装：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift.git\npip install --editable deeplift\u002F\n```\n\n## 基本使用\n\n以下示例展示如何加载一个已训练好的 Keras 模型（`.hdf5` 格式），并将其转换为 DeepLIFT 模型以计算输入层的重要性分数。\n\n### 1. 转换模型并编译计算函数\n\n```python\nimport deeplift\nfrom deeplift.conversion import kerasapi_conversion as kc\nimport numpy as np\n\n# 1. 加载并转换 Keras 模型\n# nonlinear_mxts_mode 定义了计算重要性分数的方法\n# DeepLIFT_GenomicsDefault: 对 Dense 层使用 RevealCancel 规则，对 Conv 层使用 Rescale 规则\ndeeplift_model = kc.convert_model_from_saved_files(\n    saved_hdf5_file_path='your_model.h5',  # 替换为您的模型文件路径\n    nonlinear_mxts_mode=deeplift.layers.NonlinearMxtsMode.DeepLIFT_GenomicsDefault\n)\n\n# 2. 指定要计算分数的层索引\n# 通常输入层是第 0 层，可以通过 deeplift_model.get_layers() 查看\nfind_scores_layer_idx = 0\n\n# 3. 编译计算贡献分数的函数\n# target_layer_idx: \n#   - 对于 Sigmoid\u002FSoftmax 输出，通常设为 -2 (针对 logits 层计算)\n#   - 对于线性输出的回归任务，设为 -1 (最后一层)\ndeeplift_contribs_func = deeplift_model.get_target_contribs_func(\n    find_scores_layer_idx=find_scores_layer_idx,\n    target_layer_idx=-1\n)\n```\n\n### 2. 计算重要性分数\n\n准备好输入数据后，调用编译好的函数即可得到分数。\n\n```python\n# 假设 X 是您的输入数据，形状为 (样本数, 通道, 高, 宽)，例如 MNIST 为 (n, 1, 28, 28)\n# task_idx: 输出层中目标节点的索引（例如 10 分类任务中，0 代表第一类）\nscores = np.array(deeplift_contribs_func(\n    task_idx=0,\n    input_data_list=[X],\n    batch_size=10,\n    progress_update=1000\n))\n\n# scores 的形状将与输入数据 X 相同，表示每个像素\u002F特征对预测结果的贡献度\nprint(scores.shape)\n```\n\n### 进阶提示\n\n*   **计算机视觉任务**：对于某些 CV 任务，计算较高层级卷积层的贡献分数（而非直接计算输入像素）可能会获得更好的效果。可通过调整 `find_scores_layer_idx` 参数指定层级。\n*   **参考值 (Reference)**：DeepLIFT 需要设定一个参考值（基线）。选择合适的参考值对结果影响较大，目前这仍是一个开放性问题，建议根据具体应用场景尝试不同的启发式策略（如全零、平均图像等）。\n*   **多输入支持**：如果模型有多个输入层，`input_data_list` 应包含对应数量的数据数组。","某生物信息学团队正在利用深度学习模型分析 DNA 序列，试图精准定位导致特定遗传疾病的突变位点。\n\n### 没有 deeplift 时\n- 模型虽然能高精度预测致病风险，但研究人员完全无法理解是哪些具体的碱基对结果产生了关键影响，模型如同“黑盒”。\n- 尝试使用传统梯度法解释时，受限于神经元饱和问题，许多实际重要的特征被错误地标记为零贡献，导致漏掉关键突变点。\n- 缺乏有效的归因手段使得团队难以向临床医生解释预测依据，严重阻碍了研究成果在医疗诊断中的落地应用。\n- 只能依靠耗时耗力的手动突变实验来验证特征重要性，研发周期被大幅拉长。\n\n### 使用 deeplift 后\n- 通过传播激活差异，deeplift 成功量化了每个输入碱基相对于参考序列的贡献分数，清晰揭示了驱动预测的核心基因片段。\n- 有效解决了梯度消失导致的特征遗漏问题，即使在不敏感的饱和区域也能准确捕捉到具有生物学意义的微弱信号。\n- 生成的可视化热力图直观展示了致病位点，让团队能够迅速构建令人信服的证据链，顺利通过与医学专家的合作评审。\n- 自动化的高精度特征筛选替代了部分盲目实验，将候选突变位的验证效率提升了数倍，显著缩短了发现周期。\n\ndeeplift 通过提供可信赖的特征归因分析，成功打破了生物医学深度学习模型的可解释性壁垒，让算法决策变得透明且具说服力。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fkundajelab_deeplift_88ef1da0.png","kundajelab","Kundaje Lab","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fkundajelab_b72dbf96.jpg","Compbio and machine learning code repositories from the Kundaje Lab at Stanford Genetics and Computer Science Depts.",null,"https:\u002F\u002Fkundajelab.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fkundajelab",[84],{"name":85,"color":86,"percentage":87},"Python","#3572A5",100,873,169,"2026-03-07T11:17:28","MIT",4,"未说明",{"notes":95,"python":93,"dependencies":96},"该工具主要测试于 TensorFlow 1.14.0 和 Keras 2.2.4 环境。虽然支持通过 pip 安装，但官方建议克隆仓库并使用 '--editable' 模式安装以便修改代码。该实现主要针对 Keras 模型提供自动转换功能，若使用其他框架训练模型，需使用 DeepLIFT 层重新构建模型。对于某些计算机视觉任务，建议计算较高卷积层的贡献分数而非输入像素。确定最佳参考值（reference）仍是一个开放性问题。",[97,98,99],"tensorflow==1.14.0","keras==2.2.4","numpy",[13],[67,102,103,104,105,106,107],"sensitivity-analysis","integrated-gradients","guided-backpropagation","saliency-map","interpretable-deep-learning","interpretability","2026-03-27T02:49:30.150509","2026-04-06T08:41:36.583016",[111,116,121,126,131,136],{"id":112,"question_zh":113,"answer_zh":114,"source_url":115},13383,"DeepLIFT 是否支持 Keras 2 或 TensorFlow 2 (tensorflow.keras)？","是的，DeepLIFT 已支持 Keras 2 和 tensorflow.keras。对于 Keras 2，请使用 `keras2compat` 分支（https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Ftree\u002Fkeras2compat），该分支包含兼容 Keras 2.x 的版本及示例笔记本。对于使用 `tensorflow.keras` 保存的模型，维护者已修复了转换问题，拉取最新代码后即可直接转换模型并计算重要性分数，无需手动重建模型。","https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F26",{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},13384,"如何为多输入模型（如 DNA 序列）选择适当的参考基线（Reference\u002FBaseline）？","选择基线取决于您的具体应用场景，因为网络计算的是相对于该基线的偏差对输出的影响。建议策略包括：1. 使用整数的平均值作为基线；2. 使用一组“控制”样本的平均值作为基线。无论选择何种值，都应进行健全性检查：将基线输入网络，确认其输出是否符合您对“基线输出”的预期。如果同时涉及序列输入的洗牌参考，需确保所选的整数参考值能与序列的洗牌逻辑兼容。","https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F103",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},13385,"在使用 DeepLIFT 转换模型后，发现预测结果与原模型差异巨大（例如差异为 1.0），该如何解决？","这通常是因为后端或版本不匹配导致的。DeepLIFT 针对不同配置有不同的分支：1. 若使用 Keras 2.0 + TensorFlow 后端，请切换到 `keras2compat` 分支；2. 若使用 Keras 1.2 + TensorFlow 后端，请切换到 `dev-tf` 分支。维护者已在 `keras2compat` 分支中添加了适用于 Keras 2 的 MNIST 示例笔记本，可参考该示例验证环境配置是否正确。","https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F48",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},13386,"在使用 Theano 后端时遇到 'AttributeError' 或无法转换 Keras 模型的问题怎么办？","如果您使用的是较旧版本的 Theano（如 0.9 之前）并遇到与 `T.nnet.sigmoid` 相关的错误，请尝试从 DeepLIFT 的 master 分支拉取最新代码。维护者已推送了针对 Theano 0.9 兼容性的修复补丁，更新后通常能解决此类转换错误。","https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F12",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},13387,"如何将 tf.keras 保存的 .h5 模型转换为 DeepLIFT 模型？","早期版本可能不支持直接转换，但维护者已在主分支中实施了修复。您只需拉取最新的代码修复（fixes），然后使用 `convert_model_from_saved_files` 函数即可直接加载由 `tensorflow.keras` 保存的 `.h5` 文件。此前需要手动在 Keras 中重建模型再加载权重的方法已不再必要。如果遇到问题，请确保使用的是包含最新修复的分支。","https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F92",{"id":137,"question_zh":138,"answer_zh":139,"source_url":125},13388,"DeepLIFT 对不同后端（Theano vs TensorFlow）的支持情况如何？","DeepLIFT 支持多种后端组合，但需对应正确的分支：1. Keras 2.0 + TensorFlow 后端：使用 `keras2compat` 分支；2. Keras 1.2 + TensorFlow 后端：使用 `dev-tf` 分支；3. Theano 后端：master 分支通常支持，但若遇兼容性问题（如 Theano 0.9），请更新到最新代码。请根据您的 Keras 版本和后端选择对应的分支以确保功能正常。",[141,146,151,156,161,166,171,176,181,186,191,195,200,205,209,214,219,224,229,234],{"id":142,"version":143,"summary_zh":144,"released_at":145},72081,"v0.6.13.0-alpha","对应 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F117（输出层使用 Sigmoid 函数的功能此前已支持）。","2020-11-11T09:28:34",{"id":147,"version":148,"summary_zh":149,"released_at":150},72082,"v0.6.12.0-alpha","感谢 @atseng95 提交的 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F109，该 PR 大幅提升了二核苷酸随机化效率。此版本标签还合并了 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F105 中的更改（支持提供预先生成的随机化参考序列，并已打上 v0.6.11.0 标签），以及 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F101 中的小修复（允许用户在误设无效任务索引时进行恢复，并已打上 v0.6.10.1 标签）。","2020-08-18T04:50:58",{"id":152,"version":153,"summary_zh":154,"released_at":155},72083,"v0.6.10.0-alpha","对应于 @berleon 在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F96 中提出的修复。@berleon 发现，该修复能够显著缩短包含多输入层的模型的编译时间。","2020-01-26T19:54:33",{"id":157,"version":158,"summary_zh":159,"released_at":160},72084,"v0.6.9.3-alpha","对应于 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F93 中实现的功能。主要有两项改进：(1) 修复了加载不包含偏置项的模型时的问题；(2) 原本会抛出运行时错误的目标层相关提示，现在仅会输出警告信息，因为确实存在合法场景可能导致该边缘情况发生。有关引发这些更改的问题，请参阅 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F92。","2020-01-14T20:50:56",{"id":162,"version":163,"summary_zh":164,"released_at":165},72085,"v0.6.9.2-alpha","该功能是在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fissues\u002F83 中提出的，并在 PR https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F84\u002Ffiles 中实现。当时我忘记将其合并到主分支，现在才进行合并。基因组学笔记本已在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F94 中更新，以使用此功能，并同步升级至 Python 3。","2020-01-07T23:30:23",{"id":167,"version":168,"summary_zh":169,"released_at":170},72086,"v0.6.9.1-alpha","（这样就不必通过外部设置 NumPy 的随机种子来控制随机状态，而这种做法在 Jupyter Notebook 中并不总是奏效）","2019-10-18T15:22:03",{"id":172,"version":173,"summary_zh":174,"released_at":175},72087,"v0.6.9.0","对应于 @annashcherbina 在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F78 中添加的功能。","2019-03-08T04:13:00",{"id":177,"version":178,"summary_zh":179,"released_at":180},72088,"v0.6.8.1-alpha","- 应对 Keras 2.2.3 中的破坏性变更，具体说明见此 Pull Request：https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F69\n- 此版本还包含了由 @AnjaSei 在 https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F68 中添加的 GlobalAveragePooling 层。","2018-12-12T20:03:41",{"id":182,"version":183,"summary_zh":184,"released_at":185},72089,"v0.6.7.1-alpha","此拉取请求：https:\u002F\u002Fgithub.com\u002Fkundajelab\u002Fdeeplift\u002Fpull\u002F62","2018-09-14T08:00:03",{"id":187,"version":188,"summary_zh":189,"released_at":190},72090,"v0.6.7.0-alpha","（TensorFlow 1.10.1）。同时更新了一些测试，使其能与 Keras 2.2 兼容。","2018-08-27T22:53:12",{"id":192,"version":193,"summary_zh":80,"released_at":194},72091,"v0.6.6.2-alpha","2018-08-20T04:44:12",{"id":196,"version":197,"summary_zh":198,"released_at":199},72092,"v0.6.6.1-alpha","Unit tests for batchnorm have been added for a while, but I hadn't removed the warning message.","2018-08-20T04:31:35",{"id":201,"version":202,"summary_zh":203,"released_at":204},72093,"v0.6.6-alpha","The version corresponding to what's on pypi.","2018-07-13T21:14:14",{"id":206,"version":207,"summary_zh":80,"released_at":208},72094,"v0.6.5-alpha","2018-07-12T22:21:31",{"id":210,"version":211,"summary_zh":212,"released_at":213},72095,"v0.6.4-alpha","Keras 2 compatible version based off the master branch.","2018-07-04T06:54:08",{"id":215,"version":216,"summary_zh":217,"released_at":218},72096,"v0.5.5-theano","Making a tagged version before I replace the master branch with v6 contents.","2018-07-04T06:17:21",{"id":220,"version":221,"summary_zh":222,"released_at":223},72097,"v0.6.2-alpha","@jisraeli @annashcherbina here is a tagged version that you should be able to use. It passes unit tests for both python 2 and 3.","2018-06-05T04:17:10",{"id":225,"version":226,"summary_zh":227,"released_at":228},72098,"v0.5.1-theano","Difference between 0.4.0 and 0.5.0 is functionality added to support separate treatment of positive and negative contributions for all activation functions (the \"RevealCancel\" rule - matches functionality in ICML submission). Difference between 0.5.1-theano and 0.5.0-theano (for which a release was not drafted) is that some support was added for border mode same and a cast to float32 was added to the integrated gradients function to account for cases where the supplied data might be uint8.","2017-04-23T23:18:26",{"id":230,"version":231,"summary_zh":232,"released_at":233},72099,"v0.4.0-alpha","Theano backend. 1d convolutions and pooling added. Sequential model conversion tested with keras 0.2, 0.3 and 1.1.2, and support for keras models trained with tensorflow dimension ordering is in place. No keras functional API conversion yet.\n","2016-12-12T06:06:45",{"id":235,"version":236,"summary_zh":237,"released_at":238},72100,"v0.3-alpha","Release for dragonn 0.1.2\n","2016-11-01T23:10:31"]