Train spaCy's existing POS tagger with my own training examples

你说的曾经没有我的故事 提交于 2019-12-06 09:18:51

The English model is trained on PTB tags, not UD tags. spacy's tag map gives you a pretty good idea about the correspondences, but the PTB tagset is more fine-grained that the UD tagset:

https://github.com/explosion/spaCy/blob/master/spacy/lang/en/tag_map.py

Skip the tag_map-related code (the PTB -> UD mapping is already there in the model), change your tags in your data to PTB tags (NN, NNS, JJ, etc.), and then this script should run. (You'll still have to check whether it performs well, of course.)

In general, it's better to provide training examples with full phrases or sentences, since that's what spacy will be tagging in real usage like your test sentence.

If you intend to create your own TAG_MAP, you should also disable the tagger from the model. That way, its training on the original tags won't get in the way of new learning.

This means you will have to create your own, just like with the blank example, then add it to the pipeline. I'm doing the same with pt model, here's the relevant code:

nlp = spacy.load('pt_core_news_sm', disable=['parser', 'ner', 'tagger'])

tagger = nlp.create_pipe("tagger")
for tag, values in TAG_MAP_alternate.items():
    tagger.add_label(tag, values)
nlp.add_pipe(tagger)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!