🚀 要約生成モデル
このプロジェクトでは、GPT2アーキテクチャに基づく要約生成モデルを提供しています。このモデルは、テキストの要約抽出に使用できます。モデルはcnn_dailymail
データセットを使って訓練されており、要約生成タスクで一定の効果を発揮します。
🚀 クイックスタート
右側のパネルで、このモデルを試すことができます(ただし、短いシーケンス長のみを処理します)。右側のパネルに要約したいドキュメントを入力してください。
📦 インストール
GPT2の基礎アーキテクチャに基づくモデルは、以下の方法でロードできます。
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
model = GPT2LMHeadModel.from_pretrained("philippelaban/summary_loop10")
tokenizer = GPT2TokenizerFast.from_pretrained("philippelaban/summary_loop10")
💻 使用例
基本的な使用法
以下は、このモデルを使って要約を生成する例です。
document = "Bouncing Boulders Point to Quakes on Mars. A preponderance of boulder tracks on the red planet may be evidence of recent seismic activity. If a rock falls on Mars, and no one is there to see it, does it leave a trace? Yes, and it's a beautiful herringbone-like pattern, new research reveals. Scientists have now spotted thousands of tracks on the red planet created by tumbling boulders. Delicate chevron-shaped piles of Martian dust and sand frame the tracks, the team showed, and most fade over the course of a few years. Rockfalls have been spotted elsewhere in the solar system, including on the moon and even a comet. But a big open question is the timing of these processes on other worlds — are they ongoing or did they predominantly occur in the past?"
tokenized_document = tokenizer([document], max_length=300, truncation=True, return_tensors="pt")["input_ids"].cuda()
input_shape = tokenized_document.shape
outputs = model.generate(tokenized_document, do_sample=False, max_length=500, num_beams=4, num_return_sequences=4, no_repeat_ngram_size=6, return_dict_in_generate=True, output_scores=True)
candidate_sequences = outputs.sequences[:, input_shape[1]:]
candidate_scores = outputs.sequences_scores.tolist()
for candidate_tokens, score in zip(candidate_sequences, candidate_scores):
summary = tokenizer.decode(candidate_tokens)
print("[Score: %.3f] %s" % (score, summary[:summary.index("END")]))
出力例
上記のコードを実行すると、次のような出力が得られることがあります。
[Score: -0.084] Here's what you need to know about rockfalls
[Score: -0.087] Here's what you need to know about these tracks
[Score: -0.091] Here's what we know so far about these tracks
[Score: -0.101] Here's what you need to know about rockfall
📚 ドキュメント
GitHubリポジトリで、より詳細な情報や、評価関数、訓練スクリプト、またはサンプルの訓練ログにアクセスできます。https://github.com/CannyLab/summary_loop
📄 ライセンス
このプロジェクトは、Apache 2.0ライセンスの下で提供されています。