【问题标题】:segment sentences with spaCy tokenizer exceptions changed in v2?在 v2 中更改了带有 spaCy 标记器异常的句子?
【发布时间】:2018-01-31 17:26:02
【问题描述】:

阅读this 后,它适用于 Python 3.5,spaCy 版本 1.1.2。我试过这样做

from spacy.lang.en import English
nlp = spacy.load('en')
text2 = u'he has a ph.D. in tacology'
nlp.Defaults.tokenizer_exceptions['Ph.D.'] = [{'F':'Ph.D.'}]
tokens = parser(text2)
tokens = [token.orth_ for token in tokens if not token.orth_.isspace()]

这给出了:

[u'he', u'has', u'a', u'ph', u'.', u'D.', u'in', u'tacology']

当我期待时:

[u'he', u'has', u'a', u'ph.D.', u'in', u'tacology']

为什么 tokenizer_exceptions 不起作用?是不是因为我使用的是版本 2,它的实现方式不同?

我将如何在 v2 中进行等效操作?

注意,我确实查看了 v2 spacy docs here 中的 Tokenizer.add_special-case,但我找不到解决方案

【问题讨论】:

    标签: python tokenize spacy


    【解决方案1】:

    不确定您的核心 spaCy 问题,但您可以检查“Ph”、“.”和“D.”,然后检查它们是否按顺序排列,并将它们替换为“Ph.D”作为解决方法。

    【讨论】:

    • Thx:核心问题 = 你还能在第 2 版中做 nlp.Defaults.tokenizer_exceptions['Ph.D.'] = [{'F':'Ph.D.'}] 跨度>
    猜你喜欢
    • 2019-01-14
    • 2019-04-07
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    相关资源
    最近更新 更多