{'fraction_non_alphanumeric': 0.036459506962909546, 'fraction_numerical': 0.018072017666411287, 'mean_word_length': 4.506203473945409, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 1, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Named Entity Recognition with stack residual LSTM and trainable bias decoding

Recurrent Neural Network models are the state-of-the-art for Named Entity Recognition (NER). We present two innovations to improve the performance of these models. The first innovation is the introduction of residual connections between the Stacked Recurrent Neural Network model to address the degradation problem of deep neural networks. The second innovation is a bias decoding mechanism that allows the trained system to adapt to non-differentiable and externally computed objectives, such as the entity-based F-measure. Our work improves the state-of-the-art results for both Spanish and English languages on the standard train/development/test split of the CoNLL 2003 Shared Task NER dataset.


Introduction
In Natural Language Processing, the term "Named Entity" refers to special information units such as people, organizations, location names, numerical expression (Nadeau and Sekine, 2007). Identifying the references to these special entities in text is a crucial step toward Language Understanding. Thus, there have been many works on these areas.
Some of the early systems employed handcrafted rules (Rau, 1991;Sekine and Nobata, 2004), however, the vast majority of current systems rely on machine learning models (Nadeau and Sekine, 2007) such as Conditional Random Field (CRF) (McCallum and Li, 2003), Hidden Markov Model (HMM) (Bikel et al., 1997) and Support Vector Machine (SVM) (Asahara and Matsumoto, 2003). Although the traditional machine learning models do not rely on manual rules, they require a manual feature engineering process, which is rather expensive and dependent on the domain and language.
In recent years, Recurrent Neural Network (RNN) models such as Long-Short-Term-Memory (LSTM) (Hochreiter and Schmidhuber, 1997) and Gated Recurrent Unit (GRU) (Chung et al., 2014) have been very successful in sequence modeling tasks, for example, Language Modeling (Mikolov et al., 2010;Sundermeyer et al., 2012), Machine Translation (Bahdanau et al., 2014) and Dialog Act Classification (Kalchbrenner and Blunsom, 2013;Tran et al., 2017). RNN models can learn from basic components of text (i.e. words and characters). This generalization capability facilitates the construction of Language Independent NER models (Ma and Hovy, 2016;Lample et al., 2016) that rely on unsupervised feature learning and a small annotated corpus.
One simple way of adding representational power to a neural network is layer stacking. A traditional feed forward neural network usually has three fully connected layers: an input layer, a hidden layer, and an output layer. For a Convolutional Neural Network (CNN) or Recurrent Neural Network, the number of stacked layers might be much larger (Amodei et al., 2016). One problem with this stacking scenario is the degraded representation problem (He et al., 2016). The proposed solution for this problem is the residual-identity connection (He et al., 2016). With the information from the lower-level inputs, the upper neural network layers can learn to compensate for the representation errors of lower layers. We adopt this idea for Stacking RNN, however, with a different implementation.
Most of the RNN-based models for NER and machine translation are trained with some form of maximum log-likelihood loss. However, it is often desirable to optimize task-specific metrics (Xu et al., 2016), for example, F-measure in NER, but optimizing the F-measure directly is not trivial (Busa-Fekete et al., 2015), especially in the case of complex Deep Neural Network models. It is even more difficult considering the way the F-measure is calculated in Named Entity Recognition in the CoNLL-2003 shared task 1 , where it depends on the actual/predicted entities and not on each token-prediction for which the system is trained for. Inspired by the idea of trainable decoding recently proposed in machine translation (Gu et al., 2017), we introduce a trainable percentage bias decoding system that manipulates the outputs of a base system trained with normal loss to adapt to a new objective. Our trainable bias decoding system also bears similarity to the thresholding technique (Lipton et al., 2014), traditionally used to maximize F-measures given a classifier. The proposed decoding system is trained directly on the externally computed F-measures (which relies on the the CoNLL evaluation script) using finite different gradient.
In the next sections, we describe the proposed innovations with detailed motivations and discussions. Results show that our proposed innovations improve the NER state-of-the-art for the English and Spanish languages in the CoNLL-2003 shared task data set.

Models
We describe first our RNN-CRF base architecture and then we describe our two modelling innovations: the Stack Residual RNN and the bias decoding.

The base RNN-CRF architecture
Our system is built upon the RNN-CRF architecture for Named Entity Recognition. Let us denote the input sequence of words as w 0 , ..., w n . In general, the RNN component encodes the words into a sequence of hidden vectors h 0 , ..., h n . This sequence of hidden vectors is then treated as features for a linear-chain CRF layer. The training objective will then be the log-likelihood of the correct sequence.
Following Lample et al. (2016); Ma and Hovy (2016); Yang et al. (2016), we employ the character level information and word-embeddings as features in NER. Similar to Lample et al. (2016), in our system, character information is encoded us-1 https://www.aclweb.org/aclwiki/index. php?title=CONLL-2003_(State_of_the_art) ing a bi-directional RNN (biRNN) over characters. Given a word w k ∈ w 0 , ..., w n with m characters, let us denote the character-embedding sequence of this word as c 0 , ..., c m , the biRNN function as ρ and the concat function as ψ. The character embedding representation h c k of word w k is calculated using a biRNN as in Equation 1, in which f 0 , ..., f m and b 0 , ..., b m denote the hidden units in the forward and backward RNNs respectively.
The feature vector x k of word w k is then the concatenation of h c k and the traditional wordembedding e k as shown in Equation 2. Figure 1 shows the feature extraction procedures. All the parameters of the biRNN as well as the embedding tables are jointly trained with other component of the model. The word embedding table is initialized with a pre-trained embedding table.
The most simple architecture would be a one-directional RNN over the word features: h 0 , ..., h n = RN N (x 0 , ..., x n ). However, it has been shown to be beneficial to have a bidirectional RNN over the input layer, as a bidirectional RNN captures both the left and the right context of a word: h 0 , ..., h n = ρ(x 0 , ..., x n ).
The final sequence of hidden vectors h 0 , ..., h n is treated as the features for a linear-chained CRF layer. Similar to Lample et al. (2016), the observation scores λ are calculated with a linear transformation from the hidden vectors, as show in Equation 3, where λ i is the vector observation scores for all the labels in ith time-step, W p is an l × d weight matrix, and b p is a bias vector of size l (with d is the size of vector h i ), and l is the size of the label set Y (including the special sequence begin and end labels).
Given a sequence of input words S = w 0 , ..., w n , the score of a particular sequence of labels Y = Y The probability of a sequence Y is calculated using a softmax over all the possible sequences Y (Equation 5).
During training, we maximize the loglikelihood of the correct sequence Y c . The loss function L is defined in Equation 6. Because we employ a linear-chain CRF, the term log( Ȳ ∈Y e ζ(Ȳ ,S) ) in Equation 6 can be efficiently calculated with dynamic programming.
During decoding, the best sequence can be found using the Viterbi algorithm. The original Viterbi decoding algorithm builds an l × n score table ξ in which l is the size of the label set (including the beginning and end labels) and n is the length of the sequence. ξ j (y i ) denotes the score of the most probable partial path (up to position j) with position j having the label y i . ξ j (y i ) is calculated using dynamic programming as in Equation 7.
At the end of the decoding process, sequenceŶ is predicted by selecting the best score at the end of the sequence j = n and then completing the sequence with a backward pointer (Equation 8). Figure 3 depicts the whole RNN-CRF architecturê

Stacked Residual RNN
A traditional way of adding more representational power to a neural network is layer stacking. RNN stacking has been successfully used in a lot of works (Amodei et al., 2016). However, stacking  (He et al., 2016). This is due to the difficulty in training a lot of stacked layers and fit these layers to desired underlying mappings, which leads to representational degradation.
The solution proposed to this problem, the residual connection (He et al., 2016;Prakash et al., 2016) tries to create shortcuts between nonconsecutive layers. However, the original additional residual connection (adding the input vector to the hidden representation) adds several constraints on the dimensionality of the hidden and input layers, which might require vector clipping (Prakash et al., 2016), and it might lead to a loss of information.
In the original residual connection proposed for image recognition, the residual information is summed to the output of the upper layers (F(x) + x). In our proposal, we want the upper layer of a neural network to have direct access to the original input, thus, the original input is now appended to the output of the lower layers instead of being summed. With this formulation, there is no dimensionality restriction, and furthermore, we argue that our proposed residual connection can be used to mix feature learners of different complexity ( Figure 4). For example, when equipped with our proposed residual connection, the top neural network layer can act like a shallow one-layer feature learner. The two top layers can act like a deeper two-layer feature learner. Equation set 9 shows the exact formulation of our proposed residual connection within the Stack RNN. Similar to the Equation 1, we denote the biRNN function as ρ and the concat function as ψ. This modelling procedure is depicted in Figure 4.

The bias decoding
Usually NER systems are evaluated with some form of F-measure. For example, for the CoNLL 2013 Shared Task NER dataset, the evaluation is performed by an external script using entitybased F1-measure. Although it has been noted that training on the evaluation metric is beneficial (Xu et al., 2016), most of the deep models for NER are trained with log-likelihood. The main reason for this discrepancy is the difficulty in training with F-measures. Instead of trying to train on F-measure directly, we look into a hybrid solution where we train a model on log-likelihood first, and then use a simpler "adaptation model" to manipulate the output of the base model to fit it to the F-measure. Inspired by Machine Translation research on decoding with trainable noise (Gu et al., 2017), we Figure 4: Feature learner mixture with residual connection explore the possibility of adding trainable noise to the Viterbi decoding process. Analogously to the traditional threshold technique for maximizing the F1 score in binary classification, we introduce a simple percentage noise to the decoding process. That is, during the construction of the score table ξ (Equation 7), a label-specific percentage bias is added to the calculation as in Equation 10. Figure  2 shows the application of this bias to the Viterbi decoding.
To test this new percentage bias idea, we perform a quick experiment, where we limit the use of bias to the most numerous class in the CoNLL tag set, class O (words that do not belong to any entity). We search for the best bias b O from the range of [0.5, 1.5] using a value loop with step of 0.1. For each value of b O , we calculate the F1measure on the validation set, and choose the value with the highest F1. We use our trained model based on the Stack Residual architecture above as the base probabilistic model. We find that the best b O value is 1.1 (a value of 1.0 means without any bias). Using this b O bias for the test data yields the F1-measures of 91.22 compared to the original score of 91.07 in the test set. This experiment supports our claim that the base model trained with log-likelihood might not optimize well on a different performance measure, and adding this percentage bias noise is really beneficial.
We extended this idea treating the biases as parameters. Thus the trainable bias decoding system has the number of parameters equal to the number of classes. Training with gradient descent with CoNLL's entity-based F1 loss is rather difficult, as it is hard to calculate the exact gradient. This is solved using the numerical gradient methods as an approximation, which is shown in Equation 11.
The training procedure is then very similar to stochastic gradient descent. Details on the choice of hyper parameters and other experimental settings are presented in the Experiment section.

Dataset and Experimental settings
We have prepared and evaluated the proposed methods on the English and Spanish sets of the CoNLL 2003 NER data set 2 (Tjong Kim Sang and De Meulder, 2003). We have reused the training, development and test set configuration of the CoNLL-2003 Shared Task in our study.
The training set has been used to train the system using several hyperparameter configurations, the development set has been used to select the best configuration and the reported performance of the final system is based on the test set. The Spanish dataset has 8323/1915/1517 sentences in train/dev/test sets respectively. The English dataset is almost twice as large with 14041/3250/3453 sentences in train/dev/test set. For all of our models, the word-embedding size is set to 100 for English and 64 for Spanish. The hidden vector size is 100 for both English and Spanish sets without the LM embeddings. With the LM embeddings, the hidden vector size is changed to 300 for English. We trained the model with Stochastic Gradient Descent (SGD) with momentum, using the learning rate of 0.005. For the bias decoding, the hyperparameter for each update is randomly chosen from a range of [0.01, ..., 0.1] with step-size of 0.01. Because the base model trained with sequence level log-likelihood fits very well on the training set, the gradient calculated with Equation 11 might be every small, thus we opt to calculate the finite difference with respect to the loss: log2(1 − F 1/100) instead of the F 1 to boost the gradient information in the points where F1 is very close to 100 (perfect classification). The learning rate for bias training is also set to 0.005. Statistical significance has been determined using a randomization version of the paired sample ttest (Cohen, 1996).
We first conduct several series of experiments to confirm the effectiveness of our two proposed ideas: the Stack Residual RNN and the bias decoding, and the new Language Model embedding in sub-section 3.2. The second sub-section: 3.4 compares our method with state-of-the-art results.

Component Analysis
Adding stack Residual RNN Due to computational complexity, there is a practical limit on how many RNN layers we can stack. In this series of experiment, we tested our model without Stacked Residual RNN, and with 2, 3 and 4 Stacked layers. The word embeddings are initialized using the pre-trained word vectors de-2 http://www.cnts.ua.ac.be/conll2003/ner scribed below. The result of this series of experiements is presented in Table 1.
From the result, we can see that the performance seems to increase as we add more stacked layers, and peak at three before dropping. We continue to analyze other components using 3 Stacked Residual Layers of CRF-RNN as the base model, we call this model 3 Res-RNN for short.
For English, the 3 and 4 stacked layer improvements are significant (p < 0.025) compared to the baseline model and between the stacked layer models, the improvement between 2 and 3 layers is significant (p < 0.035).
For Spanish, the 3 stacked layer improvement is significant (p < 0.03), with respect to the baseline model. Improvement between the 3 stacked layer and the 4 stacked layer models is significant (p < 0.03).
Adding Language Model Embedding Pre-trained word embeddings have shown useful in Natural Language Processing tasks, but provide information about the word but not about its context. Previous work has explored using language models in addition to word embeddings (Peters et al., 2017) with positive results. We have evaluated our system using pre-trained language models using the 3 Stacked Residual Layer configuration. First, we test the models with forward-only LM embeddings (foreLM), then we test the model with both forward and backLM (backLM). The result of this series of experiments is presented in Table 2.
The gain from the LM embedding is not consistent. It seems to work very well with English, where it improves performance substantially even though this improvement is not specially significant. However, the LM does not improve the performance at all in Spanish. Adding the foreLM and backLM significantly decreases performance.
Adding Bias Decoding We test the bias decoding on models with and without LM embeddings, with results shown in Table 3. The bias-decoding increases the performance across the board, however the performance increases are not consistent. The increases are notable on some cases (3 Res-RNN + bias on both English and Spanish, 3 Res-RNN + foreLM + backLM + bias for Spanish), while in some cases the increases are minimal (3 Res-RNN + foreLM + bias on both English and Spanish, 3 Res-RNN + foreLM + backLM + bias on English).  For English, adding bias to the 3 Res-RNN without LM yields a significant improvement (p < 0.013), while for Spanish, the boost from adding bias to the 3 Res-RNN + foreLM + backLM model is significant (p < 0.011).

Word embedding
English word embedding was obtained from Word2vec-api 3 . The embedding dimension is 100 and it was trained using GloVe with AdaGrad. For the generation of Spanish word embeddings we followed Lample et al. (2016), using Spanish Gigaword Third Edition 4 as corpus with an embedding dimension of 64, a minimum word frequency cutoff of 4 and a window size of 8.

Language Modeling
In some experiments, we used both forward and backward language models. The English forward language model was obtained from TensorFlow 5 using the One Billion Word Benchmark 6 (Chelba et al., 2013) and has a perplexity of 30. As the code generating this pre-trained model is not available, we made use of a substitute which produces a higher perplexity language model. For the backward English language model and the Spanish forward and backward ones, they were generated using an LSTM based baseline 7 (Jozefowicz et al., 2016). This code estimates a forward language model and was adapted to estimate a backward language model. Language models were estimated using the One Billion Word benchmark. The vocabulary for the backward English model is the same as the pre-generated forward model. The perplexity for estimated backward English language model is 46; despite the discrepancy in perplexity with the forward language model the performance using this language model still improves the named entity recognition task. The vocabulary for the Spanish language models was generated using tokens with frequency > 2. The perplexity for the forward and backward Spanish language models are 56 and 57 respectively. Table 4 shows the performance of our best systems compared to the state-of-the-art results on ConLL dataset. We focus our comparison to the systems with the same experimental setups (standard train/val/test split, without the use of external label data). The best previous systems (Ma and Hovy, 2016;Lample et al., 2016)   From the results above, we can see that our innovations, the Stacked Residual connection and bias decoding consistently improve the performance across both data sets. However, the improvements from bias decoding is somewhat small in some models. The numerical gradient for training is noisy, and sometimes the SGD process might take several epochs to find an improvement on the development set. This happens especially on the English dataset because the base model trained with sequence level log-likelihood fits very well on the training set. Even with the boosting trick presented during the Experiments section, the training is still very slow. At first, we expected that the biases might give us some ideas about the trade-off between precision and recall similar to the thresholding technique for binary classification, i.e. the based log-likelihood model might favors precision or recall. However, from the analysis of the biases, we found no obvious trends favoring precision or recall.

Comparative performance
Interestingly, the Language Model embeddings seem to have opposite effects on Spanish and English. While it is very helpful in English, it only degrades the performance for Spanish. The English LMs also improve convergence rate, while it is the opposite for Spanish. We attribute this difference in the quality of the Language Model involved. For English, the LMs are arguably better, with much lower perplexities than the LMs for Spanish. The Spanish models also have less data to train with, and it might affect the performance.

Conclusions and Future Work
We have explored two innovations over the baseline CRF-RNN model for sequence classification: the Stacked Residual Connection, and bias decoding. With these two improvements, it is possible to achieve state-of-the-art performance in Named Entity Recognition for both English and Spanish.
As future work, we will further investigate trainable bias decoding, and try to solve the problems presented. As the methods presented are general and language/domain independent, we plan to apply it to other domains such as health-care and expand the applications beyond NER.