最近在做NER,所以打算顺便把现有NER的技术做一个梳理,这样在具体应用模型、开发模型甚至是写一些paper,思路都比较清晰
一、定义 :
A named entity is a word or a phrase that clearly identifies one item from a set of other items that have similar attributes
二、起源与示例:
命名实体识别(NER)首次是在MUC-6(the sixth Message Understanding Conference)中被提出,当时的识别,主要用来识别文本中的组织名、人名、地理位置、货币、时间和百分比表达式等等。
命名实体识别解决的问题就是从给定的文本中识别出实体的边界以及实体的类型,实体的类型通常是由人为的提前预定义好,比如,有文本为Michael Jeffrey Jordan was born in Brooklyn, New York.那么需要把Michael Jeffrey Jordan识别为人名(Person),Brooklyn和New York分别识别为地理位置(Location)。
三、常用的公开数据集:
四、常用的工具有:
-
评价指标
-
Exact-match Evaluation
此方法要求实体的边界和类型都要预测正确。 评价方法还是使用机器学习混淆矩阵的评价方法,P(Precision)、R(Recall)和F1(是把P和R做一个加权)。我简单列一下关键的变量:
true positives (TP)、false positives (FP)、false negatives (FN),其中true和false代表人工标注样本的正确与错误;negatives和positives代表模型预测结果的正确与错误。比如TP代表人工标注是正确的,预测也是正确的样本数量,那么精确率P、召回率R和F-score的公式分别为
- macro-averaged F-score
首先计算每个实体类型的F-score,然后对所有类型求平均值。
- micro-averaged Fscore
同时计算所有实体类型的F-score
2、Relaxed-match Evaluation
对实体边界的错误看的比较轻,在实体类型预测正确的情况下,只要人工标注的实体边界覆盖了预测实体的边界,就认为是预测正确了。还有一些更加复杂的评价指标,实际应用比较少,就不过多的介绍了,有兴趣的朋友,可以参考
-
命名实体识别常用算法:
常用算法大致可以分为以下四种类型:基于规则、无监督、基于特征和深度学习的方法,下面一一介绍这四种方法的代表论文,重点介绍深度学习方法。
-
基于规则的算法
这种方法是比较早期的方法了,一般都是业务专家根据经验中特定的领域通过人为的定义一些规则来识别命名实体,这种方法目前使用的比较少,我在这里仅仅列出相关的paper,有兴趣的朋友可以自行阅读
《Definition, dictionaries and tagger for extended named entity hierarchy 》
《Unsupervised biomedical named entity recognition: Experiments with clinical and biological texts 》
《A rule-based named entity recognition system for speech input》
《Prominer: rule-based protein and gene entity recognition 》
《Named entity recognition over electronic health records through a combined dictionary-based approach 》
《University of sheffield: Description of the lasieii system as used for muc-7 》
《Description of the nerowl extractor system as used for muc-7 》
《Facile: Description of the ne system used for muc-7 》
《Sra: Description of the ie2 system used for muc-7 》
《Sri international fastus system: Muc-6 test results and analysis 》
《Named entity recognition without gazetteers 》
-
无监督算法
无监督最典型的算法就是聚类,基于聚类算法的NER问题,不需要语料的标注,它是在大规模的语料上运用统计计算和文本相似度来识别实体的,下面列出一些典型的paper供大家参考
《Unsupervised biomedical named entity recognition: Experiments with clinical and biological texts 》
《Unsupervised named- entity extraction from the web: An experimental study 》
《Unsupervised models for named entity classification 》
《Unsupervised named- entity recognition: Generating gazetteers and resolving ambi- guity 》
-
基于特征的监督学习算法
这个方法是认为NER就是一个序列的多分类问题,使用最多的机器学习算法就是HMM、CRF和ME算法,当然SVM算法也可以,只不过SVM不考虑上下文,其中CRF的效果最好,将在深度学习算法中详细讲解,这里只列出相关的paper供读者参考
《Named entities: recognition, classification and use. 》
《Named entity recognition using an hmm- based chunk tagger 》
《Biomedical named entity recognition using conditional random fields and rich feature sets 》
《A simple semi-supervised algorithm for named entity recognition 》
《A knowledge-free method for capitalized word disambiguation 》
《Exploiting wikipedia as external knowledge for named entity recognition 》
《A proposal to automatically build and maintain gazetteers for named entity recognition by using wikipedia 》
《Robust dis- ambiguation of named entities in text 》
《Extracting names from natural-language text 》
《Espotter: Adaptive named entity recognition for web browsing 》
《Joint recognition and linking of fine-grained locations from tweets 》
《An effective two-stage model for exploiting non-local dependencies in named entity recognition》
《Biomedical named entity recognition: a survey of machine-learning tools 》
《Hidden markov models 》
《Induction of decision trees 》
《Maximum-entropy models in science and engineering 》
《Support vector machines 》
《Conditional random fields: Probabilistic models for segmenting and labeling sequence data 》
《Nymble: a high-performance learning name-finder 》
《An algorithm that learns what’s in a name》
《A multilingual named entity recognition system using boosting and c4. 5 decision tree learning algorithms 》
《Nyu: Description of the mene named entity system as used in muc-7 》
《Maximum entropy models for named entity recognition》
《Named entity recognition: a maximum entropy approach using global information 》
《Language independent ner using a maximum entropy tagger 》
《Entity extraction without language-specific resources 》
《Efficient support vector classifiers for named entity recognition 》
《Svm based learning system for information extraction 》
《Early results for named entity recognition with conditional random fields, feature induction and web- enhanced lexicons 》
《Named entity recognition in tweets: an experimental study》
《Recognizing named entities in tweets 》
《Chemspot: a hybrid system for chemical named entity recognition 》
4、深度学习算法
4.1、为什么使用深度学习算法做NER?理由有三个:一、相比线性的HMM和CRF,主要得益于非线性激活函数,通过激活函数可以从原始数据中获得错综复杂的特征;二、传统的基于特征的方法需要大量的工程技巧和领域知识来构建特征,而深度学习不需要;三、深度学习是一个端到端的模型范式,所以可以设计更加复杂的NER模型。
参考paper《Deep active learning for named entity recognition 》
4.2、深度学习做NER的通用网络结构,如下图:
主要分为三个层:1)Distributed Representations for Input(输入数据的分布式表示,通过称为embedding层);2)Context Encoder Architectures(网络结构,或者是特征层);3)Tag Decoder Architectures(标签解码层),下面分别介绍这三层的经典思想:
-
Distributed Representations for Input
在神经网络中只能使用向量,所以对于输入为字符串的中文首先需要转换为向量才可以在深度学习模型中使用,通常有两种方式:一种是one-hot模式,每个向量只有一个维度是1,其他维度都是0,这样向量非常稀疏,每个向量都是正交的,也不能表示词的语义;另一种就是word embedding的方式,是一种稠密向量,俗称的分布式表示,也就是说向量的每个维度都是一个隐特征,这就可以获取文本的语义信息,比如可以通过计算向量的相似度来判断两个词的语义上的关联程度。最常见的分布式表示有三种:word-level, character-level, and hybrid representations。下面分别介绍一下这三种分布式向量:
word-level representations
基于词的embedding,首先需要使用分词算法进行分词,然后使用神经网络进行词向量学习,最经典的就是改进NNLM(neural network language model)的word2vec,下面是word2vec的两种形式:CBOW和Skip-gram
其中CBOW是根据上下文的词汇去预测中间词来学习词向量的,而Skip-gram正好相反,它是通过给定中间词去预测上下文词来学习词向量的。
当然还有其他的,比如Stanford GloVe,Facebook fastText 和SENNA
参考paper如下:
《Toward mention detection robustness with recurrent neural networks 》
《Joint extraction of entities and relations based on a novel tagging scheme》
《Fast and accurate entity recognition with iterated dilated convolutions 》
《Efficient estimation of word representations in vector space》
《Design challenges and misconceptions in neural sequence labeling 》
《Biomedical named entity recognition based on deep neutral network 》
《Neural models for sequence chunking 》
《Joint extraction of multiple relations and entities by using a hybrid neural network 》
《End-to-end sequence labeling via bi- directional lstm-cnns-crf》
《Leveraging linguistic structures for named entity recognition with bidirectional recursive neural networks》
《Code-switched named entity recognition with embedding attention》
character-level representations
基于词的embedding有一些局限性,最明显的缺点就是无法解决OOV,也就是无法解决集外词,因为所有得到词向量的词都来自训练语料,如果训练语料中没有的词,在测试集出现,就无法知道它的词向量。而基于字符的embedding是比较好的可以解决这个问题,同时也可以解决英文词的前缀和后缀的问题。基于字符的embedding方式通常有*CNN-based* and *RNN-based*两种方式,如下图:
一般*RNN-based*的模型都会采用RNN的变形LSTM和GRU来代替,从而缓解RNN梯度消失的问题。以上模型均为静态词向量,而比较好的词向量应该是根据上下文语境有所变化的,比如ELMO,2018年10月google提出的bert预训练模型。
参考paper如下:
《Charner: Character-level named entity recognition 》
《Named entity recog- nition with stack residual lstm and trainable bias decoding 》
《Segbot: A generic neural text segmentation model with pointer network 》
《Neural reranking for named entity recognition》
《Deep contextualized word representations 》
《Character-level neural network for biomedical named entity recognition 》
《Attending to characters in neural sequence labeling models 》
《Multi-task cross-lingual sequence tagging from scratch》
《Contextual string embed- dings for sequence labeling》
hybrid representations
尽管通过大量的语料训练词向量(比如bert)在很多方面表现的都超过了之前的word2vec,但是仍然有一些提升的空间,比如可以加入一些人类的先验经验,比如加入一些词典,POS等等各种特征到神经网络中。
参考paper如下:
《Robust lexical features for improved neural network named-entity recognition 》
《Disease named entity recognition by combining conditional random fields and bidirectional recurrent neural networks 》
《Multi-channel bilstm-crf model for emerging named entity recognition in social media 》
《Amulti- task approach for named entity recognition in social media data 》
《Distributed representation, lda topic modelling and deep learning for emerging named entity recognition from social media 》
《A local detection approach for named entity recognition and mention detection 》
《A fixed- size encoding method for variable-length sequences with its application to neural network language models 》
《Multimodal named entity recognition for short social media posts 》
《Bert: Pre- training of deep bidirectional transformers for language under- standing 》
《Named entity recognition in chinese clinical text using deep neural network 》
《Named entity recognition with parallel recurrent neural networks 》
-
Context Encoder Architectures
我们在获得分布式词向量后,然后就是通过上下文编码结构提取特征,目前比较流行的方法就是CNN、RNN以及transformer,下面分别介绍一下这些方法的特点:
Convolutional Neural Networks
CNN的使用方式和在CV领域类似,下图是经典的架构
输入字符串Sequence(一般是句子中每个词的one-hot形式),Distributed Representations for Input层lookup获得每个词的稠密词向量,然后使用CNN进行卷积,最后输出。
还有一种比较经典的就是ID-CNN,它与普通的CNN不同,它的卷积核中的像素并不是稠密的,它的每个像素是按照一定的数量间隔开的,这个可以增加卷积核捕捉上下文的范围,ID-CNN的block如下图:
参考的paper如下:
《Named entity recognition in chinese clinical text using deep neural network 》
Recurrent Neural Networks
RNN是捕捉序列信息的能力是有天然优势的,一般都是使用biLSTM从双向获取输入数据的特征,然后把这两部信息concat起来,如下图所示:
和CNN类似,输入字符串Sequence(一般是句子中每个词的one-hot形式),Distributed Representations for Input层lookup获得每个词的稠密词向量,然后分别从前向和后向进行编码,最后在Tag Decoder层汇总并且解码。
参考paper如下:
《Nested named entity recognition revisited》
《A neural layered model for nested named entity recognition 》
Recursive Neural Networks
Recursive Neural Networks(递归神经网络)与Recurrent Neural Networks(循环神经网络)不同,Recursive Neural Networks是一个拓扑结构,它弥补了经典sequential labeling很少考虑句法结构的不足,结构如下图:
自下而上计算每一个节点子树的语义组件,自上而下依次传播到包含子树的语法结构的节点。
Neural Language Models
语言模型是计算一个句子出现的概率*.前向语言模型可以这么理解,比如给出一个句子前(t1, . . . , tk−1) k-1个词去预测第k个单词p(t1,t2,...,tN)* 的概率*.语言模型在做NER有天然的优势,实际上NER就是序列标注问题.*
参考的paper如下*:*
《A neural layered model for nested named entity recognition 》
《Semi-supervised multitask learning for sequence labeling》
《Efficient contextualized representation: Language model pruning for sequence labeling 》
《Empower sequence labeling with task-aware neural language model》
Deep Transformer
深度神经网络提取特征最火的就是Transformer了,最核心的技术就是self-attention了,基于Transformer大放异彩的就是GPT(Generative Pre-trained Transformer)和BERT(Bidirectional Encoder Representations from Transformers)了,GPT的训练分两个阶段:第一阶段:使用Transformer在无标签数据上使语言模型为目标函数最小化来训练初始化参数;第二阶段:使用初始化参数在监督学习的目标任务上优化这些参数。BERT是双向的Transformer。下图对比了BERT、GPT、ELMo
参考的paper如下:
《Attention is all you need 》
《Generating wikipedia by summarizing long sequences 》
《Improving language understanding by generative pre-training》
《Bert: Pre- training of deep bidirectional transformers for language under- standing 》
-
Tag Decoder Architectures
本层的主要作用就是根据输入序列生成一个tag的序列,目前主流的方法有MLP+Softmax、CRF、RNN、Pointer Networks,如图所示:
下面分别介绍一下这些方法:
MLP+Softmax
这个方法是在神经网络后接一个softmax多分类,缺点是它不考虑输出tag之间的关系,每个tag的生成都是使用概率最大的。
参考paper如下:
《Domain specific named entity recognition referring to the real world by deep neural networks 》
CRF
CRF是最常用的tag decoder,在CoNLL03 and OntoNotes5.0语料上获得SOTA,然而CRF由于内部segments不能被word-level表示编码,所以不能充分利用segment-level,近期有很多CRF的改进,比如gated recursive semi-markov CRFs
参考paper如下:
《Segment-level se- quence modeling using gated recursive semi-markov conditional random fields》
《Hybrid semi-markov crf for neural sequence labeling 》
RNN
RNN作为tag decoder很少有人研究,然而,实验表明RNN的性能优于CRF,而且在tag数量很多的情况下训练速度更快,以[GO]符号作为第一个时间步,解码为y1,后面的思路就是RNN的基本原理。
参考paper如下:
《Supertagging with lstms》
Pointer Networks
Pointer networks根据输入序列token的位置,使用RNN学习输出序列的条件概率,最后softmax(长度为字典长度)的条件概率分布就是pointer。Zhai et al首次使用pointer networks生成序列tag,pointer networks首先识别出chunk或者segment,然后打标签,一直重复直到所有的输入序列都被打标签为止。
参考paper如下:
《Pointer networks 》
近期常用模型汇总:
总结一下,本文介绍了NER的定义,NER常用的公开数据集,NER常用的工具,NER常用的四类算法:基于规则的算法、无监督算法、基于特征的算法、深度学习的算法,其中深度学习算法表现的最好,因此重点介绍了深度学习算法的常用基本架构词表示层、上下文特征抽取层和label解码层.接下来将介绍一下比较前沿的NER算法:多任务学习、深度迁移学习算法、深度主动学习算法、深度强化学习算法、深度对抗学习算法和基于注意力的算法,敬请期待.