LDA模型的封装
最近一直在训练LDA模型,将LDA模型封装在一个脚本中,可以直接在终端传入参数进行LDA的训练和预测. 需要在同目录下准备一个stopwords(停用词典) #conding=utf-8 import codecs import os import re from os import mkdir from os . path import exists , isdir , abspath , join import gensim import jieba . posseg as pseg import yaml from gensim import corpora #1.数据处理工具 def data_util ( data , cut_flag = False , stopwords_file = './stopwords' ) : ''' 传入一条语料,对其进行处理,获取训练语料 :param data: 单行的语料 :param cut_flag: 是否分词,为True时,使用jieba进行分词处理 :param stopwords_file: 停用词文件 :return: list of words ''' stopwords_file = abspath ( stopwords_file ) if cut_flag : function_words = [ "d" ,