简体   繁体   English

spaCy:如何为此使用一些已加载的 model 将命名实体写入现有文档 object?

[英]spaCy: How to write named entities to an existing Doc object using some loaded model for this?

I created a Doc object from a custom list of tokens according to documentation like so:我根据文档从自定义令牌列表中创建了一个Doc object,如下所示:

import spacy
from spacy.tokens import Doc

nlp = spacy.load("my_ner_model")
doc = Doc(nlp.vocab, words=["Hello", ",", "world", "!"])

How do I write named entities tags to doc with my NER model now?我现在如何使用我的 NER model 将命名实体标签写入doc

I tried to do doc = nlp(doc) , but that didn't work for me raising a TypeError .我试图做doc = nlp(doc) ,但这对我提出TypeError不起作用。

I can't just join my list of words into a plain text to do doc = nlp(text) as usual because in this case spaCy splits some words in my texts into two tokens which I can not accept.我不能像往常一样将我的单词列表加入到纯文本中来执行doc = nlp(text) ,因为在这种情况下, spaCy将我文本中的一些单词分成两个我不能接受的标记。

You can get the NER component from your loaded model and call it directly on the constructed Doc :您可以从加载的 model 中获取 NER 组件,并直接在构造的Doc上调用它:

doc = nlp.get_pipe("ner")(doc)

You can inspect a list of all the available components in the pipeline with nlp.pipe_names and call them individually this way.您可以使用nlp.pipe_names检查管道中所有可用组件的列表,并以这种方式单独调用它们。 The tokenizer is always the first element of the pipeline when you call nlp() and it isn't included in this list, which only has the components that both take and return a Doc .当您调用nlp()时,tokenizer 始终是管道的第一个元素,并且它不包含在此列表中,该列表仅包含接受和返回Doc的组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将带有命名实体的 CoNNL 格式的文本导入 spaCy,使用我的 model 推断实体并将它们写入同一数据集(使用 Python)? - How to import text from CoNNL format with named entities into spaCy, infer entities with my model and write them to the same dataset (with Python)? 如何使用 SpaCy 从 Pandas DataFrame 中提取命名实体 - How to extract Named Entities from Pandas DataFrame using SpaCy 从 spacy 对象中删除命名实体 - Remove Named Entities from the spacy object 如何使用 spacy train 将实体添加到现有的自定义 NER 模型中? (Spacy v3.0) - How to use spacy train to add entities to an existing custom NER model? (Spacy v3.0) 使用 spacy 从文档中删除命名实体 - Removing named entities from a document using spacy 使用 SpaCy 和 python lambda 提取命名实体 - Extract Named Entities using SpaCy and python lambda 基于空间规则的匹配实体正在覆盖现有实体,如何保留 - Spacy Rule Based Matching entities are overwriting existing entities, How to preserve 如何使用 Spacy NER 模型训练全新的实体而不是预训练的实体? - How to train completely new entities instead of pre-trained entities using Spacy NER model? 使用 spacy 从文档中删除复合词命名实体 - Removing compound worded named entities from a document using spacy 如何在 REST api 请求中将 spacy doc 对象作为有效负载发送并在 api 内部重建 spacy doc 对象? - How to send spacy doc object as payload in a REST api request and reconstruct the spacy doc object back inside the api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM