我正在开发一个使用Spacy的代码库。我使用以下方法安装了spacy:
sudo pip3 install spacy
然后
sudo python3 -m spacy download en
在最后一条命令的末尾,我收到了一条消息:
Linking successful
/home/rayabhik/.local/lib/python3.5/site-packages/en_core_web_sm -->
/home/rayabhik/.local/lib/python3.5/site-packages/spacy/data/en
You can now load the m
问题
我试着用把复数词单数化。
但是,我无法修正将复数转换为单数作为复合词的错误。
我怎样才能得到像下面这样的首选输出?
cute dog
two or three word
the christmas day
发展环境
Python 3.9.1
错误
print(str(nlp(word).lemma_))
AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'lemma_'
代码
import spacy
nlp = spacy.load("en_core_web_sm
我想知道是否有一种方法可以以字符串的形式使用tokenizer(s).to_array("LOWERCASE"),而不是使用uint8格式。
from spacy.lang.en import English
from spacy.tokenizer import Tokenizer
s = "Lets pray for the people that can be the victim of the possible eruption of Taal Volcano keep safe everyone."
# Create nlp obj
nlp =
目前,我正试图使用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
我能够安装spaCy并下载标准的英文版本(en_core_web_sm)。 但是,通过加载标准数据模型,我收到了以下错误消息: import spacy
# Load English tokenizer, tagger, parser and NER
nlp = spacy.load("en_core_web_sm")
ValueError: [E1005] Unable to set attribute 'POS' in tokenizer exception for ' '.
Tokenizer exceptions are o
我想做的是 我想提取的词,这是在spaCy上,自然语言操作系统的具体标签。 specific labels on spaCy 在下面的例子中,我希望打印单词English,因为选择了标签LANGUAGE。 English 问题 没有用于提取每个单词上的标签的示例代码。 我如何修复下面的错误? TypeError: Argument 'string' has incorrect type (expected str, got spacy.tokens.token.Token) 当前代码 import spacy
from spacy import displacy
nlp =
在我用向量作为递归神经网络的输入后,我用spacy将句子中的每个单词替换成一个数字/代码。
import spacy
str="basing based base"
sp = spacy.load('en_core_web_sm')
sentence=sp(str)
for w in sentence:
print(w.text,w.lemma)
在第一层神经网络中有角点,嵌入层中,我要知道查表中的最大单词数,有人知道这个数字吗?谢谢
我尝试了ner的spacy,但结果是高度unpredictable.Sometimes的spacy无法识别特定的country.Can,有人能解释一下为什么会这样吗?我尝试了一些随意的句子。
案例1:
nlp = spacy.load("en_core_web_sm")
print(nlp)
sent = "hello china hello japan"
doc = nlp(sent)
for i in doc.ents:
print(i.text," ",i.label_)
output :在这种情况下没有输出。
案例2:
nlp = s
假设我有一个文本,并想要检查它是否包含一些复合短语,其中我还想包括各自的单词可能不会直接被彼此跟随的情况。
例如,假设您想检查一条文本是否与消防队员有关,那么这样的文本
text = "currently there are over 4000 people involved in fighting the rapidly growing fires in Australia"
也会产生积极的结果。(我实际上想把它应用到德语中,那里的例子可能不那么人工)
我在NLP方面没有专业知识,所以也许有一些聪明的方法可以做到这一点,而我只是不知道该搜索哪个词是正确的。当然,如果文本不太大
我已经安装了Spacy和en_core_web_sm数据。如果我尝试在随机新闻文章中提取个人信息的代码,我得到大约50%的正确数据。其余的都有问题和错误。
import spacy
import io
from spacy.en import English
from spacy.parts_of_speech import NOUN
from spacy.parts_of_speech import ADP as PREP
nlp = English()
ents = list(doc.ents)
for entity in ents:
if entity.label_ == &
使用空格时,您可以轻松地循环遍历文本的noun_phrases,如下所示:
S='This is an example sentence that should include several parts and also make clear that studying Natural language Processing is not difficult'
nlp = spacy.load('en_core_web_sm')
doc = nlp(S)
[chunk.text for chunk in doc.noun_chunks]
# = ['
我无法使spaCy lemmatization起作用,它总是返回空字符串。
import spacy
from spacy.lang.en import English
nlp = English()
text = "I went to the bank today for checking my bank balance."
doc = nlp(text)
这只返回空字符串:
for token in doc:
print(token.lemma_)
系统信息:
Windows 10 Pro 64bits
Python 3.8.8
spacy
我正在执行一个数据提取用例。为了对我的数据进行预处理和标记,我同时使用了spacy英语和德语标记器,因为句子都是用这两种语言的。这是我的密码:
import spacy
from spacy.lang.de import German
from spacy.lang.en import English
from spacy.lang.de import STOP_WORDS as stp_wrds_de
from spacy.lang.en.stop_words import STOP_WORDS as stp_wrds_en
import string
punctuations = str
当我尝试用以下内容从en_core_web_sm从spacy加载时:
import spacy
nlp = spacy.load('en_core_web_sm')get the following error:
发生下列错误:
OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a Python package or a valid path to a data directory.
我使用了来自spacy.io的安装说明:
pip3 install
我编写了一个小程序从文本中提取语言实体。我使用的是'en_core_web_sm‘,但它确实从下面的句子中检测到了除DATE之外的其他任何东西。
从spacy 中,我可以看到“en_core_web_sm”支持语言实体。
我认为thatI做了一些明显的错误。有人能指出我做错了什么吗?
nlp2 = spacy.load("en_core_web_sm")
test_text = "korean chinese english spanish 2019-2-13 india america 2 years 6 months united state
我正在尝试计算spacy中的标记相似度。即单词标记彼此有多近。我使用的是spacy版本2.0.5。这是我的一个简单的例子。
import spacy
from spacy.lang.en import English
from spacy.tokenizer import Tokenizer
nlp = spacy.load('en')
x = nlp(u'apple')
y = nlp(u'apple')
x.similarity(y)
它的回报率是-81216639937292144.0,但我原本预计是1.0。
此外
x = nlp(
我正尝试在PyCharm中使用spacy 'en‘模型 要运行此代码: import spacy
nlp= spacy.load('en')
doc=nlp(u'I am trying to learn natural language processing for chatbots')
for token in doc:
print(token.txt,token.pos) 但是,我尝试在pycharm中执行以下命令来运行模型: "/Users/zahraaal-nemer/Desktop/University/Le
我正在尝试使用spacy_langdetect包,我能找到的唯一示例代码是():
import spacy
from spacy_langdetect import LanguageDetector
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe(LanguageDetector(), name='language_detector', last=True)
text = 'This is an english text.'
doc = nlp(text)
print(doc._.language)
我有一个Python程序,它使用spaCy来识别句子中的名词。这是我的程序:
import spacy
nlp = spacy.load('en_core_web_sm')
sentence = "1 slice of english blue cheese, preferably a stilton (again, or 4 slices for 4 sandwiches)"
doc = nlp(sentence)
for token in doc:
if token.pos_ == "NOUN":
当我使用SpaCy来识别停止词时,如果我使用en_core_web_lg语料库,它就不起作用了,但是当我使用en_core_web_sm时,它就起作用了。这是个窃听器,还是我做错了什么?
import spacy
nlp = spacy.load('en_core_web_lg')
doc = nlp(u'The cat ran over the hill and to my lap')
for word in doc:
print(f' {word} | {word.is_stop}')
结果:
The | False
cat
我正在尝试加载en_core_web_sm spaCy模型,但没有成功。
发生的错误如下:
OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a Python package or a valid path to a data directory.
我在Anaconda虚拟环境中工作。下面的复选框被勾选:
在安装environmentThen,之前,做了conda activate gcp-env,英语语言模型运行了conda install -c conda-for
我已经分别安装了Spacy和en_core_web_sm,并且我试图用完整的路径加载en_core_web_sm。
import spacy
import en_core_web_sm
nlp = spacy.load(r'C:\Anaconda3\Lib\site-packages\en_core_web_sm\en_core_web_sm-2.0.0')
doc = nlp("The big grey dog ate all of the chocolate, but fortunately he wasn't sick!")
这将导致以下错误:
s
我正在使用spaCy对使用段落编号的文本进行句子分割,例如:
text = '3. English law takes a dim view of stealing stuff from the shops. Some may argue that this is a pity.'
我正在尝试强制spaCy的句子分割器不要将3.拆分成它自己的句子。
目前,以下代码返回三个单独的句子:
nlp = spacy.load("en_core_web_sm")
text = """3. English law takes a dim view