BERTopic 无法复现相同的结果

ubof19bj  于 2个月前  发布在  其他
关注(0)|答案(4)|浏览(24)

您好,为了使结果可复现,我们可以在开始的时候设置随机种子,以确保每次运行都获得相同的随机结果。在PyTorch中,我们可以使用 torch.manual_seed() 来设置随机种子。

brvekthn

brvekthn1#

如果你从一个基本的BERTopic模型开始,并且不改变环境,那么仅在UMAP中设置random_state就足以使其完全可复现。这意味着无论你在此基础上添加什么,无论是聚类模型、分词器还是其他内容,都需要可复现。因此,运行整个流程可能是值得的,以查看它是否确实可复现:

model = BERTopic(embedding_model=sentence_model, umap_model=umap_model)

如果确实可复现,那么你将知道其他参数中的一个可能与此相关。然后,你可以测试哪些参数可能导致你注意到的随机行为。

bjg7j2ky

bjg7j2ky2#

感谢您的回复。我会尝试一下。

ebdffaop

ebdffaop3#

嘿,@MaartenGr!

我遇到了与上面讨论的问题相同的问题。尽管我为UMAP设置了random_state=42,并且没有使用任何HDBSCAN(默认设置为None),但我在每次运行BERTopic时都得到了不同的结果。我真的很想找到解决这个问题的方法。如果你们能帮我解决这个问题,我会非常感激的。谢谢!

main_representation = KeyBERTInspired()
aspect_model2 = [KeyBERTInspired(top_n_words=30), MaximalMarginalRelevance(diversity=.5)]
aspect_model3 = PartOfSpeech()
representation_model = {
 "Main": main_representation,
 "Representation2": aspect_model2,
 "Representation3": aspect_model3
}
topic_model = BERTopic(verbose=True,
 umap_model=UMAP(n_neighbors=15,n_components=5, min_dist=0.0, metric='cosine', random_state=42),
 seed_topic_list=seed_topic_list,
 vectorizer_model=CountVectorizer(stop_words=stop_words, max_df=1.0, ngram_range=(1,2)),
 representation_model=representation_model
).fit(df.preprocessed_text, y=df.ssot_topic_id)
7rtdyuoh

7rtdyuoh4#

@alicjamalota ,我不太确定这里的原因是什么呢,但是慢慢移除参数(并在UMAP中保留random_state)可能会有稳定的行为。这样,你可以自己进行实验,看看问题出在哪里。这可能是由于seed_topic_list参数或者甚至是y参数导致的,但在没有在你这边进行一些实验的情况下,我无法确定。

相关问题