使用DTM ( Dynamic Topic Models )进行主题演化实验
最近想研究下Dynamic Topic Models(DTM),论文看了看,文科生的水平确实是看不懂,那就实验一下吧,正好Blei的主页上也提供了相应的C++工具, http://www.cs.princeton.edu/~blei/topicmodeling.html,dtm这个代码放在google code中,下载需要fq。
下载了之后看了看,C++确实是不懂,但是在github上搜了一遭,也没找到完美的java版本,所以只能硬着头皮用C++了。
同时也去网上找找看看有没有人做过类似的工作,一搜确实是有,但是不多:
1、一哥们的实验,在linux下,http://www.jgoodwin.net/experimenting-with-dynamic-topic-models/
2、一些人的疑问,有没有python版本,答案是没有。http://stackoverflow.com/questions/22469506/are-there-any-efficient-python-libraries-for-dynamic-topic-models-preferably-ex
3、邮件列表 https://lists.cs.princeton.edu/pipermail/topic-models/
看了这么多,也没看明白是什么意思,还是自己慢慢搞吧。
第1步:安装系统
下载个centos5.5,这个在readme文件中有说明,作者就是这个版本编译的,我安装到了VMware中,当然还有另外的两个版本可以用。
第2步:编译文件
这个在readme文件中也有说明,把文件放到相应目录,make一下就行了。
第3步:作者建议先用他的文件里面带的一个小例子试验一下。
在dtm/sample.sh文件中有说明。
(1)输入文件。
两个输入文件是必须的,这些文件在dtm/example文件夹下面可以看到,是test-mult.dat和test-seq.dat。
a:foo-mult.dat ,用来表示文档和词的关系
每个文档一行,每一行形式是: unique_word_count index1:count1 index2:count2 ... indexn:counnt
用中文来说就是:该文章的总词数(不重复) 词1编号(用数字表示编号):词1频次 词2编号:词2频次 词n编号:词n频次
例如:11 288:1 1248:1 5:1 1063:2 269:1 654:1 656:2 532:1 373:1 1247:1 543:1
表示这篇一共有11个不重复的词,第228个词出现1次,1248个词出现1次,这些词是所有文档中统一编号的。
需要注意的一点是:该文件中文档是按时间顺序排列的,时间最早的在最上面,时间最晚的在最下面。
b:foo-deq.dat ,这文件是用来划分时间窗的。
文件格式如下:
Number_Timestamps(时间窗总数)
number_docs_time_1(第一个时间窗的文档数,就是从第一个到第几个文档划分到第一个时间窗,我们如果按年来划分,就把每年的文档数写到这里就行)
...
number_docs_time_i
...
number_docs_time_NumberTimestamps
作者提供的例子,第一行表示分为10个时间窗,第二行表示第一个时间窗有25个文档。(看样子估计也是按年划分的):
10
25
50
75
100
100
100
100
125
150
175
当上面两个文件搞定后。作者说还有两个文件虽然不是必须的,但是也是很有用的。
C: 词典文件
文档集合中涉及的所有的词,按照上面的词的序号排列。
d:文档信息文件
每行表示一个文档的基本信息,按照文档a中的顺序排列。
上述文件都可以用text2ldac生成,在https://github.com/JoKnopp/text2ldac下载,用python打开。
使用方法,在命令行中,找到text2ldac.py目录,运行 python text2ldac.py -o ./out -e txt ./in
out文件夹为输出文件位置,in文件夹为输入文件位置。 txt为仅处理txt文件
(2)运行程序
作者在readme文件中说,通过运行./main --help命令可以查看所有选项和解释,下面是运行该命令后的结果,太多了啊
Flag initialize_lda is of type bool, but its default value is not a boolean. NOTE: This will soon be a compilations error!main: Warning: SetUsageMessage() never called
Flags from ../lib/util/gflags-1.1/src/gflags.cc:
-flagfile (load flags from file) type: string default: ""
-fromenv (set flags from the environment [use 'export FLAGS_flag1=value'])
type: string default: ""
-tryfromenv (set flags from the environment if present) type: string
default: ""
-undefok (comma-separated list of flag names that it is okay to specify on
the command line even if the program does not define a flag with that
name. IMPORTANT: flags in this list that have arguments MUST use the
flag=value format) type: string default: ""Flags from ../lib/util/gflags-1.1/src/gflags_completions.cc:
-tab_completion_columns (Number of columns to use in output for tab
completion) type: int32 default: 80
-tab_completion_word (If non-empty, HandleCommandLineCompletions() will
hijack the process and attempt to do bash-style command line flag
completion on this value.) type: string default: ""Flags from ../lib/util/gflags-1.1/src/gflags_reporting.cc:
-help (show help on all flags [tip: all flags can have two dashes])
type: bool default: true
-helpfull (show help on all flags -- same as -help) type: bool
default: false
-helpmatch (show help on modules whose name contains the specified substr)
type: string default: ""
-helpon (show help on the modules named by this flag value) type: string
default: ""
-helppackage (show help on all modules in the main package) type: bool
default: false
-helpshort (show help on only the main module for this program) type: bool
default: false
-helpxml (produce an xml version of help) type: bool default: false
-version (show version and build info and exit) type: bool default: falseFlags from data.c:
-influence_flat_years (How many years is the influence nonzero?If nonpositive, a lognormal distribution is used.)type: int32 default: -1
-influence_mean_years (How many years is the mean number of citations?)
type: double default: 20
-influence_stdev_years (How many years is the stdev number of citations?)
type: double default: 15
-max_number_time_points (Used for the influence window.) type: int32
default: 200
-resolution (The resolution. Used to determine how far out the beta mean should be.)type: double default: 1
-sigma_c (c stdev.) type: double default: 0.050000000000000003
-sigma_cv (Variational c stdev.) type: double
default: 9.9999999999999995e-07
-sigma_d (If true, use the new phi calculation.) type: double
default: 0.050000000000000003
-sigma_l (If true, use the new phi calculation.) type: double
default: 0.050000000000000003
-time_resolution (This is the number of years per time slice.) type: double
default: 0.5Flags from gsl-wrappers.c:
-rng_seed (Specifies the random seed. If 0, seeds pseudo-randomly.)
type: int64 default: 0Flags from lda-seq.c:
-fix_topics (Fix a set of this many topics. This amounts to fixing these topics' variance at 1e-10.)type: int32 default: 0
-forward_window (The forward window for deltas. If negative, we use a beta with mean 5.)type: int32 default: 1
-lda_sequence_max_iter (The maximum number of iterations.)type: int32
default: 20
-lda_sequence_min_iter (The maximum number of iterations.)type: int32 default: 1
-normalize_docs (Describes how documents's wordcounts are considered for finding influence. Options are "normalize", "none", "occurrence", "log", or "log_norm".)type: string default: "normalize"
-save_time (Save a specific time. If -1, save all times.)type: int32 default: 2147483647
Flags from lda.c:
-lambda_convergence (Specifies the level of convergence required for lambda in the phi updates.)type: double default: 0.01
Flags from main.c:
-alpha () type: double default: -10
-corpus_prefix (The function to perform. Can be dtm or dim.)type: string default: ""
-end () type: int32 default: -1
-heldout_corpus_prefix () type: string default: ""
-heldout_time (A time up to (but not including) which we wish to train, and at which we wish to test.) type: int32 default: -1
-initialize_lda (If true, initialize the model with lda.) type: bool
default: false
-lda_max_em_iter () type: int32 default: 20
-lda_model_prefix (The name of a fit model to be used for testing likelihood. Appending "info.dat" to this should give the name of the
file.) type: string default: ""
-mode (The function to perform. Can be fit, est, or time.) type: string
default: "fit"
-model (The function to perform. Can be dtm or dim.)type: string default: "dtm"
-ntopics () type: double default: -1
-outname () type: string default: ""
-output_table () type: string default: ""
-params_file (A file containing parameters for this run.) type: string
default: "settings.txt"
-start () type: int32 default: -1
-top_chain_var () type: double default: 0.0050000000000000001
-top_obs_var () type: double default: 0.5
输入下面的命令(后面的注释是我自己加的,。如果影响运行请去掉)
./main \ /*main函数*/
--ntopics=20 \ /*每个时间窗生成20个主题*/
--mode=fit \ /*这个应该有dim和fit两个选项*/
--rng_seed=0 \
--initialize_lda=true \
--corpus_prefix=example/test \
--outname=example/model_run \
--top_chain_var=0.005 \
--alpha=0.01 \
--lda_sequence_min_iter=6 \
--lda_sequence_max_iter=20 \
--lda_max_em_iter=10
(2)输出结果。 上面文件完成之后,通过运行程序生成下面的文件,并且可以通过R查看结果,我们就可以用这个结果进行分析。
a topic-???-var-e-log-prob.dat:
主要是 e-betas(词在每个主题内每个时间段的分布),一行是一个词。
从文件中,我们看以看到每行只有一个数字。
可以在dtm\example\model_run\lda-seq中看到例子,他这个应该是有48240行,应该是有4824个词,每个时间窗内有4824个词??。作者同时给出了在R中查看这些矩阵的方法。比如查看某个词在某个主题的某一个时间段的概率。
b gam.dat
gammas数据。表示文档与主题的关联。
使用DTM ( Dynamic Topic Models )进行主题演化实验的更多相关文章
- LDA进阶(Dynamic Topic Models)
转自:http://blog.csdn.net/hxxiaopei/article/details/8034308 http://blog.csdn.net/huagong_adu/article/d ...
- 概率主题模型简介 Introduction to Probabilistic Topic Models
此文为David M. Blei所写的<Introduction to Probabilistic Topic Models>的译文,供大家参考. 摘要:概率主题模型是一系列旨在发现隐藏在 ...
- 转:概率主题模型简介 --- ---David M. Blei所写的《Introduction to Probabilistic Topic Models》的译文
概率主题模型简介 Introduction to Probabilistic Topic Models 转:http://www.cnblogs.com/siegfang/archive/2 ...
- 《Dynamic Topic Detection and Tracking: A Comparison of HDP, C-Word, and Cocitation Methods》笔记
原文地址:http://onlinelibrary.wiley.com/doi/10.1002/asi.23134/abstract 黄色背景是我认为比较重要的,红色字体是我自己的话. 动态主题监测与 ...
- Gensim LDA主题模型实验
本文利用gensim进行LDA主题模型实验,第一部分是基于前文的wiki语料,第二部分是基于Sogou新闻语料. 1. 基于wiki语料的LDA实验 上一文得到了wiki纯文本已分词语料 wiki.z ...
- Topic modeling【经典模型】
http://www.cs.princeton.edu/~blei/topicmodeling.html Topic models are a suite of algorithms that unc ...
- 【转】基于LDA的Topic Model变形
转载自wentingtu 基于LDA的Topic Model变形最近几年来,随着LDA的产生和发展,涌现出了一批搞Topic Model的牛人.我主要关注了下面这位大牛和他的学生:David M. B ...
- 基于LDA的Topic Model变形
转载于: 转:基于LDA的Topic Model变形 最近有想用LDA理论的变形来解决问题,调研中.... 基于LDA的Topic Model变形 基于LDA的Topic Model变形最近几年来,随 ...
- 【Social listening实操】作为一个合格的“增长黑客”,你还得重视外部数据的分析!
本文转自知乎 作者:苏格兰折耳喵 ----------------------------------------------------- 在本文中,作者引出了"外部数据"这一概 ...
随机推荐
- zend guard Optimizer
zend guard Optimizer PHP5.3+ URL:http://www.zend.com/en/products/guard/downloads Email:test001@test0 ...
- genymotion模拟器配置X86模拟器加速器
网上下载zip包 http://download.csdn.net/download/we5868123/9430140 直接拖进去即可,虚拟机不能使用管理员权限启动 名字为:解决genymotion ...
- mysql数据库root密码忘记的修改
注:此方法root的密码可以设置成功,但是重新开启服务时可能会出现中断的异常. 1.修改MySQL的root密码,需要先关闭MySQL的服务 2.进入命令行窗口,进入MySQL的安装路径bin目录下, ...
- 微信a标签不跳转
[问题] 微信页面开发时,各个主页之间的跳转,完全是通过a链接进行的,但是来回跳转几次,再次从其他主页面跳回首页的时候,微信头部出现了跳转加载进度条,但是就是不跳转,也没有任何反应 [范围] 只出现在 ...
- 文本注释系统 + MarkDown
标记系统: 笔记的要点 题材 缘起 目标 等级: 细节性 事实性 规律 法则 适用范围: 时间.地点.人物.起因.经过.结果,who what where when why how whom 6W1H ...
- angularjs上传图片插件使用
一. angurlajs 相关 远程 jar 包 https://code.angularjs.org/angular-1.0.1.min.js 二. 正文 1. html 部分 <!-- 需要 ...
- oracle账户锁定解决方法
今天进使用orcle中,发现系统中,system账户登录里提示账户被锁定 ,后来查了查资料,问题解决,方法如下: Microsoft Windows [版本 5.2.3790] (C) 版权所有 19 ...
- Oracle技术整理(转载)
- http?https?相对协议?
1 1 1 将CDN 上所有链接的协议默认设置为“相对协议”,也就是链接以 // 开头,前面去掉了 http: 或 https: 字样, 这样做的好处是浏览器能够根据你的网站所采用的协议来自动加载 C ...
- mvn 下载源码和javadoc
1. 下载源码,两种: . mvn dependency:sources . mvn eclipse:eclipse -DdownloadSources=true 2. 下载javadoc,两种: . ...