我使用SpaCy将文本分成几个句子,在每个句子上匹配一个正则表达式模式,并根据匹配结果使用一些逻辑。我从一种天真的方法开始,比如: nlp = spacy.load("en_core_web_trf")
regex = re.compile(r'\b(foo|bar)\b')
for text in texts_list:
doc = nlp(text)
for sent in doc.sents:
if re.search(regex, str(s)):
[...]
else:
[...] 而且速度非常慢。然后我使用
我当前正在对此执行数据清理。这些文本消息中有许多省略号,例如:
mystr = 'Go until jurong point, crazy.. Available only in bugis n great world la e buffet... Cine there got amore wat...'
如您所见,有两个句点(..)或三个句点(...)的省略号
我最初的解决方案是编写一个函数spacy_tokenizer来标记我的字符串,删除停用词和标点符号:
import spacy
nlp = spacy.load('en_core_web_sm')
fr
我是新的spacy和玩下面的脚本;
import spacy
from spacy.language import Language
from spacy.matcher import Matcher
nlp = spacy.load('en_core_web_sm')
text = "Google announced a new Pixel at Google I/O. The Google I/O is a great place to get all the updates from Google I/O."
def add_event_ent(ma
与nltk相比,我之所以选择spacy来处理各种文本,是因为它的引理性能。但是当我处理数以百万计的短文本时,它总是消耗掉我所有的内存(32G)并崩溃。没有它,只要几分钟和不到10克米被消耗。
这种方法的使用有什么问题吗?是否有更好的解决方案来提高性能?谢谢!
def tokenizer(text):
try:
tokens = [ word for sent in sent_tokenize(text) for word in word_tokenize(sent)]
tokens = list(filter(lambda t: t.lower() no
我在spacy代码中有一个例子:
from numpy import dot
from numpy.linalg import norm
from spacy.lang.en import English
parser = English()
# you can access known words from the parser's vocabulary
nasa = parser.vocab[u'NASA']
# cosine similarity
cosine = lambda v1, v2: d
我刚开始使用SpaCy。我们能告诉spacy API在给令牌时忽略符号吗?
示例:
对于句子Hi, Welcome to StackOverflow.,标记是
Hi
,
Welcome
to
StackOverflow
.
我希望spacy只为有空格的单词提供标记。对于上面的例子,令牌应该是
Hi,
Welcome
to
StackOverflow.
Spacy展示了如何使用的标记器获取Conll格式的文本块的依赖关系。这是发布的解决方案:
import spacy
nlp_en = spacy.load('en')
doc = nlp_en(u'Bob bought the pizza to Alice')
for sent in doc.sents:
for i, word in enumerate(sent):
if word.head == word:
head_idx = 0
else:
我试图使用spacy为文档中的所有标记获取引理(即token.lemma_)。
代码:
sentence = 'I'm looking for all of the lemmas. Please help me find them!'
nlp = spacy.load('en', disable=['parser', 'NER])
doc = nlp(sentence)
tokens = [tokens.lemma_ for token in doc]
预期结果:
['look', 'lemma',
我将spacy用于pos_标签(部分语音标签),下面是我非常简单的方法:
import spacy
model=spacy.load('en_core_web_sm')
for i in model('I want so sit on Dining table set.'):
print((i,i.pos_))
输出为:
(I, 'PRON')
(want, 'VERB')
(so, 'ADV')
(sit, 'VERB')
(on, 'ADP')
(Dining,
我正在寻找一个句子分段,可以分裂复句成简单的句子。
示例:
Input: Andrea is beautiful but she is strict.
(expected) Output: Andrea is beautiful. she is strict.
Input: i am andrea and i work for google.
(expected) Output: i am andrea. i work for google.
Input: Italy is my favorite country; i plan to spend two weeks there next
我的句子是:She had another chemotherapy protocol history with 5-FU alone before this protocol without any significant side effects.
当我把它放在displacy ()中时,输出包含了作为名词短语的5-FU的引用。
然而,当我注释文本和搜索名词块时,我没有被显示为一个名词块。
nlp = spacy.load('en') ax = nlp(mySentence) for w in ax.noun_chunks: print(w)
另外,当我用下面的代
当我运行以下代码下载英文模型时,我按照上的说明使用蟒蛇安装了spaCy
python -m spacy download en
我得到以下错误。
/anaconda3/bin/python: No module named spacy.__main__; 'spacy' is a package and cannot be directly executed
我试图使用spaCy的四种选择中的两种来进行句子切分,它们在没有标点符号的短语上的表现似乎都同样糟糕。我正在尝试使用这样的解决方案,这些解决方案的文本范围是混合的,而不是数字化的(说话人的对话)。我的目标是识别句子的边界,我认为语言解析功能可以很好地将短语分解成单个的句子元素。
python version and spacy version with language models:
============================== Info about spaCy ==============================
spaCy version 3.4.3
我正在使用spaCy的句子分隔器。
from spacy.lang.en import English
nlp = English()
sbd = nlp.create_pipe('sentencizer')
nlp.add_pipe(sbd)
text="Please read the analysis. (You'll be amazed.)"
doc = nlp(text)
sents_list = []
for sent in doc.sents:
sents_list.append(sent.text)
print(sents_li
我有以下案文:
方法1:使用regex的基于规则的方法
text=r" this is one 2012/02/12.This is another 21-09-2021. This is third 08/09/2015 and this is final date 19870901"
import re
import pandas as pd
def extract_date_strings(text):
extracted=re.findall(r"[0-9]+[\\\-\/\_]+[0-9]+[\\\-\/\_]+[0-9]+",text)
我使用了中提供的命令。我遵循以下所有步骤:-
使用spacy格式创建模型TRAIN_DATA =[ ("Pizza is a common fast food.", {"entities": [(0, 5, "FOOD")]}), ("Pasta is an italian recipe", {"entities": [(0, 5, "FOOD")]})]
使用以下代码转换.spacy文件中的列车和开发数据:-
import os
from tqdm import tqdm
impo