dgu_net.py 1.8 KB
Newer Older
0
0YuanZhang0 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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.
"""Create model for dialogue task."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import paddle.fluid as fluid

from dgu.bert import BertModel
from dgu.utils.configure import JsonConfig


def create_net(
        is_training,
        model_input,
        num_labels,
        paradigm_inst,
        args): 
    """create dialogue task model"""
    
    src_ids = model_input.src_ids
    pos_ids = model_input.pos_ids
    sent_ids = model_input.sent_ids
    input_mask = model_input.input_mask
    labels = model_input.labels

    assert isinstance(args.bert_config_path, str)

    bert_conf = JsonConfig(args.bert_config_path)
    bert = BertModel(
        src_ids=src_ids,
        position_ids=pos_ids,
        sentence_ids=sent_ids,
        input_mask=input_mask,
        config=bert_conf,
0
0YuanZhang0 已提交
49
        use_fp16=False)
0
0YuanZhang0 已提交
50 51 52 53 54 55 56 57 58 59 60 61

    params = {'num_labels': num_labels,
              'src_ids': src_ids,
              'pos_ids': pos_ids,
              'sent_ids': sent_ids,
              'input_mask': input_mask,
              'labels': labels,
              'is_training': is_training}

    results = paradigm_inst.paradigm(bert, params)
    return results