【问题标题】:how to change parameters of fasttext api in a python script如何在python脚本中更改fasttext api的参数
【发布时间】:2018-04-12 13:35:44
【问题描述】:

我们有fasttext commands 在命令提示符下运行

我已经克隆了 github 存储库,例如在我使用的命令中更改网络参数以进行监督学习就像

 ./fasttext supervised -input FT_Race_data.txt -output race_model  -lr 0.4 -epoch 30 -loss hs

我正在改变 lr、epoch 和 loss。我可以训练并获取所需的输出。

为了用python脚本编程,我安装了fasttext库,我试过了

classifier = fasttext.supervised('FT_Race_data.txt','race_model') 

模型得到了训练,但结果并不好,在这种情况下,我没有定义任何参数。所以我尝试了

classifier = fasttext.supervised('FT_Race_data.txt','race_model', 0.4, 30, 'hs')

程序运行没有错误,但没有给出任何结果。所以我尝试了

classifier = fasttext.supervised(input = 'FT_Race_data.txt',output ='race_model', lr = 0.4,epoch= 30,loss = 'hs')

它给出了一个错误,即 fasttext 只需要两个参数。

如何在命令提示符下更改 python 脚本中的参数以微调监督学习?

【问题讨论】:

标签: python machine-learning nlp fasttext


【解决方案1】:

供将来参考,表单讨论here,似乎pip install fasttext 没有安装repo 中提供的全部功能。

所以在https://pypi.python.org/pypi/fasttext 中包含最新功能之前,对于具有训练模型和设置参数的功能的python 绑定,请按照here 概述的以下安装过程进行操作。

git clone https://github.com/facebookresearch/fastText.git
cd fastText
pip install .

然后使用train_supervised 一个返回模型对象的函数可以设置不同的参数,如下面的example in that repo

fastText.train_supervised(input, lr=0.1, dim=100, ws=5, epoch=5, minCount=1, minCountLabel=0, minn=0, maxn=0, neg=5, wordNgrams=1, loss='softmax', bucket=2000000, thread=12, lrUpdateRate=100, t=0.0001, label='__label__', verbose=2, pretrainedVectors='')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2012-08-05
    • 2018-07-05
    • 2023-04-05
    • 2012-09-11
    • 2016-05-18
    相关资源
    最近更新 更多