In R text2vec package -How can the topics generated by LDA model can be assigned to the related documents











up vote
0
down vote

favorite












Using text2vec package in R -implemented LDA model,but iam wondering how to assign each documents to the topics



BELOW HERE is my code:

library(stringr)
library(rword2vec)
library(wordVectors)
#install.packages("text2vec")
library(text2vec)
library(data.table)
library(magrittr)

prep_fun = function(x) {
x %>%
# make text lower case
str_to_lower %>%
# remove non-alphanumeric symbols
str_replace_all("[^[:alpha:]]", " ") %>%
# collapse multiple spaces
str_replace_all("\s+", " ")
}
movie_review_train = prep_fun(movie_review_train)

tokens = movie_review_train[1:1000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, progressbar = FALSE)
v = create_vocabulary(it)
v
vectorizer = vocab_vectorizer(v)
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dim(dtm_train)
stop_words = c("i", "me", "my", "myself", "we", "our", "ours", "ourselves")
t1 = Sys.time()
v = create_vocabulary(it, stopwords = stop_words)
print(difftime(Sys.time(), t1, units = 'sec'))
pruned_vocab = prune_vocabulary(v,
term_count_min = 10,
doc_proportion_max = 0.5,
doc_proportion_min = 0.001)
vectorizer = vocab_vectorizer(pruned_vocab)
# create dtm_train with new pruned vocabulary vectorizer
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dtm_train_l1_norm = normalize(dtm_train, "l1")
tfidf = TfIdf$new()
# fit model to train data and transform train data with fitted model
dtm_train_tfidf = fit_transform(dtm_train, tfidf)

dtm = transform(dtm_train_tfidf, tfidf)
lda_model <-LDA$new(n_topics = ntopics
,doc_topic_prior = alphaprior
,topic_word_prior = deltaprior
)
lda_model$get_top_words(n = 10, topic_number = c(1:5), lambda = 0.3)


After this I want to assign each document to the related topics. Iam getting list of terms below the topics but I dono how to map.










share|improve this question
























  • How about official documentation text2vec.org/topic_modeling.html#example6 ?
    – Dmitriy Selivanov
    May 2 at 15:11










  • Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
    – manjari
    May 3 at 2:19















up vote
0
down vote

favorite












Using text2vec package in R -implemented LDA model,but iam wondering how to assign each documents to the topics



BELOW HERE is my code:

library(stringr)
library(rword2vec)
library(wordVectors)
#install.packages("text2vec")
library(text2vec)
library(data.table)
library(magrittr)

prep_fun = function(x) {
x %>%
# make text lower case
str_to_lower %>%
# remove non-alphanumeric symbols
str_replace_all("[^[:alpha:]]", " ") %>%
# collapse multiple spaces
str_replace_all("\s+", " ")
}
movie_review_train = prep_fun(movie_review_train)

tokens = movie_review_train[1:1000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, progressbar = FALSE)
v = create_vocabulary(it)
v
vectorizer = vocab_vectorizer(v)
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dim(dtm_train)
stop_words = c("i", "me", "my", "myself", "we", "our", "ours", "ourselves")
t1 = Sys.time()
v = create_vocabulary(it, stopwords = stop_words)
print(difftime(Sys.time(), t1, units = 'sec'))
pruned_vocab = prune_vocabulary(v,
term_count_min = 10,
doc_proportion_max = 0.5,
doc_proportion_min = 0.001)
vectorizer = vocab_vectorizer(pruned_vocab)
# create dtm_train with new pruned vocabulary vectorizer
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dtm_train_l1_norm = normalize(dtm_train, "l1")
tfidf = TfIdf$new()
# fit model to train data and transform train data with fitted model
dtm_train_tfidf = fit_transform(dtm_train, tfidf)

dtm = transform(dtm_train_tfidf, tfidf)
lda_model <-LDA$new(n_topics = ntopics
,doc_topic_prior = alphaprior
,topic_word_prior = deltaprior
)
lda_model$get_top_words(n = 10, topic_number = c(1:5), lambda = 0.3)


After this I want to assign each document to the related topics. Iam getting list of terms below the topics but I dono how to map.










share|improve this question
























  • How about official documentation text2vec.org/topic_modeling.html#example6 ?
    – Dmitriy Selivanov
    May 2 at 15:11










  • Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
    – manjari
    May 3 at 2:19













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Using text2vec package in R -implemented LDA model,but iam wondering how to assign each documents to the topics



BELOW HERE is my code:

library(stringr)
library(rword2vec)
library(wordVectors)
#install.packages("text2vec")
library(text2vec)
library(data.table)
library(magrittr)

prep_fun = function(x) {
x %>%
# make text lower case
str_to_lower %>%
# remove non-alphanumeric symbols
str_replace_all("[^[:alpha:]]", " ") %>%
# collapse multiple spaces
str_replace_all("\s+", " ")
}
movie_review_train = prep_fun(movie_review_train)

tokens = movie_review_train[1:1000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, progressbar = FALSE)
v = create_vocabulary(it)
v
vectorizer = vocab_vectorizer(v)
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dim(dtm_train)
stop_words = c("i", "me", "my", "myself", "we", "our", "ours", "ourselves")
t1 = Sys.time()
v = create_vocabulary(it, stopwords = stop_words)
print(difftime(Sys.time(), t1, units = 'sec'))
pruned_vocab = prune_vocabulary(v,
term_count_min = 10,
doc_proportion_max = 0.5,
doc_proportion_min = 0.001)
vectorizer = vocab_vectorizer(pruned_vocab)
# create dtm_train with new pruned vocabulary vectorizer
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dtm_train_l1_norm = normalize(dtm_train, "l1")
tfidf = TfIdf$new()
# fit model to train data and transform train data with fitted model
dtm_train_tfidf = fit_transform(dtm_train, tfidf)

dtm = transform(dtm_train_tfidf, tfidf)
lda_model <-LDA$new(n_topics = ntopics
,doc_topic_prior = alphaprior
,topic_word_prior = deltaprior
)
lda_model$get_top_words(n = 10, topic_number = c(1:5), lambda = 0.3)


After this I want to assign each document to the related topics. Iam getting list of terms below the topics but I dono how to map.










share|improve this question















Using text2vec package in R -implemented LDA model,but iam wondering how to assign each documents to the topics



BELOW HERE is my code:

library(stringr)
library(rword2vec)
library(wordVectors)
#install.packages("text2vec")
library(text2vec)
library(data.table)
library(magrittr)

prep_fun = function(x) {
x %>%
# make text lower case
str_to_lower %>%
# remove non-alphanumeric symbols
str_replace_all("[^[:alpha:]]", " ") %>%
# collapse multiple spaces
str_replace_all("\s+", " ")
}
movie_review_train = prep_fun(movie_review_train)

tokens = movie_review_train[1:1000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, progressbar = FALSE)
v = create_vocabulary(it)
v
vectorizer = vocab_vectorizer(v)
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dim(dtm_train)
stop_words = c("i", "me", "my", "myself", "we", "our", "ours", "ourselves")
t1 = Sys.time()
v = create_vocabulary(it, stopwords = stop_words)
print(difftime(Sys.time(), t1, units = 'sec'))
pruned_vocab = prune_vocabulary(v,
term_count_min = 10,
doc_proportion_max = 0.5,
doc_proportion_min = 0.001)
vectorizer = vocab_vectorizer(pruned_vocab)
# create dtm_train with new pruned vocabulary vectorizer
t1 = Sys.time()
dtm_train = create_dtm(it, vectorizer)
print(difftime(Sys.time(), t1, units = 'sec'))
dtm_train_l1_norm = normalize(dtm_train, "l1")
tfidf = TfIdf$new()
# fit model to train data and transform train data with fitted model
dtm_train_tfidf = fit_transform(dtm_train, tfidf)

dtm = transform(dtm_train_tfidf, tfidf)
lda_model <-LDA$new(n_topics = ntopics
,doc_topic_prior = alphaprior
,topic_word_prior = deltaprior
)
lda_model$get_top_words(n = 10, topic_number = c(1:5), lambda = 0.3)


After this I want to assign each document to the related topics. Iam getting list of terms below the topics but I dono how to map.







nlp lda topic-modeling text2vec






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 2 at 10:17









Camellia

10312




10312










asked May 2 at 13:44









manjari

11




11












  • How about official documentation text2vec.org/topic_modeling.html#example6 ?
    – Dmitriy Selivanov
    May 2 at 15:11










  • Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
    – manjari
    May 3 at 2:19


















  • How about official documentation text2vec.org/topic_modeling.html#example6 ?
    – Dmitriy Selivanov
    May 2 at 15:11










  • Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
    – manjari
    May 3 at 2:19
















How about official documentation text2vec.org/topic_modeling.html#example6 ?
– Dmitriy Selivanov
May 2 at 15:11




How about official documentation text2vec.org/topic_modeling.html#example6 ?
– Dmitriy Selivanov
May 2 at 15:11












Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
– manjari
May 3 at 2:19




Thanks for your reference,but in that too they have mapped the distance between the topics and frequency of the terms in each topics.I want to assign each document to the topics.
– manjari
May 3 at 2:19












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The document-topic distribution, doc_topic_distr, projects each document to topic space, which can be calculated from the below code based on documentation by Dmitriy Selivanov (please see http://text2vec.org/topic_modeling.html#example6).



In fact, two important outputs of topic model are topic-word matrix and document-topic matrix. The topic-word matrix or topic-word distribution shows words weights in each topic while the document-topic matrix or document-topic distribution demonstrates topics' contributions in each document.



doc_topic_distr = 
lda_model$fit_transform(x = dtm, n_iter = 1000,
convergence_tol = 0.001, n_check_convergence = 25,
progressbar = FALSE)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50136186%2fin-r-text2vec-package-how-can-the-topics-generated-by-lda-model-can-be-assigned%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    The document-topic distribution, doc_topic_distr, projects each document to topic space, which can be calculated from the below code based on documentation by Dmitriy Selivanov (please see http://text2vec.org/topic_modeling.html#example6).



    In fact, two important outputs of topic model are topic-word matrix and document-topic matrix. The topic-word matrix or topic-word distribution shows words weights in each topic while the document-topic matrix or document-topic distribution demonstrates topics' contributions in each document.



    doc_topic_distr = 
    lda_model$fit_transform(x = dtm, n_iter = 1000,
    convergence_tol = 0.001, n_check_convergence = 25,
    progressbar = FALSE)





    share|improve this answer



























      up vote
      0
      down vote













      The document-topic distribution, doc_topic_distr, projects each document to topic space, which can be calculated from the below code based on documentation by Dmitriy Selivanov (please see http://text2vec.org/topic_modeling.html#example6).



      In fact, two important outputs of topic model are topic-word matrix and document-topic matrix. The topic-word matrix or topic-word distribution shows words weights in each topic while the document-topic matrix or document-topic distribution demonstrates topics' contributions in each document.



      doc_topic_distr = 
      lda_model$fit_transform(x = dtm, n_iter = 1000,
      convergence_tol = 0.001, n_check_convergence = 25,
      progressbar = FALSE)





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        The document-topic distribution, doc_topic_distr, projects each document to topic space, which can be calculated from the below code based on documentation by Dmitriy Selivanov (please see http://text2vec.org/topic_modeling.html#example6).



        In fact, two important outputs of topic model are topic-word matrix and document-topic matrix. The topic-word matrix or topic-word distribution shows words weights in each topic while the document-topic matrix or document-topic distribution demonstrates topics' contributions in each document.



        doc_topic_distr = 
        lda_model$fit_transform(x = dtm, n_iter = 1000,
        convergence_tol = 0.001, n_check_convergence = 25,
        progressbar = FALSE)





        share|improve this answer














        The document-topic distribution, doc_topic_distr, projects each document to topic space, which can be calculated from the below code based on documentation by Dmitriy Selivanov (please see http://text2vec.org/topic_modeling.html#example6).



        In fact, two important outputs of topic model are topic-word matrix and document-topic matrix. The topic-word matrix or topic-word distribution shows words weights in each topic while the document-topic matrix or document-topic distribution demonstrates topics' contributions in each document.



        doc_topic_distr = 
        lda_model$fit_transform(x = dtm, n_iter = 1000,
        convergence_tol = 0.001, n_check_convergence = 25,
        progressbar = FALSE)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 at 4:11

























        answered Nov 12 at 4:06









        Sam S

        849




        849






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50136186%2fin-r-text2vec-package-how-can-the-topics-generated-by-lda-model-can-be-assigned%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly