【问题标题】:Error in printing the predicted label in FastText在 FastText 中打印预测标签时出错
【发布时间】: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)

我做错了什么?

问候

【问题讨论】:

    标签: python pandas fasttext


    【解决方案1】:

    您的阈值是 0.5。由于概率总和为 1,因此一次只能有一个标签高于该标签。

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      • 2019-05-06
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 2016-01-15
      相关资源
      最近更新 更多