diff --git a/demo/multi-label-classification/multi_label_classifier.py b/demo/multi-label-classification/multi_label_classifier.py index 57e47c6dc18f9ef15f841083aa788c89beaaafda..34c535dced97a55f9fbce77c61a6461c5f30a133 100644 --- a/demo/multi-label-classification/multi_label_classifier.py +++ b/demo/multi-label-classification/multi_label_classifier.py @@ -30,36 +30,21 @@ parser.add_argument("--warmup_proportion", type=float, default=0.1, help="Warmup parser.add_argument("--checkpoint_dir", type=str, default=None, help="Directory to model checkpoint") parser.add_argument("--max_seq_len", type=int, default=128, help="Number of words of the longest seqence.") parser.add_argument("--batch_size", type=int, default=1, help="Total examples' number in batch for training.") -parser.add_argument("--use_taskid", type=ast.literal_eval, default=False, help="Whether to user ernie v2 , if not to use bert.") args = parser.parse_args() # yapf: enable. if __name__ == '__main__': # Load Paddlehub BERT pretrained model - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") + module = hub.Module(name="ernie_v2_eng_base") - inputs, outputs, program = module.context( - trainable=True, max_seq_len=args.max_seq_len) + inputs, outputs, program = module.context( + trainable=True, max_seq_len=args.max_seq_len) - # Setup feed list for data feeder - feed_list = [ - inputs["input_ids"].name, inputs["position_ids"].name, - inputs["segment_ids"].name, inputs["input_mask"].name - ] - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") - - inputs, outputs, program = module.context( - trainable=True, max_seq_len=args.max_seq_len) - - # Setup feed list for data feeder - feed_list = [ - inputs["input_ids"].name, - inputs["position_ids"].name, - inputs["segment_ids"].name, - inputs["input_mask"].name, - ] + # Setup feed list for data feeder + feed_list = [ + inputs["input_ids"].name, inputs["position_ids"].name, + inputs["segment_ids"].name, inputs["input_mask"].name + ] # Download dataset and use MultiLabelReader to read dataset dataset = hub.dataset.Toxic() diff --git a/demo/multi-label-classification/predict.py b/demo/multi-label-classification/predict.py index 2afcbd319271ab0712f79e2fe2386c963a2a71d0..c5052b96897d1b83d072bcc38925836535cdf919 100644 --- a/demo/multi-label-classification/predict.py +++ b/demo/multi-label-classification/predict.py @@ -36,38 +36,23 @@ parser.add_argument("--checkpoint_dir", type=str, default=None, help="Directory parser.add_argument("--batch_size", type=int, default=1, help="Total examples' number in batch for training.") parser.add_argument("--max_seq_len", type=int, default=128, help="Number of words of the longest seqence.") parser.add_argument("--use_gpu", type=ast.literal_eval, default=True, help="Whether use GPU for finetuning, input should be True or False") -parser.add_argument("--use_taskid", type=ast.literal_eval, default=False, help="Whether to user ernie v2 , if not to use bert.") args = parser.parse_args() # yapf: enable. if __name__ == '__main__': # Load Paddlehub BERT pretrained model - if args.use_taskid: - module = hub.Module(name="ernie_eng_base.hub_module") + module = hub.Module(name="ernie_eng_base.hub_module") - inputs, outputs, program = module.context( - trainable=True, max_seq_len=args.max_seq_len) + inputs, outputs, program = module.context( + trainable=True, max_seq_len=args.max_seq_len) - # Setup feed list for data feeder - feed_list = [ - inputs["input_ids"].name, - inputs["position_ids"].name, - inputs["segment_ids"].name, - inputs["input_mask"].name, - ] - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") - - inputs, outputs, program = module.context( - trainable=True, max_seq_len=args.max_seq_len) - - # Setup feed list for data feeder - feed_list = [ - inputs["input_ids"].name, - inputs["position_ids"].name, - inputs["segment_ids"].name, - inputs["input_mask"].name, - ] + # Setup feed list for data feeder + feed_list = [ + inputs["input_ids"].name, + inputs["position_ids"].name, + inputs["segment_ids"].name, + inputs["input_mask"].name, + ] # Download dataset and use MultiLabelReader to read dataset dataset = hub.dataset.Toxic() diff --git a/demo/multi-label-classification/run_classifier.sh b/demo/multi-label-classification/run_classifier.sh index f08026a4fe2a489613e03eafc9320e5ccd9a6e4a..93b888334c78cd4d13ab41d9daf7ec5cbd9aab52 100644 --- a/demo/multi-label-classification/run_classifier.sh +++ b/demo/multi-label-classification/run_classifier.sh @@ -16,5 +16,4 @@ python -u multi_label_classifier.py \ --learning_rate=5e-5 \ --weight_decay=0.01 \ --max_seq_len=128 \ - --num_epoch=3 \ - --use_taskid=False + --num_epoch=3 diff --git a/demo/multi-label-classification/run_predict.sh b/demo/multi-label-classification/run_predict.sh index f0976fe11f4f78fa695e9db7c52bec27d63aed3c..ea28d8d984eb8b3bbe35de5976b73e17a75b2ccc 100644 --- a/demo/multi-label-classification/run_predict.sh +++ b/demo/multi-label-classification/run_predict.sh @@ -2,4 +2,4 @@ export FLAGS_eager_delete_tensor_gb=0.0 export CUDA_VISIBLE_DEVICES=0 CKPT_DIR="./ckpt_toxic" -python -u predict.py --checkpoint_dir $CKPT_DIR --max_seq_len 128 --use_gpu True --use_taskid False +python -u predict.py --checkpoint_dir $CKPT_DIR --max_seq_len 128 --use_gpu True diff --git a/demo/regression/regression.py b/demo/regression/regression.py index ddba625955f4151154f7376bda865974d0a314f1..d49dd1a9fb4b1b7a57faaf8305ebd36e55c19812 100644 --- a/demo/regression/regression.py +++ b/demo/regression/regression.py @@ -34,7 +34,6 @@ parser.add_argument("--max_seq_len", type=int, default=512, help="Number of word parser.add_argument("--batch_size", type=int, default=32, help="Total examples' number in batch for training.") parser.add_argument("--use_pyreader", type=ast.literal_eval, default=False, help="Whether use pyreader to feed data.") parser.add_argument("--use_data_parallel", type=ast.literal_eval, default=False, help="Whether use data parallel.") -parser.add_argument("--use_taskid", type=ast.literal_eval, default=False, help="Whether to use taskid ,if yes to use ernie v2.") args = parser.parse_args() # yapf: enable. @@ -43,10 +42,7 @@ if __name__ == '__main__': # Download dataset and use ClassifyReader to read dataset if args.dataset.lower() == "sts-b": dataset = hub.dataset.GLUE("STS-B") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") else: raise ValueError("%s dataset is not defined" % args.dataset) diff --git a/demo/regression/run_regssion.sh b/demo/regression/run_regssion.sh index 2896e0d4136d9b0f2d5362282b4a4cb8b917ef9c..29de8309802c432b87299a73f992c5e1fc8f4168 100644 --- a/demo/regression/run_regssion.sh +++ b/demo/regression/run_regssion.sh @@ -16,5 +16,4 @@ python -u regression.py \ --max_seq_len=128 \ --num_epoch=3 \ --use_pyreader=True \ - --use_data_parallel=True \ - --use_taskid=False \ + --use_data_parallel=True diff --git a/demo/sequence-labeling/sequence_label.py b/demo/sequence-labeling/sequence_label.py index 94dc27a2cf2570270b2196a5b91a371b37230ab5..00b2fe8a5abf6abbeaad8336b773b30daa2a44ab 100644 --- a/demo/sequence-labeling/sequence_label.py +++ b/demo/sequence-labeling/sequence_label.py @@ -40,10 +40,6 @@ if __name__ == '__main__': module = hub.Module(name="ernie_tiny") inputs, outputs, program = module.context( trainable=True, max_seq_len=args.max_seq_len) - if module.name.startswith("ernie_v2"): - use_taskid = True - else: - use_taskid = False # Download dataset and use SequenceLabelReader to read dataset dataset = hub.dataset.MSRA_NER() diff --git a/demo/text-classification/predict.py b/demo/text-classification/predict.py index 10f14be46aeeb23b991ea5118e6bcd299c75ce35..5829fd64b90a8a6f2d33d3197816707bfdb57fcf 100644 --- a/demo/text-classification/predict.py +++ b/demo/text-classification/predict.py @@ -36,7 +36,6 @@ parser.add_argument("--use_gpu", type=ast.literal_eval, default=False, help="Whe parser.add_argument("--use_pyreader", type=ast.literal_eval, default=False, help="Whether use pyreader to feed data.") parser.add_argument("--dataset", type=str, default="chnsenticorp", help="The choice of dataset") parser.add_argument("--use_data_parallel", type=ast.literal_eval, default=False, help="Whether use data parallel.") -parser.add_argument("--use_taskid", type=ast.literal_eval, default=False, help="Whether to use taskid ,if yes to use ernie v2.") args = parser.parse_args() # yapf: enable. @@ -58,60 +57,36 @@ if __name__ == '__main__': metrics_choices = ["acc"] elif args.dataset.lower() == "mrpc": dataset = hub.dataset.GLUE("MRPC") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["f1", "acc"] # The first metric will be choose to eval. Ref: task.py:799 elif args.dataset.lower() == "qqp": dataset = hub.dataset.GLUE("QQP") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["f1", "acc"] elif args.dataset.lower() == "sst-2": dataset = hub.dataset.GLUE("SST-2") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["acc"] elif args.dataset.lower() == "cola": dataset = hub.dataset.GLUE("CoLA") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["matthews", "acc"] elif args.dataset.lower() == "qnli": dataset = hub.dataset.GLUE("QNLI") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["acc"] elif args.dataset.lower() == "rte": dataset = hub.dataset.GLUE("RTE") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["acc"] elif args.dataset.lower() == "mnli" or args.dataset.lower() == "mnli_m": dataset = hub.dataset.GLUE("MNLI_m") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["acc"] elif args.dataset.lower() == "mnli_mm": dataset = hub.dataset.GLUE("MNLI_mm") - if args.use_taskid: - module = hub.Module(name="ernie_v2_eng_base") - else: - module = hub.Module(name="bert_uncased_L-12_H-768_A-12") + module = hub.Module(name="ernie_v2_eng_base") metrics_choices = ["acc"] elif args.dataset.lower().startswith("xnli"): dataset = hub.dataset.XNLI(language=args.dataset.lower()[-2:]) diff --git a/demo/text-classification/run_predict.sh b/demo/text-classification/run_predict.sh index 9c17b4e1151419863988e5bbcf0e2cfb695d269f..281b85874c9c6fce448f8be3d44ec0f8c229d7fb 100644 --- a/demo/text-classification/run_predict.sh +++ b/demo/text-classification/run_predict.sh @@ -18,4 +18,3 @@ python -u predict.py --checkpoint_dir=$CKPT_DIR \ --use_gpu=True \ --dataset=${DATASET} \ --batch_size=150 \ - --use_taskid=False \