赞
踩
实体识别是一个经典的序列标注任务,如果有一批已经标注的样本,就可以考虑使用模型来进行训练了,传统的方式是用CRF++进行训练随着深度学习技术的兴起,任务也基本围绕着基础的LSTM+CRF的基础上或者进行微调。本文中实现了其基础版本。
def buildd_model(self): """NER 模型建立""" inpute_ = layers.Input((self.max_sentence_len,)) embed = layers.Embedding(input_dim=self.word_num, output_dim=200,mask_zero=True)(inpute_) lstm_encode = layers.Bidirectional(layers.LSTM(units=100, return_sequences=True, dropout=0.3, recurrent_dropout=0.05))(embed) dense1 = layers.TimeDistributed(layers.Dense(50,activation="tanh"))(lstm_encode) dense1 = layers.Dropout(0.05)(dense1) # dense1 = layers.Dense(units=64,activation="tanh")(dense1) crf = CRF(self.class_num, sparse_target=False) crf_res = crf(dense1) model = Model(inpute_, crf_res) adam = Adam(lr=0.001) model.compile(optimizer=adam, loss=crf.loss_function, metrics=[crf.accuracy]) print(model.summary()) return model
效果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。