fastText文本分类cheatsheet

本文详细介绍FastText工具包的使用方法,包括词向量学习、文本分类、句子向量获取及模型量化等关键技术。同时,文章还介绍了如何进行超参数优化,并提供了一系列实用的命令行操作示例。

id: cheatsheet
title: Cheatsheet

Word representation learning

In order to learn word vectors do:

$ ./fasttext skipgram -input data.txt -output model

Obtaining word vectors

Print word vectors for a text file queries.txt containing words.

$ ./fasttext print-word-vectors model.bin < queries.txt

Text classification

In order to train a text classifier do:

$ ./fasttext supervised -input train.txt -output model

Once the model was trained, you can evaluate it by computing the precision and recall at k (P@k and R@k) on a test set using:

$ ./fasttext test model.bin test.txt 1

In order to obtain the k most likely labels for a piece of text, use:

$ ./fasttext predict model.bin test.txt k

In order to obtain the k most likely labels and their associated probabilities for a piece of text, use:

$ ./fasttext predict-prob model.bin test.txt k

If you want to compute vector representations of sentences or paragraphs, please use:

$ ./fasttext print-sentence-vectors model.bin < text.txt

Quantization

In order to create a .ftz file with a smaller memory footprint do:

$ ./fasttext quantize -output model

All other commands such as test also work with this model

$ ./fasttext test model.ftz test.txt

Autotune

Activate hyperparameter optimization with -autotune-validation argument:

$ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt

Set timeout (in seconds):

$ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt -autotune-duration 600

Constrain the final model size:

$ ./fasttext supervised -input train.txt -output model -autotune-validation valid.txt -autotune-modelsize 2M
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值