- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 spacy NER 训练新实体。我尝试将我的新实体添加到现有的 spacy 'en' 模型中。然而,这影响了 'en'
的预测模型。和我的新实体。
因此,我创建了一个空白模型并训练了实体识别。这很好用。然而,它只能预测我训练过的那些,而不是常规的空间实体识别。
假设我将“马”训练为 ANIMAL 实体。
对于给定的文本
txt ='Did you know that George bought those horses for 10000 dollars?'
George - PERSON
horses - ANIMAL
10000 dollars - MONEY.
nlp = spacy.load('en')
hsnlp = spacy.load('models/spacy/animal/')
nlp.add_pipe(hsnlp.pipeline[-1][-1], 'hsner')
nlp.pipe_names
----------------------
['tagger', 'parser', 'ner', 'hsner']
----------------------
doc = nlp(txt) *<-- Gives me kernel error and stops working*
最佳答案
主要问题是如何加载和组合管道组件,以便它们使用相同的 Vocab
( nlp.vocab
),因为管道假定所有组件共享相同的词汇,否则您可能会得到与 StringStore
相关的错误.
您不应该尝试组合使用不同词向量训练的管道组件,但只要向量相同,问题就在于如何从具有相同词汇的不同模型中加载组件。
没有办法用 spacy.load()
做到这一点,所以我认为最简单的选择是使用所需的词汇初始化一个新的管道组件,并通过临时序列化将现有组件重新加载到新组件中。
为了使用易于访问的模型进行简短的工作演示,我将展示如何添加来自 de_core_news_sm
的德国 NER 模型。到英文模型en_core_web_sm
即使这不是您通常想要做的事情:
import spacy # tested with v2.2.3
from spacy.pipeline import EntityRecognizer
text = "Jane lives in Boston. Jan lives in Bremen."
# load the English and German models
nlp_en = spacy.load('en_core_web_sm') # NER tags PERSON, GPE, ...
nlp_de = spacy.load('de_core_news_sm') # NER tags PER, LOC, ...
# the Vocab objects are not the same
assert nlp_en.vocab != nlp_de.vocab
# but the vectors are identical (because neither model has vectors)
assert nlp_en.vocab.vectors.to_bytes() == nlp_de.vocab.vectors.to_bytes()
# original English output
doc1 = nlp_en(text)
print([(ent.text, ent.label_) for ent in doc1.ents])
# [('Jane', 'PERSON'), ('Boston', 'GPE'), ('Bremen', 'GPE')]
# original German output (the German model makes weird predictions for English text)
doc2 = nlp_de(text)
print([(ent.text, ent.label_) for ent in doc2.ents])
# [('Jane lives', 'PER'), ('Boston', 'LOC'), ('Jan lives', 'PER'), ('Bremen', 'LOC')]
# initialize a new NER component with the vocab from the English pipeline
ner_de = EntityRecognizer(nlp_en.vocab)
# reload the NER component from the German model by serializing
# without the vocab and deserializing using the new NER component
ner_de.from_bytes(nlp_de.get_pipe("ner").to_bytes(exclude=["vocab"]))
# add the German NER component to the end of the English pipeline
nlp_en.add_pipe(ner_de, name="ner_de")
# check that they have the same vocab
assert nlp_en.vocab == ner_de.vocab
# combined output (English NER runs first, German second)
doc3 = nlp_en(text)
print([(ent.text, ent.label_) for ent in doc3.ents])
# [('Jane', 'PERSON'), ('Boston', 'GPE'), ('Jan lives', 'PER'), ('Bremen', 'GPE')]
EntityRuler
和
EntityRecognizer
)旨在保留任何现有实体,因此新组件仅添加
Jan lives
带有德国 NER 标签
PER
并按照英语 NER 的预测保留所有其他实体。
add_pipe()
的选项以确定组件在管道中的插入位置。在默认的英语 NER 之前添加德语 NER:
nlp_en.add_pipe(ner_de, name="ner_de", before="ner")
# [('Jane lives', 'PER'), ('Boston', 'LOC'), ('Jan lives', 'PER'), ('Bremen', 'LOC')]
add_pipe()
选项在文档中:
https://spacy.io/api/language#add_pipe
spacy.load()
在一行中加载它。下一次:
nlp_en.to_disk("/path/to/model")
nlp_reloaded = spacy.load("/path/to/model")
print(nlp_reloaded.pipe_names) # ['tagger', 'parser', 'ner', 'ner_de']
关于python - 如何在 Spacy 中创建具有多个模型的 NER 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54855780/
在 spaCy < 3.0 中,我能够在经过训练的 en_core_web_sm 模型中训练 NER 组件: python -m spacy train en model training valid
代码片段如下: In [390]: t Out[390]: ['my', 'phone', 'number', 'is', '1111', '1111', '1111'] In [391]: ner_
我正在使用 python 的内置库 nltk 来获取 stanford ner tagger api 设置,但我发现此 api 的单词标记与 stanford 的 ner tagger 网站上的在线演
我已经在我的 VM 上设置了所有安装的需求包,但我发现没有安装 nvidia GPU 驱动程序,在需求中没有 nvidia GPU 驱动程序安装说明,我想知道哪个 cuda 版本和它兼容的 nvidi
我正在尝试使用Stanford CoreNLP训练NER模型,但是找不到主类。我已经在我的CLASSPATH中包含了jar文件的路径,但仍然找不到它们。有什么办法解决这个问题吗? C:\ Users
在 opennlp 的文档中提到,我们必须用 15000 行来训练我们的模型以获得良好的性能。 现在,我必须从文档中提取不同的实体,这意味着我必须为训练数据(15000 行)中的许多标记添加不同的标签
我正在编写一些代码来执行命名实体识别 (NER),这对于英文文本来说效果很好。但是,我希望能够将 NER 应用于任何语言。为此,我想 1) 识别文本的语言,然后 2) 将 NER 应用于识别的语言。对
我正在尝试训练一种新的实体类型“HE INST”——以识别大学。 那是唯一的新标签。我有一个很长的文档作为原始文本。我在其上运行 NER 并将实体保存到 TRAIN DATA 中,然后将新实体标签添加
...或者性别信息就足够了吗?更具体地说,我有兴趣知道是否可以减少斯坦福核心 NLP 加载的模型数量以提取共指。我对实际的命名实体识别不感兴趣。 谢谢 最佳答案 根据描述使用斯坦福 CoreNLP 打
我刚刚开始使用斯坦福 CoreNLP,我想构建一个自定义 NER 模型来查找人员。 不幸的是,我没有找到一个好的意大利语ner模型。我需要在简历/简历文档中找到这些实体。 这里的问题是像这样的文档可以
我从这里学会了如何用 Java 定制斯坦福 NER(命名实体识别器): http://nlp.stanford.edu/software/crf-faq.shtml#a 但是我正在使用 Python
我需要构建一个识别特定域中的 NE 的分类器。例如,如果我的域是曲棍球或足球,分类器应该接受该域中的 NE,但不接受它在网页上看到的所有代词。我的最终目标是通过 NER 改进文本分类。 对于从事该领域
我想识别特定领域(例如棒球)中的命名实体。我知道有一些可用的工具,如斯坦福NER、LingPipe、AlchemyAPI,我已经用它们做了一些测试。但正如我之前提到的,我希望它们是针对特定领域的。这怎
我正在尝试构建一个用于产品名称及其型号的自定义命名实体提取器。 我的用例包含如下句子:“微软使用了产品 ABC-300 并将其与 ASQ 集成”。上句提到的产品是:ABC-300和ASQ 我已经尝试过
我从来没有真正处理过 NLP,但对 NER 有一个想法,它不应该起作用,但在某种情况下却做得非常好。我不明白它为什么起作用,为什么不起作用或天气可以延长。 我们的想法是通过以下方式提取故事中主要人物的
我正在寻找关于以下问题的想法/想法: 我正在处理食品成分数据,例如:牛奶、糖、鸡蛋、面粉,可能含有坚果 我希望能够从这样的文本中识别和提取像可能包含坚果这样的短语,以分别对其进行预处理 这类短语在长度
我已经创建了一个用于训练 NER 数据的数据集。创建后,我想在应用于训练管道之前测试实体和数据是否匹配。使用位移我们可以以更好的方式可视化。但是如何在 spacy 3 中完成。 最佳答案 上面问题的代
执行此 Stanford NLP FAQ 中的步骤后,我能够生成模型的 zip 文件。但在文档中,他们使用 TSV 文件来计算针对已注释文件的预测准确性,但没有任何文档说明如何针对新文件对其进行测试!
我在检测以小写字母开头的命名实体时遇到问题。如果我只用小写单词训练模型,那么准确率是合理的;但是,当模型使用完全大写的标记或什至是小写和大写混合训练时,结果非常糟糕。我尝试了斯坦福 NLP 小组提供的
我现在正在使用一些 NLP 库,(stanford 和 nltk) 斯坦福我看到了演示部分,但只是想问问是否可以用它来识别更多的实体类型。 因此,目前斯坦福 NER 系统(如演示所示)可以将实体识别为
我是一名优秀的程序员,十分优秀!