The problem of rare and unknown words is an important issue that can potentially influence the performance of many NLP systems, including both the traditional count-based and the deep learning models. We propose a novel way to deal with the rare and unseen words for the neural network models using attention. Our model uses two softmax layers in order to predict the next word in conditional language models: one predicts the location of a word in the source sentence, and the other predicts a word in the shortlist vocabulary. At each time-step, the decision of which softmax layer to use choose adaptively made by an MLP which is conditioned on the context. We motivate our work from a psychological evidence that humans naturally have a tendency to point towards objects in the context or the environment when the name of an object is not known. We observe improvements on two tasks, neural machine translation on the Europarl English to French parallel corpora and text summarization on the Gigaword dataset using our proposed model.READ FULL TEXT VIEW PDF
Recent neural network sequence models with softmax classifiers have achi...
Neural language models have been widely used in various NLP tasks, inclu...
Nearly all previous work on neural machine translation (NMT) has used qu...
Training neural network language models over large vocabularies is still...
Neural language models (NLMs) have recently gained a renewed interest by...
In Neural Machine Translation (NMT) the usage of subwords and characters...
Most current work in NLP utilizes deep learning, which requires a lot of...
Words are the basic input/output units in most of the NLP systems, and thus the ability to cover a large number of words is a key to building a robust NLP system. However, considering that (i) the number of all words in a language including named entities is very large and that (ii) language itself is an evolving system (people create new words), this can be a challenging problem.
A common approach followed by the recent neural network based NLP systems is to use a softmax output layer where each of the output dimension corresponds to a word in a predefined word-shortlist. Because computing high dimensional softmax is computationally expensive, in practice the shortlist is limited to have only top- most frequent words in the training corpus. All other words are then replaced by a special word, called the unknown word (UNK).
The shortlist approach has two fundamental problems. The first problem, which is known as the rare word problem, is that some of the words in the shortlist occur less frequently in the training set and thus are difficult to learn a good representation, resulting in poor performance. Second, it is obvious that we can lose some important information by mapping different words to a single dummy token UNK. Even if we have a very large shortlist including all unique words in the training set, it does not necessarily improve the test performance, because there still exists a chance to see an unknown word at test time. This is known as the unknown word problem. In addition, increasing the shortlist size mostly leads to increasing rare words due to Zipf’s Law.
These two problems can be particularly critical in language understanding tasks such as factoid question answering [Bordes et al.2015] where the words that we are interested in are often named entities which are usually unknown or rare words.
In a similar situation, where we have a limited information on how to call an object of interest, it seems that humans (and also some primates) have an efficient behavioral mechanism of drawing attention to the object: pointing [Matthews et al.2012]. Pointing makes it possible to deliver information and to associate context to a particular object without knowing how to call it. In particular, human infants use pointing as a fundamental communication tool [Tomasello et al.2007].
In this paper, inspired by the pointing behavior of humans and recent advances in the attention mechanism [Bahdanau et al.2014] and the pointer networks [Vinyals et al.2015], we propose a novel method to deal with the rare or unknown word problem. The basic idea is that we can see in many NLP problems as a task of predicting target text given context text, where some of the target words appear in the context as well. We observe that in this case we can make the model learn to point a word in the context and copy it to the target text, as well as when to point. For example, in machine translation, we can see the source sentence as the context, and the target sentence as what we need to predict. In Figure 1, we show an example depiction of how words can be copied from source to target in machine translation. Although the source and target languages are different, many of the words such as named entities are usually represented by the same characters in both languages, making it possible to copy. Similarly, in text summarization, it is natural to use some words in the original text in the summarized text as well.
Specifically, to predict a target word at each timestep, our model first determines the source of the word generation, that is, on whether to take one from a predefined shortlist or to copy one from the context. For the former, we apply the typical softmax operation, and for the latter, we use the attention mechanism to obtain the pointing softmax probability over the context words and pick the one of high probability. The model learns this decision so as to use the pointing only when the context includes a word that can be copied to the target. This way, our model can predict even the words which are not in the shortlist, as long as it appears in the context. Although some of the words still need to be labeled asUNK, i.e., if it is neither in the shortlist nor in the context, in experiments we show that this learning when and where to point improves the performance in machine translation and text summarization.
The rest of the paper is organized as follows. In the next section, we review the related works including pointer networks and previous approaches to the rare/unknown problem. In Section 3, we review the neural machine translation with attention mechanism which is the baseline in our experiments. Then, in Section 4, we propose our method dealing with the rare/unknown word problem, called the Pointer Softmax (PS). The experimental results are provided in the Section 5 and we conclude our work in Section 6.
The attention-based pointing mechanism is introduced first in the pointer networks [Vinyals et al.2015]. In the pointer networks, the output space of the target sequence is constrained to be the observations in the input sequence (not the input space). Instead of having a fixed dimension softmax output layer, softmax outputs of varying dimension is dynamically computed for each input sequence in such a way to maximize the attention probability of the target input. However, its applicability is rather limited because, unlike our model, there is no option to choose whether to point or not; it always points. In this sense, we can see the pointer networks as a special case of our model where we always choose to point a context word.
Several approaches have been proposed towards solving the rare words/unknown words problem, which can be broadly divided into three categories. The first category of the approaches focuses on improving the computation speed of the softmax output so that it can maintain a very large vocabulary. Because this only increases the shortlist size, it helps to mitigate the unknown word problem, but still suffers from the rare word problem. The hierarchical softmax [Morin and Bengio2005], importance sampling [Bengio and Senécal2008, Jean et al.2014]
, and the noise contrastive estimation[Gutmann and Hyvärinen2012, Mnih and Kavukcuoglu2013] methods are in the class.
The second category, where our proposed method also belongs to, uses information from the context. Notable works are [Luong et al.2015] and [Hermann et al.2015]. In particular, applying to machine translation task, [Luong et al.2015] learns to point some words in source sentence and copy it to the target sentence, similarly to our method. However, it does not use attention mechanism, and by having fixed sized softmax output over the relative pointing range (e.g., -7, …, -1, 0, 1, …, 7), their model (the Positional All model) has a limitation in applying to more general problems such as summarization and question answering, where, unlike machine translation, the length of the context and the pointing locations in the context can vary dramatically. In question answering setting, [Hermann et al.2015] have used placeholders on named entities in the context. However, the placeholder id is directly predicted in the softmax output rather than predicting its location in the context.
The third category of the approaches changes the unit of input/output itself from words to a smaller resolution such as characters [Graves2013] or bytecodes [Sennrich et al.2015, Gillick et al.2015]. Although this approach has the main advantage that it could suffer less from the rare/unknown word problem, the training usually becomes much harder because the length of sequences significantly increases.
As the baseline neural machine translation system, we use the model proposed by [Bahdanau et al.2014] that learns to (soft-)align and translate jointly. We refer this model as NMT.
The encoder of the NMT is a bidirectional RNN [Schuster and Paliwal1997]. The forward RNN reads input sequence in left-to-right direction, resulting in a sequence of hidden states . The backward RNN reads in the reversed direction and outputs . We then concatenate the hidden states of forward and backward RNNs at each time step and obtain a sequence of annotationvectors where . Here, denotes the concatenation operator. Thus, each annotation vector encodes information about the -th word with respect to all the other surrounding words in both directions.
In the decoder, we usually use gated recurrent unit (GRU)[Cho et al.2014, Chung et al.2014]. Specifically, at each time-step , the soft-alignment mechanism first computes the relevance weight which determines the contribution of annotation vector to the -th target word. We use a non-linear mapping (e.g., MLP) which takes , the previous decoder’s hidden state and the previous output as input:
The outputs are then normalized as follows:
We call as the relevance score, or the alignment weight, of the -th annotation vector.
The relevance scores are used to get the context vector of the -th target word in the translation:
The hidden state of the decoder is computed based on the previous hidden state , the context vector and the output word of the previous time-step :
where is GRU.
We use a deep output layer [Pascanu et al.2013] to compute the conditional distribution over words:
where is a learned weight matrix and is a bias of the output layer.
is a single-layer feed-forward neural network.is a function that performs an affine transformation on its input. And the superscript in indicates the -th column vector of .
The whole model, including both the encoder and the decoder, is jointly trained to maximize the (conditional) log-likelihood of target sequences given input sequences, where the training corpus is a set of ’s. Figure 2 illustrates the architecture of the NMT.
In this section, we introduce our method, called as the pointer softmax (PS), to deal with the rare and unknown words. The pointer softmax can be an applicable approach to many NLP tasks, because it resolves the limitations about unknown words for neural networks. It can be used in parallel with other existing techniques such as the large vocabulary trick [Jean et al.2014]. Our model learns two key abilities jointly to make the pointing mechanism applicable in more general settings: (i) to predict whether it is required to use the pointing or not at each time step and (ii) to point any location of the context sequence whose length can vary widely over examples. Note that the pointer networks [Vinyals et al.2015] are in lack of the ability (i), and the ability (ii) is not achieved in the models by [Luong et al.2015].
To achieve this, our model uses two softmax output layers, the shortlist softmax and the location softmax. The shortlist softmax is the same as the typical softmax output layer where each dimension corresponds a word in the predefined word shortlist. The location softmax is a pointer network where each of the output dimension corresponds to the location of a word in the context sequence. Thus, the output dimension of the location softmax varies according to the length of the given context sequence.
At each time-step, if the model decides to use the shortlist softmax, we generate a word from the shortlist. Otherwise, if it is expected that the context sequence contains a word which needs to be generated at the time step, we obtain the location of the context word
from the location softmax. The key to making this possible is deciding when to use the shortlist softmax or the location softmax at each time step. In order to accomplish this, we introduce a switching network to the model. The switching network, which is a multilayer perceptron in our experiments, takes the representation of the context sequence (similar to the input annotation in NMT) and the previous hidden state of the output RNN as its input. It outputs a binary variablewhich indicates whether to use the shortlist softmax (when ) or the location softmax (when ). Note that if the word that is expected to be generated at each time-step is neither in the shortlist nor in the context sequence, the switching network selects the shortlist softmax, and then the shortlist softmax predicts UNK. The details of the pointer softmax model can be seen in Figure 3 as well.
More specifically, our goal is to maximize the probability of observing the target word sequence and the word generation source , given the context sequence :
Note that the word observation can be either a word from the shortlist softmax or a location from the location softmax, depending on the switching variable .
Considering this, we can factorize the above equation further
Here, is a set of time steps where , and is a set of time-steps where . And, and . We denote all previous observations at step by . Note also that .
Then, the joint probabilities inside each product can be further factorized as follows:
here, we omitted which is conditioned on all probabilities in the above.
The switch probability is modeled as a multilayer perceptron with binary output:
And is the shortlist softmax and is the location softmax which can be a pointer network.
stands for the sigmoid function,.
Given such context and target sequence pairs, our training objective is to maximize the following log likelihood w.r.t. the model parameter
In this section, we discuss practical details of the three fundamental components of the pointer softmax. The interactions between these components and the model is depicted in Figure 3.
: The location of the word to copy from source text to the target is predicted by the location softmax
. The location softmax outputs the conditional probability distribution
. For models using the attention mechanism such as NMT, we can reuse the probability distributions over the source words in order to predict the location of the word to point. Otherwise we can simply use a pointer network of the model to predict the location.
: The subset of the words in the vocabulary is being predicted by the shortlist softmax .
: The switching network is an MLP with sigmoid output function that outputs a scalar probability of switching between and , and represents the conditional probability distribution . For NMT model, we condition the MLP that outputs the switching probability on the representation of the context of the source text and the hidden state of the decoder . Note that, during the training, is observed, and thus we do not have to sample.
The output of the pointer softmax, will be the concatenation of the the two vectors, and .
In this section, we provide our main experimental results with the pointer softmax on machine translation and summarization tasks. In our experiments, we have used the same baseline model and just replaced the softmax layer with pointer softmax layer at the language model. We use the Adadelta [Zeiler2012] learning rule for the training of NMT models. The code for pointer softmax model is available at https://github.com/caglar/pointer_softmax.
We construct a synthetic task and run some preliminary experiments in order to compare the results with the pointer softmax and the regular softmax’s performance for the rare-words. The vocabulary size of our synthetic task is using sequences of length
. The words in the sequences are sampled according to their unigram distribution which has the form of a geometric distribution. The task is to predict the least frequent word in the sequence according to unigram distribution of the words. During the training, the sequences are generated randomly. Before the training, validation and test sets are constructed with a fixed seed.
We use a GRU layer over the input sequence and take the last-hidden state, in order to get the summary of the input sequence. The are only conditioned on , and the MLP predicting the is conditioned on the latent representations of and . We use minibatches of size 250 using adam adaptive learning rate algorithm [Kingma and Adam2015] using the learning rate of and hidden layers with 1000 units.
We train a model with pointer softmax where we assign pointers for the rarest 60 words and the rest of the words are predicted from the shortlist softmax of size 540. We observe that increasing the inverse temperature of the sigmoid output of to 2, in other words making the decisions of to become sharper, works better, i.e. .
At the end of training with pointer softmax we obtain the error rate of and by using softmax over all 600 tokens, we obtain the error-rate of .
In these series of experiments, we use the annotated Gigaword corpus as described in [Rush et al.2015]. Moreover, we use the scripts that are made available by the authors of [Rush et al.2015] 111https://github.com/facebook/NAMAS to preprocess the data, which results to approximately 3.8M training examples. This script generates about 400K validation and an equal number of test examples, but we use a randomly sampled subset of examples each for validation and testing. We also have made small modifications to the script to extract not only the tokenized words, but also system-generated named-entity tags. We have created two different versions of training data for pointers, which we call UNK-pointers data and entity-pointers data respectively.
For the UNK-pointers data, we trim the vocabulary of the source and target data in the training set and replace a word by the UNK token whenever a word occurs less than 5 times in either source or target data separately. Then, we create pointers from each UNK token in the target data to the position in the corresponding source document where the same word occurs in the source, as seen in the data before UNK’s were created. It is possible that the source can have an UNK in the matching position, but we still created a pointer in this scenario as well. The resulting data has 2.7 pointers per 100 examples in the training set and 9.1 pointers rate in the validation set.
In the entity-pointers data, we exploit the named-entity tags in the annotated corpus and first anonymize the entities by replacing them with an integer-id that always starts from 1 for each document and increments from left to right. Entities that occur more than once in a single document share the same id. We create the anonymization at token-level, so as to allow partial entity matches between the source and target for multi-token entities. Next, we create a pointer from the target to source on similar lines as before, but only for exact matches of the anonymized entities. The resulting data has 161 pointers per 100 examples in the training set and 139 pointers per 100 examples in the validation set.
If there are multiple matches in the source, either in the UNK-pointers data or the entity-pointers data, we resolve the conflict in favor of the first occurrence of the matching word in the source document. In the UNK data, we model the UNK tokens on the source side using a single placeholder embedding that is shared across all documents, and in the entity-pointers data, we model each entity-id in the source by a distinct placeholder, each of which is shared across all documents.
In all our experiments, we use a bidirectional GRU-RNN [Chung et al.2014] for the encoder and a uni-directional RNN for the decoder. To speed-up training, we use the large-vocabulary trick [Jean et al.2014] where we limit the vocabulary of the softmax layer of the decoder to words dynamically chosen from the words in the source documents of each batch and the most common words in the target vocabulary. In both experiments, we fix the embedding size to and the hidden state dimension to
. We use pre-trained word2vec vectors trained on the same corpus to initialize the embeddings, but we finetune them by backpropagating through the pre-trained embeddings during training. Our vocabulary sizes are fixed to 125K for source and 75K for target for both experiments.
We use the reference data for pointers for the model only at the training time. During the test time, the switch makes a decision at every timestep on which softmax layer to use.
For evaluation, we use full-length Rouge F1 using the official evaluation tool 222http://www.berouge.com/Pages/default.aspx. In their work, the authors of [Bahdanau et al.2014] use full-length Rouge Recall on this corpus, since the maximum length of limited-length version of Rouge recall of 75 bytes (intended for DUC data) is already long for Gigaword summaries. However, since full-length Recall can unfairly reward longer summaries, we also use full-length F1 in our experiments for a fair comparison between our models, independent of the summary length.
The experimental results comparing the Pointer Softmax with NMT model are displayed in Table 1 for the UNK pointers data and in Table 2 for the entity pointers data. As our experiments show, pointer softmax improves over the baseline NMT on both UNK data and entities data. Our hope was that the improvement would be larger for the entities data since the incidence of pointers was much greater. However, it turns out this is not the case, and we suspect the main reason is anonymization of entities which removed data-sparsity by converting all entities to integer-ids that are shared across all documents. We believe that on de-anonymized data, our model could help more, since the issue of data-sparsity is more acute in this case.
|NMT + lvt||34.87||16.54||32.27|
|NMT + lvt + PS||35.19||16.66||32.51|
Results on Gigaword Corpus when pointers are used for UNKs in the training data, using Rouge-F1 as the evaluation metric.
|NMT + lvt||34.89||16.78||32.37|
|NMT + lvt + PS||35.11||16.76||32.55|
|NMT + lvt||36.45||17.41||33.90|
|NMT + lvt + PS||37.29||17.75||34.70|
In Table 3, we provide the results for summarization on Gigaword corpus in terms of recall as also similar comparison is done by [Rush et al.2015]. We observe improvements on all the scores with the addition of pointer softmax. Let us note that, since the test set of [Rush et al.2015] is not publicly available, we sample texts with their summaries without replacement from the validation set and used those examples as our test set.
In Table 4 we present a few system generated summaries from the Pointer Softmax model trained on the UNK pointers data. From those examples, it is apparent that the model has learned to accurately point to the source positions whenever it needs to generate rare words in the summary.
|Source #1||china ’s tang gonghong set a world record with a clean and jerk lift of ### kilograms to win the women ’s over-## kilogram weightlifting title at the asian games on tuesday .|
|Target #1||china ’s tang <unk>,sets world weightlifting record|
|NMT+PS #1||china ’s tang gonghong wins women ’s weightlifting weightlifting title at asian games|
|Source #2||owing to criticism , nbc said on wednesday that it was ending a three-month-old experiment that would have brought the first liquor advertisements onto national broadcast network television .|
|Target #2||advertising : nbc retreats from liquor commercials|
|NMT+PS #2||nbc says it is ending a three-month-old experiment|
|Source #3||a senior trade union official here wednesday called on ghana ’s government to be “ mindful of the plight ” of the ordinary people in the country in its decisions on tax increases .|
|Target #3||tuc official,on behalf of ordinary ghanaians|
|NMT+PS #3||ghana ’s government urged to be mindful of the plight|
In our neural machine translation (NMT) experiments, we train NMT models with attention over the Europarl corpus [Bahdanau et al.2014] over the sequences of length up to for English to French translation. 333In our experiments, we use an existing code, provided in https://github.com/kyunghyuncho/dl4mt-material, and on the original model we only changed the last softmax layer for our experiments. All models are trained with early-stopping which is done based on the negative log-likelihood (NLL) on the development set. Our evaluations to report the performance of our models are done on newstest2011 by using BLUE score. 444We compute the BLEU score using the multi-blue.perl script from Moses on tokenized sentence pairs.
We use tokens for both the source and the target language shortlist vocabularies ( of the token is still reserved for the unknown words). The whole corpus contains unique English words and unique French words. We have created a word-level dictionary from French to English which contains translation of 15,953 words that are neither in shortlist vocabulary nor dictionary of common words for both the source and the target. There are about words shared between English and French parallel corpora of Europarl.
During the training, in order to decide whether to pick a word from the source sentence using attention/pointers or to predict the word from the short-list vocabulary, we use the following simple heuristic. If the word is not in the short-list vocabulary, we first check if the same wordappears in the source sentence. If it is not, we then check if a translated version of the word exists in the source sentence by using a look-up table between the source and the target language. If the word is in the source sentence, we then use the location of the word in the source as the target. Otherwise we check if one of the English senses from the cross-language dictionary of the French word is in the source. If it is in the source sentence, then we use the location of that word as our translation. Otherwise we just use the argmax of as the target.
For switching network , we observed that using a two-layered MLP with noisy-tanh activation [Gulcehre et al.2016]
function with residual connection from the lower layer[He et al.2015]activation function to the upper hidden layers improves the BLEU score about 1 points over the
using ReLU activation function. We initialized the biases of the last sigmoid layer ofto such that if becomes more biased toward choosing the shortlist vocabulary at the beginning of the training. We renormalize the gradients if the norm of the gradients exceed [Pascanu et al.2012].
|NMT + PS||23.76|
In Table 5, we provided the result of NMT with pointer softmax and we observe about BLEU score improvement over our baseline.
In Figure 4, we show the validation curves of the NMT model with attention and the NMT model with shortlist-softmax layer. Pointer softmax converges faster in terms of number of minibatch updates and achieves a lower validation negative-log-likelihood (NLL) () after updates over the Europarl dataset than the NMT model with shortlist softmax trained for minibatch updates (). Pointer softmax converges faster than the model using the shortlist softmax, because the targets provided to the pointer softmax also acts like guiding hints to the attention.
In this paper, we propose a simple extension to the traditional soft attention-based shortlist softmax by using pointers over the input sequence. We show that the whole model can be trained jointly with single objective function. We observe noticeable improvements over the baselines on machine translation and summarization tasks by using pointer softmax. By doing a very simple modification over the NMT, our model is able to generalize to the unseen words and can deal with rare-words more efficiently. For the summarization task on Gigaword dataset, the pointer softmax was able to improve the results even when it is used together with the large-vocabulary trick. In the case of neural machine translation, we observed that the training with the pointer softmax is also improved the convergence speed of the model as well. For French to English machine translation on Europarl corpora, we observe that using the pointer softmax can also improve the training convergence of the model.
Noise-contrastive estimation of unnormalized statistical models, with applications to natural image statistics.
The Journal of Machine Learning Research, 13(1):307–361.
, volume 5, pages 246–252. Citeseer.
[Theano Development Team2016]Theano Development Team. 2016. Theano: A Python framework for fast computation of mathematical expressions. arXiv e-prints, abs/1605.02688, May.
We would like to thank the developers of Theano 555http://deeplearning.net/software/theano/, for developing such a powerful tool for scientific computing [Theano Development Team2016]. We acknowledge the support of the following organizations for research funding and computing support: NSERC, Samsung, Calcul Québec, Compute Canada, the Canada Research Chairs and CIFAR. C. G. thanks for IBM T.J. Watson Research for funding this research during his internship between October 2015 and January 2016.