Python 如何使用gensim中的mallet设置主题模型的随机种子?

Python 如何使用gensim中的mallet设置主题模型的随机种子?,python,gensim,topic-modeling,mallet,Python,Gensim,Topic Modeling,Mallet,我一直试图通过使用mallet作为gensim中的库来保持主题建模的输出稳定。然而,我发现mallet可以设置随机种子,但我在gensim中没有看到任何参数可以设置它 这已添加到ldamallet.py包装中 def __init__(self, mallet_path, corpus=None, num_topics=100, alpha=50, id2word=None, workers=4, prefix=None, optimize_interval=0

我一直试图通过使用mallet作为gensim中的库来保持主题建模的输出稳定。然而,我发现mallet可以设置随机种子,但我在gensim中没有看到任何参数可以设置它

这已添加到ldamallet.py包装中

    def __init__(self, mallet_path, corpus=None, num_topics=100, alpha=50, id2word=None, workers=4, prefix=None,
             optimize_interval=0, iterations=1000, topic_threshold=0.0, random_seed=0):
    """

    Parameters
    ----------
    mallet_path : str
        Path to the mallet binary, e.g. `/home/username/mallet-2.0.7/bin/mallet`.
    corpus : iterable of iterable of (int, int), optional
        Collection of texts in BoW format.
    num_topics : int, optional
        Number of topics.
    alpha : int, optional
        Alpha parameter of LDA.
    id2word : :class:`~gensim.corpora.dictionary.Dictionary`, optional
        Mapping between tokens ids and words from corpus, if not specified - will be inferred from `corpus`.
    workers : int, optional
        Number of threads that will be used for training.
    prefix : str, optional
        Prefix for produced temporary files.
    optimize_interval : int, optional
        Optimize hyperparameters every `optimize_interval` iterations
        (sometimes leads to Java exception 0 to switch off hyperparameter optimization).
    iterations : int, optional
        Number of training iterations.
    topic_threshold : float, optional
        Threshold of the probability above which we consider a topic.
    random_seed: int, optional
        Random seed to ensure consistent results, if 0 - use system clock.

    """

我也遇到过同样的问题,但要使用最新版本的gensim,这有点棘手。正如Chris所说,新版本已经实现,但运行起来对我来说很麻烦。在使用旧包装时,请确保执行以下操作:

  • conda安装-c conda forge gensim
  • pip安装--升级gensim
  • 第二步完成了这项工作,仅仅安装它不会更新gensim,因为我对它有问题

    以下链接提供了有关您的问题的更多信息: