|
11 | 11 |
|
12 | 12 |
|
13 | 13 | class TestNextWord: |
14 | | - @pytest.mark.parametrize('model_identifier, expected_next_word', [ |
15 | | - pytest.param('bert-base-uncased', '.', marks=pytest.mark.memory_intense), |
16 | | - pytest.param('gpt2-xl', 'jumps', marks=pytest.mark.memory_intense), |
17 | | - ('distilgpt2', 'es'), |
| 14 | + @pytest.mark.parametrize('model_identifier, expected_next_word, bidirectional', [ |
| 15 | + pytest.param('bert-base-uncased', 'and', True, marks=pytest.mark.memory_intense), |
| 16 | + pytest.param('bert-base-uncased', '.', False, marks=pytest.mark.memory_intense), |
| 17 | + pytest.param('gpt2-xl', 'jumps', False, marks=pytest.mark.memory_intense), |
| 18 | + ('distilgpt2', 'es', False), |
18 | 19 | ]) |
19 | | - def test_single_string(self, model_identifier, expected_next_word): |
| 20 | + def test_single_string(self, model_identifier, expected_next_word, bidirectional): |
20 | 21 | """ |
21 | 22 | This is a simple test that takes in text = 'the quick brown fox', and tests the next word. |
22 | 23 | This test is a stand-in prototype to check if our model definitions are correct. |
23 | 24 | """ |
24 | 25 |
|
25 | | - model = HuggingfaceSubject(model_id=model_identifier, region_layer_mapping={}) |
| 26 | + model = HuggingfaceSubject(model_id=model_identifier, region_layer_mapping={}, bidirectional=bidirectional) |
26 | 27 | text = 'the quick brown fox' |
27 | 28 | _logger.info(f'Running {model.identifier()} with text "{text}"') |
28 | 29 | model.start_behavioral_task(task=ArtificialSubject.Task.next_word) |
29 | 30 | next_word = model.digest_text(text)['behavior'].values |
30 | 31 | assert next_word == expected_next_word |
31 | 32 |
|
32 | | - @pytest.mark.parametrize('model_identifier, expected_next_words', [ |
33 | | - pytest.param('bert-base-uncased', ['.', '.', '.'], marks=pytest.mark.memory_intense), |
34 | | - pytest.param('gpt2-xl', ['jumps', 'the', 'dog'], marks=pytest.mark.memory_intense), |
35 | | - ('distilgpt2', ['es', 'the', 'fox']), |
| 33 | + @pytest.mark.parametrize('model_identifier, expected_next_words, bidirectional', [ |
| 34 | + pytest.param('bert-base-uncased', [';', 'the', 'water'], True, marks=pytest.mark.memory_intense), |
| 35 | + pytest.param('bert-base-uncased', ['.', '.', '.'], False, marks=pytest.mark.memory_intense), |
| 36 | + pytest.param('gpt2-xl', ['jumps', 'the', 'dog'], False, marks=pytest.mark.memory_intense), |
| 37 | + ('distilgpt2', ['es', 'the', 'fox'], False), |
36 | 38 | ]) |
37 | | - def test_list_input(self, model_identifier, expected_next_words): |
| 39 | + def test_list_input(self, model_identifier, expected_next_words, bidirectional): |
38 | 40 | """ |
39 | 41 | This is a simple test that takes in text = ['the quick brown fox', 'jumps over', 'the lazy'], and tests the |
40 | 42 | next word for each text part in the list. |
41 | 43 | This test is a stand-in prototype to check if our model definitions are correct. |
42 | 44 | """ |
43 | | - model = HuggingfaceSubject(model_id=model_identifier, region_layer_mapping={}) |
| 45 | + model = HuggingfaceSubject(model_id=model_identifier, region_layer_mapping={}, bidirectional=bidirectional) |
44 | 46 | text = ['the quick brown fox', 'jumps over', 'the lazy'] |
45 | 47 | _logger.info(f'Running {model.identifier()} with text "{text}"') |
46 | 48 | model.start_behavioral_task(task=ArtificialSubject.Task.next_word) |
@@ -173,6 +175,25 @@ def test_one_text_single_target(self): |
173 | 175 | assert len(representations['neuroid']) == 768 |
174 | 176 | _logger.info(f'representation shape is correct: {representations.shape}') |
175 | 177 |
|
| 178 | + @pytest.mark.memory_intense |
| 179 | + def test_one_text_single_target_bidirectional(self): |
| 180 | + """ |
| 181 | + This is a simple test that takes in text = 'the quick brown fox', and asserts that a bidirectiona BERT model |
| 182 | + layer indexed by `representation_layer` has 1 text presentation and 768 neurons. This test is a stand-in prototype |
| 183 | + to check if our model definitions are correct. |
| 184 | + """ |
| 185 | + model = HuggingfaceSubject(model_id='bert-base-uncased', region_layer_mapping={ |
| 186 | + ArtificialSubject.RecordingTarget.language_system: 'bert.encoder.layer.4'}) |
| 187 | + text = 'the quick brown fox' |
| 188 | + _logger.info(f'Running {model.identifier()} with text "{text}"') |
| 189 | + model.start_neural_recording(recording_target=ArtificialSubject.RecordingTarget.language_system, |
| 190 | + recording_type=ArtificialSubject.RecordingType.fMRI) |
| 191 | + representations = model.digest_text(text)['neural'] |
| 192 | + assert len(representations['presentation']) == 1 |
| 193 | + assert representations['stimulus'].squeeze() == text |
| 194 | + assert len(representations['neuroid']) == 768 |
| 195 | + _logger.info(f'representation shape is correct: {representations.shape}') |
| 196 | + |
176 | 197 | @pytest.mark.memory_intense |
177 | 198 | def test_one_text_two_targets(self): |
178 | 199 | model = HuggingfaceSubject(model_id='distilgpt2', region_layer_mapping={ |
|
0 commit comments