🚀 摘要生成模型
本項目提供了一個基於GPT2架構的摘要生成模型,可對輸入的文檔進行摘要提取。該模型使用cnn_dailymail
數據集進行訓練,並以ROUGE
作為評估指標,採用Apache-2.0
許可證。
🚀 快速開始
在右側面板中,你可以嘗試使用該模型(儘管它僅處理短序列長度)。在右側面板中輸入你想要摘要的文檔。
📦 安裝指南
基於GPT2基礎架構的模型可以按以下方式加載:
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
model = GPT2LMHeadModel.from_pretrained("philippelaban/summary_loop46")
tokenizer = GPT2TokenizerFast.from_pretrained("philippelaban/summary_loop46")
💻 使用示例
基礎用法
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.153] These tracks have been spotted elsewhere on Mars. If a rockfalls on Mars has been spotted elsewhere on the red planet. Scientists have spotted thousands of tracks on Mars. A rockfalls on Mars have been spotted elsewhere on the Red Planet.
[Score: -0.154] These tracks have been spotted elsewhere on Mars. If a rockfalls on Mars has been spotted elsewhere on the red planet. Scientists have spotted thousands of tracks on Mars. A rockfalls on Mars have been spotted elsewhere on the planet.
[Score: -0.154] These tracks have been spotted elsewhere on Mars. If a rockfalls on Mars has been spotted elsewhere on the red planet. Scientists have spotted thousands of tracks on Mars. A rockfalls have been spotted elsewhere on the Red Planet.
[Score: -0.195] These tracks have been spotted elsewhere on Mars. If a rockfalls on Mars has been spotted elsewhere on the red planet. Scientists have spotted thousands of tracks on Mars. A rockfalls on Mars have been spotted elsewhere on the Red Planet. A rockfalls have been spotted everywhere on the red planet.
📚 詳細文檔
你可以在GitHub倉庫中獲取更多信息、訪問評分函數、訓練腳本或示例訓練日誌:https://github.com/CannyLab/summary_loop
📄 許可證
本項目採用Apache-2.0
許可證。
屬性 |
詳情 |
模型類型 |
基於GPT2架構的摘要生成模型 |
訓練數據 |
cnn_dailymail |
評估指標 |
ROUGE |
許可證 |
Apache-2.0 |