8

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?

Sarah ESL
  • 83
  • 4
  • May i know why `bash` is tagged in this? – sjsam Dec 19 '16 at 08:45
  • It seems that `topic-model` is not a valid type for the `--inferencer` parameter. – Arnaud Dec 19 '16 at 08:46
  • 1
    @sjsam since I am using mallet.sh which is a bash script and gets the arguments of its java code in bash format – Sarah ESL Dec 19 '16 at 09:12
  • @Berger yes, I think too...but the question is in which format should it be?! I am using the `--output-model` of the `./mallet train-topics` command as` --inferencer` for `./mallet infer-topics` – Sarah ESL Dec 19 '16 at 09:15

1 Answers1

8

There's a difference between a model and an inferencer. The --output-model FILENAME option in the train-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 running train-topics with the --input-model FILENAME and --inferencer-filename FILENAME options, with --num-iterations 0.

David Mimno
  • 1,836
  • 7
  • 7