Cargando…
Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens
Deep neural network models (DNNs) are essential to modern AI and provide powerful models of information processing in biological neural networks. Researchers in both neuroscience and engineering are pursuing a better understanding of the internal representations and operations that undergird the suc...
Autores principales: | , |
---|---|
Formato: | Online Artículo Texto |
Lenguaje: | English |
Publicado: |
Nature Publishing Group UK
2023
|
Materias: | |
Acceso en línea: | https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10474256/ https://www.ncbi.nlm.nih.gov/pubmed/37658079 http://dx.doi.org/10.1038/s41598-023-40807-0 |
_version_ | 1785100449776402432 |
---|---|
author | Taylor, JohnMark Kriegeskorte, Nikolaus |
author_facet | Taylor, JohnMark Kriegeskorte, Nikolaus |
author_sort | Taylor, JohnMark |
collection | PubMed |
description | Deep neural network models (DNNs) are essential to modern AI and provide powerful models of information processing in biological neural networks. Researchers in both neuroscience and engineering are pursuing a better understanding of the internal representations and operations that undergird the successes and failures of DNNs. Neuroscientists additionally evaluate DNNs as models of brain computation by comparing their internal representations to those found in brains. It is therefore essential to have a method to easily and exhaustively extract and characterize the results of the internal operations of any DNN. Many models are implemented in PyTorch, the leading framework for building DNN models. Here we introduce TorchLens, a new open-source Python package for extracting and characterizing hidden-layer activations in PyTorch models. Uniquely among existing approaches to this problem, TorchLens has the following features: (1) it exhaustively extracts the results of all intermediate operations, not just those associated with PyTorch module objects, yielding a full record of every step in the model's computational graph, (2) it provides an intuitive visualization of the model's complete computational graph along with metadata about each computational step in a model's forward pass for further analysis, (3) it contains a built-in validation procedure to algorithmically verify the accuracy of all saved hidden-layer activations, and (4) the approach it uses can be automatically applied to any PyTorch model with no modifications, including models with conditional (if–then) logic in their forward pass, recurrent models, branching models where layer outputs are fed into multiple subsequent layers in parallel, and models with internally generated tensors (e.g., injections of noise). Furthermore, using TorchLens requires minimal additional code, making it easy to incorporate into existing pipelines for model development and analysis, and useful as a pedagogical aid when teaching deep learning concepts. We hope this contribution will help researchers in AI and neuroscience understand the internal representations of DNNs. |
format | Online Article Text |
id | pubmed-10474256 |
institution | National Center for Biotechnology Information |
language | English |
publishDate | 2023 |
publisher | Nature Publishing Group UK |
record_format | MEDLINE/PubMed |
spelling | pubmed-104742562023-09-03 Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens Taylor, JohnMark Kriegeskorte, Nikolaus Sci Rep Article Deep neural network models (DNNs) are essential to modern AI and provide powerful models of information processing in biological neural networks. Researchers in both neuroscience and engineering are pursuing a better understanding of the internal representations and operations that undergird the successes and failures of DNNs. Neuroscientists additionally evaluate DNNs as models of brain computation by comparing their internal representations to those found in brains. It is therefore essential to have a method to easily and exhaustively extract and characterize the results of the internal operations of any DNN. Many models are implemented in PyTorch, the leading framework for building DNN models. Here we introduce TorchLens, a new open-source Python package for extracting and characterizing hidden-layer activations in PyTorch models. Uniquely among existing approaches to this problem, TorchLens has the following features: (1) it exhaustively extracts the results of all intermediate operations, not just those associated with PyTorch module objects, yielding a full record of every step in the model's computational graph, (2) it provides an intuitive visualization of the model's complete computational graph along with metadata about each computational step in a model's forward pass for further analysis, (3) it contains a built-in validation procedure to algorithmically verify the accuracy of all saved hidden-layer activations, and (4) the approach it uses can be automatically applied to any PyTorch model with no modifications, including models with conditional (if–then) logic in their forward pass, recurrent models, branching models where layer outputs are fed into multiple subsequent layers in parallel, and models with internally generated tensors (e.g., injections of noise). Furthermore, using TorchLens requires minimal additional code, making it easy to incorporate into existing pipelines for model development and analysis, and useful as a pedagogical aid when teaching deep learning concepts. We hope this contribution will help researchers in AI and neuroscience understand the internal representations of DNNs. Nature Publishing Group UK 2023-09-01 /pmc/articles/PMC10474256/ /pubmed/37658079 http://dx.doi.org/10.1038/s41598-023-40807-0 Text en © The Author(s) 2023 https://creativecommons.org/licenses/by/4.0/Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/ (https://creativecommons.org/licenses/by/4.0/) . |
spellingShingle | Article Taylor, JohnMark Kriegeskorte, Nikolaus Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title | Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title_full | Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title_fullStr | Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title_full_unstemmed | Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title_short | Extracting and visualizing hidden activations and computational graphs of PyTorch models with TorchLens |
title_sort | extracting and visualizing hidden activations and computational graphs of pytorch models with torchlens |
topic | Article |
url | https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10474256/ https://www.ncbi.nlm.nih.gov/pubmed/37658079 http://dx.doi.org/10.1038/s41598-023-40807-0 |
work_keys_str_mv | AT taylorjohnmark extractingandvisualizinghiddenactivationsandcomputationalgraphsofpytorchmodelswithtorchlens AT kriegeskortenikolaus extractingandvisualizinghiddenactivationsandcomputationalgraphsofpytorchmodelswithtorchlens |