lexrank icon indicating copy to clipboard operation
lexrank copied to clipboard

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

Open korunosk opened this issue 5 years ago • 10 comments

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"

korunosk avatar Feb 27 '20 14:02 korunosk

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

gniewus avatar Nov 17 '20 01:11 gniewus

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"

LozanoAlvarezb avatar Jan 15 '21 08:01 LozanoAlvarezb

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).

openprivacy avatar Feb 08 '22 18:02 openprivacy

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.

hansharhoff avatar May 12 '22 12:05 hansharhoff

@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...

openprivacy avatar May 13 '22 00:05 openprivacy

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

hansharhoff avatar May 13 '22 06:05 hansharhoff

@hansharhoff thank you - that worked!

openprivacy avatar May 14 '22 21:05 openprivacy

Works perfectly thanks @hansharhoff

agombert avatar Jul 06 '22 09:07 agombert

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.

enayet-hossain avatar May 19 '23 15:05 enayet-hossain

@hansharhoff thank you!

deankim07 avatar May 23 '23 08:05 deankim07