Is there an option (or a workaround) in Rmallet to use a random seed, as is possible through the mallet command line (i.e. --random-seed 1)?
Asked
Active
Viewed 256 times
1 Answers
2
Yes, via the rJava interface to the underlying ParallelTopicModel.setRandomSeed
method (see here)
library(mallet)
library(rJava)
m <- MalletLDA(num.topics=20, alpha.sum=5, beta=0.1)
m$model$setRandomSeed(42L)
The seed has to be an explicit integer (hence the L
in 42L
).
If you are using the development version of RMallet from github, you'd need
m$setRandomSeed(42L)

agoldst
- 36
- 1
-
Great answer; thanks a bunch! m$model$setRandomSeed(42L) worked great as long as it was called before documents were loaded. – shackett May 21 '16 at 17:54
-
1You're welcome. Glad it worked. You're right about setting the seed before loading documents. I had to look at [the source](https://github.com/mimno/Mallet/blob/master/src/cc/mallet/topics/ParallelTopicModel.java#L224) to understand why there was any randomness there: the initial random assignment of tokens to topics is done when you load documents. – agoldst May 22 '16 at 14:48