使用 NLP 進行文本摘要

一、說明

????????文本摘要是為較長的文本文檔生成簡短、流暢且最重要的是準確摘要的過程。自動文本摘要背后的主要思想是能夠從整個集合中找到最重要信息的一小部分,并以人類可讀的格式呈現。隨著在線文本數據的增長,自動文本摘要方法可能會非常有用,因為可以在短時間內有用的信息。

二、為什么要自動文本摘要?

  1. 摘要減少了閱讀時間。
  2. 研究文檔時,摘要使選擇過程變得更加容易。
  3. 自動摘要提高了索引的有效性。
  4. 自動摘要算法比人工摘要的偏差更小。
  5. 個性化摘要在問答系統中非常有用,因為它們提供個性化信息。
  6. 使用自動或半自動摘要系統使商業摘要服務能夠增加其能夠處理的文本文檔的數量。

三、文本總結的依據?

????????在下圖,至少出現了三個環節,1)文檔歸類? 2)文檔目的歸類 3)主題信息抽取。

3.1 基于輸入類型:

  1. Single?Document?輸入長度較短。許多早期的摘要系統處理單文檔摘要。
  2. 多文檔,輸入可以任意長。

3.2 根據目的的歸類

  1. 通用,模型不對要總結的文本的領域或內容做出任何假設,并將所有輸入視為同類。已完成的大部分工作都是圍繞通用摘要展開的。
  2. 特定領域,模型使用特定領域的知識來形成更準確的摘要。例如,總結特定領域的研究論文、生物醫學文獻等。
  3. 基于查詢,其中摘要僅包含回答有關輸入文本的自然語言問題的信息。

3.3 根據輸出類型:

  1. 提取,從輸入文本中選擇重要的句子以形成摘要。當今大多數總結方法本質上都是提取性的。
  2. 抽象,模型形成自己的短語和句子,以提供更連貫的摘要,就像人類會生成的一樣。這種方法肯定更有吸引力,但比提取摘要困難得多。

四、如何進行文本摘要

  • 文字清理
  • 句子標記化
  • 單詞標記化
  • 詞頻表
  • 總結

4.1 文字清理:

# !pip instlla -U spacy
# !python -m spacy download en_core_web_sm
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
stopwords = list(STOP_WORDS)
nlp = spacy.load(‘en_core_web_sm’)
doc = nlp(text)

4.2 單詞標記化:

tokens = [token.text for token in doc]
print(tokens)
punctuation = punctuation + ‘\n’
punctuation
word_frequencies = {}
for word in doc:
if word.text.lower() not in stopwords:
if word.text.lower() not in punctuation:
if word.text not in word_frequencies.keys():
word_frequencies[word.text] = 1
else:
word_frequencies[word.text] += 1
print(word_frequencies)

4.3 句子標記化:

max_frequency = max(word_frequencies.values())
max_frequency
for word in word_frequencies.keys():
word_frequencies[word] = word_frequencies[word]/max_frequency
print(word_frequencies)
sentence_tokens = [sent for sent in doc.sents]
print(sentence_tokens)

4.4 建立詞頻表:

sentence_scores = {}
for sent in sentence_tokens:
for word in sent:
if word.text.lower() in word_frequencies.keys():
if sent not in sentence_scores.keys():
sentence_scores[sent] = word_frequencies[word.text.lower()]
else:
sentence_scores[sent] += word_frequencies[word.text.lower()]
sentence_scores

4.5 主題信息總結:

from heapq import nlargest
select_length = int(len(sentence_tokens)*0.3)
select_length
summary = nlargest(select_length, sentence_scores, key = sentence_scores.get)
summary
final_summary = [word.text for word in summary]
summary = ‘ ‘.join(final_summary)

輸入原始文檔:

text = “””
Maria Sharapova has basically no friends as tennis players on the WTA Tour. The Russian player has no problems in openly speaking about it and in a recent interview she said: ‘I don’t really hide any feelings too much.
I think everyone knows this is my job here. When I’m on the courts or when I’m on the court playing, I’m a competitor and I want to beat every single person whether they’re in the locker room or across the net.
So I’m not the one to strike up a conversation about the weather and know that in the next few minutes I have to go and try to win a tennis match.
I’m a pretty competitive girl. I say my hellos, but I’m not sending any players flowers as well. Uhm, I’m not really friendly or close to many players.
I have not a lot of friends away from the courts.’ When she said she is not really close to a lot of players, is that something strategic that she is doing? Is it different on the men’s tour than the women’s tour? ‘No, not at all.
I think just because you’re in the same sport doesn’t mean that you have to be friends with everyone just because you’re categorized, you’re a tennis player, so you’re going to get along with tennis players.
I think every person has different interests. I have friends that have completely different jobs and interests, and I’ve met them in very different parts of my life.
I think everyone just thinks because we’re tennis players we should be the greatest of friends. But ultimately tennis is just a very small part of what we do.
There are so many other things that we’re interested in, that we do.’
“””

4.6 輸出(最終摘要):摘要

I think just because you’re in the same sport doesn’t mean that you have to be friends with everyone just because you’re categorized, you’re a tennis player, so you’re going to get along with tennis players. Maria Sharapova has basically no friends as tennis players on the WTA Tour. I have friends that have completely different jobs and interests, and I’ve met them in very different parts of my life. I think everyone just thinks because we’re tennis players So I’m not the one to strike up a conversation about the weather and know that in the next few minutes I have to go and try to win a tennis match. When she said she is not really close to a lot of players, is that something strategic that she is doing?

有關完整代碼,請查看我的存儲庫:

五、結語

????????本文至少精簡地告訴大家,文章自動摘要需要哪些關鍵環節。

????????創建數據集可能是一項繁重的工作,并且經常是學習數據科學中被忽視的部分,實際工作要給以重視。不過,這是另一篇博客文章。阿努普·辛格

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/41929.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/41929.shtml
英文地址,請注明出處:http://en.pswp.cn/news/41929.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C語言好題解析(一)

目錄 選擇題1選擇題2選擇題3選擇題4編程題一 選擇題1 執行下面程序,正確的輸出是( )int x 5, y 7; void swap() {int z;z x;x y;y z; } int main() {int x 3, y 8;swap();printf("%d,%d\n",x, y);return 0; }A: 5,7 B: …

H5前端外包開發框架排名

以下是一些常見的網頁前端開發框架以及它們的排名和特點。請注意,隨著時間的推移,框架的排名和特點可能會有所變化。不同的項目和團隊對于框架的選擇會受到多個因素的影響,包括開發團隊的技能、項目的規模和要求、性能需求等。北京木奇移動技…

try-with-resource

git https://gitee.com/my739168148/auto-close-try-with-resource.git 限制 try-with-resource是java7版本引入的。 java版本說明 Autocloseable 只要是java.lang.Autocloseable接口的實現類,那么都可以使用try-with-resource來自動關閉資源。 使用 JDK1.8開…

【網絡】網絡層——IP協議

🐱作者:一只大喵咪1201 🐱專欄:《網絡》 🔥格言:你只管努力,剩下的交給時間! 網絡層中,IP協議首部和有效載荷組成的完整數據稱為數據報。 IP協議 🍉TCP和IP的…

C# Linq源碼分析之Take (二)

概要 本文主要分析Linq中Take帶Range參數的重載方法的源碼。 源碼分析 基于Range參數的Take重載方法,主要分成兩部分實現,一部分是Range中的開始和結束索引都是正數的情況例如取第一個到第三個元素的情況;另一部分是開始或結束索引中有倒數…

華為AI戰略的CANN

基于TVM的華為昇騰體系中—— 異構計算架構(CANN)是對標英偉達的CUDA CuDNN的核心軟件層,向上支持多種AI框架,向下服務AI處理器,發揮承上啟下的關鍵作用,是提升昇騰AI處理器計算效率的關鍵平臺 主要包括有…

ES安裝問題匯總

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] 問題描述 ES啟動報錯。其原因是ES需要的的最小max file descriptors為65535,我們設置的是4096,需要增大max file descriptors的值。 解決方案 調大…

“new出對象“原理的深層解密

🎈個人主頁:🎈 :???初階牛??? 🐻推薦專欄1: 🍔🍟🌯C語言初階 🐻推薦專欄2: 🍔🍟🌯C語言進階 🔑個人信條: 🌵知行合一 &#x1f…

正規的股票杠桿公司_杠桿公司排名(2023年版的)

本文將介紹一些正規的股票杠桿公司,并重點介紹配先查網站的特點,該網站是一家專業查詢實盤杠桿平臺的網站,提供相關信息和參考。 杠桿公司排名(2023年版的):廣盛網、一鼎盈、尚紅網、盛多網、紅騰網、富燈…

Oracle/PL/SQL奇技淫巧之ROWNUM偽列

ROWNUM偽列 ROWNUM是一個偽列,它是根據每次查詢的結果動態生成的一列遞增編號,表示 Oracle 從表中選擇該行的順序,選擇的第一行ROWNUM為1,第二行ROWNUM為2,以此類推。 注意1: ROWNUM偽列是在WHERE子句之…

Mybatis——返回值(resultType&resultMap)詳解

之前的文章里面有對resultType和resultMap的簡單介紹這一期出點詳細的 resultType&#xff1a; 1&#xff0c;返回值為簡單類型。 直接使用resultType“類型”&#xff0c;如string&#xff0c;Integer等。 String getEmpNameById(Integer id); <!-- 指定 result…

Linux內核源碼剖析之TCP保活機制(KeepAlive)

寫在前面&#xff1a; 版本信息&#xff1a; Linux內核2.6.24&#xff08;大部分centos、ubuntu應該都在3.1。但是2.6的版本比較穩定&#xff0c;后續版本本質變化也不是很大&#xff09; ipv4 協議 https://blog.csdn.net/ComplexMaze/article/details/124201088 本文使用案例…

高級AI賦能Fortinet FortiXDR解決方案

擴展檢測和響應 (XDR&#xff1a;Extended Detection and Response) 解決方案旨在幫助組織整合分布式安全技術&#xff0c;更有效地識別和響應活動的威脅。雖然 XDR 是一種新的技術概念&#xff0c;但其構建基礎是端點檢測和響應 (EDR&#xff1a;Endpoint Detection and Respo…

代碼隨想錄算法訓練營第50天|動態規劃part11

8.16周三 123.買賣股票的最佳時機III 188.買賣股票的最佳時機IV 詳細布置 123.買賣股票的最佳時機III 題目&#xff1a;最多買賣兩次 題解&#xff1a; 1、 dp[i][0]沒有操作 &#xff08;其實我們也可以不設置這個狀態&#xff09; dp[i][1]第一次持有股票 dp[i][2]第一…

CSDN?索尼 toio?應用創意開發征集征集活動 創意公示! 入選的用戶看過來~

索尼toio?應用創意開發征集活動自開啟以來&#xff0c;收到了很多精彩的創意&#xff01;接下來&#xff0c;我們將公示入選的20個優秀創意和10個入圍創意&#xff0c;以下提到ID的小伙伴注意啦&#xff0c;你們將有機會順利進入活動的第二階段&#xff0c;注意查收你們的信箱…

javaScript:快樂學習計時器

目錄 一.前言 二.計時器 1.計時器的分類 2. 創建計時器的方式 創建間隔計時器 創建方式三種 1.匿名函數 2.使用函數直接作為計時器的執行函數 2.使用函數直接作為計時器的執行函數,用字符串的形式寫入 3.計時器的返回值 4.清除計時器 5.延遲計時器 相關代碼 一.前言 在…

Linux--實用指令與方法(部分)

下文主要是一些工作中零碎的常用指令與方法 實用指令與方法&#xff08;部分&#xff09; linux長時間保持ssh連接 這個問題的原因是&#xff1a;設置檢測時間太短&#xff0c;或者沒有保持tcp長連接。 解決步驟&#xff1a; 步驟1&#xff1a;打開sshd配置文件&#xff0…

nbcio-boot從3.0升級到3.1的出現用戶管理與數據字典bug

升級后出現 系統管理里的用戶管理出現下面問題 2023-08-17 09:44:38.902 [http-nio-8080-exec-4] [1;31mERROR[0;39m [36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m - java.lang.String cannot be cast to java.lang.Long java.lang.ClassCastException:…

【JS 線性代數算法之向量與矩陣】

線性代數算法 一、向量的加減乘除1. 向量加法2. 向量減法3. 向量數乘4. 向量點積5. 向量叉積 二、矩陣的加減乘除1. 矩陣加法2. 矩陣減法3. 矩陣數乘4. 矩陣乘法 常用數學庫 線性代數是數學的一個分支&#xff0c;用于研究線性方程組及其解的性質、向量空間及其變換的性質等。在…

windows bat腳本,使用命令行增加/刪除防火墻:入站-出站,規則

常常手動設置防火墻的入站或出站規則&#xff0c;比較麻煩&#xff0c;其實可以用命令行搞定。 下面是禁用BCompare.exe連接網絡的例子&#xff1a; ECHO OFF&(PUSHD "%~DP0")&(REG QUERY "HKU\S-1-5-19">NUL 2>&1)||(powershell -Comm…