fastText文本分类学习笔记
先下载,然后make,得到可执行c文件
$ gitclone https://github.com/facebookresearch/fastText.Git
$ cdfastText
$ make
文本分类,linux命令行:
./fasttext supervised -input train.txt -output model
训练集train.txt的输入格式为:
标签是以字符串label作为前缀的单词,后面的数字对应类别。我们可以将训练数据处理成这种形式,训练自己的文本分类模型。
一旦模型被训练,您可以通过使用以下方法计算测试集上的k的精度和召回率来对其进行评估:
$ ./fasttext test model.bin test.txt k
参数k可选,默认为1
为了预测获得一个文本的k个最可能的标签,使用:
$ ./fasttext predict model.bin test.txt k
其中test.txt包含要按行分类的文本。 这样输出为每一行的k个最可能的标签。
如果要计算句子或段落的向量表示,请使用:
$ ./fasttext print-sentence-vectors model.bin < text.txt
这假设text.txt文件包含您要获取向量的段落,一段为一行。 该程序将在文件中每行输出一个向量表示。
参数的命令以及可用的参数及其默认值:
$ ./fasttext supervised
Empty input or output path.
The following arguments are mandatory:
-input training file path 输入文件路径
-output output file path 输出文件路径
The following arguments are optional:
-verbose verbosity level [2]
The following arguments for the dictionary are optional:
-minCount minimal number of word occurences [5]
-minCountLabel minimal number of label occurences [0]
-wordNgrams max length of word ngram [1] 几元语言模型
-bucket number of buckets [2000000]
-minn min length of char ngram [3] 单词的最小长度
-maxn max length of char ngram [6] 单词的最大长度
-t sampling threshold [0.0001]
-label labels prefix [label] 标签前缀的选择
The following arguments for training are optional: 训练集可选参数
-lr learning rate [0.05]
-lrUpdateRate change the rate of updates for the learning rate [100]
-dim size of word vectors [100]
-ws size of the context window [5]
-epoch number of epochs [5]
-neg number of negatives sampled [5]
-loss loss function {ns, hs, softmax} [ns]
-thread number of threads [12]
-pretrainedVectors pretrained word vectors for supervised learning []
-saveOutput whether output params should be saved [0]