fasttext error: predict processes one line at a time (remove '\n')
Asked Answered
S

1

5

Hi I have a dataframe column contains text. I want to use fasttext model to make prediction from it. I can achieve this by passing an array of text to fasttext model.

import fasttext
d = {'id':[1, 2, 3], 'name':['a', 'b', 'c']}
df = pd.DataFrame(data=d)

I removed '\n' from the series

name_list = df['name'].tolist()
name_list = [name.strip() for name in name_list]

and make prediction model.predict(name_list)

However, I got ValueError: predict processes one line at a time (remove '\n')

I don't have '\n' in the list and '\n' in name_list returns False

I also found a post with the similar issue but still got the same error.

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
Standpoint answered 21/1, 2021 at 3:55 Comment(0)
P
8

Before giving model.predict(name_list), try giving a for loop:

for item in name_list:
   item = item.replace("\n"," ")
   model.predict(item)
Philae answered 27/1, 2021 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.