[英]How to add a custom tag to spacy NER
I would like to add some tags to "en_core_web_sm"
For example: I want the Spacy NER model to tag "16GB" as a RAM and "Intel core i7" as a CPU How can I do this?我想在
"en_core_web_sm"
中添加一些标签 例如:我希望 Spacy NER 模型将“16GB”标记为 RAM,将“Intel core i7”标记为 CPU 我该怎么做?
I tried the following:我尝试了以下方法:
nlp = spacy.load("en_core_web_sm")
ruler = EntityRuler(nlp)
patterns = [{"label": "RAM", "pattern": "16gb ram"}]
ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns(patterns)
doc = nlp("16gb ram is my order")
for ent in doc.ents:
print(ent.text,ent.label_)
and the output was: 16 CARDINAL输出是:16 CARDINAL
If you just want to add new tags with the EntityRuler you can do that by setting overwrite_ents = True
.如果您只想使用 EntityRuler 添加新标签,您可以通过设置
overwrite_ents = True
来实现。 See here in the docs, but it looks something like this:请参阅此处的文档,但它看起来像这样:
config = {"overwrite_ents": True}
nlp.add_pipe("entity_ruler", config=config)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.