我想删除一个停止词列表,即
from gensim.parsing.preprocessing import STOPWORDS
print(STOPWORDS)
在gensim中,使用^{
我读取文本并删除停止字的代码如下:
def read_text(text_path):
text = []
with open(text_path) as file:
lines = file.readlines()
for index, line in enumerate(lines):
text.append(simple_preprocess(remove_stopwords(line)))
return text
text = read_text('/content/text.txt')
text = [x for x in text if x]
text[:3]
这是我得到的输出,其中包含诸如“we”或“however”之类的单词,这些单词应该从original text中删除,尽管例如“the”已经从第一个设置中正确删除。我很困惑。。。我错过了什么
[['clinical', 'guidelines', 'management', 'ibd'],
['polygenetic',
'risk',
'scores',
'add',
'predictive',
'power',
'clinical',
'models',
'response',
'anti',
'tnfα',
'therapy',
'inflammatory',
'bowel',
'disease'],
['anti',
'tumour',
'necrosis',
'factor',
'alpha',
'tnfα',
'therapy',
'widely',
'management',
'crohn',
'disease',
'cd',
'ulcerative',
'colitis',
'uc',
'however',
'patients',
'respond',
'induction',
'therapy',
'patients',
'lose',
'response',
'time',
'to',
'aid',
'patient',
'stratification',
'polygenetic',
'risk',
'scores',
'identified',
'predictors',
'response',
'anti',
'tnfα',
'therapy',
'we',
'aimed',
'replicate',
'association',
'polygenetic',
'risk',
'scores',
'response',
'anti',
'tnfα',
'therapy',
'independent',
'cohort',
'patients',
'establish',
'clinical',
'validity']]
文本(完整文件可用here)
IBD治疗的临床指南
多基因风险评分不能增加炎症性肠病中抗TNFα治疗反应的临床模型的预测能力。 抗肿瘤坏死因子-α(TNF-α)治疗广泛用于克罗恩病(CD)和溃疡性结肠炎(UC)的治疗。然而,多达三分之一的患者对诱导治疗没有反应,另外三分之一的患者随着时间的推移失去反应。为了帮助患者分层,多基因风险评分已被确定为抗TNFα治疗反应的预测因子。我们的目的是在一个独立的患者队列中复制多基因风险评分与抗TNFα治疗反应之间的关联,以确定其临床有效性
remove_stopwords()函数区分大小写,不会忽略标点符号。例如,“However”不在STOPWORDS中,但“However”在。您应该首先调用simple_preprocess()函数。这应该起作用:
相关问题 更多 >
编程相关推荐