- 将主题模型由词-主题格式转化成主题-词格式,{(word_id, topic_count), (word_id, topic_count), …},即每一行代表一个主题的词分布;
- 计算每个主题下词的总数topic_sum;
- 遍历每个主题下每一个词,计算其所占比例(topic_count+beta)/(topic_sum+beta_sum),如果所占比例 ≤ compress_thresh,即删去该(word_id, topic_count)条目。
conf
是模型配置文件,默认为lda.confcompress
是压缩策略threshold
是设定阈值,占比低于该阈值的条目会被删除- 是输出文件
采样维度压缩
- 计算每个主题下词的总数topic_sum;
- 对于模型中的每个词下的每个主题,计算其在对应主题下所占比例,即(count+beta)/(topic_sum+V*beta),其中V表示词表大小,beta是主题模型超参;
使用方法
运行以下命令,针对新闻LDA模型进行采样维度压缩
python compress_runner.py --model_dir=../model/news --conf=lda.conf --compress=alias_compress --threshold=0.001 --output_file=news_lda.compress.model
model_dir
是模型目录- 是模型配置文件,默认为lda.conf
compress
是压缩策略threshold
是设定阈值,占比低于该阈值的条目会被删除