【发布时间】:2022-12-05 18:35:24
【问题描述】:
我遇到了我的数组不正确的值错误,这非常奇怪,因为我已经确认我的数组不为零。我打印出了每个特征和训练集的“len”。找到具有 0 个特征 (shape=(7, 0)) 的数组,而 SVC 至少需要 1 个特征。我正在使用 spacy 3.4.1 和 python 3.8.10。我究竟做错了什么?
import spacy
from sklearn import svm
nlp = spacy.load("en_core_web_trf")
train_x = [
"good characters and plot progression",
"check out the book",
"good story. would recommend",
"novel recommendation",
"need to make a deposit to the bank",
"balance inquiry savings",
"save money"
]
train_y = [
"BOOKS",
"BOOKS",
"BOOKS",
"BOOKS",
"BANK",
"BANK",
"BANK",
]
docs = [nlp(text) for text in train_x]
train_x_vectors = [doc.vector for doc in docs]
print (len(train_x_vectors))
print (len(train_y))
clf_svm = svm.SVC(kernel='linear')
clf_svm.fit(train_x_vectors, train_y)
【问题讨论】:
-
默认情况下,
Doc.vector将在 spaCy 中使用 trf 管道为空。你确定你不是在发送空向量吗?
标签: python-3.x nlp spacy-3