【发布时间】:2018-01-28 23:57:50
【问题描述】:
我有一个新闻文章数据集,这些文章是根据他们使用术语“欧洲怀疑论”或“欧洲怀疑论”的标准收集的。我一直在使用lda 包(在quanteda 中内置dfm 矩阵)运行主题模型,以确定这些文章的主要主题;但是,我感兴趣的词没有出现在任何主题中。因此,我想将这些词植入模型中,但我不确定该怎么做。
我看到包topicmodels 允许一个名为seedwords 的参数,它“可以指定为matrix 或simple_triplet_matrix 的对象类”,但没有其他说明。似乎simple_triplet_matrix 只接受整数,而不接受字符串——有人知道我会在模型中植入“euroscepticism”和“eurosceptic”这两个词吗?
这是代码的简化版本:
library("quanteda")
library("lda")
##Load UK texts/create corpus
UKcorp <- corpus(textfile(file="~Michael/DM6/*"))
##Create document feature matrix
UKdfm2 <- dfm(UKcorp, ngrams =1, verbose = TRUE, toLower = TRUE,
removeNumbers = TRUE, removePunct = TRUE, removeSeparators = TRUE,
removeTwitter = FALSE, stem = TRUE, ignoredFeatures =
stopwords(kind="english"), keptFeatures = NULL, language = "english",
thesaurus = NULL, dictionary = NULL, valuetype = "fixed"))
##Convert to lda model
UKlda2 <- convert(UKdfm2, to = "lda")
##run model
UKmod2 <- lda.collapsed.gibbs.sampler(UKlda2$documents, K = 15, UKlda2$vocab,
num.iterations = 1500, alpha = .1,eta = .01, initial = NULL, burnin
= NULL, compute.log.likelihood = TRUE, trace = 0L, freeze.topics = FALSE)
【问题讨论】:
-
在运行
lda之前,您确定您要查找的单词在dtm中吗?如果单词相当稀疏,它们可能会被丢弃。此外,您正在使用stem = TRUE。这可能会将“欧洲怀疑论”一词缩小为“欧元”。可能需要检查一下。
标签: r lda quanteda topicmodels