使用 NLP 进行文本摘要
一、说明
二、为什么要自动文本摘要?
- 摘要减少了阅读时间。
- 研究文档时,摘要使选择过程变得更加容易。
- 自动摘要提高了索引的有效性。
- 自动摘要算法比人工摘要的偏差更小。
- 个性化摘要在问答系统中非常有用,因为它们提供个性化信息。
- 使用自动或半自动摘要系统使商业摘要服务能够增加其能够处理的文本文档的数量。
三、文本总结的依据
在下图,至少出现了三个环节,1)文档归类 2)文档目的归类 3)主题信息抽取。

3.1 基于输入类型:
- Single Document ,输入长度较短。许多早期的摘要系统处理单文档摘要。
- 多文档,输入可以任意长。
3.2 根据目的的归类
- 通用,模型不对要总结的文本的领域或内容做出任何假设,并将所有输入视为同类。已完成的大部分工作都是围绕通用摘要展开的。
- 特定领域,模型使用特定领域的知识来形成更准确的摘要。例如,总结特定领域的研究论文、生物医学文献等。
- 基于查询,其中摘要仅包含回答有关输入文本的自然语言问题的信息。
3.3 根据输出类型:
- 提取,从输入文本中选择重要的句子以形成摘要。当今大多数总结方法本质上都是提取性的。
- 抽象,模型形成自己的短语和句子,以提供更连贯的摘要,就像人类会生成的一样。这种方法肯定更有吸引力,但比提取摘要困难得多。
四、如何进行文本摘要
- 文字清理
- 句子标记化
- 单词标记化
- 词频表
- 总结
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?
有关完整代码,请查看我的存储库:
五、结语
本文至少精简地告诉大家,文章自动摘要需要哪些关键环节。
创建数据集可能是一项繁重的工作,并且经常是学习数据科学中被忽视的部分,实际工作要给以重视。不过,这是另一篇博客文章。阿努普·辛格
相关文章:
使用 NLP 进行文本摘要
一、说明 文本摘要是为较长的文本文档生成简短、流畅且最重要的是准确摘要的过程。自动文本摘要背后的主要思想是能够从整个集合中找到最重要信息的一小部分,并以人类可读的格式呈现。随着在线文本数据的增长,自动文本摘要方法可能会非常有用,…...
vue3挂载全局方法和组件
话不多说直接上代码 main.js import { createApp } from vue import App from ./App.vueconst app createApp(App)// 注册全局方法和组件 function myMethod(){console.log(Hello, world!); } app.provide("myMethod", myMethod) // provide注册全局方法 inject获取…...
mybatisplus学习笔记
1.踩过的坑 1.MybatisPlus 要与其代码生成器的版本一致; 2.要使用新版代码(3.5.1及以上)生成器则要使用springboot3,如果用springboot2使用新版代码生成器会导致builder.parent(“com.sdfsf”) // 设置父包名》重复!&…...
go mod 添加私有库GOPRIVATE
私有地址 形式仓库域名/组织名形式仓库域名形式*仓库域名 示例私有地址: gitee.com/takujo_admin 或者igitlab.com 多个私有地址,分割,示例: gitee.com,igitlab.com 修改env go env -w GOPRIVATE"私有地址" go env -w …...
07-HDFS入门及shell命令
1 文件系统 是一种存储和组织数据的方法,它使得文件访问和查询变得容易使得文件和树形目录的抽象逻辑概念代替了磁盘等物理设备使用数据块的概念,用户使用文件系统来保存数据不必关心数据底层存在硬盘哪里,只需记住这个文件的所属目录和文件…...
TiDB在科捷物流神州金库核心系统的应用与实践
业务背景 北京科捷物流有限公司于2003年在北京正式成立,是ISO质量管理体系认证企业、国家AAAAA级物流企业、海关AEO高级认证企业,注册资金1亿元,是中国领先的大数据科技公司——神州控股的全资子公司。科捷物流融合B2B和B2C的客户需求&#…...
React 18 更新 state 中的数组
参考文章 更新 state 中的数组 数组是另外一种可以存储在 state 中的 JavaScript 对象,它虽然是可变的,但是却应该被视为不可变。同对象一样,当想要更新存储于 state 中的数组时,需要创建一个新的数组(或者创建一份已…...
【css】css中使用变量var
CSS 变量可以有全局或局部作用域。 全局变量可以在整个文档中进行访问/使用,而局部变量只能在声明它的选择器内部使用。 如需创建具有全局作用域的变量,请在 :root 选择器中声明它。 :root 选择器匹配文档的根元素。 如需创建具有局部作用域的变量&am…...
判断自己网络所在的NAT类型
文章目录 各NAT类型介绍软件准备流程 各NAT类型介绍 NAT0: OpenInternet,没有经过NAT地址转换,公网IP NAT1: Full Cone NAT,动态家宽可以达到最优的状态,外网设备可以主动发信息给NAT1网络内的设备。 NAT2: Address-Restricted C…...
ClickHouse(十九):Clickhouse SQL DDL操作-1
进入正文前,感谢宝子们订阅专题、点赞、评论、收藏!关注IT贫道,获取高质量博客内容! 🏡个人主页:含各种IT体系技术,IT贫道_Apache Doris,大数据OLAP体系技术栈,Kerberos安全认证-CSDN博客 &…...
小程序保留2位小数据,不四舍五入
方法1: parseInt toFixed /* * 保留2位小数,不四舍五入 * 5.992550 >5.99 , 2 > 2.00 * */ const toFixed2Decimal (value) > {return (parseInt(value*100)/100).toFixed(2) } console.log(587.67*100) console.log(toFixed2Decimal(587.67…...
【linux-nginx】nginx限流以及控制访问方法
一、限流 可以使用一些模块和指令来实现限流。以下是一些常用的方法: 使用 ngx_http_limit_req_module 模块:该模块可以限制每个客户端的请求速率。你可以在 Nginx 的配置文件中启用该模块,并使用 limit_req_zone 指令来定义限流规则。例如…...
菜单和内容滚动的联动原理及代码
之前写代码有个需求:左侧是一个菜单,右边是内容,点击左侧菜单右边内容滚动到对应位置,右边内容滚动到某位置时,左侧菜单也会选中对应的菜单项。UI如下:这是大多网站的移动端都会有的需求。 解决方案一&…...
Python爬虫:单线程、多线程、多进程
前言 在使用爬虫爬取数据的时候,当需要爬取的数据量比较大,且急需很快获取到数据的时候,可以考虑将单线程的爬虫写成多线程的爬虫。下面来学习一些它的基础知识和代码编写方法。 一、进程和线程 进程可以理解为是正在运行的程序的实例。进…...
超强的Everything,吊打系统自带文件搜索功能!
目录 一、软件简介 二、软件下载 三、软件说明 一、软件简介 Everything是一款由David OReilly开发的电脑搜索软件,它可以帮助用户快速找到电脑上的文件和文件夹。与其他搜索工具不同的是,Everything使用了一种非常快速和高效的搜索算法,…...
flink配置参数
flink-conf.yaml 基础配置 # jobManager 的IP地址jobmanager.rpc.address: localhost# JobManager 的端口号jobmanager.rpc.port: 6123# JobManager JVM heap 内存大小jobmanager.heap.size: 1024m# TaskManager JVM heap 内存大小taskmanager.heap.size: 1024m# 每个 TaskMan…...
学习Vue:安装Vue.js和设置开发环境
当您决定进入现代前端开发的世界,Vue.js 无疑是一个令人激动的选择。它以其简洁、灵活和高效的特点在开发者社区中备受赞誉。本文将为您详细介绍如何安装 Vue.js 并设置开发环境,让您能够迅速开始编写 Vue 应用程序。 步骤1:安装 Node.js 和 …...
代理技术在网络安全、爬虫和数据隐私中的多重应用
1. Socks5代理:灵活的数据中转 Socks5代理协议在网络通信中起着关键作用。与其他代理技术不同,Socks5代理不仅支持TCP连接,还能够处理UDP流量,使其在需要实时数据传输的场景中表现尤为出色。通过将请求和响应中转到代理服务器&am…...
Python 3 使用Hadoop 3之MapReduce总结
MapReduce 运行原理 MapReduce简介 MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,解决海量数据的计算问题。 MapReduce分成两个部分:Map(映射)和Reduce(归纳)。…...
KU Leuven TU Berlin 推出“RobBERT”,一款荷兰索塔 BERT
荷兰语是大约24万人的第一语言,也是近5万人的第二语言,是继英语和德语之后第三大日耳曼语言。来自比利时鲁汶大学和柏林工业大学的一组研究人员最近推出了基于荷兰RoBERTa的语言模型RobBERT。 谷歌的BERT(来自Transformers的B idirectional …...
(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...
docker详细操作--未完待续
docker介绍 docker官网: Docker:加速容器应用程序开发 harbor官网:Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台,用于将应用程序及其依赖项(如库、运行时环…...
visual studio 2022更改主题为深色
visual studio 2022更改主题为深色 点击visual studio 上方的 工具-> 选项 在选项窗口中,选择 环境 -> 常规 ,将其中的颜色主题改成深色 点击确定,更改完成...
使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台
🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...
Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?
Redis 的发布订阅(Pub/Sub)模式与专业的 MQ(Message Queue)如 Kafka、RabbitMQ 进行比较,核心的权衡点在于:简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...
PAN/FPN
import torch import torch.nn as nn import torch.nn.functional as F import mathclass LowResQueryHighResKVAttention(nn.Module):"""方案 1: 低分辨率特征 (Query) 查询高分辨率特征 (Key, Value).输出分辨率与低分辨率输入相同。"""def __…...
并发编程 - go版
1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...
基于Springboot+Vue的办公管理系统
角色: 管理员、员工 技术: 后端: SpringBoot, Vue2, MySQL, Mybatis-Plus 前端: Vue2, Element-UI, Axios, Echarts, Vue-Router 核心功能: 该办公管理系统是一个综合性的企业内部管理平台,旨在提升企业运营效率和员工管理水…...
Python 实现 Web 静态服务器(HTTP 协议)
目录 一、在本地启动 HTTP 服务器1. Windows 下安装 node.js1)下载安装包2)配置环境变量3)安装镜像4)node.js 的常用命令 2. 安装 http-server 服务3. 使用 http-server 开启服务1)使用 http-server2)详解 …...
【学习笔记】erase 删除顺序迭代器后迭代器失效的解决方案
目录 使用 erase 返回值继续迭代使用索引进行遍历 我们知道类似 vector 的顺序迭代器被删除后,迭代器会失效,因为顺序迭代器在内存中是连续存储的,元素删除后,后续元素会前移。 但一些场景中,我们又需要在执行删除操作…...
