I am trying to infer the topics of a document based on my trained topic model by MALLET. I am using the following command in the mallet dir
./mallet infer-topics --inferencer topic-model --input indata.mallet --output-doc-topics infered_docs
but it gets stuck in cast exception:
java.lang.ClassCastException: cc.mallet.topics.ParallelTopicModel cannot be cast to cc.mallet.topics.TopicInferencer
how can I solve this?
There's a difference between a model and an inferencer. The
--output-model FILENAME
option in thetrain-topics
command produces a file (a model) that contains the training data along with all the inferred parameters. The--inferencer-filename FILENAME
produces a much smaller file (an inferencer) that only contains the parameters needed to infer topics for new documents.The
infer-topics
command needs a topic inferencer, not a complete model. You can create an inferencer from the existing model file by runningtrain-topics
with the--input-model FILENAME
and--inferencer-filename FILENAME
options, with--num-iterations 0
.