2

I'm using spaCy to analyze a large set of medical text for commentary about diagnoses, which was working fine when I left it last week.

Now when I try to load the scispaCy library en_ner_bc5cdr_md I am getting the type error TypeError: issubclass() arg 1 must be a class

I used this exact library to analyze the same text last week and the only thing that has changed is that I've restarted my computer.

I'm running an anaconda distribution with python 3.8.8 on OSX Version 13.5.2 (22G91)

Any ideas what's going on?

This is the code, it never gets past importing the model.

import spacy
import scispacy
import pandas as pd

text = """The patient was diagnosed with pneumonia last year. He has a history of asthma and hypertension.  
His COPD symptoms have worsened over the last 2 months. The patient also suffers from migraines."""

nlp = spacy.load("en_ner_bc5cdr_md") 

doc = nlp(text)

labels = []
counts = []

for ent in doc.ents:
    if ent.label_ == 'DISEASE':
        if ent.text not in labels:
            labels.append(ent.text)
            counts.append(1)
        else:
            idx = labels.index(ent.text)
            counts[idx] += 1
            
df = pd.DataFrame({'Diagnosis': labels, 'Count': counts})
print(df)

If you are able to run on you machine please let me know the parameters. You will also need to run - !pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.4.0/en_ner_bc5cdr_md-0.4.0.tar.gz

4
  • Does this answer your question? TypeError: issubclass() arg 1 must be a class Commented Sep 25, 2023 at 16:15
  • I saw this already, unfortunately no. Thanks though! Commented Sep 25, 2023 at 16:20
  • Are you getting the error at import scispacy or at nlp = spacy.load("en_ner_bc5cdr_md") ? Commented Sep 25, 2023 at 18:11
  • nlp = spacy.load("en_ner_bc5cdr_md") Commented Sep 25, 2023 at 18:13

1 Answer 1

2

I was able to load en_ner_bc5cdr_md with spacy == 3.0.9 and python 3.10.12. You can try the following steps:

  1. !pip install spacy==3.0.9 ('!' is for notebook cell)
  2. !pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.4.0/en_ner_bc5cdr_md-0.4.0.tar.gz

And then try:

import spacy
nlp = spacy.load("en_ner_bc5cdr_md") 

Sorry, currently I don't have any local machine but I tested it on google colab and it's working fine on my end.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's super helpful. Did not fix it locally unfortunately but i hadn't thought to use google collab so was ablle to run the code which is the main thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.