quanteda / quanteda.classifiers

quanteda textmodel extensions for classifying documents
21 stars 2 forks source link

Match predict.textmodel_slstm() to format of other quanteda predict methods #6

Closed kbenoit closed 5 years ago

kbenoit commented 5 years ago

predict.textmodel_slstm() needs to output predictions in a similar format to predict.textmodel_svm() (and the other quanteda textmodel functions).

pchest commented 5 years ago

I've updated predict.textmodel_nnseq so that it works similarly to predict.textmodel_svm. I should note that the keras model generates an error when newdata is input as the matrix.csr.dfm type. Currently, newdata is converted to a dfm and that is used to make predictions without issue. I'll keep working to figure out what is preventing as.matrix.csr.dfm from being recognized by the keras model.

kbenoit commented 5 years ago

That's because the matrix.csr is a format for the SparseM package that is only required by the library that fits the linear SVM. The matrix.csr is not applicable for the new function.

If you check the input format for the keras sequential model, it's just a regular matrix. So (unfortunately) we will need to coerce the dfm to a dense matrix it using as.matrix().