brainscore-language 2.1.0__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 (161) hide show
  1. brainscore_language-2.1.0/LICENSE +21 -0
  2. brainscore_language-2.1.0/PKG-INFO +87 -0
  3. brainscore_language-2.1.0/README.md +44 -0
  4. brainscore_language-2.1.0/brainscore_language/__init__.py +80 -0
  5. brainscore_language-2.1.0/brainscore_language/__main__.py +14 -0
  6. brainscore_language-2.1.0/brainscore_language/artificial_subject.py +140 -0
  7. brainscore_language-2.1.0/brainscore_language/benchmark_helpers/__init__.py +47 -0
  8. brainscore_language-2.1.0/brainscore_language/benchmarks/blank2014/__init__.py +4 -0
  9. brainscore_language-2.1.0/brainscore_language/benchmarks/blank2014/benchmark.py +50 -0
  10. brainscore_language-2.1.0/brainscore_language/benchmarks/blank2014/ceiling.py +204 -0
  11. brainscore_language-2.1.0/brainscore_language/benchmarks/blank2014/test.py +75 -0
  12. brainscore_language-2.1.0/brainscore_language/benchmarks/fedorenko2016/__init__.py +5 -0
  13. brainscore_language-2.1.0/brainscore_language/benchmarks/fedorenko2016/benchmark.py +56 -0
  14. brainscore_language-2.1.0/brainscore_language/benchmarks/futrell2018/__init__.py +4 -0
  15. brainscore_language-2.1.0/brainscore_language/benchmarks/futrell2018/__pycache__/__init__.cpython-311.pyc +0 -0
  16. brainscore_language-2.1.0/brainscore_language/benchmarks/futrell2018/__pycache__/benchmark.cpython-311.pyc +0 -0
  17. brainscore_language-2.1.0/brainscore_language/benchmarks/futrell2018/benchmark.py +90 -0
  18. brainscore_language-2.1.0/brainscore_language/benchmarks/futrell2018/test.py +43 -0
  19. brainscore_language-2.1.0/brainscore_language/benchmarks/pereira2018/__init__.py +5 -0
  20. brainscore_language-2.1.0/brainscore_language/benchmarks/pereira2018/benchmark.py +101 -0
  21. brainscore_language-2.1.0/brainscore_language/benchmarks/pereira2018/ceiling_packaging.py +268 -0
  22. brainscore_language-2.1.0/brainscore_language/benchmarks/pereira2018/test.py +88 -0
  23. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/README.md +79 -0
  24. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/__init__.py +71 -0
  25. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/benchmark.py +172 -0
  26. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/gpt2_precomputed.py +1131 -0
  27. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/requirements.txt +2 -0
  28. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/sg_prediction.py +234 -0
  29. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/sg_suite.py +192 -0
  30. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/center_embed.json +2014 -0
  31. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/center_embed_mod.json +2239 -0
  32. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/cleft.json +4865 -0
  33. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/cleft_modifier.json +5506 -0
  34. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/fgd_hierarchy.json +6056 -0
  35. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/fgd_object.json +3699 -0
  36. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/fgd_pp.json +3699 -0
  37. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/fgd_subject.json +3699 -0
  38. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/mvrr.json +3413 -0
  39. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/mvrr_mod.json +3862 -0
  40. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npi_orc_any.json +6450 -0
  41. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npi_orc_ever.json +6450 -0
  42. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npi_src_any.json +6450 -0
  43. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npi_src_ever.json +6450 -0
  44. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npz_ambig.json +2929 -0
  45. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npz_ambig_mod.json +3314 -0
  46. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npz_obj.json +2929 -0
  47. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/npz_obj_mod.json +3314 -0
  48. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/number_orc.json +2934 -0
  49. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/number_prep.json +2629 -0
  50. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/number_src.json +2934 -0
  51. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_orc_fem.json +2934 -0
  52. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_orc_masc.json +2934 -0
  53. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_prep_fem.json +2629 -0
  54. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_prep_masc.json +2629 -0
  55. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_src_fem.json +2934 -0
  56. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/reflexive_src_masc.json +2934 -0
  57. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/subordination.json +1701 -0
  58. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/subordination_orc-orc.json +2439 -0
  59. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/subordination_pp-pp.json +2439 -0
  60. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/suites/syntaxgym-2020/subordination_src-src.json +2439 -0
  61. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/test.py +94 -0
  62. brainscore_language-2.1.0/brainscore_language/benchmarks/syntaxgym/test_suites.json +33 -0
  63. brainscore_language-2.1.0/brainscore_language/benchmarks/tuckute2024/__init__.py +7 -0
  64. brainscore_language-2.1.0/brainscore_language/benchmarks/tuckute2024/benchmark.py +57 -0
  65. brainscore_language-2.1.0/brainscore_language/benchmarks/wikitext_next_word/__init__.py +4 -0
  66. brainscore_language-2.1.0/brainscore_language/benchmarks/wikitext_next_word/benchmark.py +65 -0
  67. brainscore_language-2.1.0/brainscore_language/benchmarks/wikitext_next_word/test.py +25 -0
  68. brainscore_language-2.1.0/brainscore_language/data/blank2014/__init__.py +22 -0
  69. brainscore_language-2.1.0/brainscore_language/data/blank2014/data_packaging.py +508 -0
  70. brainscore_language-2.1.0/brainscore_language/data/blank2014/test.py +28 -0
  71. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/__init__.py +34 -0
  72. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run1_stim_set1.csv +49 -0
  73. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run1_stim_set2.csv +49 -0
  74. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run1_stim_set3.csv +49 -0
  75. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run1_stim_set4.csv +49 -0
  76. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run1_stim_set5.csv +49 -0
  77. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run2_stim_set1.csv +49 -0
  78. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run2_stim_set2.csv +49 -0
  79. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run2_stim_set3.csv +49 -0
  80. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run2_stim_set4.csv +49 -0
  81. brainscore_language-2.1.0/brainscore_language/data/fedorenko2010_localization/langloc_fmri_run2_stim_set5.csv +49 -0
  82. brainscore_language-2.1.0/brainscore_language/data/fedorenko2016/__init__.py +23 -0
  83. brainscore_language-2.1.0/brainscore_language/data/fedorenko2016/data_packaging.py +114 -0
  84. brainscore_language-2.1.0/brainscore_language/data/fedorenko2016/test.py +14 -0
  85. brainscore_language-2.1.0/brainscore_language/data/futrell2018/__init__.py +27 -0
  86. brainscore_language-2.1.0/brainscore_language/data/futrell2018/__pycache__/__init__.cpython-311.pyc +0 -0
  87. brainscore_language-2.1.0/brainscore_language/data/futrell2018/data_packaging.py +133 -0
  88. brainscore_language-2.1.0/brainscore_language/data/futrell2018/test.py +19 -0
  89. brainscore_language-2.1.0/brainscore_language/data/pereira2018/__init__.py +27 -0
  90. brainscore_language-2.1.0/brainscore_language/data/pereira2018/data_packaging.py +171 -0
  91. brainscore_language-2.1.0/brainscore_language/data/pereira2018/test.py +26 -0
  92. brainscore_language-2.1.0/brainscore_language/data/tuckute2024/__init__.py +18 -0
  93. brainscore_language-2.1.0/brainscore_language/data/tuckute2024/data_packaging.py +138 -0
  94. brainscore_language-2.1.0/brainscore_language/data/tuckute2024/test.py +24 -0
  95. brainscore_language-2.1.0/brainscore_language/data/wikitext/__init__.py +12 -0
  96. brainscore_language-2.1.0/brainscore_language/data/wikitext/requirements.txt +1 -0
  97. brainscore_language-2.1.0/brainscore_language/data/wikitext/test.py +11 -0
  98. brainscore_language-2.1.0/brainscore_language/metrics/accuracy/__init__.py +4 -0
  99. brainscore_language-2.1.0/brainscore_language/metrics/accuracy/metric.py +15 -0
  100. brainscore_language-2.1.0/brainscore_language/metrics/accuracy/test.py +23 -0
  101. brainscore_language-2.1.0/brainscore_language/metrics/cka/__init__.py +4 -0
  102. brainscore_language-2.1.0/brainscore_language/metrics/cka/metric.py +111 -0
  103. brainscore_language-2.1.0/brainscore_language/metrics/linear_predictivity/__init__.py +5 -0
  104. brainscore_language-2.1.0/brainscore_language/metrics/linear_predictivity/metric.py +184 -0
  105. brainscore_language-2.1.0/brainscore_language/metrics/linear_predictivity/requirements.txt +1 -0
  106. brainscore_language-2.1.0/brainscore_language/metrics/linear_predictivity/test.py +62 -0
  107. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/__init__.py +4 -0
  108. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/__pycache__/__init__.cpython-311.pyc +0 -0
  109. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/__pycache__/metric.cpython-311.pyc +0 -0
  110. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/metric.py +18 -0
  111. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/requirements.txt +1 -0
  112. brainscore_language-2.1.0/brainscore_language/metrics/pearson_correlation/test.py +26 -0
  113. brainscore_language-2.1.0/brainscore_language/metrics/rdm/__init__.py +13 -0
  114. brainscore_language-2.1.0/brainscore_language/metrics/rdm/metric.py +106 -0
  115. brainscore_language-2.1.0/brainscore_language/model_helpers/__init__.py +1 -0
  116. brainscore_language-2.1.0/brainscore_language/model_helpers/container.py +329 -0
  117. brainscore_language-2.1.0/brainscore_language/model_helpers/embedding.py +132 -0
  118. brainscore_language-2.1.0/brainscore_language/model_helpers/huggingface.py +326 -0
  119. brainscore_language-2.1.0/brainscore_language/model_helpers/localize.py +171 -0
  120. brainscore_language-2.1.0/brainscore_language/model_helpers/modeling_suma.py +1176 -0
  121. brainscore_language-2.1.0/brainscore_language/model_helpers/preprocessing.py +24 -0
  122. brainscore_language-2.1.0/brainscore_language/models/earley_parser/__init__.py +4 -0
  123. brainscore_language-2.1.0/brainscore_language/models/earley_parser/parser.py +322 -0
  124. brainscore_language-2.1.0/brainscore_language/models/earley_parser/requirements.txt +1 -0
  125. brainscore_language-2.1.0/brainscore_language/models/earley_parser/test.py +267 -0
  126. brainscore_language-2.1.0/brainscore_language/models/earley_parser/treebank/sample_treebank +11 -0
  127. brainscore_language-2.1.0/brainscore_language/models/earley_parser/utils.py +162 -0
  128. brainscore_language-2.1.0/brainscore_language/models/glove/__init__.py +4 -0
  129. brainscore_language-2.1.0/brainscore_language/models/glove/model.py +38 -0
  130. brainscore_language-2.1.0/brainscore_language/models/glove/test.py +19 -0
  131. brainscore_language-2.1.0/brainscore_language/models/gpt/__init__.py +33 -0
  132. brainscore_language-2.1.0/brainscore_language/models/gpt/__pycache__/__init__.cpython-311.pyc +0 -0
  133. brainscore_language-2.1.0/brainscore_language/models/gpt/test.py +77 -0
  134. brainscore_language-2.1.0/brainscore_language/models/lm1b/__init__.py +406 -0
  135. brainscore_language-2.1.0/brainscore_language/models/lm1b/data_utils.py +152 -0
  136. brainscore_language-2.1.0/brainscore_language/models/lm1b/requirements.txt +1 -0
  137. brainscore_language-2.1.0/brainscore_language/models/lm1b/test.py +67 -0
  138. brainscore_language-2.1.0/brainscore_language/models/random_embedding/__init__.py +35 -0
  139. brainscore_language-2.1.0/brainscore_language/models/random_embedding/test.py +52 -0
  140. brainscore_language-2.1.0/brainscore_language/models/rnng/__init__.py +63 -0
  141. brainscore_language-2.1.0/brainscore_language/models/rnng/test.py +30 -0
  142. brainscore_language-2.1.0/brainscore_language/models/rnnlm/__init__.py +12 -0
  143. brainscore_language-2.1.0/brainscore_language/models/rnnlm/test.py +58 -0
  144. brainscore_language-2.1.0/brainscore_language/models/suma/__init__.py +30 -0
  145. brainscore_language-2.1.0/brainscore_language/submission/__init__.py +0 -0
  146. brainscore_language-2.1.0/brainscore_language/submission/config.py +7 -0
  147. brainscore_language-2.1.0/brainscore_language/submission/endpoints.py +59 -0
  148. brainscore_language-2.1.0/brainscore_language/utils/__init__.py +17 -0
  149. brainscore_language-2.1.0/brainscore_language/utils/ceiling.py +17 -0
  150. brainscore_language-2.1.0/brainscore_language/utils/s3.py +42 -0
  151. brainscore_language-2.1.0/brainscore_language/utils/transformations.py +248 -0
  152. brainscore_language-2.1.0/brainscore_language/utils/xarray.py +54 -0
  153. brainscore_language-2.1.0/brainscore_language.egg-info/PKG-INFO +87 -0
  154. brainscore_language-2.1.0/brainscore_language.egg-info/SOURCES.txt +159 -0
  155. brainscore_language-2.1.0/brainscore_language.egg-info/dependency_links.txt +1 -0
  156. brainscore_language-2.1.0/brainscore_language.egg-info/requires.txt +14 -0
  157. brainscore_language-2.1.0/brainscore_language.egg-info/top_level.txt +1 -0
  158. brainscore_language-2.1.0/pyproject.toml +77 -0
  159. brainscore_language-2.1.0/setup.cfg +4 -0
  160. brainscore_language-2.1.0/tests/test___init__.py +3 -0
  161. brainscore_language-2.1.0/tests/test_integration.py +101 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 language-brainscore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.4
2
+ Name: brainscore_language
3
+ Version: 2.1.0
4
+ License: MIT License
5
+
6
+ Copyright (c) 2021 language-brainscore
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+
26
+ Requires-Python: >=3.11
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: tqdm
30
+ Requires-Dist: numpy>=1.21
31
+ Requires-Dist: brainscore-core
32
+ Requires-Dist: fire
33
+ Requires-Dist: scikit-learn
34
+ Requires-Dist: torch>=1.9.1
35
+ Requires-Dist: transformers>=4.11.3
36
+ Requires-Dist: gensim
37
+ Requires-Dist: joblib
38
+ Requires-Dist: requests
39
+ Provides-Extra: test
40
+ Requires-Dist: pytest; extra == "test"
41
+ Requires-Dist: pytest-check<=1.3.0; extra == "test"
42
+ Dynamic: license-file
43
+
44
+ [![Build Status](https://app.travis-ci.com/brain-score/language.svg?token=vqt7d2yhhpLGwHsiTZvT&branch=main)](https://app.travis-ci.com/brain-score/language)
45
+ [![Documentation Status](https://readthedocs.org/projects/brain-score-language/badge/?version=latest)](https://brain-score-language.readthedocs.io/en/latest/?badge=latest)
46
+ [![Website Status](https://img.shields.io/website.svg?down_color=red&down_message=offline&up_message=online&url=http%3A%2F%2Fwww.brain-score.org/language)](http://www.brain-score.org/language/)
47
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
48
+
49
+ Brain-Score Language is a platform to evaluate computational models of language on their match to behavioral and neural
50
+ measurements in the domain of language processing. The intent of Brain-Score is to adopt many (ideally all) the
51
+ experimental benchmarks in the field for the purpose of model testing, falsification, and comparison. To that end,
52
+ Brain-Score operationalizes experimental data into quantitative benchmarks that any model candidate following
53
+ the `BrainModel` interface can be scored on.
54
+
55
+ See the [Documentation](https://brain-score-language.readthedocs.io) for more details.
56
+
57
+ Brain-Score is made by and for the community. To contribute,
58
+ please [send in a pull request](https://github.com/brain-score/language/pulls).
59
+
60
+ ## Alpha status
61
+ This repository is under active development, and should be considered to be in an alpha status.
62
+ Code is likely to change substantially, without backwards compatibility.
63
+ Please let us know of any problems by [creating an issue](https://github.com/brain-score/language/issues/new).
64
+
65
+ ## Setup
66
+
67
+ ```bash
68
+ python -m pip install -e "." # change "." to ".[test]" to include testing dependencies
69
+ ```
70
+
71
+ Please note that plugins (models, benchmarks, data, and metrics) may require additional dependencies beyond those installed here. Default behavior will install these dependencies directly into the runtime environment.
72
+
73
+ To avoid conflicts, we encourage either using an environment manager or setting the `BS_INSTALL_DEPENDENCIES` environment variable to either `no` or `newenv` (e.g. `export BS_INSTALL_DEPENDENCIES=newenv`).
74
+
75
+ `no` will leave all dependency installation up to the user, whereas `newenv` will create a new `conda` environment for the duration of the run. If you would like to use the `newenv` option and do not already have `conda` installed, you can follow the installation instructions [here](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html).
76
+
77
+ ## Usage
78
+
79
+ Score an existing model on an existing benchmark:
80
+
81
+ ```bash
82
+ python brainscore_language score --model_identifier='distilgpt2' --benchmark_identifier='Futrell2018-pearsonr'
83
+ ```
84
+
85
+ ## License
86
+
87
+ MIT license
@@ -0,0 +1,44 @@
1
+ [![Build Status](https://app.travis-ci.com/brain-score/language.svg?token=vqt7d2yhhpLGwHsiTZvT&branch=main)](https://app.travis-ci.com/brain-score/language)
2
+ [![Documentation Status](https://readthedocs.org/projects/brain-score-language/badge/?version=latest)](https://brain-score-language.readthedocs.io/en/latest/?badge=latest)
3
+ [![Website Status](https://img.shields.io/website.svg?down_color=red&down_message=offline&up_message=online&url=http%3A%2F%2Fwww.brain-score.org/language)](http://www.brain-score.org/language/)
4
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
5
+
6
+ Brain-Score Language is a platform to evaluate computational models of language on their match to behavioral and neural
7
+ measurements in the domain of language processing. The intent of Brain-Score is to adopt many (ideally all) the
8
+ experimental benchmarks in the field for the purpose of model testing, falsification, and comparison. To that end,
9
+ Brain-Score operationalizes experimental data into quantitative benchmarks that any model candidate following
10
+ the `BrainModel` interface can be scored on.
11
+
12
+ See the [Documentation](https://brain-score-language.readthedocs.io) for more details.
13
+
14
+ Brain-Score is made by and for the community. To contribute,
15
+ please [send in a pull request](https://github.com/brain-score/language/pulls).
16
+
17
+ ## Alpha status
18
+ This repository is under active development, and should be considered to be in an alpha status.
19
+ Code is likely to change substantially, without backwards compatibility.
20
+ Please let us know of any problems by [creating an issue](https://github.com/brain-score/language/issues/new).
21
+
22
+ ## Setup
23
+
24
+ ```bash
25
+ python -m pip install -e "." # change "." to ".[test]" to include testing dependencies
26
+ ```
27
+
28
+ Please note that plugins (models, benchmarks, data, and metrics) may require additional dependencies beyond those installed here. Default behavior will install these dependencies directly into the runtime environment.
29
+
30
+ To avoid conflicts, we encourage either using an environment manager or setting the `BS_INSTALL_DEPENDENCIES` environment variable to either `no` or `newenv` (e.g. `export BS_INSTALL_DEPENDENCIES=newenv`).
31
+
32
+ `no` will leave all dependency installation up to the user, whereas `newenv` will create a new `conda` environment for the duration of the run. If you would like to use the `newenv` option and do not already have `conda` installed, you can follow the installation instructions [here](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html).
33
+
34
+ ## Usage
35
+
36
+ Score an existing model on an existing benchmark:
37
+
38
+ ```bash
39
+ python brainscore_language score --model_identifier='distilgpt2' --benchmark_identifier='Futrell2018-pearsonr'
40
+ ```
41
+
42
+ ## License
43
+
44
+ MIT license
@@ -0,0 +1,80 @@
1
+ from typing import Dict, Any, Union, Callable
2
+
3
+ from brainio.assemblies import DataAssembly
4
+ from brainscore_core.benchmarks import Benchmark
5
+ from brainscore_core.metrics import Score, Metric
6
+ from brainscore_core.plugin_management.conda_score import wrap_score
7
+ from brainscore_core.plugin_management.import_plugin import import_plugin
8
+ from brainscore_language.artificial_subject import ArtificialSubject
9
+
10
+ data_registry: Dict[str, Callable[[], Union[DataAssembly, Any]]] = {}
11
+ """ Pool of available data """
12
+
13
+ metric_registry: Dict[str, Callable[[], Metric]] = {}
14
+ """ Pool of available metrics """
15
+
16
+ benchmark_registry: Dict[str, Callable[[], Benchmark]] = {}
17
+ """ Pool of available benchmarks """
18
+
19
+ model_registry: Dict[str, Callable[[], ArtificialSubject]] = {}
20
+ """ Pool of available models """
21
+
22
+
23
+ def load_dataset(identifier: str) -> Union[DataAssembly, Any]:
24
+ import_plugin('brainscore_language', 'data', identifier)
25
+
26
+ return data_registry[identifier]()
27
+
28
+
29
+ def load_metric(identifier: str, *args, **kwargs) -> Metric:
30
+ import_plugin('brainscore_language', 'metrics', identifier)
31
+
32
+ return metric_registry[identifier](*args, **kwargs)
33
+
34
+
35
+ def load_benchmark(identifier: str) -> Benchmark:
36
+ import_plugin('brainscore_language', 'benchmarks', identifier)
37
+
38
+ return benchmark_registry[identifier]()
39
+
40
+
41
+ def load_model(identifier: str) -> ArtificialSubject:
42
+ import_plugin('brainscore_language', 'models', identifier)
43
+
44
+ model = model_registry[identifier]()
45
+ model.identifier = identifier
46
+
47
+ return model
48
+
49
+ def _run_score(model_identifier: str, benchmark_identifier: str) -> Score:
50
+ """
51
+ Score the model referenced by the `model_identifier` on the benchmark referenced by the `benchmark_identifier`.
52
+ """
53
+ model: ArtificialSubject = load_model(model_identifier)
54
+ benchmark: Benchmark = load_benchmark(benchmark_identifier)
55
+ score: Score = benchmark(model)
56
+ score.attrs['model_identifier'] = model_identifier
57
+ score.attrs['benchmark_identifier'] = benchmark_identifier
58
+ return score
59
+
60
+
61
+ def score(model_identifier: str, benchmark_identifier: str, conda_active: bool=False) -> Score:
62
+ """
63
+ Score the model referenced by the `model_identifier` on the benchmark referenced by the `benchmark_identifier`.
64
+ The model needs to implement the :class:`~brainscore_language.artificial_subject.ArtificialSubject` interface
65
+ so that the benchmark can interact with it.
66
+ The benchmark will be looked up from the :data:`~brainscore_language.benchmarks` and evaluates the model
67
+ (looked up from :data:`~brainscore_language.models`) on how brain-like it is under that benchmark's
68
+ experimental paradigm, primate measurements, comparison metric, and ceiling.
69
+ This results in a quantitative
70
+ `Score <https://brain-score-core.readthedocs.io/en/latest/modules/metrics.html#brainscore_core.metrics.Score>`_
71
+ ranging from 0 (least brain-like) to 1 (most brain-like under this benchmark).
72
+
73
+ :param model_identifier: the identifier for the model
74
+ :param benchmark_identifier: the identifier for the benchmark to test the model against
75
+ :return: a Score of how brain-like the candidate model is under this benchmark. The score is normalized by
76
+ this benchmark's ceiling such that 1 means the model matches the data to ceiling level.
77
+ """
78
+ return wrap_score(__file__,
79
+ model_identifier=model_identifier, benchmark_identifier=benchmark_identifier,
80
+ score_function=_run_score, conda_active=conda_active)
@@ -0,0 +1,14 @@
1
+ from pathlib import Path
2
+
3
+ import fire
4
+
5
+ from brainscore_language import score as _score_function
6
+
7
+
8
+ def score(model_identifier: str, benchmark_identifier: str, conda_active: bool=False):
9
+ result = _score_function(model_identifier, benchmark_identifier, conda_active)
10
+ print(result) # print instead of return because fire has issues with xarray objects
11
+
12
+
13
+ if __name__ == '__main__':
14
+ fire.Fire()
@@ -0,0 +1,140 @@
1
+ from typing import Dict, List, Union
2
+
3
+ from brainio.assemblies import DataAssembly
4
+
5
+
6
+ class ArtificialSubject:
7
+ def identifier(self) -> str:
8
+ """
9
+ The unique identifier for this model.
10
+
11
+ :return: e.g. `'glove'`, or `'distilgpt2'`
12
+ """
13
+ raise NotImplementedError()
14
+
15
+ class Task:
16
+ """ task to perform """
17
+ # ideally we would define these as enums (also for RecordingTarget and RecordingType)
18
+ # but accessing enums gives weird Enum objects whereas this setup just gives a string
19
+
20
+ next_word = 'next_word'
21
+ """
22
+ Predict the next word from the preceding context. Output a :class:`~brainio.assemblies.BehavioralAssembly` with
23
+ next-word predictions as the values and preceding stimulus in the `stimulus` coordinate.
24
+
25
+ Example:
26
+
27
+ Calling `digest_text(text = 'the quick brown')` could output
28
+
29
+ .. code-block:: python
30
+
31
+ {'behavior': <xarray.BehavioralAssembly (presentation: 1)>
32
+ array(['fox']), # the actual next word
33
+ Coordinates:
34
+ * presentation (presentation) MultiIndex
35
+ - stimulus (presentation) object 'the quick brown'
36
+ - stimulus_id (presentation) int64 0}
37
+
38
+ Example:
39
+
40
+ Calling `digest_text(text = ['the quick brown', 'fox jumps', 'over the lazy'])` could output
41
+
42
+ .. code-block:: python
43
+
44
+ {'behavior': <xarray.BehavioralAssembly (presentation: 3)>
45
+ array(['fox', 'over', 'dog']), # the actual next words
46
+ Coordinates:
47
+ * presentation (presentation) MultiIndex
48
+ - stimulus (presentation) object 'the quick brown' 'fox jumps', 'over the lazy'
49
+ - stimulus_id (presentation) int64 0 1 2}
50
+ """
51
+
52
+ reading_times = 'reading_times'
53
+ """
54
+ Output how long it took to read a given text, in milliseconds.
55
+ Output a :class:`~brainio.assemblies.BehavioralAssembly` with reading times in milliseconds as the values and
56
+ text in the `stimulus` coordinate.
57
+
58
+ Example:
59
+
60
+ Calling `digest_text(text = 'the quick brown')` could output
61
+
62
+ .. code-block:: python
63
+
64
+ {'behavior': <xarray.BehavioralAssembly (presentation: 1)>
65
+ array([329.15]), # reading time in milliseconds
66
+ Coordinates:
67
+ * presentation (presentation) MultiIndex
68
+ - stimulus (presentation) object 'the quick brown'
69
+ - stimulus_id (presentation) int64 0}
70
+
71
+ Example:
72
+
73
+ Calling `digest_text(text = ['the quick brown', 'fox jumps', 'over the lazy'])` could output
74
+
75
+ .. code-block:: python
76
+
77
+ {'behavior': <xarray.BehavioralAssembly (presentation: 3)>
78
+ array([329.15, 337.53, 341.13]), # reading times in milliseconds
79
+ Coordinates:
80
+ * presentation (presentation) MultiIndex
81
+ - stimulus (presentation) object 'the quick brown' 'fox jumps', 'over the lazy'
82
+ - stimulus_id (presentation) int64 0 1 2}
83
+ """
84
+
85
+ def start_behavioral_task(self, task: Task):
86
+ """
87
+ Instruct the subject to output behavior when queried with
88
+ :meth:`~brainscore_language.artificial_subject.ArtificialSubject.digest_text`. Calling
89
+ :meth:`~brainscore_language.artificial_subject.ArtificialSubject.digest_text` will then output a
90
+ :class:`~brainio.assemblies.BehavioralAssembly` in the `'behavior'` part of the output dict.
91
+
92
+ :param task: Which :class:`~brainscore_language.artificial_subject.ArtificialSubject.Task` to use.
93
+ """
94
+ raise NotImplementedError()
95
+
96
+ class RecordingTarget:
97
+ """ location to record from """
98
+ language_system = "language_system"
99
+ language_system_left_hemisphere = "language_system_left_hemisphere"
100
+ language_system_right_hemisphere = "language_system_right_hemisphere"
101
+
102
+ class RecordingType:
103
+ """ method of recording """
104
+
105
+ fMRI = "fMRI"
106
+ """ functional magnetic resonance imaging """
107
+ ECoG = "ECoG"
108
+ """ Electrocorticography """
109
+
110
+ def start_neural_recording(self, recording_target: RecordingTarget, recording_type: RecordingType):
111
+ """
112
+ Begin neural recordings from this subject. Calling
113
+ :meth:`~brainscore_language.artificial_subject.ArtificialSubject.digest_text` will then output a
114
+ :class:`~brainio.assemblies.NeuroidAssembly` in the `'neural'` part of the output dict.
115
+
116
+ :param recording_target: where in the language-involved parts of the brain to record from.
117
+ :param recording_type: What recording method should be used.
118
+ """
119
+ raise NotImplementedError()
120
+
121
+ def digest_text(self, text: Union[str, List[str]]) -> Dict[str, DataAssembly]:
122
+ """
123
+ :param text: text to pass to the subject, either a single string (e.g. `"the quick brown fox jumped"`),
124
+ or a list of strings (e.g. `["the quick", "brown fox jumped"]`)
125
+ :return: a dictionary mapping from `'behavior'` and `'neural'` to a :class:`~brainio.assemblies.DataAssembly`,
126
+ if the subject was instructed to
127
+ :meth:`~brainscore_language.artificial_subject.ArtificialSubject.start_behavioral_task` and/or
128
+ :meth:`~brainscore_language.artificial_subject.ArtificialSubject.start_neural_recording` respectively.
129
+ The :class:`~brainio.assemblies.DataAssembly` always contains a `presentation` dimension, corresponding to
130
+ the presentation of text stimuli (including a `stimulus` coordinate for the text,
131
+ and a `stimulus_id` coordinate that uniquely identifies each stimulus).
132
+ Values along the `presentation` dimension are ordered in the same way as the input.
133
+ The `behavior` output has no other dimension, while the `neural` output has a `neuroid` dimension
134
+ (including a `neuroid_id` coordinate to uniquely identify each recording unit), and sometimes a
135
+ `time_bin` dimension (including `time_bin_start` and `time_bin_end`).
136
+ Note that model state is not saved between every time that `digest_text` is called. For keeping states,
137
+ between different inputs, `text` should be a list.
138
+
139
+ """
140
+ raise NotImplementedError()
@@ -0,0 +1,47 @@
1
+ import numpy as np
2
+ from typing import List
3
+
4
+ from brainio.assemblies import walk_coords, array_is_element, DataAssembly
5
+
6
+
7
+ def ci_error(samples, center, confidence=.95):
8
+ low, high = 100 * ((1 - confidence) / 2), 100 * (1 - ((1 - confidence) / 2))
9
+ confidence_below, confidence_above = np.nanpercentile(samples, low), np.nanpercentile(samples, high)
10
+ confidence_below, confidence_above = center - confidence_below, confidence_above - center
11
+ return confidence_below, confidence_above
12
+
13
+
14
+ def manual_merge(*elements: List[DataAssembly], on='neuroid') -> DataAssembly:
15
+ """
16
+ Manually merge a set of assemblies where xarray's automated merge might fail.
17
+ This function likely covers only covers a small number of use-cases, and should thus be used with caution.
18
+ """
19
+ dims = elements[0].dims
20
+ assert all(element.dims == dims for element in elements[1:])
21
+ merge_index = dims.index(on)
22
+ # the coordinates in the merge index should have the same keys
23
+ assert _coords_match(elements, dim=on,
24
+ match_values=False), f"coords in {[element[on] for element in elements]} do not match"
25
+ # all other dimensions, their coordinates and values should already align
26
+ for dim in set(dims) - {on}:
27
+ assert _coords_match(elements, dim=dim,
28
+ match_values=True), f"coords in {[element[dim] for element in elements]} do not match"
29
+ # merge values without meta
30
+ merged_values = np.concatenate([element.values for element in elements], axis=merge_index)
31
+ # piece together with meta
32
+ result = type(elements[0])(merged_values, coords={
33
+ **{coord: (dims, values)
34
+ for coord, dims, values in walk_coords(elements[0])
35
+ if not array_is_element(dims, on)},
36
+ **{coord: (dims, np.concatenate([element[coord].values for element in elements]))
37
+ for coord, dims, _ in walk_coords(elements[0])
38
+ if array_is_element(dims, on)}}, dims=elements[0].dims)
39
+ return result
40
+
41
+
42
+ def _coords_match(elements, dim, match_values=False):
43
+ """ Helper method for `manual_merge` """
44
+ first_coords = [(key, tuple(value)) if match_values else key for _, key, value in walk_coords(elements[0][dim])]
45
+ other_coords = [[(key, tuple(value)) if match_values else key for _, key, value in walk_coords(element[dim])]
46
+ for element in elements[1:]]
47
+ return all(tuple(first_coords) == tuple(coords) for coords in other_coords)
@@ -0,0 +1,4 @@
1
+ from brainscore_language import benchmark_registry
2
+ from .benchmark import Blank2014Linear
3
+
4
+ benchmark_registry['Blank2014-linear'] = Blank2014Linear
@@ -0,0 +1,50 @@
1
+ import xarray as xr
2
+
3
+ from brainscore_core.benchmarks import BenchmarkBase
4
+ from brainscore_core.metrics import Score
5
+ from brainscore_language import load_dataset, load_metric
6
+ from brainscore_language.artificial_subject import ArtificialSubject
7
+ from brainscore_language.benchmarks.blank2014.ceiling import ExtrapolationCeiling
8
+ from brainscore_language.data.blank2014 import BIBTEX
9
+ from brainscore_language.utils.ceiling import ceiling_normalize
10
+
11
+
12
+ class Blank2014Linear(BenchmarkBase):
13
+ """
14
+ Evaluate model ability to predict neural activity in human language system functional regions of interest (fROIs)
15
+ in response to natural stories, recorded by Blank et al. 2014.
16
+ Alignment of neural activity between model and human subjects is evaluated via cross-validated linear predictivity.
17
+
18
+ This benchmark builds off the Blank2014 benchmark introduced in Schrimpf et al. 2021
19
+ (https://www.pnas.org/doi/10.1073/pnas.2105646118), but requires the model to have committed to neural readouts
20
+ (e.g. "layer 41 corresponds to the language system"), rather than testing every layer separately.
21
+ """
22
+
23
+ def __init__(self):
24
+ self.data = load_dataset('Blank2014.fROI')
25
+ self.metric = load_metric('linear_pearsonr')
26
+ ceiler = ExtrapolationCeiling()
27
+ ceiling = ceiler(assembly=self.data, metric=self.metric)
28
+ super(Blank2014Linear, self).__init__(
29
+ identifier='Blank2014-linear',
30
+ version=1,
31
+ parent='neural_language',
32
+ ceiling=ceiling,
33
+ bibtex=BIBTEX)
34
+
35
+ def __call__(self, candidate: ArtificialSubject) -> Score:
36
+ candidate.start_neural_recording(recording_target=ArtificialSubject.RecordingTarget.language_system,
37
+ recording_type=ArtificialSubject.RecordingType.fMRI)
38
+ stimuli = self.data['stimulus']
39
+ stories = self.data['story'].values
40
+ predictions = []
41
+ for story in sorted(set(stories)): # go over individual stories, sorting to keep consistency across runs
42
+ story_indexer = [stimulus_story == story for stimulus_story in stories]
43
+ story_stimuli = stimuli[story_indexer]
44
+ story_predictions = candidate.digest_text(story_stimuli.values)['neural']
45
+ story_predictions['stimulus_id'] = 'presentation', story_stimuli['stimulus_id'].values
46
+ predictions.append(story_predictions)
47
+ predictions = xr.concat(predictions, dim='presentation')
48
+ raw_score = self.metric(predictions, self.data)
49
+ score = ceiling_normalize(raw_score, self.ceiling)
50
+ return score