Named entity recognition practice (LSTM+CRF)

Mission scenario

Entity recognition is a classic sequence labeling task. If you have a batch of labeled samples, you can consider using the model for training. The traditional way is to use CRF++ for training. With the rise of deep learning technology, the task basically revolves around the foundation Based on the LSTM+CRF or fine-tuned. The basic version is implemented in this article.


    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

effect:
Insert picture description here

Guess you like

Origin blog.csdn.net/cyinfi/article/details/87656027