Closed cschwem2er closed 4 years ago
It seems that the issue is caused by a specific "debate" in the data which cannot compatible with quanteda. After cleaning up data a bit, I found a specific debate which causes error for textmodel_wordfish()
. Here is a replication code.
load("~/Downloads/wordshoal_svd_error.RData")
library(stringi)
library(quanteda)
library(wordshoal)
docvars(dfm15d, c('TopID', "AgentID")) %>% table %>% table
dfm15d_group <- dfm_group(dfm15d, groups = c("AgentID", 'TopID'))
docvars(dfm15d_group, "AgentID") <- substr(rownames(dfm15d_group), 1, 7)
docvars(dfm15d_group, "TopID") <- stri_replace_first_regex(rownames(dfm15d_group), "^.{8}", "")
docvars(dfm15d_group,'TopID') %>% factor %>% levels -> group_names
group_names[19]
dfm_su <- dfm_subset(dfm15d_group, TopID == group_names[19])
textmodel_wordfish(dfm_su)
I think this is a behaviour which should not happen with wordfish. The debate number is "15000037".
I suspected the rank of the matrix would be an issue but that was not the case.
> library(Matrix)
> dim(dfm_su)
[1] 8 4421
> dfm_su %>% convert('matrix') %>% rankMatrix()
[1] 8
attr(,"method")
[1] "tolNorm2"
attr(,"useGrad")
[1] FALSE
attr(,"tol")
[1] 9.816592e-13
@kbenoit, should I file an issue at quanteda
?
It's a known issue with the sparse SVD we use for starting values. I'm beginning to think this was not such a great idea.
It works fine if you call it as
textmodel_wordfish(dfm_trim(dfm_su), sparse = FALSE)
which disables the warning messages about empty features (the dfm_trim
part) and avoids the SVD failure (the sparse = FALSE
part). We should probably set sparse = FALSE
as the default for textmodel_wordfish()
, but definitely also should add an option to pass this through from textmodel_wordshoal()
.
if you allow to pass this parameter to wordshoal, this would also eliminate the non-deterministic behavior right? What's the tradeoff? "Stupid" starting values?
I don't know a lot about latent variable models and finding starting values, but in the long run, is the deterministic spectral initialization that Brandon uses for stm
an option for wordfish as well?
Yes that's exactly the "known issue" to which I referred. I'm going to change shortly in quanteda forso thattextmodel_wordfish(x, sparse = FALSE)
, which will also solve the problem. But agree we should allow passing parameters (probably through ...
) to wordfish through textmodel_wordshoal()
.
I just changed the default in quanteda.
Hi,
using the latest version of wordshoal and quanteda, the following example (dfm for reproduction available here) raises an error:
This seems to happen during the wordfish SVD for one of the debates.