pytorch-concepts 0.0.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. pytorch_concepts-0.0.12/.circleci/config.yml +38 -0
  2. pytorch_concepts-0.0.12/.coveragerc +21 -0
  3. pytorch_concepts-0.0.12/.gitignore +77 -0
  4. pytorch_concepts-0.0.12/.readthedocs.yml +8 -0
  5. pytorch_concepts-0.0.12/.travis.yml +37 -0
  6. pytorch_concepts-0.0.12/LICENSE +201 -0
  7. pytorch_concepts-0.0.12/MANIFEST.in +2 -0
  8. pytorch_concepts-0.0.12/PKG-INFO +160 -0
  9. pytorch_concepts-0.0.12/README.md +102 -0
  10. pytorch_concepts-0.0.12/appveyor.yml +37 -0
  11. pytorch_concepts-0.0.12/doc/Makefile +184 -0
  12. pytorch_concepts-0.0.12/doc/_static/css/project-template.css +16 -0
  13. pytorch_concepts-0.0.12/doc/_static/img/pyc_logo.png +0 -0
  14. pytorch_concepts-0.0.12/doc/_static/js/copybutton.js +63 -0
  15. pytorch_concepts-0.0.12/doc/_templates/class.rst +16 -0
  16. pytorch_concepts-0.0.12/doc/_templates/function.rst +12 -0
  17. pytorch_concepts-0.0.12/doc/_templates/numpydoc_docstring.py +16 -0
  18. pytorch_concepts-0.0.12/doc/conf.py +77 -0
  19. pytorch_concepts-0.0.12/doc/index.rst +82 -0
  20. pytorch_concepts-0.0.12/doc/make.bat +242 -0
  21. pytorch_concepts-0.0.12/doc/modules/base.rst +7 -0
  22. pytorch_concepts-0.0.12/doc/modules/data/celeba.rst +7 -0
  23. pytorch_concepts-0.0.12/doc/modules/data/mnist.rst +7 -0
  24. pytorch_concepts-0.0.12/doc/modules/data/toy.rst +7 -0
  25. pytorch_concepts-0.0.12/doc/modules/data/traffic.rst +7 -0
  26. pytorch_concepts-0.0.12/doc/modules/metrics.rst +7 -0
  27. pytorch_concepts-0.0.12/doc/modules/nn/base.rst +7 -0
  28. pytorch_concepts-0.0.12/doc/modules/nn/bottleneck.rst +7 -0
  29. pytorch_concepts-0.0.12/doc/modules/nn/functional.rst +7 -0
  30. pytorch_concepts-0.0.12/doc/modules/utils.rst +7 -0
  31. pytorch_concepts-0.0.12/doc/user_guide/license.rst +212 -0
  32. pytorch_concepts-0.0.12/environment.yml +6 -0
  33. pytorch_concepts-0.0.12/examples/high-level/concept_bottleneck_model.py +59 -0
  34. pytorch_concepts-0.0.12/examples/high-level/concept_bottleneck_residual_model.py +60 -0
  35. pytorch_concepts-0.0.12/examples/high-level/concept_embedding_model.py +61 -0
  36. pytorch_concepts-0.0.12/examples/high-level/stochastic_concept_bottleneck_model.py +110 -0
  37. pytorch_concepts-0.0.12/examples/loading-data/celeba.py +28 -0
  38. pytorch_concepts-0.0.12/examples/loading-data/mnist.py +22 -0
  39. pytorch_concepts-0.0.12/examples/loading-data/toy.py +32 -0
  40. pytorch_concepts-0.0.12/examples/low-level/any_concept_bottleneck_model.py +100 -0
  41. pytorch_concepts-0.0.12/examples/low-level/concept_bottleneck_model.py +67 -0
  42. pytorch_concepts-0.0.12/examples/low-level/concept_embedding_model.py +78 -0
  43. pytorch_concepts-0.0.12/examples/low-level/concept_memory_reasoner.py +98 -0
  44. pytorch_concepts-0.0.12/examples/low-level/deep_concept_reasoner.py +121 -0
  45. pytorch_concepts-0.0.12/examples/low-level/linear_concept_embedding_model.py +114 -0
  46. pytorch_concepts-0.0.12/examples/low-level/linear_concept_memory_reasoner.py +158 -0
  47. pytorch_concepts-0.0.12/examples/low-level/stochastic_concept_bottleneck_model.py +106 -0
  48. pytorch_concepts-0.0.12/examples/mid-level/concept_bottleneck_model.py +69 -0
  49. pytorch_concepts-0.0.12/examples/mid-level/concept_embedding_model.py +90 -0
  50. pytorch_concepts-0.0.12/examples/mid-level/concept_memory_reasoner.py +98 -0
  51. pytorch_concepts-0.0.12/examples/mid-level/linear_concept_embedding_model.py +103 -0
  52. pytorch_concepts-0.0.12/examples/mid-level/stochastic_concept_bottleneck_model.py +102 -0
  53. pytorch_concepts-0.0.12/examples/model_example.py +125 -0
  54. pytorch_concepts-0.0.12/experiments/configs/awa2.yaml +100 -0
  55. pytorch_concepts-0.0.12/experiments/configs/cub.yaml +108 -0
  56. pytorch_concepts-0.0.12/experiments/experiment_summaries.py +60 -0
  57. pytorch_concepts-0.0.12/experiments/experiment_utils.py +561 -0
  58. pytorch_concepts-0.0.12/experiments/mnist_addition.py +320 -0
  59. pytorch_concepts-0.0.12/experiments/mnist_addition_partial_concepts.py +307 -0
  60. pytorch_concepts-0.0.12/experiments/mnist_even_odd.py +313 -0
  61. pytorch_concepts-0.0.12/experiments/run_experiment.py +657 -0
  62. pytorch_concepts-0.0.12/experiments/toy.py +293 -0
  63. pytorch_concepts-0.0.12/experiments/utils.py +64 -0
  64. pytorch_concepts-0.0.12/pyproject.toml +3 -0
  65. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/PKG-INFO +160 -0
  66. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/SOURCES.txt +115 -0
  67. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/dependency_links.txt +1 -0
  68. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/not-zip-safe +1 -0
  69. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/requires.txt +18 -0
  70. pytorch_concepts-0.0.12/pytorch_concepts.egg-info/top_level.txt +1 -0
  71. pytorch_concepts-0.0.12/requirements.txt +4 -0
  72. pytorch_concepts-0.0.12/setup.cfg +13 -0
  73. pytorch_concepts-0.0.12/setup.py +88 -0
  74. pytorch_concepts-0.0.12/tests/__init__.py +0 -0
  75. pytorch_concepts-0.0.12/tests/test_base_nn.py +78 -0
  76. pytorch_concepts-0.0.12/tests/test_base_objects.py +80 -0
  77. pytorch_concepts-0.0.12/tests/test_bottleneck.py +74 -0
  78. pytorch_concepts-0.0.12/tests/test_data.py +76 -0
  79. pytorch_concepts-0.0.12/tests/test_functional.py +304 -0
  80. pytorch_concepts-0.0.12/tests/test_metrics.py +95 -0
  81. pytorch_concepts-0.0.12/tests/test_models.py +95 -0
  82. pytorch_concepts-0.0.12/torch_concepts/__init__.py +13 -0
  83. pytorch_concepts-0.0.12/torch_concepts/_version.py +1 -0
  84. pytorch_concepts-0.0.12/torch_concepts/assets/__init__.py +0 -0
  85. pytorch_concepts-0.0.12/torch_concepts/assets/ambulance.png +0 -0
  86. pytorch_concepts-0.0.12/torch_concepts/assets/lights.png +0 -0
  87. pytorch_concepts-0.0.12/torch_concepts/assets/single_lane_road_intersection.png +0 -0
  88. pytorch_concepts-0.0.12/torch_concepts/assets/white_black_car.png +0 -0
  89. pytorch_concepts-0.0.12/torch_concepts/assets/white_car.png +0 -0
  90. pytorch_concepts-0.0.12/torch_concepts/base.py +494 -0
  91. pytorch_concepts-0.0.12/torch_concepts/data/__init__.py +14 -0
  92. pytorch_concepts-0.0.12/torch_concepts/data/awa2.py +423 -0
  93. pytorch_concepts-0.0.12/torch_concepts/data/cebab.py +162 -0
  94. pytorch_concepts-0.0.12/torch_concepts/data/celeba.py +72 -0
  95. pytorch_concepts-0.0.12/torch_concepts/data/cub.py +888 -0
  96. pytorch_concepts-0.0.12/torch_concepts/data/mnist.py +268 -0
  97. pytorch_concepts-0.0.12/torch_concepts/data/toy.py +357 -0
  98. pytorch_concepts-0.0.12/torch_concepts/data/traffic.py +380 -0
  99. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/README.md +100 -0
  100. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/__init__.py +19 -0
  101. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/cars.py +150 -0
  102. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/generate_data.py +1033 -0
  103. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/intersection.py +137 -0
  104. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/lights.py +293 -0
  105. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/shared.py +10 -0
  106. pytorch_concepts-0.0.12/torch_concepts/data/traffic_construction/utils.py +166 -0
  107. pytorch_concepts-0.0.12/torch_concepts/data/utils.py +166 -0
  108. pytorch_concepts-0.0.12/torch_concepts/metrics.py +135 -0
  109. pytorch_concepts-0.0.12/torch_concepts/nn/__init__.py +44 -0
  110. pytorch_concepts-0.0.12/torch_concepts/nn/base.py +122 -0
  111. pytorch_concepts-0.0.12/torch_concepts/nn/bottleneck.py +672 -0
  112. pytorch_concepts-0.0.12/torch_concepts/nn/functional.py +612 -0
  113. pytorch_concepts-0.0.12/torch_concepts/nn/minimize_constraint.py +336 -0
  114. pytorch_concepts-0.0.12/torch_concepts/nn/models.py +1449 -0
  115. pytorch_concepts-0.0.12/torch_concepts/semantic.py +78 -0
  116. pytorch_concepts-0.0.12/torch_concepts/utils.py +137 -0
@@ -0,0 +1,38 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ build:
5
+ docker:
6
+ - image: circleci/python:3.6.1
7
+ working_directory: ~/repo
8
+ steps:
9
+ - checkout
10
+ - run:
11
+ name: install dependencies
12
+ command: |
13
+ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
14
+ chmod +x miniconda.sh && ./miniconda.sh -b -p ~/miniconda
15
+ export PATH="~/miniconda/bin:$PATH"
16
+ conda update --yes --quiet conda
17
+ conda create -n testenv --yes --quiet python=3
18
+ source activate testenv
19
+ conda install --yes pip numpy scipy scikit-learn matplotlib sphinx sphinx_rtd_theme numpydoc pillow
20
+ pip install sphinx-gallery
21
+ pip install .
22
+ cd doc
23
+ make html
24
+ - store_artifacts:
25
+ path: doc/_build/html/
26
+ destination: doc
27
+ - store_artifacts:
28
+ path: ~/log.txt
29
+ - run: ls -ltrh doc/_build/html
30
+ filters:
31
+ branches:
32
+ ignore: gh-pages
33
+
34
+ workflows:
35
+ version: 2
36
+ workflow:
37
+ jobs:
38
+ - build
@@ -0,0 +1,21 @@
1
+ # Configuration for coverage.py
2
+
3
+ [run]
4
+ branch = True
5
+ source = template
6
+ include = */template/*
7
+ omit =
8
+ */setup.py
9
+
10
+ [report]
11
+ exclude_lines =
12
+ pragma: no cover
13
+ def __repr__
14
+ if self.debug:
15
+ if settings.DEBUG
16
+ raise AssertionError
17
+ raise NotImplementedError
18
+ if 0:
19
+ if __name__ == .__main__.:
20
+ if self.verbose:
21
+ show_missing = True
@@ -0,0 +1,77 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # scikit-learn specific
10
+ doc/_build/
11
+ doc/auto_examples/
12
+ doc/modules/generated/
13
+ doc/datasets/generated/
14
+
15
+ # Distribution / packaging
16
+
17
+ .Python
18
+ env/
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ *.egg-info/
31
+ .installed.cfg
32
+ *.egg
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *,cover
53
+ .hypothesis/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+
62
+ # Sphinx documentation
63
+ doc/_build/
64
+ doc/generated/
65
+
66
+ # PyBuilder
67
+ target/
68
+
69
+ # pycharm
70
+ .idea/*
71
+
72
+ # lightning logs
73
+ examples/lightning_logs/
74
+ lightning_logs/
75
+
76
+ # results
77
+ model_results.csv
@@ -0,0 +1,8 @@
1
+ formats:
2
+ - none
3
+ requirements_file: requirements.txt
4
+ python:
5
+ pip_install: true
6
+ extra_requirements:
7
+ - tests
8
+ - docs
@@ -0,0 +1,37 @@
1
+ dist: trusty
2
+ sudo: false
3
+
4
+ language: python
5
+
6
+ cache:
7
+ directories:
8
+ - $HOME/.cache/pip
9
+
10
+ matrix:
11
+ include:
12
+ - env: PYTHON_VERSION="3.7" NUMPY_VERSION="*" SCIPY_VERSION="*"
13
+ PANDAS_VERSION="*"
14
+
15
+ install:
16
+ # install miniconda
17
+ - deactivate
18
+ - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
19
+ - MINICONDA_PATH=/home/travis/miniconda
20
+ - chmod +x miniconda.sh && ./miniconda.sh -b -p $MINICONDA_PATH
21
+ - export PATH=$MINICONDA_PATH/bin:$PATH
22
+ - conda update --yes conda
23
+ # create the testing environment
24
+ - conda create -n testenv --yes python=$PYTHON_VERSION pip
25
+ - source activate testenv
26
+ - pip install codecov
27
+ - pip install -r requirements.txt .
28
+
29
+ #script:
30
+ # - mkdir for_test
31
+ # - cd for_test
32
+ # - pytest -v --cov=dbgen --pyargs dbgen
33
+ script:
34
+ - coverage run -m unittest || python3 -m unittest || python -m unittest
35
+
36
+ after_success:
37
+ - codecov
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ include requirements.txt
2
+ recursive-include torch_concepts/assets *
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytorch_concepts
3
+ Version: 0.0.12
4
+ Summary: Concept-Based Deep Learning Library for PyTorch.
5
+ Home-page: https://github.com/pyc-team/pytorch_concepts
6
+ Download-URL: https://github.com/pyc-team/pytorch_concepts
7
+ Author: PyC Team
8
+ Author-email: pyc.devteam@gmail.com
9
+ Maintainer: PyC Team
10
+ Maintainer-email: pyc.devteam@gmail.com
11
+ License: Apache 2.0
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX
18
+ Classifier: Operating System :: Unix
19
+ Classifier: Programming Language :: Python :: 2.7
20
+ Classifier: Programming Language :: Python :: 3.5
21
+ Classifier: Programming Language :: Python :: 3.6
22
+ Classifier: Programming Language :: Python :: 3.7
23
+ Classifier: Programming Language :: Python
24
+ Classifier: Topic :: Scientific/Engineering
25
+ Classifier: Topic :: Software Development
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy
29
+ Requires-Dist: opencv-python
30
+ Requires-Dist: pandas
31
+ Requires-Dist: Pillow==9.5.0
32
+ Requires-Dist: scikit-learn
33
+ Requires-Dist: scipy
34
+ Requires-Dist: torch
35
+ Provides-Extra: tests
36
+ Requires-Dist: pytest-cov; extra == "tests"
37
+ Requires-Dist: pytest; extra == "tests"
38
+ Provides-Extra: docs
39
+ Requires-Dist: matplotlib; extra == "docs"
40
+ Requires-Dist: numpydoc; extra == "docs"
41
+ Requires-Dist: sphinx_rtd_theme; extra == "docs"
42
+ Requires-Dist: sphinx-gallery; extra == "docs"
43
+ Requires-Dist: sphinx; extra == "docs"
44
+ Dynamic: author
45
+ Dynamic: author-email
46
+ Dynamic: classifier
47
+ Dynamic: description
48
+ Dynamic: description-content-type
49
+ Dynamic: download-url
50
+ Dynamic: home-page
51
+ Dynamic: license
52
+ Dynamic: license-file
53
+ Dynamic: maintainer
54
+ Dynamic: maintainer-email
55
+ Dynamic: provides-extra
56
+ Dynamic: requires-dist
57
+ Dynamic: summary
58
+
59
+ ![PyC Logo](https://raw.githubusercontent.com/pyc-team/pytorch_concepts/dev/doc/_static/img/pyc_logo.png)
60
+
61
+ # PyTorch Concepts
62
+
63
+ PyC (PyTorch Concepts) is a library built upon PyTorch to easily write and train Concept-Based Deep Learning models.
64
+
65
+ ## Low-level APIs
66
+
67
+ **Concept data types** (`pyc.base`):
68
+
69
+ - `AnnotatedTensor`: A subclass of `torch.Tensor` which assigns names to individual elements of each tensor dimension.
70
+
71
+ **Base concept layers** (`pyc.nn.base`):
72
+
73
+ - `Annotate`: A layer taking as input a common `tensor` and producing an `AnnotatedTensor` as output.
74
+ - `LinearConceptLayer`: A layer which first applies a linear transformation to the input tensor, then it reshapes and annotates the output tensor.
75
+
76
+ **Base functions** (`pyc.nn.functional`):
77
+
78
+ - `intervene`: A function to intervene on concept scores.
79
+ - `intervene_on_concept_graph`: A function to intervene on a concept adjacency matrix (it can be used to perform do-interventions).
80
+ - `concept_embedding_mixture`: A function to generate a mixture of concept embeddings and concept predictions.
81
+
82
+ ## High-level APIs
83
+
84
+ **Concept bottleneck layers** (`pyc.nn.bottleneck`):
85
+
86
+ - `LinearConceptBottleneck`: A vanilla concept bottleneck from ["Concept Bottleneck Models"](https://arxiv.org/pdf/2007.04612) (ICML 2020).
87
+ - `LinearConceptResidualBottleneck`: A residual bottleneck composed of a set of supervised concepts and a residual unsupervised embedding from ["Promises and Pitfalls of Black-Box Concept Learning Models"](https://arxiv.org/abs/2106.13314) (ICML 2021, workshop).
88
+ - `ConceptEmbeddingBottleneck`: A bottleneck composed of supervised concept embeddings from ["Concept Embedding Models: Beyond the Accuracy-Explainability Trade-Off"](https://arxiv.org/abs/2209.09056) (NeurIPS 2022).
89
+
90
+ ## Evaluation APIs
91
+
92
+ **Datasets** (`pyc.data`):
93
+
94
+ - `TrafficLights`: A dataset loader for traffic scenarios representing road intersections.
95
+ - `ToyDataset`: A toy dataset loader. XOR, Trigonometry, and Dot datasets are from ["Concept Embedding Models: Beyond the Accuracy-Explainability Trade-Off"](https://arxiv.org/abs/2209.09056) (NeurIPS 2022). The Checkmark dataset is from ["Causal Concept Embedding Models: Beyond Causal Opacity in Deep Learning"](https://arxiv.org/abs/2405.16507).
96
+ - `CompletenessDataset`: A dataset loader for the completeness score from ["Beyond Concept Bottleneck Models: How to Make Black Boxes Intervenable?"](https://arxiv.org/abs/2401.13544).
97
+ - `ColorMNISTDataset`: A dataset loader for MNIST Even/Odd where colors act as confounders inspired from ["Explaining Classifiers with Causal Concept Effect (CaCE)"](https://arxiv.org/abs/1907.07165) and ["Interpretable Concept-Based Memory Reasoning"](https://arxiv.org/abs/2407.15527).
98
+ - `CelebA`: A dataset loader for CelebA dataset with attributes as concepts from ["Deep Learning Face Attributes in the Wild"](https://arxiv.org/abs/1411.7766) (ICCV 2015).
99
+
100
+ **Metrics** (`pyc.metrics`):
101
+
102
+ - `intervention_score`: A score measuring the effectiveness of concept interventions from ["Concept Bottleneck Models"](https://arxiv.org/pdf/2007.04612) (ICML 2020).
103
+ - `completeness_score`: A score measuring concept completeness from ["On Completeness-aware Concept-Based Explanations in Deep Neural Networks"](https://arxiv.org/abs/1910.07969) (NeurIPS 2020).
104
+ - `cace_score`: A score measuring causal concept effects (CaCE) from ["Explaining Classifiers with Causal Concept Effect (CaCE)"](https://arxiv.org/abs/1907.07165).
105
+
106
+ ## Contributing
107
+
108
+ - Use the `dev` branch to write and test your contributions locally.
109
+ - Make small commits and use ["Gitmoji"](https://gitmoji.dev/) to add emojis to your commit messages.
110
+ - Make sure to write documentation and tests for your contributions.
111
+ - Make sure all tests pass before submitting the pull request.
112
+ - Submit a pull request to the `main` branch.
113
+
114
+ ## PyC Book
115
+
116
+ You can find further reading materials and tutorials in our book [Concept-based Interpretable Deep Learning in Python](https://pyc-team.github.io/pyc-book/).
117
+
118
+ ## Authors
119
+
120
+ - [Pietro Barbiero](http://www.pietrobarbiero.eu/), Universita' della Svizzera Italiana (CH) and University of Cambridge (UK).
121
+ - [Gabriele Ciravegna](https://dbdmg.polito.it/dbdmg_web/gabriele-ciravegna/), Politecnico di Torino (IT).
122
+ - [David Debot](https://www.kuleuven.be/wieiswie/en/person/00165387), KU Leuven (BE).
123
+ - [Michelangelo Diligenti](https://docenti.unisi.it/en/diligenti), Università degli Studi di Siena (IT).
124
+ - [Gabriele Dominici](https://pc.inf.usi.ch/team/gabriele-dominici/), Universita' della Svizzera Italiana (CH).
125
+ - [Mateo Espinosa Zarlenga](https://hairyballtheorem.com/), University of Cambridge (UK).
126
+ - [Francesco Giannini](https://www.francescogiannini.eu/), Scuola Normale Superiore di Pisa (IT).
127
+ - [Giuseppe Marra](https://www.giuseppemarra.com/), KU Leuven (BE).
128
+
129
+ ## Licence
130
+
131
+ Copyright 2024 Pietro Barbiero, Gabriele Ciravegna, David Debot, Michelangelo Diligenti, Gabriele Dominici, Mateo Espinosa Zarlenga, Francesco Giannini, Giuseppe Marra.
132
+
133
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: <http://www.apache.org/licenses/LICENSE-2.0>.
134
+
135
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136
+
137
+ See the License for the specific language governing permissions and limitations under the License.
138
+
139
+
140
+ ## Cite this library
141
+
142
+ If you found this library useful for your blog post, research article or product, we would be grateful if you would cite it like this:
143
+
144
+ ```
145
+ Barbiero P., Ciravegna G., Debot D., Diligenti M.,
146
+ Dominici G., Espinosa Zarlenga M., Giannini F., Marra G. (2024).
147
+ Concept-based Interpretable Deep Learning in Python.
148
+ https://pyc-team.github.io/pyc-book/intro.html
149
+ ```
150
+
151
+ Or use the following bibtex entry:
152
+
153
+ ```
154
+ @book{pycteam2024concept,
155
+ title = {Concept-based Interpretable Deep Learning in Python},
156
+ author = {Pietro Barbiero, Gabriele Ciravegna, David Debot, Michelangelo Diligenti, Gabriele Dominici, Mateo Espinosa Zarlenga, Francesco Giannini, Giuseppe Marra},
157
+ year = {2024},
158
+ url = {https://pyc-team.github.io/pyc-book/intro.html}
159
+ }
160
+ ```
@@ -0,0 +1,102 @@
1
+ ![PyC Logo](https://raw.githubusercontent.com/pyc-team/pytorch_concepts/dev/doc/_static/img/pyc_logo.png)
2
+
3
+ # PyTorch Concepts
4
+
5
+ PyC (PyTorch Concepts) is a library built upon PyTorch to easily write and train Concept-Based Deep Learning models.
6
+
7
+ ## Low-level APIs
8
+
9
+ **Concept data types** (`pyc.base`):
10
+
11
+ - `AnnotatedTensor`: A subclass of `torch.Tensor` which assigns names to individual elements of each tensor dimension.
12
+
13
+ **Base concept layers** (`pyc.nn.base`):
14
+
15
+ - `Annotate`: A layer taking as input a common `tensor` and producing an `AnnotatedTensor` as output.
16
+ - `LinearConceptLayer`: A layer which first applies a linear transformation to the input tensor, then it reshapes and annotates the output tensor.
17
+
18
+ **Base functions** (`pyc.nn.functional`):
19
+
20
+ - `intervene`: A function to intervene on concept scores.
21
+ - `intervene_on_concept_graph`: A function to intervene on a concept adjacency matrix (it can be used to perform do-interventions).
22
+ - `concept_embedding_mixture`: A function to generate a mixture of concept embeddings and concept predictions.
23
+
24
+ ## High-level APIs
25
+
26
+ **Concept bottleneck layers** (`pyc.nn.bottleneck`):
27
+
28
+ - `LinearConceptBottleneck`: A vanilla concept bottleneck from ["Concept Bottleneck Models"](https://arxiv.org/pdf/2007.04612) (ICML 2020).
29
+ - `LinearConceptResidualBottleneck`: A residual bottleneck composed of a set of supervised concepts and a residual unsupervised embedding from ["Promises and Pitfalls of Black-Box Concept Learning Models"](https://arxiv.org/abs/2106.13314) (ICML 2021, workshop).
30
+ - `ConceptEmbeddingBottleneck`: A bottleneck composed of supervised concept embeddings from ["Concept Embedding Models: Beyond the Accuracy-Explainability Trade-Off"](https://arxiv.org/abs/2209.09056) (NeurIPS 2022).
31
+
32
+ ## Evaluation APIs
33
+
34
+ **Datasets** (`pyc.data`):
35
+
36
+ - `TrafficLights`: A dataset loader for traffic scenarios representing road intersections.
37
+ - `ToyDataset`: A toy dataset loader. XOR, Trigonometry, and Dot datasets are from ["Concept Embedding Models: Beyond the Accuracy-Explainability Trade-Off"](https://arxiv.org/abs/2209.09056) (NeurIPS 2022). The Checkmark dataset is from ["Causal Concept Embedding Models: Beyond Causal Opacity in Deep Learning"](https://arxiv.org/abs/2405.16507).
38
+ - `CompletenessDataset`: A dataset loader for the completeness score from ["Beyond Concept Bottleneck Models: How to Make Black Boxes Intervenable?"](https://arxiv.org/abs/2401.13544).
39
+ - `ColorMNISTDataset`: A dataset loader for MNIST Even/Odd where colors act as confounders inspired from ["Explaining Classifiers with Causal Concept Effect (CaCE)"](https://arxiv.org/abs/1907.07165) and ["Interpretable Concept-Based Memory Reasoning"](https://arxiv.org/abs/2407.15527).
40
+ - `CelebA`: A dataset loader for CelebA dataset with attributes as concepts from ["Deep Learning Face Attributes in the Wild"](https://arxiv.org/abs/1411.7766) (ICCV 2015).
41
+
42
+ **Metrics** (`pyc.metrics`):
43
+
44
+ - `intervention_score`: A score measuring the effectiveness of concept interventions from ["Concept Bottleneck Models"](https://arxiv.org/pdf/2007.04612) (ICML 2020).
45
+ - `completeness_score`: A score measuring concept completeness from ["On Completeness-aware Concept-Based Explanations in Deep Neural Networks"](https://arxiv.org/abs/1910.07969) (NeurIPS 2020).
46
+ - `cace_score`: A score measuring causal concept effects (CaCE) from ["Explaining Classifiers with Causal Concept Effect (CaCE)"](https://arxiv.org/abs/1907.07165).
47
+
48
+ ## Contributing
49
+
50
+ - Use the `dev` branch to write and test your contributions locally.
51
+ - Make small commits and use ["Gitmoji"](https://gitmoji.dev/) to add emojis to your commit messages.
52
+ - Make sure to write documentation and tests for your contributions.
53
+ - Make sure all tests pass before submitting the pull request.
54
+ - Submit a pull request to the `main` branch.
55
+
56
+ ## PyC Book
57
+
58
+ You can find further reading materials and tutorials in our book [Concept-based Interpretable Deep Learning in Python](https://pyc-team.github.io/pyc-book/).
59
+
60
+ ## Authors
61
+
62
+ - [Pietro Barbiero](http://www.pietrobarbiero.eu/), Universita' della Svizzera Italiana (CH) and University of Cambridge (UK).
63
+ - [Gabriele Ciravegna](https://dbdmg.polito.it/dbdmg_web/gabriele-ciravegna/), Politecnico di Torino (IT).
64
+ - [David Debot](https://www.kuleuven.be/wieiswie/en/person/00165387), KU Leuven (BE).
65
+ - [Michelangelo Diligenti](https://docenti.unisi.it/en/diligenti), Università degli Studi di Siena (IT).
66
+ - [Gabriele Dominici](https://pc.inf.usi.ch/team/gabriele-dominici/), Universita' della Svizzera Italiana (CH).
67
+ - [Mateo Espinosa Zarlenga](https://hairyballtheorem.com/), University of Cambridge (UK).
68
+ - [Francesco Giannini](https://www.francescogiannini.eu/), Scuola Normale Superiore di Pisa (IT).
69
+ - [Giuseppe Marra](https://www.giuseppemarra.com/), KU Leuven (BE).
70
+
71
+ ## Licence
72
+
73
+ Copyright 2024 Pietro Barbiero, Gabriele Ciravegna, David Debot, Michelangelo Diligenti, Gabriele Dominici, Mateo Espinosa Zarlenga, Francesco Giannini, Giuseppe Marra.
74
+
75
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: <http://www.apache.org/licenses/LICENSE-2.0>.
76
+
77
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
+
79
+ See the License for the specific language governing permissions and limitations under the License.
80
+
81
+
82
+ ## Cite this library
83
+
84
+ If you found this library useful for your blog post, research article or product, we would be grateful if you would cite it like this:
85
+
86
+ ```
87
+ Barbiero P., Ciravegna G., Debot D., Diligenti M.,
88
+ Dominici G., Espinosa Zarlenga M., Giannini F., Marra G. (2024).
89
+ Concept-based Interpretable Deep Learning in Python.
90
+ https://pyc-team.github.io/pyc-book/intro.html
91
+ ```
92
+
93
+ Or use the following bibtex entry:
94
+
95
+ ```
96
+ @book{pycteam2024concept,
97
+ title = {Concept-based Interpretable Deep Learning in Python},
98
+ author = {Pietro Barbiero, Gabriele Ciravegna, David Debot, Michelangelo Diligenti, Gabriele Dominici, Mateo Espinosa Zarlenga, Francesco Giannini, Giuseppe Marra},
99
+ year = {2024},
100
+ url = {https://pyc-team.github.io/pyc-book/intro.html}
101
+ }
102
+ ```