[Python] Classify Text with Gensim LDA Model

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    For reference, I already looked at the following questions:

    1. Gensim LDA for text classification
    2. Python Gensim LDA Model show_topics funciton

    I am looking to have my LDA model trained from Gensim classify a sentence under one of the topics that the model creates. Something long the lines of

    lda = models.LdaModel(corpus=corpus, id2word=id2word, num_topics=7, passes=20)
    lda.print_topics()
    for line in document: # where each line in the document is its own sentence for simplicity
    print('Sentence: ', line)
    topic = lda.parse(line) # where the classification would occur
    print('Topic: ', topic)


    I know gensim does not have a parse function, but how would one go about accomplishing this? Here is the documentation that I've been following but I haven't gotten anywhere with it:

    https://radimrehurek.com/gensim/aut...amples-core-run-topics-and-transformations-py

    Thanks in advance.

    edit: More documentation- https://radimrehurek.com/gensim/models/ldamodel.html

    Continue reading...

Compartilhe esta Página