NLP を使用したテキストの要約

1. 説明

        テキストの要約は、長いテキスト文書の短く、流暢で、最も重要なことに正確な要約を生成するプロセスです。自動テキスト要約の背後にある主なアイデアは、コレクション全体から最も重要な情報の小さなサブセットを見つけて、それを人間が読める形式で表示できるようにすることです。オンライン テキスト データの増加に伴い、より多くの有用な情報を短時間で読むことができるため、自動テキスト要約方法は非常に役立ちます。

2. なぜ自動テキスト要約を行うのですか?

  1. 要約を利用すると読む時間が短縮されます。
  2. 文書を調査する場合、概要を使用すると選択プロセスがはるかに簡単になります。
  3. 自動要約により、インデックスの有効性が高まります。
  4. 自動要約アルゴリズムは、人間による要約よりも偏りが少ないです。
  5. パーソナライズされた概要は、パーソナライズされた情報を提供するため、質問応答システムで非常に役立ちます。
  6. 自動または半自動要約システムを使用すると、商用要約サービスが処理できるテキスト ドキュメントの数を増やすことができます。

3. テキスト要約の基礎 

        以下の図には、1) 文書分類、2) 文書目的分類、3) 主題情報抽出の少なくとも 3 つのリンクがあります。

3.1 入力タイプに基づく:

  1. 入力長が短い単一ドキュメント 。 初期の要約システムの多くは、単一文書の要約を扱っていました。
  2. 複数のドキュメントの場合、入力は任意の長さにすることができます。

3.2 目的による分類

  1. 一般的なモデルでは、要約するテキストのドメインや内容について何の仮定も行わず、すべての入力を同種のものとして扱います。これまでに行われた作業のほとんどは、一般的な抽象化を中心に展開されています。
  2. ドメイン固有のモデルは、ドメイン固有の知識を使用して、より正確な要約を作成します。たとえば、特定の分野の研究論文、生物医学文献などを要約します。
  3. クエリに基づいており、概要には入力テキストに関する自然言語の質問に答える情報のみが含まれています。

3.3 出力タイプに応じて:

  1. 入力テキストから重要な文を選択して要約を作成する抽出。今日のほとんどの要約手法は本質的に抽出的です。
  2. 抽象化。人間が生成するのと同じように、モデルが独自のフレーズや文章を形成して、より一貫した要約を提供します。このアプローチは確かに魅力的ですが、ダイジェストを抽出するよりもはるかに困難です。

4. テキスト要約の実行方法

  • テキストのクリーニング
  • 文のトークン化
  • 単語のトークン化
  • 単語頻度表
  • 要約する

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?

完全なコードについては、私のリポジトリをチェックしてください。

V. 結論

        この記事では、記事の自動要約に必要な主要なリンクについて少なくとも簡単に説明します。

        データセットの作成は多大な作業となる可能性があり、データ サイエンスの学習では実際の作業に注目が集まるため、見落とされがちです。ただし、それは別のブログ投稿です。アヌプ・シン

おすすめ

転載: blog.csdn.net/gongdiwudu/article/details/132258609