Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • PaddleHub
  • Issue
  • #693

P
PaddleHub
  • 项目概览

PaddlePaddle / PaddleHub
大约 2 年 前同步成功

通知 285
Star 12117
Fork 2091
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 200
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 4
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
PaddleHub
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 200
    • Issue 200
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 4
    • 合并请求 4
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 6月 16, 2020 by saxon_zh@saxon_zhGuest

模型部署中模型预加载错误

Created by: Malestudents

模型代码

-- coding:utf-8 --

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.

"""Finetuning on classification task """ from future import absolute_import from future import division from future import print_function

import os

import numpy as np from paddlehub.common.logger import logger from paddlehub.module.module import moduleinfo, serving import paddlehub as hub

@moduleinfo( name="ERNIEFinetuned", version="1.0.0", summary="ERNIE tiny which was fine-tuned on the chnsenticorp dataset.", author="anonymous", author_email="", type="nlp/semantic_model") class ERNIEFinetuned(hub.Module): def _initialize(self, ckpt_dir="ckpt_ner", num_class=3, max_seq_len=128, use_gpu=False, batch_size=16): self.ckpt_dir = os.path.join(self.directory, ckpt_dir) self.num_class = num_class self.MAX_SEQ_LEN = max_seq_len

    self.params_path = os.path.join(self.ckpt_dir, 'best_model')

    # Load Paddlehub ERNIE Tiny pretrained model
    self.module = hub.Module(name='ernie')
    inputs, outputs, program = self.module.context(max_seq_len=128)

    # Download dataset and use accuracy as metrics
    # Choose dataset: GLUE/XNLI/ChinesesGLUE/NLPCC-DBQA/LCQMC
    # metric should be acc, f1 or matthews
    # For ernie_tiny, it use sub-word to tokenize chinese sentence
    # If not ernie tiny, sp_model_path and word_dict_path should be set None
    reader = hub.reader.SequenceLabelReader(
        vocab_path=self.module.get_vocab_path(),
        max_seq_len=128)

    # Construct transfer learning network
    # Use "pooled_output" for classification tasks on an entire sentence.
    # Use "sequence_output" for token-level output.
    sequence_output = outputs["sequence_output"]

    # Setup feed list for data feeder
    # Must feed all the tensor of module need
    feed_list = [
        inputs["input_ids"].name,
        inputs["position_ids"].name,
        inputs["segment_ids"].name,
        inputs["input_mask"].name,
    ]
    strategy = hub.AdamWeightDecayStrategy(
        weight_decay=0.01,
        warmup_proportion=0.1,
        learning_rate=5e-5)
    # Setup runing config for PaddleHub Finetune API
    config = hub.RunConfig(
        use_cuda=False,
        num_epoch=1,
        checkpoint_dir=self.ckpt_dir,
        batch_size=16,
        eval_interval=50,
        strategy=strategy)

    # Define a classfication finetune task by PaddleHub's API
    self.cls_task = hub.SequenceLabelTask(
        data_reader=reader,
        feature=sequence_output,
        feed_list=feed_list,
        add_crf=True,
        max_seq_len=128,
        num_classes=3,
        config=config)


def predict(self, data, return_result=False, accelerate_mode=True):
    """
    Get prediction results
    """
    run_states = self.cls_task.predict(
        data=data,
        return_result = return_result,
        accelerate_mode = accelerate_mode)
    print(run_states)
    return result1

if name == "main": ernie_tiny = ERNIEFinetuned( ckpt_dir="./ckpt_ner", num_class=3) # Data to be prdicted data=[] result = '梅小二主治医师查房记录' data.append(["\002".join(result)]) print(data) predictions = ernie_tiny.predict(data=data) print(predictions) 错误代码: 1592271505(1)

指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/PaddleHub#693
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7