Advertisement

利用pytorch-transformers进行实体识别

阅读量:

作为自然语言处理领域中的基础性任务,命名实体识别在信息抽取、关系抽取以及知识图谱构建等多个应用场景中均发挥着关键作用。

复制代码
    # -*- coding: utf-8 -*-
    import torch
    import torch.nn as nn
    from transformers import BertModel, BertConfig
    from torchcrf import CRF
    import os
    class Bert_BiLSTM_CRF(nn.Module): # BiLSTM加上并无多大用处,速度还慢了,可去掉LSTM层
    def __init__(self, tag_to_ix, embedding_dim=768, hidden_dim=256):
        super(Bert_BiLSTM_CRF, self).__init__()
        self.tag_to_ix = tag_to_ix
        self.tagset_size = len(tag_to_ix)
        self.hidden_dim = hidden_dim
        self.embedding_dim = embedding_dim
    
        self.bert = 

全部评论 (0)

还没有任何评论哟~