【发布时间】:2021-02-16 15:55:35
【问题描述】:
我正在使用来自 FastText 的 module.predict。根据documentation,要显示的标签数量需要由k 参数指定。但是,就我而言,它不起作用,因此我只有概率最高的标签。这是我的代码:
import pandas as pd
import fasttext as ft
# here you load the csv into pandas dataframe
df=pd.read_csv('../input_data/data.csv')
# here you load your fasttext module
model=ft.load_model('../model/model.bin')
# line by line, you make the predictions and store them in a list
predictions=[]
for line in df['subject']:
pred_label=model.predict(line, k=5, threshold=0.5)
predictions.append(pred_label)
# you add the list to the dataframe, then save the datframe to new csv
df[['prediction','value']]=predictions
print(df)
df.to_csv('csv_file_w_pred.csv',sep=',',index=False)
我做错了什么?
问候
【问题讨论】: