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

ImportError: cannot import name 'degree_centrality_scores' from 'lexrank' #34

Open
korunosk opened this issue Feb 27, 2020 · 10 comments
Open

Comments

@korunosk
Copy link

Got this issue on MacBook Pro. Python version: 3.7.4

Reproducibility:

python3 -m venv env
source env/bin/activate
pip3 install lexrank
python3 -c "from lexrank import degree_centrality_scores"
@gniewus
Copy link

gniewus commented Nov 17, 2020

Currently, the degree_centrality_scores function's code is only on dev. So the easiest would be to just clone the repository somewhere near your own code, checkout dev, and just import the function like that:

import sys
sys.path.append("../../lexrank/")
from lexrank.lexrank import  degree_centrality_score

@LozanoAlvarezb
Copy link

Currently, the degree_centrality_scores function's code is only on dev. So the easiest would be to just clone the repository somewhere near your own code, checkout dev, and just import the function like that:

import sys
sys.path.append("../../lexrank/")
from lexrank.lexrank import  degree_centrality_score

Just for anyone who is here with the same problem

The import is

from lexrank.lexrank import degree_centrality_scores

with an "s"

Also, in the README there is a typo. Change every instance of "thershold" for "threshold"

@openprivacy
Copy link

I want to install the dev branch of lexrank from requirements.txt. https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch suggests I can use

pip install -U git+https://github.com/crabcamp/lexrank.git@dev

but this results in installing lexrank-0.1.0 (a tag, not the dev branch). Any other suggestions (as the one suggested here fails pre-commit hooks).

@hansharhoff
Copy link

You can point to a specific commit e.g. git+https://github.com/crabcamp/lexrank.git@07bdd1579c408cf73cc822da303734d0a70cf3f7

but the current dev branch seems to be in a broken state where you cannot import lexrank at all.

@openprivacy
Copy link

@hansharhoff Thank you for the response. I tried adding that to requirements.txt and get the following:

(rato-processing) » pip install -r requirements.txt 
Collecting en-core-web-sm@ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.2.0/en_core_web_sm-3.2.0.tar.gz
  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.2.0/en_core_web_sm-3.2.0.tar.gz (13.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.9/13.9 MB 11.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting lexrank@ git+https://github.com/crabcamp/lexrank.git@07bdd1579c408cf73cc822da303734d0a70cf3f7
  Cloning https://github.com/crabcamp/lexrank.git (to revision 07bdd1579c408cf73cc822da303734d0a70cf3f7) to /tmp/pip-install-xa9e1of4/lexrank_5f66269c2deb4851b465f2dcf499c643
  Running command git clone --filter=blob:none --quiet https://github.com/crabcamp/lexrank.git /tmp/pip-install-xa9e1of4/lexrank_5f66269c2deb4851b465f2dcf499c643
  Running command git rev-parse -q --verify 'sha^07bdd1579c408cf73cc822da303734d0a70cf3f7'
  Running command git fetch -q https://github.com/crabcamp/lexrank.git 07bdd1579c408cf73cc822da303734d0a70cf3f7
  Resolved https://github.com/crabcamp/lexrank.git to commit 07bdd1579c408cf73cc822da303734d0a70cf3f7
  Preparing metadata (setup.py) ... done
...
Building wheels for collected packages: lexrank
  Building wheel for lexrank (setup.py) ... done
  Created wheel for lexrank: filename=lexrank-0.1.0-py3-none-any.whl size=69896 sha256=35ab5ddf261aaefa33f8051eb3f37c0eadbced9639bdbf1d658f609cc486188c
  Stored in directory: /home/fen/.cache/pip/wheels/17/44/a6/7f5d731bb4dab8c972e429a5edf728ad82830eb6cb4f4c4975
Successfully built lexrank
Installing collected packages: lexrank
Successfully installed lexrank-0.1.0

which, of course, is not the version I want. Is it because "the current dev branch seems to be in a broken state where you cannot import lexrank at all"? Can anything be done (without access to pushing changes)? I suppose I could fork it...

@hansharhoff
Copy link

hansharhoff commented May 13, 2022

I endend up using this example which has copied the relevant code to a single file:

https://github.com/UKPLab/sentence-transformers/tree/master/examples/applications/text-summarization

@openprivacy
Copy link

@hansharhoff thank you - that worked!

@agombert
Copy link

agombert commented Jul 6, 2022

Works perfectly thanks @hansharhoff

@enayet-hossain
Copy link

I am using the bert-extractive-summarizer package. However, sometimes I get +/-inf values as the centrality score. I dug a little deeper and found that the eigenvalues are coming as +/-inf. And this is probably caused by near-zero cosine similarity scores. If I add a constant such as 1.1 with all the cosine similarity scores, I do not get the +/-inf values anymore.
My question is - does adding a particular constant to the cosine similarity score, in this case, bias the centrality score? I just wanted to know if there is any better solution in this particular case.
Thank you in advance.

@deankim07
Copy link

@hansharhoff thank you!

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

8 participants