Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'pytextrank' has no attribute 'TextRank' #92

Closed
Anthonyive opened this issue Mar 8, 2021 · 5 comments
Closed

Comments

@Anthonyive
Copy link
Contributor

Steps to Reproduce

corpus = st.CorpusFromParsedDocuments(
    convention_df,
    category_col='category',
    parsed_col='parse',
    feats_from_spacy_doc=st.PyTextRankPhrases()
).build(
).compact(
    AssociationCompactor(2000, use_non_text_features=True)
)

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

...

~/.local/share/virtualenvs/.../lib/python3.8/site-packages/scattertext/features/PyTextRankPhrases.py in get_doc_metadata(self, doc)
     32         import pytextrank
     33         phrase_counter = Counter()
---> 34         tr = pytextrank.TextRank()
     35         tr.doc = doc
     36         phrases = tr.calc_textrank()

AttributeError: module 'pytextrank' has no attribute 'TextRank'

Expected behavior

No error.

Environment

  • Scattertext version (e.g., 0.0.2.75): 0.1.0.0
  • OS (e.g., Linux): Ubuntu 20.04
  • How you installed PyTorch (conda, pip, source): pipenv
  • Python version: 3.8
  • Any other relevant information: spacy 3.0.1

Additional context

Looks like pytextrank no longer has the attribute TextRank. Maybe you should change the code in scattertext/features/PyTextRankPhrases.py from tr = pytextrank.TextRank() to spacy pipeline.

@JasonKessler
Copy link
Owner

Thanks for the bug report. I ran into some issues using PyTextRank to parse multiple documents with the same spaCy Language instance. Not sure if these persist in PTR v3, but the easiest thing to do would be to explicitly use an earlier version.

@JasonKessler
Copy link
Owner

I just released v0.1.2 which enables Scattertext to work with PTR v3. The results on the convention data set look a little better using the new version.

@peterelbert
Copy link

peterelbert commented Jan 18, 2022

How’s this going? I just got the same error, following the documentation:

https://spacy.io/universe/project/spacy-pytextrank

pytextrank has no attribute “TextRank”. It doesn’t appear in dir(pytextrank):

['BaseTextRank', 'BaseTextRankFactory', 'BiasedTextRank', 'BiasedTextRankFactory', 'Language', 'Lemma', 'MIN_PY_VERSION', 'Paragraph', 'Phrase', 'PositionRank', 'PositionRankFactory', 'Sentence', 'StopWordsLike', 'VectorElem', '_DEFAULT_CONFIG', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'version', '_check_version', '_create_component_br', '_create_component_pr', '_create_component_tr', '_versify', 'base', 'biasedrank', 'default_scrubber', 'filter_quotes', 'groupby_apply', 'maniacal_scrubber', 'pathlib', 'positionrank', 'split_grafs', 'typing', 'util', 'version']

I guess that Spacy page is just outdated because the official PTR GitHub has different instructions.

@JasonKessler
Copy link
Owner

JasonKessler commented Jan 18, 2022 via email

@Dopamine-TX
Copy link

nlp.add_pipe("textrank")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants