chrisjbryant / errant

ERRor ANnotation Toolkit: Automatically extract and classify grammatical errors in parallel original and corrected sentences.
MIT License
436 stars 107 forks source link

API Quickstart script not working - Please update with fix provided #47

Closed JoyLinWQ closed 11 months ago

JoyLinWQ commented 11 months ago

Hi @chrisjbryant , the API quickstart script below is not working.

import errant

annotator = errant.load('en')
orig = annotator.parse('This are gramamtical sentence .')
cor = annotator.parse('This is a grammatical sentence .')
edits = annotator.annotate(orig, cor)
for e in edits:
    print(e.o_start, e.o_end, e.o_str, e.c_start, e.c_end, e.c_str, e.type)

Error:

OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

After python3 -m spacy download en_core_web_sm, it says

Successfully installed en_core_web_sm-2.3.1
✔ Download and installation successful
You can now load the model via spacy.load('en_core_web_sm')
You do not have sufficient privilege to perform this operation.
✘ Couldn't link model to 'en'
Creating a symlink in spacy/data failed. Make sure you have the required
permissions and try re-running the command as admin, or use a virtualenv. You
can still import the model as a module and call its load() method, or create the
symlink manually.
C:\Users\xxx\anaconda3\envs\chat-langchain\lib\site-packages\en_core_web_sm
--> C:\Users\xxx\anaconda3\envs\chat-langchain\lib\site-packages\spacy\data\en
⚠ Download successful but linking failed
Creating a shortcut link for 'en' didn't work (maybe you don't have admin
permissions?), but you can still load the model via its full package name: nlp =
spacy.load('en_core_web_sm')

I had to update the code to below before it works.

import errant
import spacy
import spacy.cli 

# spacy.cli.download("en_core_web_md")
nlp = spacy.load('en_core_web_md')
annotator = errant.load('en', nlp)
# annotator = errant.load('en_core_web_md')
orig = annotator.parse('This are gramamtical sentence .')
cor = annotator.parse('This is a grammatical sentence .')
edits = annotator.annotate(orig, cor)
for e in edits:
    print(e.o_start, e.o_end, e.o_str, e.c_start, e.c_end, e.c_str, e.type)
chrisjbryant commented 11 months ago

Ah good catch - on it!

chrisjbryant commented 11 months ago

Hmm. Mine is working fine, although you reminded me to make an adjustment to the readme.

It might be an anaconda issue, as I also encountered errors when updating spacy. One of your logs does seem to show it installed en_core_web_sm-2.3.1 which is totally the wrong model version.

Also, I literally just updated it, so there might have been some momentary instability!!