我正在尝试使用python制作一个聊天机器人,为此我使用Spacy进行实体识别,因此我安装了预建Spacy英语语言模型(Medium)来从用户话语中提取实体,但问题是,当我加载模型以从用户话语中提取实体时,需要31秒来加载模型,因为在我的情况下,我正在使聊天机器人的时间变得非常重要。需要你们所有人的一些指导吗,还有其他选择吗?任何帮助都将不胜感激
下面是从用户话语中提取实体的代码:
import spacy
import time
def extractEntity(userUtterance):
''' This funtion returns a list
英语语言模式在德语敬语实体上的表现是否比德语模型更好?
# pip install spacy
# python -m spacy download en
# python -m spacy download de
nlp = spacy.load('en')
# Uncomment line below to get less good results
# nlp = spacy.load('de')
# Process text
text = (u"Das Auto kauft Herr Müller oder Frau Meier, Frank
我在使用香料方面是新手。我想从句子中提取文本值。
training_sentence="I want to add a text field having name as new data"
OR
training_sentence=" add a field and label it as advance data"
因此,我想从上面的句子中提取“新数据”和“预发数据”。
现在,我能够提取实体,如“添加”,“字段”和“标签”使用自定义纳。
但是我无法提取文本值,因为这些值可以是任何内容,而且我也不知道如何在spacy中使用自定义NER来提取文本
我一直在一些文本上训练我的NER模型,并试图在其中找到具有自定义实体的城市。
示例:-
('paragraph Designated Offices Party A New York Party B Delaware paragraph pricing source calculation Market Value shall generally accepted pricing source reasonably agreed parties paragraph Spot rate Spot Rate specified paragraph reasonably agreed
假设我有一个字符串,想要标记一些实体,比如组织。
string = I was working as a marketing executive for Bank of India, a 4 months..
string_tagged = I was working as a marketing executive for [Bank of India], a 4 months..
我想要识别标记的实体旁边的单词。如何定位被标记的实体的位置并提取实体旁边的单词?
我的代码:
import spacy
nlp = spacy.load('en')
doc = nlp(s
我正在尝试使用Spacy从文档中删除命名实体。我没有发现任何识别命名实体的麻烦。使用以下代码:
ne = [(ent.text, ent.label_) for ent in doc.ents]
print(ne)
persons = [ent.text for ent in doc.ents if ent.label_ == 'PERSON']
print(persons)
输出:
'Timothy D. Cook',
'Peter',
'Peter',
'Benjamin A. Reitzes',
我使用从文本中提取一些与我的问题相关的命名实体,例如日期、时间、GPE等等。
例如,我需要识别以下句子中的时区:
"Australian Central Time"
使用Spacy模型en_core_web_lg,我得到了以下结果:
doc = nlp("Australian Central Time")
print([(ent.label_, ent.text) for ent in doc.ents])
>> [('NORP', 'Australian')]
,我的问题是:我对实体NORP的确切含义不太清
我正试着训练新的实体为斯佩西纳。我尝试将我的新实体添加到现有的spacy 'en‘模型中。然而,这影响了'en'和我的新实体的预测模型。
因此,我建立了一个空白模型并训练了实体识别。这个效果很好。然而,它只能预测我训练过的对象,而不能预测常规的spacy实体识别。
比如说我把“马”训练成动物实体。
对于给定的文本
txt ='Did you know that George bought those horses for 10000 dollars?'
我期待着下列实体得到认可
George - PERSON
horses - ANIMAL
10000
假设我有以下两句话:"Onions are being cut. However, a great big cut to the onions have been observed",我希望匹配短语“切洋葱”。这只是一个最小的例子。 我的要求是,算法遍历所有句子,并返回一个bool,即句子是否包含该短语。另外,我只希望匹配词汇化的版本,在短语之间有0个或更多的单词是可以的。因此,在上面的示例中,我希望它返回[False, True]。我该怎么做呢? 我的半个尝试如下(我需要帮助的地方被标记为TODO): import spacy
from spacy.matcher imp
我正在尝试查找句子的命名实体,如下所示
import spacy.lang.en
parser = spacy.lang.en.English()
ParsedSentence = parser(u"Alphabet is a new startup in China")
for Entity in ParsedSentence.ents:
print (Entity.label, Entity.label_, ' '.join(t.orth_ for t in Entity))
我希望得到的结果是“字母表”,“中国”,但我得到的结果是一个空集。我
我使用spaCy管道从文章中提取所有实体。我需要将这些实体保存在一个变量上,这取决于它们被标记的标签。现在我有了这个解决方案,但我认为这不是最合适的解决方案,因为我需要遍历每个标签的所有实体:
nlp = spacy.load("es_core_news_md")
text = # I upload my text here
doc = nlp(text)
personEntities = list(set([e.text for e in doc.ents if e.label_ == "PER"]))
locationEntities = list(set
我已经有了一个现有的spaCy模型,我想在运行时用额外的训练数据来改进它。
例如,我的训练模型中的训练dataSet如下所示:
text="Anna lives in Munich and works at BMW"
entity: name=Anna
entity: city=Munich
entity: company=BMW
在我的实现中,在开始新的训练之前,我从现有模型中获取ner:
nlp = spacy.load(modelPath)
ner = nlp.get_pipe('ner')
然后我用新的TrainingData训练我现有
为什么像西班牙语(es_dep_news_trf)这样的语言的空间转换器模型没有命名实体识别。
然而,对于英语(en_core_web_trf),它是这样的。
代码:
import spacy
nlp=spacy.load("en_core_web_trf")
doc=nlp("my name is John Smith and I work at Apple and I like visiting the Eiffel Tower")
print(doc.ents)
(John Smith, Apple, the Eiffel Tower)