您好,我有一个包含文本的数据框列。我想使用 fasttext 模型从中进行预测。 我可以通过传递 array of text 来实现这一点到 fasttext 模型。
import fasttext
d = {'id':[1, 2, 3], 'name':['a', 'b', 'c']}
df = pd.DataFrame(data=d)
我从系列中删除了'\n'
name_list = df['name'].tolist()
name_list = [name.strip() for name in name_list]
并进行预测 model.predict(name_list)
但是,我得到了 ValueError: predict processes one line at a time (remove '\n')
我在列表中没有 '\n' 并且 '\n' in name_list
返回 False
我还找到了一个 post有类似的问题,但仍然有同样的错误。
predictions=[]
for line in df['name']:
pred_label=model.predict(line, k=-1, threshold=0.5)[0][0]
predictions.append(pred_label)
df['prediction']=predictions
最佳答案
在给出 model.predict(name_list) 之前,尝试给出一个 for 循环:
for item in name_list:
item = item.replace("\n"," ")
model.predict(item)
关于pandas - 快速文本错误 : predict processes one line at a time (remove '\n' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65820960/