New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add nnseq function to quanteda.classifiers #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I rewrote this pretty substantially, and fixed the CI so that it installs tensorflow before trying the tests. I also fixed a few inconsistent behaviours.
@pchest I reverted the function signature to the one I'd developed in the (now removed) slstm function since we only need the arguments not passed through to keras::fit()
via ...
. The rest are either hardwired or included as options in the function. This is clearly documented in the Rd now.
Also there were some errors, especially about how the "one-hot encoding" (that is such a stupid term) of the outcome variable was done, so if you were using this in the paper before, I suspect the results were wrong. Check the diff carefully - in fact this is worth studying closely both to check what I did and to learn from it.
Issues to note:
predict(tmod, type = "class")
(for both models) now returns a factor with the levels equal to those from the training set. This is true even if a single case is predicted (it will still have as many levels as originally existed). This is howtextmodel_nb()
works so I thought we should make the behaviour consistent with that.- The keras NN models are inherently stochastic. This means that setting the seed in R will not affect this. There is a discussion about this "problem" here along with some suggestions, but the results, especially for the small datasets we use, are just not deterministic. A slight problem from a replication standpoint!
- I added an example using our new datasets to
?textmodel_nnseq
for immigration sentences, check it out since the results are very encouraging. This is also as clean a workflow as I can provide as an example. - The
model
object in keras operates differently from most other R objects that are passed by value, in that they are just references to objects modified "in place". Our function seems to work now, where the (pointer?) is attached to the fitted model object asobject$seqfitted
and it seems to work when we save it, and then restart R and then reload the saved object, but this might cause some weirdnesses later. I guess we will solve those when we come to them.
Hey Ken, I'm glad that you found these errors and thank you for correcting them!
|
On the one-hot encoding error, it was at aa319ab#diff-c3df496465c72d7d97b36a144fd2093fL60. The indexing is from 0:numclasses, and somehow the earlier code included an extra class. |
No description provided.