标签: topic-modeling

使用 Java 中的 Mallet 在 LDA 中折叠(估计新文档的主题)

我正在通过 Java 使用 Mallet,但我不知道如何根据我训练过的现有主题模型评估新文档。

我生成模型的初始代码与Mallett Developers Guide for Topic Modeling中的代码非常相似,之后我只是将模型保存为 Java 对象。在稍后的过程中,我从文件中重新加载该 Java 对象,通过添加新实例.addInstances(),然后仅根据原始训练集中的主题评估这些新实例。

这个 stats.SE 线程提供了一些高级建议,但我看不到如何将它们应用到 Mallet 框架中。

非常感谢任何帮助。

java mallet topic-modeling

2
推荐指数
1
解决办法
2336
查看次数

LDA 可以为一个单词分配多个主题吗?

我刚刚开始阅读有关潜在狄利克雷分配 LDA 的文章,并希望将其应用到我的项目中。

我想知道 LDA 是否能够将一个主题分配给多个单词?

例如,文章A谈论“河岸”,而文章B谈论“银行在金融中的作用”。因此,LDA 是否允许将“银行”一词分配给两个不同的主题?

lda topic-modeling

2
推荐指数
1
解决办法
1629
查看次数

python IndexError使用gensim进行LDA主题建模

另一个线程有一个与我类似的问题,但遗漏了可重现的代码。

有问题的脚本的目标是创建一个尽可能具有内存效率的进程。所以我尝试编写一个类corpus()来利用 gensims 的功能。但是,我遇到了一个 IndexError,我不确定在创建lda = models.ldamodel.LdaModel(corpus_tfidf, id2word=checker.dictionary, num_topics=int(options.number_of_topics)).

我使用的文档与 gensim 教程中使用的文档相同,我将其放入 tutorial_example.txt:

$ cat tutorial_example.txt 
Human machine interface for lab abc computer applications
A survey of user opinion of computer system response time
The EPS user interface management system
System and human system engineering testing of EPS
Relation of user perceived response time to error measurement
The generation of random binary unordered trees
The intersection graph of paths in trees
Graph minors IV Widths …
Run Code Online (Sandbox Code Playgroud)

python lda gensim topic-modeling

2
推荐指数
1
解决办法
2046
查看次数

用于Python主题建模的LDA

我是Python的新手,我正在尝试使用LDA软件包(https://pypi.python.org/pypi/lda)。我列出了每个人都涉及的标题和主题。但是,我不知道如何首先使用该软件包。我已经阅读了软件包的文档,但是它含糊不清。没有有关输入结构和所有内容的信息。有人使用过吗?谢谢!

python nlp machine-learning lda topic-modeling

2
推荐指数
1
解决办法
1215
查看次数

绘制LDA主题随时间的演变

我想描绘一个特定主题的比例如何随时间变化,但是我在隔离单个主题和绘制时间方面遇到了一些麻烦,特别是对于分别绘制多组文档(让我们创建两组进行比较 - 期刊A和B).我在一个名为的函数中保存了与这些日志相关的日期dateConverter.

这是我到目前为止(非常感谢@scoa):

library(tm); library(topicmodels);


txtfolder <- "~/path/to/documents/"
source <- DirSource(txtfolder)

myCorpus <- Corpus(source, readerControl=list(reader=readPlain))


for (i in 1:10){
  meta(myCorpus[[i]], tag = "origin") <- "A"
}
for (i in 11:length(myCorpus)){
  meta(myCorpus[[i]], tag = "origin") <- "B"
}
dates <- do.call("c", dateConverter)
for (i in 1:length(myCorpus)){
  meta(myCorpus[[i]], tag = "datetimestamp") <- dates[i]
}

dtm <- DocumentTermMatrix(myCorpus, control = list(minWordLength=3))


n.topics <- 10
lda.model <- LDA(dtm, n.topics)
terms(lda.model,10)
df <- data.frame(id=names(topics(lda.model)),
                 topic=posterior(lda.model),
                 date=as.POSIXct(unlist(lapply(meta(myCorpus,type="local",tag="datetimestamp"),as.character))),
                 origin=unlist(meta(myCorpus,type="local",tag="origin"))    )
Run Code Online (Sandbox Code Playgroud)

我该如何绘制这些?

r ggplot2 lda topic-modeling tm

2
推荐指数
1
解决办法
1523
查看次数

R 中随时间变化的动态主题模型/主题

我有一个关于 1998 年至 2008 年水政策的报纸文章数据库。我想看看在此期间报纸发布的变化。我的问题是,我应该使用 Dynamic Topic Modeling 还是 Topic Over Time 模型来处理这个任务?它们是否会明显优于传统的 LDA 模型(其中我基于整个文本语料库拟合主题模型,并根据每个文档的标记方式绘制主题趋势)?如果是,是否有我可以用于 R 中的 DTA/ToT 模型的包?

r text-mining topic-modeling

2
推荐指数
1
解决办法
2941
查看次数

带有Mallet LDA实现的pyLDAvis:LdaMallet对象没有属性“推断”

是否可以使用LDA的Mallet实现绘制pyLDAvis?我没有LDA_Model的麻烦,但是当我使用Mallet时,我得到了:

'LdaMallet' object has no attribute 'inference'
Run Code Online (Sandbox Code Playgroud)

我的代码:

pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(mallet_model, corpus, id2word)
vis
Run Code Online (Sandbox Code Playgroud)

mallet gensim topic-modeling

2
推荐指数
1
解决办法
2025
查看次数

如何在r中使用整洁的文本进行二元组主题建模?

所以我尝试使用tidytext包来做bigrams主题建模,按照tidytext网站上的步骤操作:https://www.tidytextmining.com/ngrams.html .

我能够进入"word_counts"部分,其中R计算每个bi-gram的频率.

"word_counts"返回以下内容:

   customer_id       word          n
   <chr>            <chr>        <int>
 1 00000001234  sample text        45
 2 00000002345  good morning       30
 3 00000003456  happy friday       24
Run Code Online (Sandbox Code Playgroud)

下一步是将上面的信息放入dtm格式

我的代码如下:

lda_dtm <- word_counts %>%
  cast_dtm(customer_id, word, n)
Run Code Online (Sandbox Code Playgroud)

提出了一条警告信息:

Warning message:
Trying to compute distinct() for variables not found in the data:
- `row_col`, `column_col`
This is an error, but only a warning is raised for compatibility reasons.
The operation will return the input unchanged. 
Run Code Online (Sandbox Code Playgroud)

但是"lda_dtm"看起来像是正确的格式.

lda_dtm
<<DocumentTermMatrix (documents: 9517, terms: 341545)>> …
Run Code Online (Sandbox Code Playgroud)

r text-mining n-gram topic-modeling tidytext

2
推荐指数
1
解决办法
462
查看次数

如何在python中保存LDA模型 - LatentDirichletAllocation

我已经使用下面的命令训练了一个 LDA 模型,需要了解如何保存它。

lda_model = LatentDirichletAllocation(n_components=25, random_state=100)
Run Code Online (Sandbox Code Playgroud)

我已经尝试过以下方法,但它说

AttributeError:“LatentDirichletAllocation”对象没有属性“save”

lda_model.save("xyz.model")
Run Code Online (Sandbox Code Playgroud)

训练模型花了 16 个小时。重新创建它会非常耗时。任何建议将非常感激!

python lda topic-modeling

2
推荐指数
1
解决办法
4787
查看次数

包装器的 Genism 模块属性错误

我将找到 LDA 的最佳主题数。为此,我使用了 GENSIM 如下:

def compute_coherence_values(dictionary, corpus, texts, limit, start=2, step=3):
    coherence_values = []
    model_list = []
    for num_topics in range(start, limit, step):
        model = gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, num_topics=num_topics, id2word=id2word)
        model_list.append(model)
        coherencemodel = CoherenceModel(model=model, texts=texts, dictionary=dictionary, coherence='c_v')
        coherence_values.append(coherencemodel.get_coherence())

    return model_list, coherence_values

    
Run Code Online (Sandbox Code Playgroud)

但是我有一个属性错误:我使用了spyder。

AttributeError: module 'gensim.models' has no attribute 'wrappers'
Run Code Online (Sandbox Code Playgroud)

python lda gensim topic-modeling

2
推荐指数
1
解决办法
1776
查看次数

标签 统计

topic-modeling ×10

lda ×6

python ×4

gensim ×3

r ×3

mallet ×2

text-mining ×2

ggplot2 ×1

java ×1

machine-learning ×1

n-gram ×1

nlp ×1

tidytext ×1

tm ×1