NLP之Fasttext

NLP之Fasttext

一、简介

     Fasttext是2016年facebook开源的一个机器学习模型,可用于生成词向量和文本分类。文本分类方面据说有着和深度学习模型接近的效果,并且训练速度更快(其中一个原因是使用了层次化softmax加快了运算过程)。模型的输入是一个句子及其n-gram特征,输出类别。

二、语料(文本分类)

      输入的数据需要经过一些简单的处理,fasttext有着自己的数据格式:
     					  ‘__label__[类别] 文本’
    另外fasttext用于监督学习的时候,训练及其预测过程类似于机器学习,它可调用fasttext.supervised(参数)训练,这里有一点需要注意,输入数据不是直接输入训练文本,而是输入训练文本所在的路径。但是在预测的时候,输入的是文本序列。

三、Fasttext.supervised常用参数:

		Input: 训练文本的路径
		output: 模型的保存路径

	下面是一些可选参数:
		-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]   (select with bucket)
		-minCount: minimal number of word occurences [1]
		-neg :number of negatives sampled [5]
		-wordNgrams :max length of word ngram [1]
		-loss: loss function {ns, hs, softmax} [ns]
		-bucket: number of buckets [2000000]
		-minn :min length of char ngram [3]
		-maxn: max length of char ngram [6]
		-thread: number of threads [12]
		-t :sampling threshold [0.0001]
		-labe:l labels prefix [__label__]

四、精度评估&预测:

	精度评估:
				result = model.test(‘test.txt’)
				print(‘precision:{}’.format(result.precison))
				Print(‘recall:{}’.format(result.recall))
				print(‘Number of examples’, result.nexample)
	模型预测:
				(1)model.predict(texts)	# 仅标签类别
				(2)model.predict_proba(texts)	# 带概率的标签类别,比如[[('0', 0.998047)]]

五、其它

	(1)词向量的特点:词向量的距离可以衡量单词间的语义相似度
	(2)Fasttext模型类似于word2vec的CBOW模型,但CBOW是用上下文预测目标词汇,而fasttext是预测类别。具体可参考下面的博文:
	FastText:快速的文本分类器  https://blog.csdn.net/john_bh/article/details/79268850

六、参考文献

	[1]博文:http://albertxiebnu.github.io/fasttext/
	[2]Fasttext源码:https://github.com/facebookresearch/fastText
	[3]word2vec详解 https://blog.csdn.net/itplus/article/details/37969519
	[4]使用fasttext文本分类实践:https://cloud.tencent.com/developer/article/1061909
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值