mahout中LDA简介以及示例

1 篇文章 0 订阅
1 篇文章 0 订阅

翻译自: https://cwiki.apache.org/confluence/display/MAHOUT/Latent+Dirichlet+Allocation

 

简介:

Latent Dirichlet Allocation (Blei et al, 2003)是一个强大的学习方法将words聚到一些topics里面,以及把一些document表示成topics的一些集合。
主题模型就是document在topics上的概率分布,和words在topics上的分布的一个层次贝叶斯模型,举个例子,一个topic是包括“体育”,“篮球”,"全垒打"等词,一个document讲述一些在篮球比赛中使用违禁药,可能包含"体育",“篮球”,“违禁药”,这些词,是事先被人类定义的标签,算法只不过给这些词跟概率关联上。模型中参数估计的目的是把这些topic学习出来,一个document跟这些topic的概率是多少。
另一个理解主题模型的视角是把他看作类似于 Dirichlet Process Clustering  的混合模型,从一个正常的混合模型开始,我们有一个全局混合的几个分布,我们可以说每一个document都有他全局分布之上自己的一个分布,在dirichlet process clustering中,每一个document在全局混合分布上有他自己的隐变量决定他属于哪个模型,在LDA中每一个词又有在document上的一个分布。
我们按照一定概率混合一些模型来解释已观测到的数据,每一个被观测到的数据假设是来自于许多模型中的一个,但是我们并不知道来自于哪一个,所以我们用一个称之为隐含变量的名字来指他从哪里来。
Collapsed Variational Bayes
CVB算法在LDA mahout的实现中结合了variational bayes 和 gibbs sampling .
使用方法:
mahout中LDA的实现需要工作在 一个稀疏的词频的向量上,词频一定要是一个非负数的,在概率模型中,负数没有意义,确保用的是TF而不是IDF作为词频。
调用方法如下:
bin/mahout cvb \
    -i <input path for document vectors> \
    -dict <path to term-dictionary file(s) , glob expression supported> \
    -o <output path for topic-term distributions>
    -dt <output path for doc-topic distributions> \
    -k <number of latent topics> \
    -nt <number of unique features defined by input document vectors> \
    -mt <path to store model state after each iteration> \
    -maxIter <max number of iterations> \
    -mipd <max number of iterations per doc for learning> \
    -a <smoothing for doc topic distributions> \
    -e <smoothing for term topic distributions> \
    -seed <random seed> \
    -tf <fraction of data to hold for testing> \
    -block <number of iterations per perplexity check, ignored unless test_set_percentage>0> \
 选择topic的数量的时候,建议多试几次。
在运行LDA之后,可以使用工具打印出来结果:
bin/mahout ldatopics \
    -i <input vectors directory> \
    -d <input dictionary file> \
    -w <optional number of words to print> \
    -o <optional output working directory. Default is to console> \
    -h <print out help> \
    -dt <optional dictionary type (text|sequencefile). Default is text>
 示例:
在mahout/examples/bin/build-reuters.sh  有详细的示例脚本,脚本自动下载数据集,建立lucence索引,把lucence索引再变成 向量的形式,注释掉最后两行,让他运行你的LDA,打印出来结果。
把样例改成你所需要的形式,需要自己建立lucence索引,需要一个adapter,剩下的东西都差不多。
参数估计:
使用EM算法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值