mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Extend tagger and senter tests
So that they, like the other tests, also check that we get no activations if no activations were requested.
This commit is contained in:
		
							parent
							
								
									009a96085b
								
							
						
					
					
						commit
						c8a12c5d85
					
				|  | @ -115,12 +115,16 @@ def test_store_activations(): | ||||||
|         train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) |         train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) | ||||||
| 
 | 
 | ||||||
|     nlp.initialize(get_examples=lambda: train_examples) |     nlp.initialize(get_examples=lambda: train_examples) | ||||||
|  |     nO = senter.model.get_dim("nO") | ||||||
|  | 
 | ||||||
|  |     doc = nlp("This is a test.") | ||||||
|  |     assert len(list(doc.activations["senter"].keys())) == 0 | ||||||
| 
 | 
 | ||||||
|     senter.store_activations = True |     senter.store_activations = True | ||||||
|     doc = nlp("This is a test.") |     doc = nlp("This is a test.") | ||||||
|     assert "senter" in doc.activations |     assert "senter" in doc.activations | ||||||
|     assert set(doc.activations["senter"].keys()) == {"guesses", "probs"} |     assert set(doc.activations["senter"].keys()) == {"guesses", "probs"} | ||||||
|     assert doc.activations["senter"]["probs"].shape == (5, 2) |     assert doc.activations["senter"]["probs"].shape == (5, nO) | ||||||
|     assert doc.activations["senter"]["guesses"].shape == (5,) |     assert doc.activations["senter"]["guesses"].shape == (5,) | ||||||
| 
 | 
 | ||||||
|     senter.store_activations = ["probs"] |     senter.store_activations = ["probs"] | ||||||
|  |  | ||||||
|  | @ -222,6 +222,9 @@ def test_store_activations(): | ||||||
|         train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) |         train_examples.append(Example.from_dict(nlp.make_doc(t[0]), t[1])) | ||||||
|     nlp.initialize(get_examples=lambda: train_examples) |     nlp.initialize(get_examples=lambda: train_examples) | ||||||
| 
 | 
 | ||||||
|  |     doc = nlp("This is a test.") | ||||||
|  |     assert len(list(doc.activations["tagger"].keys())) == 0 | ||||||
|  | 
 | ||||||
|     tagger.store_activations = True |     tagger.store_activations = True | ||||||
|     doc = nlp("This is a test.") |     doc = nlp("This is a test.") | ||||||
|     assert "tagger" in doc.activations |     assert "tagger" in doc.activations | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user