使用 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.hqwc.cn/news/67854.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ubuntu环境上搭建ros2

环境搭建 设置系统区域。 首先需要确保安装环境支持 UTF-8 格式 sudo apt install locales sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALLen_US.UTF-8 LANGen_US.UTF-8 export LANGen_US.UTF-8 locale添加 ROS2 的代码仓库 设置你的sources.list&#xff0…

Python自动化小技巧16——分类汇总写入excel不同sheet表

案例背景 上了两个月班的社畜博主最近终于有空来总结一下最近写的代码了。 因为上班都是文职工作,天天不是word就是excel就是PPT和pdf....这和什么机器学习还有数据科学不一样,任务更多的是处理实在的文字和表格等格式,按照领导要求来完成&…

wsl2安装docker引擎(Install Docker Engine on Debian)

安装 1.卸载旧版本 在安装 Docker 引擎之前,您必须首先确保卸载任何冲突的软件包。 发行版维护者在他们的存储库。必须先卸载这些软件包,然后才能安装 Docker 引擎的正式版本。 要卸载的非官方软件包是: docker.iodocker-composedocker-…

使用GUI Guider工具开发嵌入式GUI应用 (3) - 使用label组件

使用GUI Guider工具开发嵌入式GUI应用 (3) - 使用label组件 文章目录 使用GUI Guider工具开发嵌入式GUI应用 (3) - 使用label组件引言在GUI Guider工程中创建label组件编译MCU工程并下载到开发板 引言 本节讲述在GUI Guider中,应用各种UI的基本元素,并顺…

企业中商业智能BI,常见的工具和技术

商业智能(Business Intelligence,简称BI)数据可视化是通过使用图表、图形和其他可视化工具来呈现和解释商业数据的过程。它旨在帮助组织更好地理解和分析他们的数据,从而做出更明智的商业决策。 常见的商业智能数据可视化工具和技…

c51单片机串口通信(中断方式接收数据)(单片机--单片机通信)示例代码 附proteus图

单片机一般采用中断方式接受数据,这样便于及时处理 #include "reg51.h" #include "myheader.h" #define uchar unsigned char int szc[10]{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; int bufferc[6]{0}; int sza[6]{0x01,0x02,0x0…

Redis_缓存1_缓存类型

14.redis缓存 14.1简介 穿透型缓存: 缓存与后端数据交互在一起,对服务端的调用隐藏细节。如果从缓存中可以读到数据,就直接返回,如果读不到,就到数据库中去读取,从数据库中读到数据,也是先更…

二次封装element-plus上传组件,提供校验、回显等功能

二次封装element-plus上传组件 0 相关介绍1 效果展示2 组件主体3 视频组件4 Demo 0 相关介绍 基于element-plus框架,视频播放器使用西瓜视频播放器组件 相关能力 提供图片、音频、视频的预览功能提供是否为空、文件类型、文件大小、文件数量、图片宽高校验提供图片…

实录分享 | 使用Prometheus和Grafana监控Alluxio运行状况

欢迎来到【微直播间】,2min纵览大咖观点 本次分享主要包括三个方面: Prometheus&Grafana简介环境搭建手动调优 一、 Prometheus&Grafana简介关于Prometheus: Prometheus 是一个开源的完整监控解决方案,其对传统监控系…

js操作剪贴板讲解

文章目录 复制(剪切)到剪贴板Document.execCommand()Clipboard复制Clipboard.writeText()Clipboard.write() copy,cut事件 从剪贴板进行粘贴document.execCommand(paste)Clipboard粘贴Clipboard.readText()Clipboard.read() paste 事件 安全性…

领航未来!探索开源无人机与5G组网的前沿技术

近年来无人机行业高速发展,无人机被广泛应用于航拍、农业、电力、消防、科研等领域。随着无人机市场不断增长,其对实时超高清图传、远程低时延控制、海量数据处理等需求也在不断扩张,这无疑给通信链路带来了巨大的挑战。 为应对未来的需求变…

NLP文本匹配任务Text Matching [有监督训练]:PointWise(单塔)、DSSM(双塔)、Sentence BERT(双塔)项目实践

NLP文本匹配任务Text Matching [有监督训练]:PointWise(单塔)、DSSM(双塔)、Sentence BERT(双塔)项目实践 0 背景介绍以及相关概念 本项目对3种常用的文本匹配的方法进行实现:Poin…