Views
No views yet
conda create -n memsum python=3.10source activate memsumpip install torch torchvision torchaudiopip install -r requirements.txt1import os
2import subprocess
3import wget
4
5for dataset_name in [ "arxiv", "pubmed", "gov-report"]:
6 print(dataset_name)
7 os.makedirs( "data/"+dataset_name, exist_ok=True )
8
9 ## dataset is stored at huggingface hub
10 train_dataset_path = f"https://huggingface.co/datasets/nianlong/long-doc-extractive-summarization-{dataset_name}/resolve/main/train.jsonl"
11 val_dataset_path = f"https://huggingface.co/datasets/nianlong/long-doc-extractive-summarization-{dataset_name}/resolve/main/val.jsonl"
12 test_dataset_path = f"https://huggingface.co/datasets/nianlong/long-doc-extractive-summarization-{dataset_name}/resolve/main/test.jsonl"
13
14 wget.download( train_dataset_path, out = "data/"+dataset_name )
15 wget.download( val_dataset_path, out = "data/"+dataset_name )
16 wget.download( test_dataset_path, out = "data/"+dataset_name )1from huggingface_hub import snapshot_download
2## download the pretrained glove word embedding (200 dimension)
3snapshot_download('nianlong/memsum-word-embedding', local_dir = "model/word_embedding" )
4
5## download model checkpoint on the arXiv dataset
6snapshot_download('nianlong/memsum-arxiv-summarization', local_dir = "model/memsum-arxiv" )
7
8## download model checkpoint on the PubMed dataset
9snapshot_download('nianlong/memsum-pubmed-summarization', local_dir = "model/memsum-pubmed" )
10
11## download model checkpoint on the Gov-Report dataset
12snapshot_download('nianlong/memsum-gov-report-summarization', local_dir = "model/memsum-gov-report" )1from src.summarizer import MemSum
2from tqdm import tqdm
3from rouge_score import rouge_scorer
4import json
5import numpy as np1rouge_cal = rouge_scorer.RougeScorer(['rouge1','rouge2', 'rougeLsum'], use_stemmer=True)
2
3memsum_arxiv = MemSum( "model/memsum-arxiv/model.pt",
4 "model/word_embedding/vocabulary_200dim.pkl",
5 gpu = 0 , max_doc_len = 500 )
6
7memsum_pubmed = MemSum( "model/memsum-pubmed/model.pt",
8 "model/word_embedding/vocabulary_200dim.pkl",
9 gpu = 0 , max_doc_len = 500 )
10
11memsum_gov_report = MemSum( "model/memsum-gov-report/model.pt",
12 "model/word_embedding/vocabulary_200dim.pkl",
13 gpu = 0 , max_doc_len = 500 )1test_corpus_arxiv = [ json.loads(line) for line in open("data/arxiv/test.jsonl") ]
2test_corpus_pubmed = [ json.loads(line) for line in open("data/pubmed/test.jsonl") ]
3test_corpus_gov_report = [ json.loads(line) for line in open("data/gov-report/test.jsonl") ]1def evaluate( model, corpus, p_stop, max_extracted_sentences, rouge_cal ):
2 scores = []
3 for data in tqdm(corpus):
4 gold_summary = data["summary"]
5 extracted_summary = model.extract( [data["text"]], p_stop_thres = p_stop, max_extracted_sentences_per_document = max_extracted_sentences )[0]
6
7 score = rouge_cal.score( "\n".join( gold_summary ), "\n".join(extracted_summary) )
8 scores.append( [score["rouge1"].fmeasure, score["rouge2"].fmeasure, score["rougeLsum"].fmeasure ] )
9
10 return np.asarray(scores).mean(axis = 0)evaluate( memsum_arxiv, test_corpus_arxiv, 0.5, 5, rouge_cal )100%|█████████████████████████████████████████████████████████████| 6440/6440 [08:00<00:00, 13.41it/s]
array([0.47946925, 0.19970128, 0.42075852])evaluate( memsum_pubmed, test_corpus_pubmed, 0.6, 7, rouge_cal )100%|█████████████████████████████████████████████████████████████| 6658/6658 [09:22<00:00, 11.84it/s]
array([0.49260137, 0.22916328, 0.44415123])evaluate( memsum_gov_report, test_corpus_gov_report, 0.6, 22, rouge_cal )100%|███████████████████████████████████████████████████████████████| 973/973 [04:33<00:00, 3.55it/s]
array([0.59445629, 0.28507926, 0.56677073])document = test_corpus_pubmed[0]["text"]1extracted_summary = memsum_pubmed.extract( [ document ],
2 p_stop_thres = 0.6,
3 max_extracted_sentences_per_document = 7
4 )[0]
5extracted_summary['more specifically , we found that pd patients with anxiety were more impaired on the trail making test part b which assessed attentional set - shifting , on both digit span tests which assessed working memory and attention , and to a lesser extent on the logical memory test which assessed memory and new verbal learning compared to pd patients without anxiety . taken together ,',
'this study is the first to directly compare cognition between pd patients with and without anxiety .',
'results from this study showed selective verbal memory deficits in rpd patients with anxiety compared to rpd without anxiety , whereas lpd patients with anxiety had greater attentional / working memory deficits compared to lpd without anxiety .',
'given that research on healthy young adults suggests that anxiety reduces processing capacity and impairs processing efficiency , especially in the central executive and attentional systems of working memory [ 26 , 27 ] , we hypothesized that pd patients with anxiety would show impairments in attentional set - shifting and working memory compared to pd patients without anxiety .',
'the findings confirmed our hypothesis that anxiety negatively influences attentional set - shifting and working memory in pd .',
'seventeen pd patients with anxiety and thirty - three pd patients without anxiety were included in this study ( see table 1 ) .']1extracted_summary_batch, extracted_indices_batch = memsum_pubmed.extract( [ document ],
2 p_stop_thres = 0.6,
3 max_extracted_sentences_per_document = 7,
4 return_sentence_position=1
5 )extracted_summary_batch[0]['more specifically , we found that pd patients with anxiety were more impaired on the trail making test part b which assessed attentional set - shifting , on both digit span tests which assessed working memory and attention , and to a lesser extent on the logical memory test which assessed memory and new verbal learning compared to pd patients without anxiety . taken together ,',
'this study is the first to directly compare cognition between pd patients with and without anxiety .',
'results from this study showed selective verbal memory deficits in rpd patients with anxiety compared to rpd without anxiety , whereas lpd patients with anxiety had greater attentional / working memory deficits compared to lpd without anxiety .',
'given that research on healthy young adults suggests that anxiety reduces processing capacity and impairs processing efficiency , especially in the central executive and attentional systems of working memory [ 26 , 27 ] , we hypothesized that pd patients with anxiety would show impairments in attentional set - shifting and working memory compared to pd patients without anxiety .',
'the findings confirmed our hypothesis that anxiety negatively influences attentional set - shifting and working memory in pd .',
'seventeen pd patients with anxiety and thirty - three pd patients without anxiety were included in this study ( see table 1 ) .']extracted_indices_batch[0][50, 48, 70, 14, 49, 16]
1from data_preprocessing.utils import greedy_extract
2import json
3test_corpus_custom_data = [ json.loads(line) for line in open("data/custom_data/test.jsonl")]
4example_data = test_corpus_custom_data[0]example_data.keys()dict_keys(['text', 'summary'])greedy_extract( example_data["text"], example_data["summary"], beamsearch_size = 1 )[0][[50, 13, 41, 24, 31, 0, 3, 48], 0.4563635838327488]@inproceedings{gu-etal-2022-memsum,
title = "{M}em{S}um: Extractive Summarization of Long Documents Using Multi-Step Episodic {M}arkov Decision Processes",
author = "Gu, Nianlong and
Ash, Elliott and
Hahnloser, Richard",
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = may,
year = "2022",
address = "Dublin, Ireland",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.acl-long.450",
pages = "6507--6522",
abstract = "We introduce MemSum (Multi-step Episodic Markov decision process extractive SUMmarizer), a reinforcement-learning-based extractive summarizer enriched at each step with information on the current extraction history. When MemSum iteratively selects sentences into the summary, it considers a broad information set that would intuitively also be used by humans in this task: 1) the text content of the sentence, 2) the global text context of the rest of the document, and 3) the extraction history consisting of the set of sentences that have already been extracted. With a lightweight architecture, MemSum obtains state-of-the-art test-set performance (ROUGE) in summarizing long documents taken from PubMed, arXiv, and GovReport. Ablation studies demonstrate the importance of local, global, and history information. A human evaluation confirms the high quality and low redundancy of the generated summaries, stemming from MemSum{'}s awareness of extraction history.",
}