尝试加载`nlp = spacy.load("en_ner_bc5cdr_md")`时出现`TypeError: issubclass() arg 1 must be a class`

问题描述 投票:0回答:1

我正在使用 spaCy 分析大量医学文本以对诊断进行评论,当我上周离开它时,它运行良好。

现在,当我尝试加载 scispaCy 库时

en_ner_bc5cdr_md
我收到类型错误
TypeError: issubclass() arg 1 must be a class

上周我使用了这个完全相同的库来分析相同的文本,唯一改变的是我重新启动了计算机。

我正在 OSX 上使用 python

3.8.8
运行 anaconda 发行版
Version 13.5.2 (22G91)

有什么想法吗?

这是代码,它永远无法通过导入模型。

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)

如果您能够在您的机器上运行,请告诉我参数。您还需要运行 -

!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

python tensorflow machine-learning nlp spacy
1个回答
0
投票

我能够使用

en_ner_bc5cdr_md
和 python
spacy == 3.0.9
加载
3.10.12
。您可以尝试以下步骤:

  1. !pip install spacy==3.0.9
    (“!”用于笔记本电脑)
  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

然后尝试:

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

抱歉,目前我没有任何本地机器,但我在 google colab 上测试了它,它在我这边工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.