Views
No views yet
(query, candidate) pairs with tunable hyperparameters
alpha and beta. This is supported in our code as well with the --wsc-alpha and
--wsc-beta arguments. However, we achieved slightly better (and more robust)
results on the development set by instead using a single cross entropy loss term
over the log-probabilities for the query and all mined candidates. The
candidates are mined using spaCy from each input sentence in isolation, so the
approach remains strictly pointwise. This reduces the number of
hyperparameters and our best model achieved 92.3% development set accuracy,
compared to ~90% accuracy for the margin loss. Later versions of the RoBERTa
arXiv paper will describe this updated formulation.1wget https://dl.fbaipublicfiles.com/glue/superglue/data/v2/WSC.zip
2unzip WSC.zip
3
4# we also need to copy the RoBERTa dictionary into the same directory
5wget -O WSC/dict.txt https://dl.fbaipublicfiles.com/fairseq/gpt2_bpe/dict.txt1TOTAL_NUM_UPDATES=2000 # Total number of training steps.
2WARMUP_UPDATES=250 # Linearly increase LR over this many steps.
3LR=2e-05 # Peak LR for polynomial LR scheduler.
4MAX_SENTENCES=16 # Batch size per GPU.
5SEED=1 # Random seed.
6ROBERTA_PATH=/path/to/roberta/model.pt
7
8# we use the --user-dir option to load the task and criterion
9# from the examples/roberta/wsc directory:
10FAIRSEQ_PATH=/path/to/fairseq
11FAIRSEQ_USER_DIR=${FAIRSEQ_PATH}/examples/roberta/wsc
12
13CUDA_VISIBLE_DEVICES=0,1,2,3 fairseq-train WSC/ \
14 --restore-file $ROBERTA_PATH \
15 --reset-optimizer --reset-dataloader --reset-meters \
16 --no-epoch-checkpoints --no-last-checkpoints --no-save-optimizer-state \
17 --best-checkpoint-metric accuracy --maximize-best-checkpoint-metric \
18 --valid-subset val \
19 --fp16 --ddp-backend no_c10d \
20 --user-dir $FAIRSEQ_USER_DIR \
21 --task wsc --criterion wsc --wsc-cross-entropy \
22 --arch roberta_large --bpe gpt2 --max-positions 512 \
23 --dropout 0.1 --attention-dropout 0.1 --weight-decay 0.01 \
24 --optimizer adam --adam-betas '(0.9, 0.98)' --adam-eps 1e-06 \
25 --lr-scheduler polynomial_decay --lr $LR \
26 --warmup-updates $WARMUP_UPDATES --total-num-update $TOTAL_NUM_UPDATES \
27 --max-sentences $MAX_SENTENCES \
28 --max-update $TOTAL_NUM_UPDATES \
29 --log-format simple --log-interval 100 \
30 --seed $SEED--update-freq=4.1from fairseq.models.roberta import RobertaModel
2from examples.roberta.wsc import wsc_utils # also loads WSC task and criterion
3roberta = RobertaModel.from_pretrained('checkpoints', 'checkpoint_best.pt', 'WSC/')
4roberta.cuda()
5nsamples, ncorrect = 0, 0
6for sentence, label in wsc_utils.jsonl_iterator('WSC/val.jsonl', eval=True):
7 pred = roberta.disambiguate_pronoun(sentence)
8 nsamples += 1
9 if pred == label:
10 ncorrect += 1
11print('Accuracy: ' + str(ncorrect / float(nsamples)))
12# Accuracy: 0.9230769230769231winogrande task and criterion for finetuning on the
WinoGrande like datasets
where there are always two candidates and one is correct.
It's more efficient implementation for such subcases.1TOTAL_NUM_UPDATES=23750 # Total number of training steps.
2WARMUP_UPDATES=2375 # Linearly increase LR over this many steps.
3LR=1e-05 # Peak LR for polynomial LR scheduler.
4MAX_SENTENCES=32 # Batch size per GPU.
5SEED=1 # Random seed.
6ROBERTA_PATH=/path/to/roberta/model.pt
7
8# we use the --user-dir option to load the task and criterion
9# from the examples/roberta/wsc directory:
10FAIRSEQ_PATH=/path/to/fairseq
11FAIRSEQ_USER_DIR=${FAIRSEQ_PATH}/examples/roberta/wsc
12
13cd fairseq
14CUDA_VISIBLE_DEVICES=0 fairseq-train winogrande_1.0/ \
15 --restore-file $ROBERTA_PATH \
16 --reset-optimizer --reset-dataloader --reset-meters \
17 --no-epoch-checkpoints --no-last-checkpoints --no-save-optimizer-state \
18 --best-checkpoint-metric accuracy --maximize-best-checkpoint-metric \
19 --valid-subset val \
20 --fp16 --ddp-backend no_c10d \
21 --user-dir $FAIRSEQ_USER_DIR \
22 --task winogrande --criterion winogrande \
23 --wsc-margin-alpha 5.0 --wsc-margin-beta 0.4 \
24 --arch roberta_large --bpe gpt2 --max-positions 512 \
25 --dropout 0.1 --attention-dropout 0.1 --weight-decay 0.01 \
26 --optimizer adam --adam-betas '(0.9, 0.98)' --adam-eps 1e-06 \
27 --lr-scheduler polynomial_decay --lr $LR \
28 --warmup-updates $WARMUP_UPDATES --total-num-update $TOTAL_NUM_UPDATES \
29 --max-sentences $MAX_SENTENCES \
30 --max-update $TOTAL_NUM_UPDATES \
31 --log-format simple --log-interval 100