我正在尝试将一个自定义PhraseMatcher()组件集成到我的nlp管道中,这样我就可以加载自定义Spacy模型,而不必在每次加载时将我的自定义组件重新添加到通用模型中。
如何加载包含自定义管道组件的Spacy模型?
我创建组件,将其添加到管道中,并使用以下方法保存它:
import requests
from spacy.lang.en import English
from spacy.matcher import PhraseMatcher
from spacy.tokens import Doc, Span, Token
class RESTCountriesComponent(
以下代码运行时没有错误
import spacy
from spacy.matcher import PhraseMatcher
nlp = spacy.load('en_core_web_lg')
test = nlp(' FWCA rate of pay')
phrase_pattern = [r'Rate of Pay']
pattern_name = 'RATES'
patterns = [nlp.make_doc(name) for name in phrase_pattern]
matcher = PhraseM
我最近在使用spacy时遇到了一个奇怪的行为,那就是当我处理字符串时, 在字符串是单个字符串对象的情况下,我必须使用nlp( string ), 而对于由字符串元素组成的列表,我必须使用nlp.pipe(一个列表)。 示例如下。 string='this is a string to be process by nlp'
doc =['this','is','a','string','list','to','be','processed','
我创建了一个文本和图像的混合模型。当我训练我的模型时,我在每一个时代都得到同样的结果。下面是我的密码。
import tensorflow as tf
import pandas as pd
import numpy as np
base_dir = "D:/Dataset/xxxx/datasets/xxx/xx/xxxxx/"
import os
train_dir = os.path.join(base_dir,"trin.jsonl")
test_dir = os.path.join(base_dir,"tst.jsonl")
de
我正在尝试在spaCy中编写一个自定义句子分段程序,它将整个文档作为一个句子返回。
我编写了一个自定义管道组件,它使用来自的代码来完成它。
不过,我不能让它起作用,因为它不是改变句子的边界,而是将整个文档作为一个句子来处理,它会抛出两个不同的错误。
如果我创建一个空白语言实例,并且只将我的自定义组件添加到管道中,则会得到以下错误:
ValueError: Sentence boundary detection requires the dependency parse, which requires a statistical model to be installed and loaded.
我制作了一个卷积网络,在一些层中进行了膨胀,在训练时得到了以下错误:tensorflow.python.framework.errors_impl.InvalidArgumentError: padded_shape[0]=170 is not divisible by block_shape[0]=4 错误发生在名为encoder_5的层上,该层是第一次应用膨胀。当我在该层中使用padding="valid"时,不会出现错误,但这不是一个选项,因为我需要维护尺寸,以便能够在以后的阶段进行连接。我不明白这个错误是从哪里来的,好像填充不能正常工作。错误与这里相同:https:
我已经用以下步骤定制了NER管道
doc = nlp("I am going to Vallila. I am going to Sörnäinen.")
for ent in doc.ents:
print(ent.text, ent.label_)
LABEL = 'DISTRICT'
TRAIN_DATA = [
(
'We need to deliver it to Vallila', {
'entities': [(25, 32, 'DISTRICT')]
因此,我是Python新手,我一直在从事斯坦福NLP的工作。下面是我创建的两个管道。
nlp = stanza.Pipeline(lang='en', processors='tokenize,mwt,pos,lemma,depparse')
doc = nlp('This is Prince Georges medic 829 were en route with a fourteen year old male, gunshot wound. The patient has two wounds both, um, both approximate
我正试着训练新的实体为斯佩西纳。我尝试将我的新实体添加到现有的spacy 'en‘模型中。然而,这影响了'en'和我的新实体的预测模型。
因此,我建立了一个空白模型并训练了实体识别。这个效果很好。然而,它只能预测我训练过的对象,而不能预测常规的spacy实体识别。
比如说我把“马”训练成动物实体。
对于给定的文本
txt ='Did you know that George bought those horses for 10000 dollars?'
我期待着下列实体得到认可
George - PERSON
horses - ANIMAL
10000
要更改语言模型中IS_CURRENCY的定义,请使用以下代码。
from spacy.lang.nl import EnglishDefaults, English
def is_currency(text):
"""
Custom function used for detecting currency symbols.
:param text: The text that is to be checked.
:return: A boolean.
"""
# Stripping pu
目前,我正试图使用spacy来训练文本分类器,我遇到了以下问题:使用spacy.blank('en')创建空白模型与使用经过预先训练的模型spacy.load('en_core_web_sm')有什么区别。为了了解我编写的代码的不同之处:
text = "hello everyone, it's a wonderful day today"
nlp1 = spacy.load('en_core_web_sm')
for token in nlp1(text):
print(token.text, token.le
我正在尝试设置一个简单的代码,在其中传递一个数据,并使用johnSnowLabs Spark库提供的经过预先训练的解释管道来测试它。我正在使用anaconda的jupyter笔记本,并使用apache安装了。每次我运行应该加载预先训练的管道的步骤时,它都会抛出一个tensorflow错误。有什么方法可以在本地windows上运行吗?
I was trying this in a maven project earlier and the same error had happened. Another colleague tried it on a linux system and it wo
我正在使用spacy的PhraseMatcher来识别用户评论中的药物名称。当应用服务器启动时,我正在从一个大文件中预装名称,但不希望在每个文档进程中都这样做,因为这需要一段时间。在处理新文档时,我希望在短语中添加识别出的新药物,以便它识别新的名称。然而,spacy不会接受同样的match_id的新药。任何帮助都将不胜感激。
# Global preload when application server starts
import spacy
from spacy.matcher import PhraseMatcher
nlp = spacy.blank("en")
dr
我在解决这一错误方面面临困难。我想将Layer对象传递给python中的一个类,我面临一个导入错误。这是错误消息。
Traceback (most recent call last):
File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/annotate_docs.py", line 3, in <module>
from wrap import Sequence
File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/wrap.py", li
我想要运行一些多处理模块,以运行一些短语匹配的文档并行。为此,我考虑在一个进程中创建短语匹配对象,然后通过创建PhraseMatcher对象的副本在多个进程之间共享。这段代码似乎失败了,没有给出任何错误。为了让事情变得更简单,我尝试过这样做,以展示我正在努力实现的目标。
import copy
import spacy
from spacy.matcher import PhraseMatcher
nlp = spacy.load('en')
color_patterns = [nlp(text) for text in ('red', 'green
基于此链接:Is it possible to use spacy with already tokenized input? 我可以让Spacy接受标记化的文档作为输入,并进一步处理文档。代码如下: def nlp_process(self, token_tuple):
# token_tuple = ("This is a test", ['This','is','a','test'])
doc = Doc(self.nlp.vocab, words=token_tuple[1])
fo
我面临以下错误:
InvalidArgumentError: indices3 = 0,2917出现故障。许多稀疏操作都需要排序索引。使用tf.sparse.reorder 创建一个正确排序的副本。--我不知道如何修复这个错误。我试着用重新排序的方法,但没有用
以下代码如下:
def score_transform(X):
y_reshaped = np.reshape(X['rating'].values, (-1, 1))
for index, val in enumerate(y_reshaped):
if val >= 8:
我在同时注释多个句子时遇到了并发问题。我不清楚是我做错了什么,还是CoreNLP中有个bug。
我的目标是使用几个并行运行的线程,使用流水线"tokenize,ssplit,pos,lemma,ner,parse,dcoref“来注释句子。每个线程分配自己的StanfordCoreNLP实例,然后将其用于注释。
问题是在某个时刻抛出了一个异常:
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at jav
我要处理数十万条短信。我发现在以下情况中,耗时最长的是:
nlp = English()
ruler = EntityRuler(nlp)
patterns = [...]
ruler.add_patterns(patterns)
nlp.add_pipe(ruler)
...
#This line takes longer than I would like
doc = nlp(whole_chat)
诚然,我有很多模式。但是有没有办法加快速度呢?我只有实体标尺管道,没有其他的。