Skip to content

使用 ernie + crf 进行序列标注任务时,无法使用paddle.jit.save 保存,可能是paddlenlp中的自带的crf代码写法不支持动静转换,请问crf代码这块后续会调整吗,还是直接推荐使用静态版里面的crf #424

Answered by joey12300
Wakp asked this question in Q&A
Discussion options

You must be logged in to vote

@Wakp 我刚使用您的代码写了一版,可作参考

import paddle
import paddle.nn as nn
from paddlenlp.transformers import BertModel, BertTokenizer, ErnieModel, ErnieTokenizer
from paddlenlp.layers import crf
from paddle.static import InputSpec
import numpy as np

class MutilErnieCrf(nn.Layer):
    def __init__(self, out_num=3, model_name_or_path='bert-wwm-chinese', dropout=None):
        super(MutilErnieCrf, self).__init__()
        self.ernie = BertModel.from_pretrained(model_name_or_path)
        self.linear_to_label = nn.Linear(768, out_num)
        self.crf = crf.LinearChainCrf(out_num, crf_lr=0.1, with_start_stop_tag=False)
        self.crf_loss = crf.LinearChainCrfLoss(self.crf)
        self.viterbi = crf.Vi…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ZeyuChen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #419 on May 20, 2021 14:58.