【问题标题】:How to get all docoments per topic in bertopic modeling如何在 bertopic 建模中获取每个主题的所有文档
【发布时间】:2021-12-12 21:04:14
【问题描述】:

我有一个数据集并尝试使用 berTopic 建模将其转换为主题,但问题是,我无法获取主题的所有文档。 berTopic 每个主题仅返回 3 个文档。

topic_model  = BERTopic(verbose=True, embedding_model=embedding_model,
                                nr_topics = 'auto',
                                n_gram_range = (3,3),
                                top_n_words = 10,
                               calculate_probabilities=True, 
                              seed_topic_list = topic_list,
                              )
topics, probs = topic_model.fit_transform(docs_test)
representative_doc = topic_model.get_representative_docs(topic#1)
representative_doc

this topic contain more then 300 documents but bertopic only shows 3 of them with .get_representative_docs

【问题讨论】:

    标签: nlp text-classification bert-language-model topic-modeling


    【解决方案1】:

    可能有更优雅的解决方案,因为我不是专家,但我可以分享对我有用的解决方案(因为还没有答案):

    "topics, probs = topic_model.fit_transform(docs_test)" 返回主题。

    因此,您可以将此输出与文档结合起来。 例如,使用

    将它们组合成一个(熊猫)数据框
    df = pd.DataFrame({'topic': topics, 'document': docs_test})
    

    现在您可以为每个主题过滤此数据框以识别引用文档。

    topic_0 = df[df.topic == 0]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-12
      • 2022-01-11
      • 2020-07-07
      • 2020-10-02
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      相关资源
      最近更新 更多