【最新试验】使用BertForTokenClassification做命名实体识别序列标注pytorch版

本文介绍了如何利用BertForTokenClassification在PyTorch中进行命名实体识别(NER)。通过加载tokenizer和预训练的BERT模型,处理输入id和标签,然后通过dropout和classifier层进行模型构建。在forward方法中,BERT获取序列特征,classifier将其转换为对应标签数的输出,使用交叉熵计算损失。下篇将详细讲解数据构造方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

阅读这篇文章你需要知道什么是bert?

bert几乎时最新最强的预训练模型之一。使用方法很简单,只需要一块gpu,大概8g显存,再取github上找到pytorch transformer这个repo,最后运行里面的run glue.py恭喜你!成功打开新世界大门

 

但是,如何用bert做ner呢?我们现在的run glue只能解决句子分类,而ner相当于词级分类,所以只能自己想怎么搭建模型了。

 

幸好,现在出了新的class,BertForTokenClassicification,这个时用来做ner的模型。如何使用呢?

 

class BertForTokenClassification(BertPreTrainedModel):
    r"""
        **labels**: (`optional`) ``torch.LongTensor`` of shape ``(batch_size, sequence_length)``:
            Labels for computing the token classification loss.
            Indices should be in ``[0, ..., config.num_labels - 1]``.

    Outputs: `Tuple` comprising various elements depending on the configuration (config) and inputs:
        **loss**: (`optional`, returned when 	
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值