Если я правильно вас понимаю, я считаю, что вам нужна функция augment()
, которая возвращает таблицу с одной строкой на исходную пару термин-документ, связанную с темами.
Sys.setlocale("LC_ALL","Chinese") # reset to simplified Chinese encoding as the text data is in Chinese
#> Warning in Sys.setlocale("LC_ALL", "Chinese"): OS reports request to set
#> locale to "Chinese" cannot be honored
#> [1] ""
library(foreign)
library(dplyr)
library(plyr)
#> -------------------------------------------------------------------------
#> You have loaded plyr after dplyr - this is likely to cause problems.
#> If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
#> library(plyr); library(dplyr)
#> -------------------------------------------------------------------------
#>
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:dplyr':
#>
#> arrange, count, desc, failwith, id, mutate, rename, summarise,
#> summarize
library(tidyverse)
library(tidytext)
library(tm)
library(topicmodels)
sample_dtm <- readRDS(gzcon(url("https://www.dropbox.com/s/gznqlncd9psx3wz/sample_dtm.rds?dl=1")))
lda_out <- LDA(sample_dtm, k = 2, control = list(seed = 1234))
augment(lda_out, sample_dtm)
#> # A tibble: 18,676 x 4
#> document term count .topic
#> <chr> <chr> <dbl> <dbl>
#> 1 649 作揖 1 1
#> 2 649 拳头 1 1
#> 3 649 赞 1 1
#> 4 656 住 1 1
#> 5 656 小区 1 1
#> 6 656 没 1 1
#> 7 656 注意 2 1
#> 8 1916 中国 1 1
#> 9 1916 中国台湾 1 1
#> 10 1916 反对 1 1
#> # … with 18,666 more rows
Создано в 2019-06-04 пакетом Представить (v0.2.1)
Это связывает идентификатор документа изLDA модель для темы.Звучит так, как будто вы уже это понимаете, но только для повторения:
- матрица
beta
- это вероятности для слов - матрица
gamma
- это вероятности для документов