我需要通过以下方式进行主题建模:
例如:
我需要从作为单个文档的document.The文档中提取5个主题。我有5个主题的关键字,并与这5个关键字相关,我需要提取这些主题。
5个主题的关键词是:关键词1-(汽车,赛车,...)关键词2-(事故,保险,...) ......
相应的输出应该是: Topic 1-(车辆,扭矩,速度...)主题2-(索赔,金额,...)
如何做到这一点呢?
发布于 2014-10-14 05:06:16
为与NodeJS一起使用而编写的这个LDA主题建模库是一个很好的起点。
https://www.npmjs.org/package/lda
var lda = require('lda');
// Example document.
var text = 'Cats are small. Dogs are big. Cats like to chase mice. Dogs like to eat bones.';
// Extract sentences.
var documents = text.match( /[^\.!\?]+[\.!\?]+/g );
// Run LDA to get terms for 2 topics (5 terms each).
var result = lda(documents, 2, 5);
The above example produces the following result with two topics (topic 1 is "cat-related", topic 2 is "dog-related"):
Topic 1
cats (0.21%)
dogs (0.19%)
small (0.1%)
mice (0.1%)
chase (0.1%)
Topic 2
dogs (0.21%)
cats (0.19%)
big (0.11%)
eat (0.1%)
bones (0.1%)这应该会让你开始走上这条路。请注意,您可能需要调整主题和文档的数量,以适应您希望提取的信息量。
这不是魔法。
http://en.wikipedia.org/wiki/Latent_Dirichlet_allocation
https://stackoverflow.com/questions/26195508
复制相似问题