如何在fasttext python中获取文本数据的预测?

问题描述

我正在建立一个用于快速文本中文分类的监督模型。

要预测特定字符串的输出,我们可以在python中使用它

model.predict("Why not put knives in the dishwasher?")

但是如何通过python命令获得整个测试集的预测?在命令行中可以这样做

./fasttext predict <path to model> <path to test file> k > <path to prediction file>

解决方法

我找到了解决方法

def predict(row):
    return model.predict(row['input'])
test['predictions'] = test.apply(predict,axis=1)