LaxRank抽取式文本總結(jié)(Text Summarization)

1 引言

在《生成摘要(Summarization)的新方法》中,我們使用了Transformers的pipeline方法和標(biāo)記方法分別對一段文本生成摘要,結(jié)果顯示標(biāo)記方法得出的結(jié)果更可靠些。在這個(gè)筆記中,我們使用LaxRank進(jìn)行抽取式文本總結(jié)而生成摘要,檢查其結(jié)果是否可靠。 測試是在虛擬環(huán)境(C:\Users\Administrator\anaconda3\envs\st)下進(jìn)行的,主要模塊安裝了截至2021/8/02的最新版本,關(guān)鍵庫如下:

Transformers V4.9.1

Torch V1.9.0 

Sentence-transformers V2.0.0

Lexrank 0.1.0

SentenceTransformers可用于抽取式文本總結(jié)。首先文件被分解成單句,并由SentenceTransformers嵌入,計(jì)算所有可能句子組合的余弦相似度,然后用Lexrank進(jìn)行排序。


2 LexRank

SentenceTransformers使用Lexrank庫尋找文件中最核心的句子,這些中心句子用來構(gòu)成文檔總結(jié)。Lexrank庫的最新版本仍然停留在0.1.0(2018/5/03),自此以后沒有再更新。LexRank以基于圖的句子中心性評分,是一種無監(jiān)督的文本總結(jié)方法。其中心思想是,句子向讀者 "推薦 "其他類似的句子。因此,如果一個(gè)句子與其他許多句子非常相似,那么它將可能是一個(gè)非常重要的句子。這個(gè)句子的重要性也源于 "推薦 "它的句子的重要性。因此,為了獲得高排名并被放在摘要中,一個(gè)句子必須與許多句子相似,而這些句子又與其他許多句子相似。這具有直觀的意義,并允許將算法應(yīng)用于任何任意的新文本。Lexrank的算法源于2004年的一篇論文:

LaxRank抽取式文本總結(jié)(Text Summarization)的圖1

Laxrank通過輸入degree_centrality_scores計(jì)算句子之間的相似度。不過這個(gè)函數(shù)處于測試階段,不能直接用pip install Laxrank實(shí)現(xiàn),必須手動下載源碼通過python setup.py install

安裝,然后配置路徑,這個(gè)過程挺麻煩的。

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

把測試代碼放在F:\Geotech\mydata\sentence-transformers\lexrank

目錄下(text-summarization-1.py), 這樣才能正確輸入laxrank庫。


3 抽取式總結(jié)

Laxrank只是根據(jù)句子的重要性進(jìn)行抽取式總結(jié),對原句不做任何改動。模型選用paraphrase-mpnet-base-v2,文本與《生成摘要(Summarization)的新方法》中使用的文本相同。首先把文本分割成單句:

sentences = nltk.sent_tokenize(document)

然后計(jì)算句子的嵌入:

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

接下來計(jì)算句子之間余弦相似度:

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

計(jì)算每個(gè)句子的中心度:

centrality_scores = degree_centrality_scores(cos_scores, threshold=None)

最后進(jìn)行排序,使第一個(gè)元素是得分最高的句子。

most_central_sentence_indices = np.argsort(-centrality_scores)

取出的5個(gè)得分最高的句子如下:

[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 結(jié)束語

文本摘要生成的確定過程和隨機(jī)過程》《生成摘要(Summarization)的新方法》和本文使用了不同的方法從不同角度對文本中心思想進(jìn)行重構(gòu),形成了“自動生成文檔總結(jié)”一章的核心內(nèi)容。 


登錄后免費(fèi)查看全文
立即登錄
App下載
技術(shù)鄰APP
工程師必備
  • 項(xiàng)目客服
  • 培訓(xùn)客服
  • 平臺客服

TOP