Search code examples
pythonscikit-learnlda

How to change the alpha and eta parameters when using GuidedLda


I would like to know how to change the hyperparameters on an LDA model when using the great GuidedLDA package. To provide a working example I have pinched the following from the official docs:

X = guidedlda.datasets.load_data(guidedlda.datasets.NYT)
model = guidedlda.GuidedLDA(n_topics=5, n_iter=100, random_state=7, refresh=20)
model.fit(X)

On reading the documentation, GuidedLda "follows the conventions found in scikit-learn", I have read up on sklearn.decomoposition.LatentDirichletAllocation and to alter the alpha and eta for that model you can include the parameters doc_topic_prior and topic_word_prior respectively.

In general, I feel like I am missing a large section of the GuidedLda docs so my question is either does anyone know where to find the full documentation, or how to add this functionality to GuidedLda? I tried adding this as an options to the GuidedLda as

model = guidedlda.GuidedLDA(n_topics=5, n_iter=100, random_state=7, refresh=20,
doc_topic_prior = 0.5)

but unsurprisingly it isn't so simple, but the above is my target function.

Thank you.


Solution

  • I solved this problem and just incase it comes up again in the future I'll post the solution here.

    I cannot find more in-depth documentation but you can access the methods and functions for each GuidedLda object, for example and Lda model defined as in the question by viewing the object in an Object Viewer on your IDE. E.g. by right clicking and selecting Object Viewer within Spyder.

    This provides a window into the documentation.

    To change the alpha and eta parameters simply pass them as options when initialising the model like:

    model = guidedlda.GuidedLDA(n_topics=5, n_iter=100, random_state=7, refresh=20, alpha=0.5, eta=0.3)