【发布时间】:2019-01-25 05:47:38
【问题描述】:
我想使用 spacy 来标记维基百科的抓取。理想情况下,它会像这样工作:
text = 'procedure that arbitrates competing models or hypotheses.[2][3] Researchers also use experimentation to test existing theories or new hypotheses to support or disprove them.[3][4]'
# run spacy
spacy_en = spacy.load("en")
doc = spacy_en(text, disable=['tagger', 'ner'])
tokens = [tok.text.lower() for tok in doc]
# desired output
# tokens = [..., 'models', 'or', 'hypotheses', '.', '[2][3]', 'Researchers', ...
# actual output
# tokens = [..., 'models', 'or', 'hypotheses.[2][3', ']', 'Researchers', ...]
问题是'hypotheses.[2][3]'被粘在一起成为一个标记。
如何防止 spacy 将此“[2][3]”连接到前一个令牌? 只要是从hypotheses这个词和句末的point中分离出来的,我不管怎么处理。但是个别单词和语法应该远离句法噪音。
因此,例如,以下任何一个都是理想的输出:
'hypotheses', '.', '[2][', '3]'- '
hypotheses', '.', '[2', '][3]'
【问题讨论】:
标签: python python-3.x nlp tokenize spacy