Sagemaker LDA主题模型 - 如何访问训练模型的参数?还有一种捕捉连贯性的简单方法

问题描述 投票:0回答:1

我是Sagemaker的新手,我正在运行一些测试来测量AWS上NTM和LDA的性能,与LDA槌和原生Gensim LDA模型相比。

我想在Sagemaker上检查训练有素的模型,看看哪些词对每个主题的贡献最大。并且还要衡量模型的一致性。

通过下载输出文件解压缩并解压缩暴露3个文件params,symbol.json和meta.json,我已经能够成功地获得对Sagemaker上NTM的每个主题贡献最高的单词。

但是,当我尝试为LDA执行相同的过程时,无法解压缩未解压缩的输出文件。

也许我错过了一些东西,或者应该为LDA做一些与NTM不同的事情,但是我还没有找到任何关于此的文档。还有,有人发现了一种计算模型连贯性的简单方法吗?

任何帮助将不胜感激!

python lda amazon-sagemaker
1个回答
1
投票

This SageMaker notebook,潜入LDA的科学细节,也演示了如何检查模型工件。具体来说,如何获得Dirichlet先前alpha和主题词分布矩阵beta的估计。您可以在标题为“检查训练模型”的部分中找到说明。为方便起见,我将在此重现相关代码:

import tarfile
import mxnet as mx

# extract the tarball
tarflie_fname = FILENAME_PREFIX + 'model.tar.gz' # wherever the tarball is located
with tarfile.open(tarfile_fname) as tar:
    tar.extractall()

# obtain the model file (should be the only file starting with "model_")
model_list = [
    fname
    for fname in os.listdir(FILENAME_PREFIX)
    if fname.startswith('model_')
]
model_fname = model_list[0]

# load the contents of the model file into MXNet arrays
alpha, beta = mx.ndarray.load(model_fname)

这应该可以获得模型数据。请注意,存储为beta行的主题不以任何特定顺序显示。

© www.soinside.com 2019 - 2024. All rights reserved.