文本摘要简介

2025年6月21日 | 阅读11分钟

文本摘要是自然语言处理中的一项重要操作,它将大量文本浓缩成更短、更有意义的版本。由于数字内容激增,摘要为个人和企业提供了从冗长的文档、新闻文章、研究论文和报告中快速提取见解的方法。广义而言,文本摘要主要有两种类型:抽取式和抽象式。抽取式摘要涉及从源文本中逐字选择相关句子或短语,选择标准可以采用统计或语言机制(例如,词频、句子重要性、语义相关性)。这种方法保证了语法正确、简洁的介绍,但在大多数情况下无法提供逻辑上合理的流畅性。另一方面,抽象式摘要根据对文本的理解生成新句子,然后像人类一样重新表述。这种方法需要深度学习模型,例如序列到序列架构,并且转换器应包括 BERT 和 T5 以及循环神经网络,以构建流畅连贯的摘要。

现在我们将使用 Seq2Seq LSTM 模型执行文本摘要。

Introduction to Text Summarisation

代码

输出

Introduction to Text Summarisation

这是带有注意力的 LSTM

代码

输出

Introduction to Text Summarisation

现在让我们进行一些数据清理。

代码

输出

 
Time to clean up everything: 7.68 mins   

利用 spaCy 的 .pipe() 函数提高文本处理任务的效率

代码

输出

 
Time to clean up everything: 1.91 mins   

我们来看看。

代码

输出

Introduction to Text Summarisation

现在我们也将看看摘要。

代码

输出

 
'_START_ upgrad learner switches to a career in ml al with 90% salary hike _END_'   

绘制文本和摘要。

代码

输出

Introduction to Text Summarisation

确定包含 15 个或更少单词的“cleaned_brief_intro”条目的百分比

代码

输出

 
0.9978234465335472   

#检查有多少百分比的文本包含 0-70 个单词

代码

输出

 
0.9578389933440218   

定义文本摘要的最大字数限制。

代码

输出

Introduction to Text Summarisation

#在

代码

输出

Introduction to Text Summarisation

Seq2Seq 模型构建

代码

输出

Introduction to Text Summarisation

在这里,我们将分析文本中的稀有词。

代码

输出

 
Size of vocabulary in X = 33412   

在这里,我们将对摘要中的稀有词进行分析。

代码

输出

Introduction to Text Summarisation

我们需要知道大小。

代码

输出

 
Size of vocabulary in Y = 11581   

现在,“摘要”(Y)(训练集和验证集)都只包含 START 和 END,我们将删除它们。

代码

输出

Introduction to Text Summarisation
Introduction to Text Summarisation

使用 RMSprop 优化器和稀疏分类交叉熵损失编译模型

代码

输出

Introduction to Text Summarisation
Introduction to Text Summarisation

代码

输出

Introduction to Text Summarisation

让我们构建一个字典,将目标和源词汇表的索引转换为单词

代码

对于评论和摘要,让我们定义将整数序列转换为单词序列的函数。

代码

输出

Introduction to Text Summarisation
Introduction to Text Summarisation
下一主题生成对抗网络