LaxRank抽取式文本总结(Text Summarization)

1 引言

在《生成摘要(Summarization)的新方法》中,我们使用了Transformers的pipeline方法和标记方法分别对一段文本生成摘要,结果显示标记方法得出的结果更可靠些。在这个笔记中,我们使用LaxRank进行抽取式文本总结而生成摘要,检查其结果是否可靠。 测试是在虚拟环境(C:\Users\Administrator\anaconda3\envs\st)下进行的,主要模块安装了截至2021/8/02的最新版本,关键库如下:

Transformers V4.9.1

Torch V1.9.0 

Sentence-transformers V2.0.0

Lexrank 0.1.0

SentenceTransformers可用于抽取式文本总结。首先文件被分解成单句,并由SentenceTransformers嵌入,计算所有可能句子组合的余弦相似度,然后用Lexrank进行排序。


2 LexRank

SentenceTransformers使用Lexrank库寻找文件中最核心的句子,这些中心句子用来构成文档总结。Lexrank库的最新版本仍然停留在0.1.0(2018/5/03),自此以后没有再更新。LexRank以基于图的句子中心性评分,是一种无监督的文本总结方法。其中心思想是,句子向读者 "推荐 "其他类似的句子。因此,如果一个句子与其他许多句子非常相似,那么它将可能是一个非常重要的句子。这个句子的重要性也源于 "推荐 "它的句子的重要性。因此,为了获得高排名并被放在摘要中,一个句子必须与许多句子相似,而这些句子又与其他许多句子相似。这具有直观的意义,并允许将算法应用于任何任意的新文本。Lexrank的算法源于2004年的一篇论文:

LaxRank抽取式文本总结(Text Summarization)的图1

Laxrank通过输入degree_centrality_scores计算句子之间的相似度。不过这个函数处于测试阶段,不能直接用pip install Laxrank实现,必须手动下载源码通过python setup.py install

安装,然后配置路径,这个过程挺麻烦的。

import syssys.path.append("./lexrank/lexrank")

把测试代码放在F:\Geotech\mydata\sentence-transformers\lexrank

目录下(text-summarization-1.py), 这样才能正确输入laxrank库。


3 抽取式总结

Laxrank只是根据句子的重要性进行抽取式总结,对原句不做任何改动。模型选用paraphrase-mpnet-base-v2,文本与《生成摘要(Summarization)的新方法》中使用的文本相同。首先把文本分割成单句:

sentences = nltk.sent_tokenize(document)

然后计算句子的嵌入:

embeddings = model.encode(sentences, convert_to_tensor=True)

接下来计算句子之间余弦相似度:

cos_scores = util.cos_sim(embeddings, embeddings).numpy()

计算每个句子的中心度:

centrality_scores = degree_centrality_scores(cos_scores, threshold=None)

最后进行排序,使第一个元素是得分最高的句子。

most_central_sentence_indices = np.argsort(-centrality_scores)

取出的5个得分最高的句子如下:

[1] A new underground mine is being developed to access the ore body situated beneath the present open pit mine.

[2] The conceptual engineering for the underground Chuquicamata mine began in 2007 and was finalised in March 2009.

[3] The new underground mine, scheduled begin operations in 2019, will comprise of four production levels, a 7.5km main access tunnel, five clean air injection ramps, and two air-extraction shafts.

[4] Chuquicamata, one of the largest open pit copper mines and the second deepest open-pit mine in the world, is located 1,650km north of Santiago, Chile.

[5] The century-old copper mine is owned and operated by Codelco and forms part of the company’s Codelco Norte division, which includes the Radomiro Tomic (RT) mine found on the same mineralised system.


4 结束语

文本摘要生成的确定过程和随机过程》《生成摘要(Summarization)的新方法》和本文使用了不同的方法从不同角度对文本中心思想进行重构,形成了“自动生成文档总结”一章的核心内容。 


默认 最新
当前暂无评论,小编等你评论哦!
点赞 评论 收藏
关注