Fix more BasicTextFieldEmbedder warnings
@@ -18,6 +18,7 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
self.vocab.add_token_to_namespace("3")
self.vocab.add_token_to_namespace("4")
params = Params({
+ "token_embedders": {
"words1": {
"type": "embedding",
"embedding_dim": 2
@@ -30,6 +31,7 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
"type": "embedding",
"embedding_dim": 3
}
+ }
})
self.token_embedder = BasicTextFieldEmbedder.from_params(vocab=self.vocab, params=params)
self.inputs = {
@@ -54,6 +56,7 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
def test_forward_works_on_higher_order_input(self):
params = Params({
+ "token_embedders": {
"words": {
"type": "embedding",
"num_embeddings": 20,
@@ -72,6 +75,7 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
"ngram_filter_sizes": [3],
},
}
+ }
})
token_embedder = BasicTextFieldEmbedder.from_params(vocab=self.vocab, params=params)
inputs = {
@@ -105,7 +109,6 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
token_embedder(inputs)
def test_old_from_params_new_from_params(self):
-
old_params = Params({
"words1": {
"type": "embedding",
@@ -121,8 +124,9 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
}
})
+ # Allow loading the parameters in the old format
with pytest.warns(DeprecationWarning):
- BasicTextFieldEmbedder.from_params(params=old_params, vocab=self.vocab)
+ old_embedder = BasicTextFieldEmbedder.from_params(params=old_params, vocab=self.vocab)
new_params = Params({
"token_embedders": {
@@ -141,5 +145,8 @@ class TestBasicTextFieldEmbedder(AllenNlpTestCase):
}
})
- token_embedder = BasicTextFieldEmbedder.from_params(params=new_params, vocab=self.vocab)
- assert token_embedder(self.inputs).size() == (1, 4, 10)
+ # But also allow loading the parameters in the new format
+ new_embedder = BasicTextFieldEmbedder.from_params(params=new_params, vocab=self.vocab)
+ assert old_embedder._token_embedders.keys() == new_embedder._token_embedders.keys() #pylint: disable=protected-access
+
+ assert new_embedder(self.inputs).size() == (1, 4, 10)
