-
Notifications
You must be signed in to change notification settings - Fork 29.5k
[examples] SummarizationModule improvements #4951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
255 commits
Select commit
Hold shift + click to select a range
71850ad
copy decoder layers
sshleifer b01f1d5
Failing test
sshleifer 937d3d6
Merge branch 'master' into distilbart
sshleifer fcc49a0
can import
sshleifer 4f5790f
passing
sshleifer 4be1287
real data test passes
sshleifer 8afb88c
relatif importschlossen
sshleifer d2cc12b
boom boom
sshleifer 1edc50f
bash
sshleifer 174aaf3
Fast dev run
sshleifer 5a35811
boom boom
sshleifer 6302fb0
bs=8
sshleifer 5a3ed99
Cache tokenized
sshleifer 70cf536
Merge branch 'distilbart' of github.com:sshleifer/transformers_fork i…
sshleifer ca9c685
rouge
sshleifer 7081d0f
add rouge
sshleifer 0ed4156
boom boom
sshleifer 04a8ace
boom boom
sshleifer 696c8c2
boom boom
sshleifer 3cebd56
boom boom
sshleifer bf5782e
boom boom
sshleifer 74704ce
boom boom
sshleifer bbc4e52
assert student small
sshleifer c4530f9
batch
sshleifer 2ee9388
boom boom
sshleifer 51221fb
boom boom
sshleifer abb81df
boom boom
sshleifer bef77fc
boom boom
sshleifer 2b7132c
metrics saving, but no val_check_interval honored
sshleifer 2c72948
val check test passing with smaller batch size
sshleifer af315c1
boom boom
sshleifer 5fbf422
summaries for file
sshleifer 09cc1e6
save preds
sshleifer 5947812
add files
sshleifer 59c658d
fixes
sshleifer beda65d
bash
sshleifer c774160
imports
sshleifer c79351a
fix flatten
sshleifer 05bfb1e
Support fewer layers
sshleifer cd461e1
fix
sshleifer 67f9553
Run encoder once
sshleifer f281724
wandb
sshleifer 1fc653f
log_metrics
sshleifer b62bfe6
spelling
sshleifer a250d1c
boom boom
sshleifer 18524d8
boom boom
sshleifer a2671a6
boom boom
sshleifer fee71b4
npars
sshleifer a642076
boom boom
sshleifer cf47a6f
boom boom
sshleifer ce0de90
boom boom
sshleifer b39c39f
boom boom
sshleifer 7a7dcd3
l2copy[1] = 0
sshleifer 910da0f
boom boom
sshleifer 2c2a10e
orig tests pass
sshleifer 21a2cc0
delete run_distiller -> main
sshleifer 07da062
avoid losing bart grouped batch sampler work
sshleifer dd418e8
boom boom
sshleifer ac72c7a
convenience method
sshleifer 88b4b97
switch copy logic
sshleifer 3f73cb7
boom boom
sshleifer 15a2d4e
boom boom
sshleifer 3461e24
boom boom
sshleifer ca82946
boom boom
sshleifer f5606df
boom boom
sshleifer 5d75172
Freeze encoder fix
sshleifer aa995f9
freeze after init
sshleifer bcb9996
overcautious freezing
sshleifer 29499c9
boom boom
sshleifer 705ed2f
Better desc
sshleifer db3d85a
boom boom
sshleifer c6f7e14
progbar
sshleifer fa0eda4
boom boom
sshleifer 021d2b9
only train
sshleifer c779c38
boom boom
sshleifer d4830f9
rename
sshleifer a78603c
boom boom
sshleifer 1ca011f
test_mtl=140 default
sshleifer 8fbdd7d
boom boom
sshleifer ef45ee9
boom boom
sshleifer d328871
add RougeTracker
sshleifer 584c329
encoder different
sshleifer 20abeec
passing
sshleifer e48a829
boom boom
sshleifer 9f21462
boom boom
sshleifer 6f03e39
boom boom
sshleifer 2443a7e
boom boom
sshleifer 4d3617a
boom boom
sshleifer 6f1757d
boom boom
sshleifer af8b962
boom boom
sshleifer c7f6e62
boom boom
sshleifer c154fb3
style
sshleifer a42f09e
warmup_steps=500
sshleifer 88f9f91
Sortish Sampler
sshleifer 800dcdc
boom boom
sshleifer db52f37
save fewer checkpoints
sshleifer f5e697b
Dont require model_name_or_path
sshleifer 20a5968
passing with enc mse
sshleifer 12f2d9e
early quitting for encoder only loss
sshleifer 0933e11
boom boom
sshleifer 56aedac
boom boom
sshleifer 63521f1
boom boom
sshleifer 0c3d22e
boom boom
sshleifer 81e939f
boom boom
sshleifer c10bb9f
boom boom
sshleifer d3611c9
Run distiller: no data defaults
sshleifer d2cd7b4
Somehow passing with better freezing logic
sshleifer e7d9dc3
dont default teacher
sshleifer ee18f81
Merge branch 'distilbart' of github.com:sshleifer/transformers_fork i…
sshleifer 298ec53
--freeze_encoder
sshleifer f750d80
boom boom
sshleifer 9b54356
Logging adjustments
sshleifer 4f19747
boom boom
sshleifer d92a69f
boom boom
sshleifer 99e7161
boom boom
sshleifer 7f1af24
freeze decoder
sshleifer 44743e8
fix ckpt bug maybe
sshleifer 84ea9fa
Fixed tests
sshleifer 0c3d6d8
boom boom
sshleifer 516bbca
boom boom
sshleifer 175efd8
getstate
sshleifer 3c34cae
distrib hacks
sshleifer 3f6463a
attempt logger.name fix
sshleifer 324d4dc
No wandb if ddp
sshleifer eb4b3cc
boom boom
sshleifer d53236c
boom boom
sshleifer 7c52e73
boom boom
sshleifer 25edee1
boom boom
sshleifer 6689b59
boom boom
sshleifer 8fb24ce
boom boom
sshleifer bd361ea
rename generic_train -> build_trainer
sshleifer 105d83d
undo rename
sshleifer 7b9557f
boom boom
sshleifer 60a9014
rouge tracker fix
sshleifer 82a6b83
Merge branch 'master' into distilbart
sshleifer e17df74
merged master
sshleifer 789f06e
less annoying requirements
sshleifer fb6adb2
backup rouge dfs
sshleifer b11fc69
boom boom
sshleifer 8c6769e
boom boom
sshleifer df0b28a
boom boom
sshleifer 8f614af
broken
sshleifer a2ba031
boom boom
sshleifer 440744a
Distiller brewer does not break
sshleifer 20aedfb
boom boom
sshleifer 3e47e61
Disable cos loss
sshleifer a65ab52
boom boom
sshleifer cc83d34
boom boom
sshleifer 0b98750
boom boom
sshleifer 8d4f075
boom boom
sshleifer 24f483c
boom boom
sshleifer e3a00a4
boom boom
sshleifer 8b98c4c
boom boom
sshleifer 8f68b91
boom boom
sshleifer 055167b
boom boom
sshleifer e446fd2
boom boom
sshleifer 014c061
boom boom
sshleifer e146713
passing
sshleifer 9fc692d
boom boom
sshleifer 3abbf78
boom boom
sshleifer 47c226e
Merge branch 'distilbart' of github.com:sshleifer/transformers_fork i…
sshleifer bb1bffc
Save top1
sshleifer 09f199b
Merge branch 'distilbart' of github.com:sshleifer/transformers_fork i…
sshleifer 3b304af
boom boom
sshleifer c294e5e
boom boom
sshleifer 7ccd236
Evaluate_checkpoint
sshleifer b32d283
boom boom
sshleifer c59be9b
boom boom
sshleifer ecff6f9
V8 and generate_summaries fixes
sshleifer e46e101
boom boom
sshleifer bcb4624
boom boom
sshleifer 3467f1c
boom boom
sshleifer 582efc0
boom boom
sshleifer 9f6596e
boom boom
sshleifer 3c38444
boom boom
sshleifer 630af0c
boom boom
sshleifer 318a585
boom boom
sshleifer 31b4c8c
boom boom
sshleifer fa7f818
t5 failing
sshleifer 0dc32e6
boom boom
sshleifer a79f5fb
boom boom
sshleifer 0098872
Deleted SummarizationDistiller
sshleifer a387c05
boom boom
sshleifer 76377c9
boom boom
sshleifer 315ab6b
boom boom
sshleifer b5adf48
boom boom
sshleifer d3b8694
boom boom
sshleifer dc785f0
boom boom
sshleifer af05c0e
boom boom
sshleifer 913bb8f
boom boom
sshleifer d26f5da
stuck on t5 mask
sshleifer c553e12
t5 works
sshleifer 7f3f9fa
boom boom
sshleifer 6624b63
boom boom
sshleifer bad1b75
boom boom
sshleifer a549aaa
boom boom
sshleifer 574ffbb
boom boom
sshleifer b2b222d
boom boom
sshleifer a2f2d5d
undo some chg
sshleifer 6aa28bd
ignore student
sshleifer 585bb57
passing cpu
sshleifer 5a28144
fp16_ever=False
sshleifer e5728e4
boom boom
sshleifer 10b092e
boom boom
sshleifer ac47dbd
boom boom
sshleifer c7d05f7
boom boom
sshleifer 4224ac9
boom boom
sshleifer 3f3040a
boom boom
sshleifer 9d99761
passing
sshleifer bdf0b1a
boom boom
sshleifer fb6eb09
Failing but minimal
sshleifer af3f86f
remove some cruft
sshleifer c5a1de5
boom boom
sshleifer e67ad41
boom boom
sshleifer 0274338
original tests pass
sshleifer abee3e2
Merge branch 'master' into distilbart-clean
sshleifer de7035d
style
sshleifer e2d4544
style
sshleifer eab9779
better mask logic
sshleifer 350eeb7
style
sshleifer 3e62d96
add git-python requirement
sshleifer 379e8c7
Cleanup
sshleifer 35a82ee
boom boom
sshleifer 6bf996f
boom boom
sshleifer 5526be3
boom boom
sshleifer eb84b9d
boom boom
sshleifer 4606bda
Bash cleanup
sshleifer 9f98a6a
docs
sshleifer 969c271
more honest docs
sshleifer f179e7b
Allow wandb logger
sshleifer c34b886
Wandb logger
sshleifer c9597fe
docs
sshleifer 9e95429
docs
sshleifer 99de2c3
pass through logger
sshleifer 6bdfb14
boom boom
sshleifer 5283878
Move stuff to utils
sshleifer 8d867e9
on_save_checkpoint
sshleifer b7bb7cb
Fix decoder mask
sshleifer 9508199
Better logger name
sshleifer 68f6ccd
Fixed merge conflicts
sshleifer 1ffd6cb
style
sshleifer 0d592c5
fix import
sshleifer 7ff1d78
Merge branch 'master' into distilbart-clean
sshleifer 99a4866
Merge branch 'master' into distilbart-clean
sshleifer d25442a
rename -> SummarizationModule
sshleifer b56b4d8
more tips
sshleifer 2deff3b
Fix README
sshleifer f28fc63
cleanup
sshleifer 0ce2375
Cleanup more
sshleifer b7e1d5e
indent
sshleifer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,70 @@ | ||
### Get CNN Data | ||
To be able to reproduce the authors' results on the CNN/Daily Mail dataset you first need to download both CNN and Daily Mail datasets [from Kyunghyun Cho's website](https://cs.nyu.edu/~kcho/DMQA/) (the links next to "Stories") in the same folder. Then uncompress the archives by running: | ||
### Data | ||
|
||
CNN/DailyMail data | ||
```bash | ||
cd examples/summarization | ||
wget https://s3.amazonaws.com/datasets.huggingface.co/summarization/cnn_dm.tgz | ||
tar -xzvf cnn_dm.tgz | ||
export CNN_DIR=${PWD}/cnn_dm | ||
``` | ||
|
||
this should make a directory called cnn_dm/ with files like `test.source`. | ||
To use your own data, copy that files format. Each article to be summarized is on its own line. | ||
|
||
XSUM Data: | ||
```bash | ||
cd examples/summarization | ||
wget https://s3.amazonaws.com/datasets.huggingface.co/summarization/xsum.tar.gz | ||
tar -xzvf xsum.tar.gz | ||
export XSUM_DIR=${PWD}/xsum | ||
``` | ||
|
||
|
||
### Evaluation | ||
|
||
To create summaries for each article in dataset, run: | ||
```bash | ||
python evaluate_cnn.py <path_to_test.source> test_generations.txt <model-name> --score_path rouge_scores.txt | ||
python run_eval.py <path_to_test.source> test_generations.txt <model-name> --score_path rouge_scores.txt | ||
``` | ||
The default batch size, 8, fits in 16GB GPU memory, but may need to be adjusted to fit your system. | ||
The default batch size, 4, fits in 16GB GPU memory, but may need to be adjusted to fit your system. | ||
|
||
|
||
### Training | ||
Run/modify `finetune_bart.sh` or `finetune_t5.sh` | ||
Run/modify `finetune.sh` | ||
|
||
### Stanford CoreNLP Setup | ||
``` | ||
ptb_tokenize () { | ||
cat $1 | java edu.stanford.nlp.process.PTBTokenizer -ioFileList -preserveLines > $2 | ||
} | ||
|
||
sudo apt install openjdk-8-jre-headless | ||
sudo apt-get install ant | ||
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip | ||
unzip stanford-corenlp-full-2018-10-05.zip | ||
cd stanford-corenlp-full-2018-10-05 | ||
export CLASSPATH=stanford-corenlp-3.9.2.jar:stanford-corenlp-3.9.2-models.jar | ||
The following command should work on a 16GB GPU: | ||
```bash | ||
export me=`git config user.name` | ||
./finetune.sh \ | ||
--data_dir $XSUM_DIR \ | ||
--train_batch_size=1 \ | ||
--eval_batch_size=1 \ | ||
--output_dir="$me"_xsum_results \ | ||
--num_train_epochs 1 | ||
``` | ||
Then run `ptb_tokenize` on `test.target` and your generated hypotheses. | ||
### Rouge Setup | ||
Install `files2rouge` following the instructions at [here](https://github.com/pltrdy/files2rouge). | ||
I also needed to run `sudo apt-get install libxml-parser-perl` | ||
|
||
```python | ||
from files2rouge import files2rouge | ||
from files2rouge import settings | ||
files2rouge.run(<path_to_tokenized_hypo>, | ||
<path_to_tokenized_target>, | ||
saveto='rouge_output.txt') | ||
|
||
Tips: | ||
- 1 epoch at batch size 1 for bart-large takes 24 hours, requires 13GB GPU RAM with fp16 on an NVIDIA-V100. | ||
- try `bart-base`, `--freeze_encoder` or `--freeze_embeds` for faster training/larger batch size. (3hr/epoch with bs=8, see below) | ||
- `fp16_opt_level=O1` (the default works best). | ||
- If you are finetuning on your own dataset, start from `bart-large-cnn` if you want long summaries and `bart-large-xsum` if you want short summaries. | ||
(It rarely makes sense to start from `bart-large` unless you are a researching finetuning methods). | ||
- In addition to the pytorch-lightning .ckpt checkpoint, a transformers checkpoint will be saved. | ||
Load it with `BartForConditionalGeneration.from_pretrained(f'{output_dir}/best_tfmr)`. | ||
- At the moment, `--do_predict` does not work in a multi-gpu setting. You need to use `evaluate_checkpoint` or the `run_eval.py` code. | ||
- If you want to run experiments on improving the summarization finetuning process, try the XSUM Shared Task (below). It's faster to train than CNNDM because the summaries are shorter. | ||
|
||
### XSUM Shared Task | ||
Compare XSUM results with others by using `--logger wandb_shared`. This requires `wandb` registration. | ||
Here is an example command | ||
```bash | ||
export me=`git config user.name` | ||
./finetune.sh \ | ||
--data_dir $XSUM_DIR \ | ||
--output_dir "$me"_xsum_frozen_embs \ | ||
--logger wandb_shared \ | ||
--train_batch_size 16 --eval_batch_size 16 --freeze_embeds --freeze_encoder \ | ||
--num_train_epochs 6 | ||
``` | ||
|
||
Results can be viewed [here](https://app.wandb.ai/sshleifer/hf_summarization/table?workspace=user-) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.