共指消解/指代消解 spacy+neuralcoref 排坑
创始人
2024-06-01 20:41:07
0

背景

模型需要用到指代消解功能,查询到比较好用的是spaCy+neuralcoref。代码简单,但是出现了很多兼容性问题,neuralcoref相当于一个插件,在spaCy框架下实现指代消解,安装很多版本都不能顺利运行,各种error。最终找到一个匹配的版本。

问题

  1. Segmentation fault (core dumped)
  2. KeyError: “[E002] Can’t find factory for ‘tok2vec’. This usually happens when spaCy calls nlp.create_pipe with a component name that’s not built in - for example, when constructing the pipeline from a model’s meta.json. If you’re using a custom component, you can write to Language.factories['tok2vec'] or remove it from the model meta and add it via nlp.add_pipe instead.”
  3. ValueError: spacy.strings.StringStore size changed, may indicate binary incompatibility. Expected 80 from C header, got 64 from PyObject

解决

版本

python 3.8.16
spacy 2.1.0
neuralcoref 4.0
en_core_web_sm 2.1.0

其中en_core_web_sm是英文模型,可以用python -m spacy validate 查看spacy对应版本的模型版本。

包源码下载地址:

spacy:https://github.com/explosion/spaCy/tags?after=v3.4.3
en_core_web_sm:https://github.com/explosion/spacy-models/releases
neuralcoref:内网下比较容易安装

example

import spacy
import neuralcoref
# Load English tokenizer, tagger, parser and NER
nlp = spacy.load("en_core_web_sm")
neuralcoref.add_to_pipe(nlp)
# Process whole documents
text = ("When Sebastian Thrun started working on self-driving cars at ""Google in 2007, few people outside of the company took him ""seriously. “I can tell you very senior CEOs of major American ""car companies would shake my hand and turn away because I wasn’t ""worth talking to,” said Thrun, in an interview with Recode earlier ""this week.")
doc = nlp(text)for c in doc._.coref_clusters:print(c)# Analyze syntax
print("Noun phrases:", [chunk.text for chunk in doc.noun_chunks])
print("Verbs:", [token.lemma_ for token in doc if token.pos_ == "VERB"])# Find named entities, phrases and concepts
for entity in doc.ents:print(entity.text, entity.label_, entity.start_char, entity.end_char)

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
一帆风顺二龙腾飞三阳开泰祝福语... 本篇文章极速百科给大家谈谈一帆风顺二龙腾飞三阳开泰祝福语,以及一帆风顺二龙腾飞三阳开泰祝福语结婚对应...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...