Search code examples
rtopic-modelingmallet

Using a random seed in Rmallet


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)?


Solution

  • 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)