diff --git a/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/README.md b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/README.md index efb254e08423ab48e685a021c73c0af7571495fa..948820a6480b1f81429a29cb7a1ccd85885f4814 100644 --- a/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/README.md +++ b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/README.md @@ -43,8 +43,13 @@ The downloaded data will be saved into `data/mrqa` (combined MRQA training and d In our MTL experiments, we use BERT as our shared encoder. The parameters are initialized from the Whole Word Masking BERT (BERTwwm), further fine-tuned on the SQuAD 2.0 task with synthetic generated question answering corpora. The model parameters in Tensorflow format can be downloaded [here](https://worksheets.codalab.org/worksheets/0x3852e60a51d2444680606556d404c657). The following command can be used to convert the parameters to the format that is readable for PaddlePaddle. ``` -cd scripts && python convert_model_params.py --init_tf_checkpoint tf_model --fluid_params_dir paddle_model && cd .. +1、cd scripts +2、download cased_model_01.tar.gz from link +3、mkdir cased_model_01 && mv cased_model_01.tar.gz cased_model_01 && cd cased_model_01 && tar -xvf cased_model_01.tar.gz && cd .. +4、python convert_model_params.py --init_tf_checkpoint cased_model_01/model.ckpt --fluid_params_dir params +5、mkdir fluid_models && mv cased_model_01/vocab.txt cased_model_01/bert_config.json params fluid_models ``` + Alternatively, user can directly **download the parameters that we have converted**: ``` diff --git a/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/args.py b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/args.py new file mode 100644 index 0000000000000000000000000000000000000000..b9be634f0f383db61eb667df2345a89262179fd8 --- /dev/null +++ b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/args.py @@ -0,0 +1,48 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Arguments for configuration.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import six +import argparse + + +def str2bool(v): + # because argparse does not support to parse "true, False" as python + # boolean directly + return v.lower() in ("true", "t", "1") + + +class ArgumentGroup(object): + def __init__(self, parser, title, des): + self._group = parser.add_argument_group(title=title, description=des) + + def add_arg(self, name, type, default, help, **kwargs): + type = str2bool if type == bool else type + self._group.add_argument( + "--" + name, + default=default, + type=type, + help=help + ' Default: %(default)s.', + **kwargs) + + +def print_arguments(args): + print('----------- Configuration Arguments -----------') + for arg, value in sorted(six.iteritems(vars(args))): + print('%s: %s' % (arg, value)) + print('------------------------------------------------') diff --git a/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/convert_model_params.py b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/convert_model_params.py index fb99bb01926e3786610bd0ba5d3165b6df572f28..b1c0652c9991467e59ef1e6414b05c8d6ccdb107 100644 --- a/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/convert_model_params.py +++ b/PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/convert_model_params.py @@ -20,7 +20,7 @@ from __future__ import print_function import numpy as np import argparse import collections -from utils.args import print_arguments +from args import print_arguments import tensorflow as tf import paddle.fluid as fluid from tensorflow.python import pywrap_tensorflow