使用 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.mzph.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…