空间符号化撇号

2024-04-25 21:29:30 发布

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

我正在尝试恰当地分割单词以适合我的语料库。为此,我已经找到了以下内容:

Spacy custom tokenizer to include only hyphen words as tokens using Infix regex

它修复了连字符的单词,我似乎搞不懂如何用撇号来表示缩略语,比如:can't,woll't,don't,he's,等等 作为一个象征在一起。更具体地说,我正在研究如何对荷兰语单词进行处理:zon,auto's,massa's等等,但是这个问题应该是独立于语言的。在

我有以下标记器:

def custom_tokenizer(nlp):
    prefix_re = compile_prefix_regex(nlp.Defaults.prefixes)
    suffix_re = compile_suffix_regex(nlp.Defaults.suffixes)
    infix_re = re.compile(r'''[.\,\?\:\;\...\‘\’\'\`\“\”\"\'~]''')

    return Tokenizer(nlp.vocab, prefix_search=prefix_re.search,
                     suffix_search=suffix_re.search,
                     infix_finditer=infix_re.finditer,
                     token_match=None)
nlp = spacy.load('nl_core_news_sm')
nlp.tokenizer = custom_tokenizer(nlp)

有了这个标志:

'Mijn'、'eigen'、'huis'、'staat'、'zo'、''、'n'、'zes'、'meter'、'onder'、'het'、'wateroppervlak'、'van'、'de'、'Noordzee'、'。'

代币应为:

'Mijn'、'eigen'、'huis'、'staat'、“zon”、'zes'、'meter'、'onder'、'het'、'wateroppervlak'、'van'、'de'、'Noordzee'、'。'

我知道可以添加自定义规则,例如:

^{pr2}$

但我正在寻找一个更普遍的解决办法。在

我尝试过从另一个线程编辑中缀正则表达式,但似乎对这个问题没有任何影响。我能做些什么设置或改变来解决这个问题吗?任何帮助都将不胜感激。在


Tags: researchprefixnlpcustom单词suffixregex
1条回答
网友
1楼 · 发布于 2024-04-25 21:29:30

最近,spaCy有一项工作正在进行中,以修复荷兰语的这些词汇形式。今天的拉取请求中有更多信息:https://github.com/explosion/spaCy/pull/3409

更具体地说,nl/punctuation.pyhttps://github.com/explosion/spaCy/pull/3409/files#diff-84f02ed25ff9e44641672ca0ba5c1839)显示了如何通过改变后缀来解决这个问题:

enter image description here

相关问题 更多 >