下面是我的python代码:
import spacy
nlp = spacy.load('en')
line = u'Algorithms; Deterministic algorithms; Adaptive algorithms; Something...'
line = line.lower()
print ' '.join([token.lemma_ for token in nlp(line)])
输出为:
^{pr2}$为什么第三个algorithms
没有转换成“算法”?
当我删除lower()
函数时,我得到:
algorithms ; deterministic algorithms ; adaptive algorithm ; something...
这次无法转换第一个和第二个algorithms
。
这个问题让我发疯了,我怎样才能解决这个问题,使每个单词都被柠檬化?在
我认为三段论解释得更好。但还有另一种方法:
输出:
^{pr2}$你用的是什么版本?使用
lower
它对我来说工作正常:如果没有
lower
,则标记者将Algorithms
指定给标记NNP,即专有名词。这就防止了词缀化,因为模型已经从统计学上猜测了这个词是一个专有名词。在如果愿意,可以在标记器中设置一个特殊的大小写规则,告诉spaCy
^{pr2}$Algorithms
从来不是专有名词。在tokenizer.add_special_case
函数允许您指定如何将字符串标记化,并在每个副标题上设置属性。在相关问题 更多 >
编程相关推荐