spacy 标记化撇号
spacy tokenize apostrophe
我正在尝试正确拆分单词以适合我的语料库。我已经在使用 修复带连字符的单词,我似乎无法弄清楚的是 how to keep words with apostrophes for contractions like: can't, won 't, don't, he's, 等等一起作为spacy中的一个token.
更具体地说,我正在搜索如何为荷兰语单词执行此操作:zo'n、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',"zo'n",'zes' ,'meter','onder','het','wateroppervlak','van','de','Noordzee','.'
我知道可以添加自定义规则,例如:
case = [{ORTH: "zo"}, {ORTH: "'n", LEMMA: "een"}]
tokenizer.add_special_case("zo'n",case)
但我正在寻找更通用的解决方案。
我试过从另一个线程编辑 infix_re
正则表达式,但我似乎对这个问题没有任何影响。我可以做任何设置或更改来解决这个问题吗?
spaCy
最近有一项正在进行的工作,用于修复荷兰语的这些类型的词汇形式。今天的 Pull Request 中有更多信息:https://github.com/explosion/spaCy/pull/3409
更具体地说,nl/punctuation.py
(https://github.com/explosion/spaCy/pull/3409/files#diff-84f02ed25ff9e44641672ca0ba5c1839) 展示了如何通过更改后缀来解决此问题:
我正在尝试正确拆分单词以适合我的语料库。我已经在使用
更具体地说,我正在搜索如何为荷兰语单词执行此操作:zo'n、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',"zo'n",'zes' ,'meter','onder','het','wateroppervlak','van','de','Noordzee','.'
我知道可以添加自定义规则,例如:
case = [{ORTH: "zo"}, {ORTH: "'n", LEMMA: "een"}]
tokenizer.add_special_case("zo'n",case)
但我正在寻找更通用的解决方案。
我试过从另一个线程编辑 infix_re
正则表达式,但我似乎对这个问题没有任何影响。我可以做任何设置或更改来解决这个问题吗?
spaCy
最近有一项正在进行的工作,用于修复荷兰语的这些类型的词汇形式。今天的 Pull Request 中有更多信息:https://github.com/explosion/spaCy/pull/3409
更具体地说,nl/punctuation.py
(https://github.com/explosion/spaCy/pull/3409/files#diff-84f02ed25ff9e44641672ca0ba5c1839) 展示了如何通过更改后缀来解决此问题: