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

Issue with Spacy and the en_core_web_lg. #57

Closed
EmanueleLM opened this issue Aug 22, 2020 · 3 comments
Closed

Issue with Spacy and the en_core_web_lg. #57

EmanueleLM opened this issue Aug 22, 2020 · 3 comments

Comments

@EmanueleLM
Copy link

EmanueleLM commented Aug 22, 2020

Hi,

I'm trying to run this simple snippet of code, after having successfully (i.e., no error/warning) installed anchor, spacy and all the requirements (included the command 'python -m spacy download en_core_web_lg'):

import spacy
from anchor import anchor_text

nlp = spacy.load('en_core_web_lg')
explainer = anchor_text.AnchorText(nlp, ['negative', 'positive'], use_unk_distribution=False, use_bert=False)

But I obtain the following error:

Exception                                 Traceback (most recent call last)
<ipython-input-5-7f4e7f3d6066> in <module>
----> 1 explainer = anchor_text.AnchorText(nlp, ['negative', 'positive'], use_unk_distribution=False, use_bert=False)

~/.local/lib/python3.7/site-packages/anchor/anchor_text.py in __init__(self, nlp, class_names, use_unk_distribution, use_bert, mask_string)
    117         self.tg = None
    118         self.use_bert = use_bert
--> 119         self.neighbors = utils.Neighbors(self.nlp)
    120         self.mask_string = mask_string
    121         if not self.use_unk_distribution and self.use_bert:

~/.local/lib/python3.7/site-packages/anchor/utils.py in __init__(self, nlp_obj)
    319         self.to_check = [w for w in self.nlp.vocab if w.prob >= -15 and w.has_vector]
    320         if not self.to_check:
--> 321             raise Exception('No vectors. Are you using en_core_web_sm? It should be en_core_web_lg')
    322         self.n = {}
    323 

Exception: No vectors. Are you using en_core_web_sm? It should be en_core_web_lg

I'm using this setting:

Fedora 30 (but I can replicate it on Ubuntu 18.04)
python 3.7.4
spacy 2.3.2 (but I've also tried with 2.2.3)

Thank you,
Emanuele

@EmanueleLM
Copy link
Author

EmanueleLM commented Aug 22, 2020

I can add that if I modify line 319 of ~/.local/lib/python3.7/site-packages/anchor/anchor_text.py, i.e.

    319         self.to_check = [w for w in self.nlp.vocab if w.prob >= -15 and w.has_vector]

with

    319         self.to_check = [w for w in self.nlp.vocab if w.prob >= -20 and w.has_vector]

it starts working, this because the values in w.prob are all equal to 20.

@marcotcr
Copy link
Owner

It seems that spacy phased out w.prob and also en_core_web_lg in the newer versions. I think I'll just remove spacy support, BERT is just better.

@marcotcr
Copy link
Owner

Did so in 5f38997

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

2 participants