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

Internal server error invoking NER predict end point #6

Open
asehmi opened this issue Aug 26, 2020 · 2 comments
Open

Internal server error invoking NER predict end point #6

asehmi opened this issue Aug 26, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@asehmi
Copy link

asehmi commented Aug 26, 2020

Hi,

I have all other models working except for NER, which uses spaCy. lexemes.bin seems to be missing. I've used spaCy before, but not with an unpackaged model like this appears to be. Any pointers welcomed.

This is my trace:

nginx_1           | 172.20.0.1 - - [26/Aug/2020:12:29:56 +0000] "GET /api/v1/ner/docs HTTP/1.1" 200 910 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"
ner_1             | INFO:     172.20.0.6:56800 - "GET /api/v1/ner/openapi.json HTTP/1.0" 200 OK
nginx_1           | 172.20.0.1 - - [26/Aug/2020:12:29:57 +0000] "GET /api/v1/ner/openapi.json HTTP/1.1" 200 2724 "http://localhost:8080/api/v1/ner/docs" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"
nginx_1           | 172.20.0.1 - - [26/Aug/2020:12:30:15 +0000] "GET /api/v1/ner/info HTTP/1.1" 200 163 "http://localhost:8080/api/v1/ner/docs" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"
ner_1             | INFO:     172.20.0.6:56802 - "GET /api/v1/ner/info HTTP/1.0" 200 OK
ner_1             | INFO:     172.20.0.6:56810 - "POST /api/v1/ner/predict HTTP/1.0" 500 Internal Server Error
ner_1             | ERROR:    Exception in ASGI application
ner_1             | Traceback (most recent call last):
ner_1             |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
ner_1             |     result = await app(self.scope, self.receive, self.send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
ner_1             |     return await self.app(scope, receive, send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/fastapi/applications.py", line 140, in __call__
ner_1             |     await super().__call__(scope, receive, send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__
ner_1             |     await self.error_middleware(scope, receive, send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 178, in __call__
ner_1             |     raise exc from None
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 156, in __call__
ner_1             |     await self.app(scope, receive, _send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 73, in __call__
ner_1             |     raise exc from None
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 62, in __call__
ner_1             |     await self.app(scope, receive, sender)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 590, in __call__
ner_1             |     await route(scope, receive, send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 208, in __call__
ner_1             |     await self.app(scope, receive, send)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 41, in app
ner_1             |     response = await func(request)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/fastapi/routing.py", line 127, in app
ner_1             |     raw_response = await dependant.call(**values)
ner_1             |   File "./app/api/ner.py", line 46, in named_entity_recognition
ner_1             |     ner_process = NerProcessor(model=item.model.lower())
ner_1             |   File "./app/api/nerpro.py", line 21, in __init__
ner_1             |     self.model = spacy.load("./app/api/spacy/", disable=["tagger", "parser"])
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/__init__.py", line 21, in load
ner_1             |     return util.load_model(name, **overrides)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/util.py", line 116, in load_model
ner_1             |     return load_model_from_path(Path(name), **overrides)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/util.py", line 156, in load_model_from_path
ner_1             |     return nlp.from_disk(model_path)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/language.py", line 647, in from_disk
ner_1             |     util.from_disk(path, deserializers, exclude)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/util.py", line 511, in from_disk
ner_1             |     reader(path / key)
ner_1             |   File "/usr/local/lib/python3.7/site-packages/spacy/language.py", line 635, in <lambda>
ner_1             |     self.vocab.from_disk(p) and _fix_pretrained_vectors_name(self))),
ner_1             |   File "vocab.pyx", line 377, in spacy.vocab.Vocab.from_disk
ner_1             |   File "/usr/local/lib/python3.7/pathlib.py", line 1203, in open
ner_1             |     opener=self._opener)
ner_1             |   File "/usr/local/lib/python3.7/pathlib.py", line 1058, in _opener
ner_1             |     return self._accessor.open(self, flags, mode)
ner_1             | FileNotFoundError: [Errno 2] No such file or directory: 'app/api/spacy/vocab/lexemes.bin'
nginx_1           | 172.20.0.1 - - [26/Aug/2020:12:32:00 +0000] "POST /api/v1/ner/predict HTTP/1.1" 500 21 "http://localhost:8080/api/v1/ner/docs" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36" "-"

This is the request body I used from Swagger:

{
  "model": "spaCy",
  "text": "Dense, real valued vectors representing distributional similarity information are now a cornerstone of practical NLP. The most common way to train these vectors is the Word2vec family of algorithms. If you need to train a word2vec model, we recommend the implementation in the Python library Gensim.",
  "query": "string"
}
@abhimishra91 abhimishra91 self-assigned this Aug 27, 2020
@abhimishra91 abhimishra91 added the bug Something isn't working label Aug 27, 2020
@mbenetti
Copy link

mbenetti commented Sep 2, 2020

I think is because on line 16 of neropro.py
self.model_path = self.path + "model.bin"

ask for a file called model.bin, and that file is missing.

When I used spaCy before I had to download en_core_web_md separately.

@asehmi
Copy link
Author

asehmi commented Sep 18, 2020

@mbenetti Thanks for the hint. I solved the issue by:

  1. Deleting everything under ./app/api/spacy/
  2. Replacing...
    self.model = spacy.load("./app/api/spacy/", disable=["tagger", "parser"]
    with...
    self.model = spacy.load("en_core_web_sm", disable=["tagger", "parser"])
  3. In main.py added these two lines at the top:
    from spacy.cli import download
    download("en_core_web_sm", direct=False)
  4. For good measure, I deleted the src_fastapi_ner container, and its image, and re-ran docker-compose up

Using the Swagger API with my request above, I was returned this response result:

{
"entites": [
{
"text": "NLP",
"entity_type": "ORG",
"start": 113,
"end": 116
},
{
"text": "Word2vec",
"entity_type": "PERSON",
"start": 168,
"end": 176
},
{
"text": "Gensim",
"entity_type": "PRODUCT",
"start": 292,
"end": 298
}
]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants