From 1925731a45e66d7ab253aed04f01117491b213dc Mon Sep 17 00:00:00 2001 From: 0YuanZhang0 <953963890@qq.com> Date: Wed, 16 Oct 2019 18:42:02 +0800 Subject: [PATCH] fix_dnet_bug (#3623) (#3625) --- .../multi_task_learning/README.md | 7 ++- .../multi_task_learning/scripts/args.py | 48 +++++++++++++++++++ .../scripts/convert_model_params.py | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 PaddleNLP/Research/MRQA2019-D-NET/multi_task_learning/scripts/args.py 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 efb254e0..948820a6 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 00000000..b9be634f --- /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 fb99bb01..b1c0652c 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 -- GitLab