在R text2vec包中 - LDA模型可以显示文档中每个标记的主题分布吗?

时间:2017-09-11 06:15:27

标签: r lda topic-modeling text2vec

library (text2vec)
library (parallel)
library (doParallel)

N <- parallel::detectCores()
cl <- makeCluster (N)
registerDoParallel (cl)
Ky_young <- read.csv("./Ky_young.csv")

IT <- itoken_parallel (Ky_young$TEXTInfo,
                       ids          = Ky_young$ID,
                       tokenizer    = word_tokenizer,
                       progressbar  = F)

##stopword
stop_words = readLines("./stopwrd1.txt", encoding="UTF-8")

VOCAB <- create_vocabulary (
        IT, stopwords = stop_words
        ngram = c(1, 1)) %>%
        prune_vocabulary (term_count_min = 5)


VoCAB.order <- VOCAB[order((VOCAB$term_count), decreasing = T),]

VECTORIZER <- vocab_vectorizer (VOCAB)

DTM <- create_dtm (IT, VECTORIZER, distributed = F)


LDA_MODEL <- 
      LatentDirichletAllocation$new (n_topics         = 200,
                                     #vocabulary       = VOCAB, <= ERROR
                                     doc_topic_prior  = 0.1,  
                                     topic_word_prior = 0.01) 


##topic-document distribution
LDA_FIT <- LDA_MODEL$fit_transform (
        x = DTM, 
        n_iter = 50, 
        convergence_tol = -1, 
        n_check_convergence = 10)

#topic-word distribution
topic_word_prior = LDA_MODEL$topic_word_distribution

我在text2vec中创建了测试LDA代码,我可以获得word-topic分发和文档主题分发。 (这很疯狂)

顺便说一句,我想知道是否有可能从text2vec的LDA模型中获取文档中每个标记的主题分布?

据我所知,LDA分析过程结果是文档中的每个标记属于特定主题,因此每个文档都有主题分布。

如果我可以获得每个令牌的主题分发,我想通过分类文档(如句号)检查每个主题的主要词语更改。有可能吗?

如果还有其他方式,我将非常感谢让我知道。

1 个答案:

答案 0 :(得分:0)

不幸的是,无法为给定文档中的每个标记分配主题。文档主题计数是随时计算/聚合的,#34;因此,文档 - 令牌 - 主题分发不会存储在任何地方。

相关问题