# How to use fitted RTM model to predict new topics

I am using the lda package in R (documentation pdf) for its Relational Topic Modeling functionality. The package enables you to determine topic assignments and document links (mainly what I am interested in) for the training set of documents and lets you determine links between documents as well. However, it does not appear to let you determine topic distributions on unseen documents with the trained RTM model. I know that there are ways to do this with different LDA packages and software (MALLET, topicmodels, etc.), but none that I can find with RTM. I am primarily interested in determining new links.

Can someone please explain how to use a trained RTM model to predict the topic distributions on an unseen document? Blei mentioned it very briefly in the paper below in the section about prediction (in section 3), but I am unable to understand / implement it.

Here is the original paper:

• Chang, J, & Blei, DM. Relational Topic Models for Document Networks. Proceedings of the 12th International Conference on Artificial Intelligence and Statistics (AISTATS) 2009, Clearwater Beach, Florida, USA. Volume 5 of JMLR: W&CP 5 (pdf)
• If you are only asking how to use R / this package, that would be off topic here. If you have a question about topic models per se, please edit to clarify. Jul 3 '16 at 22:38
• Hi, I mean to ask whether or not there exists a topic model package that allows you to infer new topic distributions given a trained RTM. If that is also off-topic, where should I post it? Jul 3 '16 at 22:41
• You could ask here about how to infer new topic distributions given a trained RTM. If you just want to ask for a package, that would be off topic. You could try on the r-help listserv. Jul 3 '16 at 22:43
• OK, I retracted my close vote. Jul 3 '16 at 22:55

call lda.collapsed.gibbs.sampler on your test documents, setting freeze.topics=TRUE and initial = list(topics = model\$topics, topic_sums = model\$topic_sums), where model is the result of the RTM run. The resulting document_sums will give you the (unnormalized) distribution over topics for the test documents. Normalize them, and compute the inner product, weighted by the RTM coefficients to get the predicted link probability (or use predictive.link.probability)