CogStack / MedCATservice

Running MedCAT as a RESTful web service
17 stars 14 forks source link

Intermittent bug with SNOMED / context_vectors #34

Closed lauraste1 closed 8 months ago

lauraste1 commented 1 year ago

I have set up the MedCATService using the SNOMED modelpack but am running into this error with some requests but not others... e.g. curl -XPOST http://localhost:5000/api/process \ -H 'Content-Type: application/json' \ -d '{"content":{"text":"The patient was diagnosed with leukemia."}}' results in the following

[2023-03-25 10:16:28,236] [ERROR] API: Traceback (most recent call last):
  File "/cat/medcat_service/api/api.py", line 48, in process
    result = nlp_service.nlp.process_content(payload['content'])
  File "/cat/medcat_service/nlp_processor/medcat_processor.py", line 124, in process_content
    entities = self.cat.get_entities(text)
  File "/usr/local/lib/python3.11/site-packages/medcat/cat.py", line 1059, in get_entities
    doc = self(text)
  File "/usr/local/lib/python3.11/site-packages/medcat/cat.py", line 401, in __call__
    return self.pipe(text)  # type: ignore
  File "/usr/local/lib/python3.11/site-packages/medcat/pipe.py", line 241, in __call__
    return self._nlp(text) if len(text) > 0 else None  # type: ignore
  File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1016, in __call__
    error_handler(name, proc, [doc], e)
  File "/usr/local/lib/python3.11/site-packages/spacy/util.py", line 1689, in raise_error
    raise e
  File "/usr/local/lib/python3.11/site-packages/spacy/language.py", line 1011, in __call__
    doc = proc(doc, **component_cfg.get(name, {}))  # type: ignore[call-arg]
  File "/usr/local/lib/python3.11/site-packages/medcat/linking/context_based_linker.py", line 109, in __call__
    cui, context_similarity = self.context_model.disambiguate(cuis, entity, name, doc)
  File "/usr/local/lib/python3.11/site-packages/medcat/linking/vector_context_model.py", line 136, in disambiguate
    vectors = self.get_context_vectors(entity, doc)
  File "/usr/local/lib/python3.11/site-packages/medcat/linking/vector_context_model.py", line 71, in get_context_vectors
    values.extend([self.config.linking['weighted_average_function'](step) * self.vocab.vec(tkn.lower_)
TypeError: 'builtin_function_or_method' object is not subscriptable

But replacing leukemia with e.g. anemia gives an expected response. Admittedly I had trouble using the APP_MEDCAT_MODEL_PACK env var as it did not unpack the contents correctly and so had to copy-paste the contents of the folder to the models folder so wonder if this is at all part of the problem.

vladd-bit commented 8 months ago

Probably some past issues with spacy versions in older medcat releases. Not really a service problem I believe.