更快速、准确、简单的中文摘要实现,更快速中文摘要实现,全程矩阵运算,速度快通过


全程矩阵运算,速度快

通过句子之间的相似度,而不是单纯计算某些句子含有的关键字数量,考虑到了整个句子的信息

基于pagerank的算法,考虑到了句子的全文信息

# -*- coding: UTF-8 -*-import cProfile as profileimport pstatsimport numpy as npfrom sklearn.feature_extraction.text import CountVectorizerfrom sklearn.feature_extraction.text import TfidfTransformerfrom sklearn.feature_extraction.text import TfidfVectorizerimport networkx as nxdef text_rank4(content):    sents = list(cut_sentence(content))    vect = TfidfVectorizer(min_df=1,tokenizer=Tokenize)    tfidf = vect.fit_transform(sents)    tfidf_graph = tfidf*tfidf.T    nx_graph = nx.from_scipy_sparse_matrix(tfidf_graph)    scores = nx.pagerank(nx_graph)    res = sorted(((scores[i],i) for i,s in enumerate(sents)), reverse=True)    top_n_summary = [sents[i] for _,i in sorted(res[:3])]    print 'text_rank4', u'。 '.join(top_n_summary).replace('\\r','').replace('\\n','')+u'。''''prof = profile.Profile()prof.run('test4()')stats = pstats.Stats(prof)stats.strip_dirs().print_stats()'''#该片段来自于http://byrx.net

评论关闭