chartbeat-labs / textacy

NLP, before and after spaCy
https://textacy.readthedocs.io
Other
2.22k stars 250 forks source link

AttributeError: module 'textacy' has no attribute 'tm' #344

Closed Fourthought closed 3 years ago

Fourthought commented 3 years ago

context

Hi There,

I'm attempting to do Topic Modelling, however, I keep getting the following error code.

AttributeError: module 'textacy' has no attribute 'tm'

I'm following the code in the documentation: https://textacy.readthedocs.io/en/latest/api_reference/tm.html

steps to reproduce

doc = hs_corpus[0] termslist = (term.lemma for term in textacy.extract.terms(doc, ngs=1, ents=True))

vectorizer = textacy.representations.vectorizers.Vectorizer( tf_type="linear", idf_type="smooth", norm="l2", min_df=10, max_df=0.9)

doc_term_matrix = vectorizer.fit_transform(terms_list)

model = textacy.tm.TopicModel("nmf", n_topics=20) model.fit(doc_term_matrix)

expected vs. actual behavior

I would expect the code to create a topic model, however, the module does not seem to be installed.

bdewilde commented 3 years ago

Hi @Fourthought , I believe the solution is simple: just execute import textacy.tm before attempting to create a topic model. Here's a tutorial that you can reference for topic modeling: https://textacy.readthedocs.io/en/latest/tutorials/tutorial-2.html