基于潜在Dirichlet分配的主题建模

ldafork的Python项目详细描述


Zenodo citation

lda使用折叠Gibbs实现潜在Dirichlet分配(LDA) 取样。lda速度很快,在Linux、OS X和Windows上进行了测试。这是 为新的Python版本提供的原始代码的维护分支。在

您可以在the documentation中阅读有关lda的更多信息。在

注意

这是由 Allan Riddell为更新的Python版本、OS版本和 依赖关系。与原始实现的唯一区别是为此实现了兼容性修复 目的。这个fork专门为python3.6到python3.8提供了轮子(可安装的二进制软件包) Linux、MacOS和Windows 10。在

安装

pip install ldafork

入门

lda.LDA实现潜在的Dirichlet分配(LDA)。界面如下所示 在scikit-learn中找到约定。在

下面演示如何检查路透社子集的模型 新闻数据集。下面的输入X,是一个文档项矩阵(稀疏矩阵 接受)。在

>>>importnumpyasnp>>>importlda>>>importlda.datasets>>>X=lda.datasets.load_reuters()>>>vocab=lda.datasets.load_reuters_vocab()>>>titles=lda.datasets.load_reuters_titles()>>>X.shape(395,4258)>>>X.sum()84010>>>model=lda.LDA(n_topics=20,n_iter=1500,random_state=1)>>>model.fit(X)# model.fit_transform(X) is also available>>>topic_word=model.topic_word_# model.components_ also works>>>n_top_words=8>>>fori,topic_distinenumerate(topic_word):...topic_words=np.array(vocab)[np.argsort(topic_dist)][:-(n_top_words+1):-1]...print('Topic {}: {}'.format(i,' '.join(topic_words)))Topic0:britishchurchillsalemillionmajorletterswestbritainTopic1:churchgovernmentpoliticalcountrystatepeoplepartyagainstTopic2:elviskingfanspresleylifeconcertyoungdeathTopic3:yeltsinrussianrussiapresidentkremlinmoscowmichaeloperationTopic4:popevaticanpauljohnsurgeryhospitalpontiffromeTopic5:familyfuneralpolicemiamiversacecunanancityserviceTopic6:simpsonformeryearscourtpresidentwifesouthchurchTopic7:ordermothersuccessorelectionnunschurchnirmalaheadTopic8:charlesprincedianaroyalkingqueenparkerbowlesTopic9:filmfrenchfranceagainstbardotparisposteranimalTopic10:germanygermanwarnaziletterchristianbookjewsTopic11:eastpeaceprizeawardtimorquebecbeloleaderTopic12:n't life show told very love television fatherTopic13:yearsyeartimelastchurchworldpeoplesayTopic14:motherteresaheartcalcuttacharitynunhospitalmissionariesTopic15:citysalonikacapitalbuddhistculturalvietnambyzantineshowTopic16:musictouroperasingerisraelpeoplefilmisraeliTopic17:churchcatholicbernardincardinalbishopwrightdeathcancerTopic18:harrimanclintonu.sambassadorparispresidentchurchillfranceTopic19:citymuseumartexhibitioncenturymillionchurchesset

文档主题发行版在model.doc_topic_中提供。在

^{pr2}$

要求

Python3.6+是必需的。以下软件包是必需的,当您 使用pip

警告

lda旨在简化。(它碰巧很快,就像重要的部件一样 如果你正在处理一个非常大的语料库,你可以 希望使用更复杂的主题模型,例如在hca中实现的主题模型 和MALLEThca完全是用C编写的,MALLET是用Java编写的。 与lda不同,hca一次可以使用多个处理器。MALLEThca实现已知比标准潜在的更健壮的主题模型 Dirichlet分配。在

注释

潜在Dirichlet分配在Blei et al. (2003)Pritchard et al. (2000)中描述。中描述了使用折叠Gibbs抽样的推断 Griffiths and Steyvers (2004)。在

其他实现

许可证

lda是根据Mozilla公共许可证的2.0版授权的。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
面向批处理的java非阻塞队列   java如何基于HttpComponent获取html内容   java为什么我的程序会显示此错误?   java spring控制器如何处理应用程序/octetstream请求?   尝试将数据插入数据库时出现java常规错误   无法在java多线程处理中维护生产者任务的顺序   java为什么JSON数据无法访问ViewPager?   java获取Maven中特定分支的SVN buildnumber   java客户端无法从服务器接收信息   java等轴测地图绘制,生成   java无法调试ProcessBuilder   java热点JVM阵列分配   在数组中存储“inputdialog”数据的java   saml Java Inflater引发DataFormatException“无效代码长度集”   从集合(爬虫、Jsoup、Java)写入文件