quanteda / quanteda.textmodels

Text scaling and classification models for quanteda
42 stars 6 forks source link

Undocumented breaking change in textmodel_nb #28

Closed vriezer closed 4 years ago

vriezer commented 4 years ago

From quanteda.textmodels 0.9.0 to 0.9.1 there is an undocumented breaking change in textmodel_nb that causes predict.textmodel_nb to fail when used in combination with a model created with v0.9.0 or earlier. The reason for this is changes in object naming in commit 8483900116d9b10dabc7fdfa26109263410191b8 textmodel_nb.R. Perhaps it is possible to add some code to convert NB models in the old format to the new format.

kbenoit commented 4 years ago

Do you mean https://github.com/quanteda/quanteda.textmodels/commit/8483900116d9b10dabc7fdfa26109263410191b8#diff-6326e84a41623a0dfb906f670bfea49aR168-R170

or do you mean https://github.com/quanteda/quanteda.textmodels/commit/8483900116d9b10dabc7fdfa26109263410191b8#diff-6326e84a41623a0dfb906f670bfea49aR168-R170 ?

vriezer commented 4 years ago

I mean https://github.com/quanteda/quanteda.textmodels/commit/8483900116d9b10dabc7fdfa26109263410191b8#diff-6326e84a41623a0dfb906f670bfea49aR172-R173

kbenoit commented 4 years ago

How about this then:

tmod <- textmodel_nb(data_dfm_lbgexample, y = c("A", "A", "B", "C", "C", NA))

names(tmod)[which(names(tmod) == "priors")] <- "Pc"
names(tmod)[which(names(tmod) == "param")] <- "PwGc"

or better yet, change your code for the new version.

vriezer commented 4 years ago

This example is the other way around, you modify the new textmodel to work with the old predict function. The issue for me is the other way around, namely that an old model doesn't work with the new predict function. Of course I can modify the code above to change the names of the objects in the model, but my problem is more that the error thrown when using an old model with the new predict function is uninformative. I've created a pull request with a proposed fix. https://github.com/quanteda/quanteda.textmodels/pull/29