https://github.com/google-research/pegasus
ICML 2020 接收的論文,https://arxiv.org/abs/1912.08777
Pre-training with Extracted Gap-sentences for Abstractive SUmmarization Sequence-to-sequence models, or PEGASUS, uses self-supervised objective Gap Sentences Generation (GSG) to train a transformer encoder-decoder model.
PEGASUS:基於句子間隙的抽取式摘要預訓練模型
PEGASUS專用於機器摘要生成。使用谷歌預訓練的模型,在1000個樣本進行測試,結果不差於人類評估結果。
谷歌發現,選擇“重要”句子去遮擋效果最好,這會使自監督樣本的輸出與摘要更加相似。根據ROUGE標准對輸出結果進行評判,通過查找與文檔其余部分最相似的句子來自動識別這些句子。
與谷歌之前提出的T5對比,參數數量僅為T5的5%。
使用3種模型在12個數據集做實驗,訓練動態間隙句生成模型
12個不同的數據集,包括新聞、科學論文、專利文件、短篇小說、電子郵件、法律文件和使用說明,表明該模型框架適用於各種主題。
准備環境
代碼是需要機器和環境才可以運行的。
源代碼給出的是gcloud命令,我沒有使用它,而是使用阿里雲機器。
具體配置為:
ubuntu 16.04 64位
硬盤500G
1塊V100
GPU驅動相關版本號:
CUDA:10.2.89
Driver:440.64.00
CUDNN:7.6.5
試了CUDA10.1.168,有報錯。所以,CUDA版本很重要,別選錯。具體谷歌自己使用的是哪個版本,我目前沒找到相關資料。
cat /usr/local/cuda/version.txt
CUDA Version 10.1.168
tensorflow.python.framework.errors_impl.NotFoundError: libtensorflow_framework.so.2: cannot open shared object file: No such file or directory
正確的提示是:
2020-06-22 11:08:56.423661: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
gcloud也試了一下,提示權限不對。國內FQ有些費勁呀。
安裝pegasus
我使用的是Ancona3
cd ~/git
git clone https://github.com/google-research/pegasus
cd pegasus
source ~/anaconda3/bin/activate
# conda create --name env_pegasus python=3.7 創建時需要
conda activate env_pegasus
pip3 install -r requirements.txt
pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
python3 setup.py install & build
下載數據
共12個數據集,使用gsutil工具下載。
gsutil工具安裝參考https://cloud.google.com/storage/docs/gsutil_install
需要准備35G磁盤空間。我電腦磁盤空間不夠,用了外掛移動硬盤。
gsutil工具安裝完畢之后,就可以下載數據了。
mkdir ckpt
gsutil cp -r gs://pegasus_ckpt/ ckpt/
下載完畢之后,將預訓練的模型文件上傳到服務器對應的目錄。 下載速度依網速而定,我用了大概兩天時間吧。
最終的數據為:
訓練完畢之后,pegasus/ckpt/pegasus_ckpt/aeslc
目錄:
數據集
下面的訓練和評估,均使用aeslc數據集。
AESLC (Zhang & Tetreault, 2019) consists of 18k email bodies and their subjects from the Enron corpus (Klimt & Yang, 2004), a collection of email messages of employees in the Enron Corporation.
訓練
python3 pegasus/bin/train.py --params=aeslc_transformer \
--param_overrides=vocab_filename=ckpt/pegasus_ckpt/c4.unigram.newline.10pct.96000.model \
--train_init_checkpoint=ckpt/pegasus_ckpt/model.ckpt-1500000 \
--model_dir=ckpt/pegasus_ckpt/aeslc
以上代碼我在運行的時候有報錯,依賴模塊未找到。我把train.py 文件拷貝到倉庫根目錄,然后再運行,結果顯示可以。
評估
訓練完畢之后,就可以評估模型了。
python3 pegasus/bin/evaluate.py --params=aeslc_transformer \
--param_overrides=vocab_filename=ckpt/pegasus_ckpt/c4.unigram.newline.10pct.96000.model,batch_size=1,beam_size=5,beam_alpha=0.6 \
--model_dir=ckpt/pegasus_ckpt/aeslc
同上,evaluate.py文件也拷貝到倉庫的根目錄。
評估結果:
可見,和谷歌公布的結果基本一致。
37.69/21.85/36.84
使用自己的數據
支持2種格式的數據集:TensorFlow Datasets (TFDS) 、 TFRecords.
評測指標
ROUGE is the main metric for summarization quality.
BLEU is an alternative quality metric for language generation.
Extractive Fragments Coverage & Density are metrics that measures the abstractiveness of the summary.
Repetition Rates measures generation repetition failure modes.
Length statistics measures the length distribution of decodes comparing to gold summary.
摘要結果示例:
數據集
7個領域,共12個數據集。
7個領域分別為:新聞、科學、短篇小說、說明、電子郵件、專利、立法法案
1. news (Hermann et al., 2015; Narayan et al., 2018; Grusky et al., 2018; Rush et al., 2015; Fabbri et al., 2019), 【新聞,5個數據集】
2. science (Cohan et al., 2018), 【科學,2個數據集】
3. short stories (Kim et al., 2019), 【短故事/短篇小說,1個數據集】
4. instructions (Koupaee & Wang, 2018), 【網頁/說明,1個數據集】
5. emails (Zhang & Tetreault, 2019), 【郵件,1個數據集】
6. patents (Sharma et al., 2019), 【專利,1個數據集】
7. legislative bills (Kornilova & Eidelman, 2019). 【立法法案,1個數據集】
【科學】數據集
arXiv, PubMed (Cohan et al., 2018) are two long document datasets of scientific publications from arXiv.org (113k) and PubMed (215k). The task is to generate the abstract from the paper body.
【網頁/說明】數據集
WikiHow (Koupaee &Wang, 2018) is a large-scale dataset of instructions from the online WikiHow.com website. Each of 200k examples consists of multiple instruction-step para- graphs along with a summarizing sentence. The task is to generate the concatenated summary-sentences from the paragraphs.
Koupaee, M. and Wang, W. Y. Wikihow: A large scale text summarization dataset. arXiv preprint arXiv:1810.09305, 2018.
【新聞】數據集
NEWSROOM摘要是一句話