import gensim
from gensim import corpora
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import warnings
# from gensim.models import LdaModelimport pandas as pd
from gensim.corpora import Dictionary
from gensim import corpora, models
import csv
import pyLDAvis.gensim_models as gensims
import pyLDAvis
warnings.filterwarnings('ignore')# To ignore all warnings that arise here to enhance clarityfrom gensim.models.coherencemodel import CoherenceModel
from gensim.models.ldamodel import LdaModel
计算困惑度和coherence
# 准备数据
PATH ="C:\\Users\\mat\\Desktop\data\\各阶段关键短语抽取\\stage1_关键短语.txt"
file_object2=open(PATH,encoding ='utf-8',errors ='ignore').read().split('\n')#一行行的读取内容
data_set=[]#建立存储分词的列表for i inrange(len(file_object2)