spaCy:Scispacy缩写大型文档

2024-09-30 06:27:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现这个post正在寻找一种在我的数据框架中识别和清除缩写的方法。该代码对我的用例很有效

然而,我正在处理一个大型数据集,我想知道是否有更好或更熟练的方法可以在不处理内存问题的情况下应用它

为了让我运行代码snipet,我对原始数据集的10%进行了采样,它运行得非常好。如果我运行完整的数据集,我的笔记本电脑会锁定

以下是原始代码的更新版本:

import spacy
from scispacy.abbreviation import AbbreviationDetector

nlp = spacy.load("en_core_web_sm")
nlp.max_length = 43793966

abbreviation_pipe = AbbreviationDetector(nlp)
nlp.add_pipe(abbreviation_pipe)

text = [nlp(text, disable = ['ner', 'parser','tagger']) for text in train.text]

text = ' '.join([str(elem) for elem in text]) 


doc = nlp(text)

#Print the Abbreviation and it's definition
print("Abbreviation", "\t", "Definition")
for abrv in doc._.abbreviations:
    print(f"{abrv} \t ({abrv.start}, {abrv.end}) {abrv._.long_form}")

Tags: 数据方法代码textinimportfordoc

热门问题