gpt4 book ai didi

pandas - 快速文本错误 : predict processes one line at a time (remove '\n' )

转载 作者:行者123 更新时间:2023-12-05 01:32:02 74 4
gpt4 key购买 nike

您好,我有一个包含文本的数据框列。我想使用 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/

74 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com