SlowGuess/ACL_2020_OCR huggingface dataset:
Hiroshi Noji
Artificial Intelligence Research Center
AIST, Tokyo, Japan
hiroshi.noji@aist.go.jp
Hiroya Takamura
takamura.hiroya@aist.go.jp
We explore the utilities of explicit negative examples in training neural language models. Negative examples here are incorrect words in a sentence, such as barks in *The dogs barks*. Neural language models are commonly trained only on positive examples, a set of sentences in the training data, but recent studies suggest that the models trained in this way are not capable of robustly handling complex syntactic constructions, such as long-distance agreement. In this paper, we first demonstrate that appropriately using negative examples about particular constructions (e.g., subject-verb agreement) will boost the model's robustness on them in English, with a negligible loss of perplexity. The key to our success is an additional margin loss between the log-likelihoods of a correct word and an incorrect word. We then provide a detailed analysis of the trained models. One of our findings is the difficulty of object-relative clauses for RNNs. We find that even with our direct learning signals the models still suffer from resolving agreement across an object-relative clause. Augmentation of training sentences involving the constructions somewhat helps, but the accuracy still does not reach the level of subject-relative clauses. Although not directly cognitively appealing, our method can be a tool to analyze the true architectural limitation of neural models on challenging linguistic constructions.
Despite not being exposed to explicit syntactic supervision, neural language models (LMs), such as recurrent neural networks, are able to generate fluent and natural sentences, suggesting that they induce syntactic knowledge about the language to some extent. However, it is still under debate whether such induced knowledge about grammar is
robust enough to deal with syntactically challenging constructions such as long-distance subject-verb agreement. So far, the results for RNN language models (RNN-LMs) trained only with raw text are overall negative; prior work has reported low performance on the challenging test cases (Marvin and Linzen, 2018) even with the massive size of the data and model (van Schijndel et al., 2019), or argue the necessity of an architectural change to track the syntactic structure explicitly (Wilcox et al., 2019b; Kuncoro et al., 2018). Here the task is to evaluate whether a model assigns a higher likelihood on a grammatically correct sentence (1a) over an incorrect sentence (1b) that is minimally different from the original one (Linzen et al., 2016).
(1) a. The author that the guards like laughs. b. \* The author that the guards like laugh.
In this paper, to obtain a new insight into the syntactic abilities of neural LMs, in particular RNN-LMs, we perform a series of experiments under a different condition from the prior work. Specifically, we extensively analyze the performance of the models that are exposed to explicit negative examples. In this work, negative examples are the sentences or tokens that are grammatically incorrect, such as (1b) above.
Since these negative examples provide a direct learning signal on the task at test time it may not be very surprising if the task performance goes up. We acknowledge this, and argue that our motivation for this setup is to deepen understanding, in particular the limitation or the capacity of the current architectures, which we expect can be reached with such strong supervision. Another motivation is engineering: we could exploit negative examples in different ways, and establishing a better way will be of practical importance toward building an LM or generator that can be robust on particular linguistic constructions.
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 3375-3385 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
The first research question we pursue is about this latter point: what is a better method to utilize negative examples that help LMs to acquire robustness on the target syntactic constructions? Regarding this point, we find that adding additional token-level loss trying to guarantee a margin between log-probabilities for the correct and incorrect words (e.g.,  $\log p(\text{laughs}|h)$  and  $\log p(\text{laughs}|h)$  for (1a)) is superior to the alternatives. On the test set of Marvin and Linzen (2018), we show that LSTM language models (LSTM-LMs) trained by this loss reach near perfect level on most syntactic constructions for which we create negative examples, with only a slight increase of perplexity about 1.0 point.
Past work conceptually similar to us is Enguehard et al. (2017), which, while not directly exploiting negative examples, trains an LM with additional explicit supervision signals to the evaluation task. They hypothesize that LSTMs do have enough capacity to acquire robust syntactic abilities but the learning signals given by the raw text are weak, and show that multi-task learning with a binary classification task to predict the upcoming verb form (singular or plural) helps models aware of the target syntax (subject-verb agreement). Our experiments basically confirm and strengthen this argument, with even stronger learning signals from negative examples, and we argue this allows us to evaluate the true capacity of the current architectures. In our experiments (Section 4), we show that our margin loss achieves higher syntactic performance than their multi-task learning.
Another relevant work on the capacity of LSTM-LMs is Kuncoro et al. (2019), which shows that by distilling from syntactic LMs (Dyer et al., 2016), LSTM-LMs can improve their robustness on various agreement phenomena. We show that our LMs with the margin loss outperform theirs in most of the aspects, further strengthening the argument about a stronger capacity of LSTM-LMs.
The latter part of this paper is a detailed analysis of the trained models and introduced losses. Our second question is about the true limitation of LSTM-LMs: are there still any syntactic constructions that the models cannot handle robustly even with our direct learning signals? This question can be seen as a fine-grained one raised by Enguehard et al. (2017) with a stronger tool and improved evaluation metric. Among tested constructions, we find that syntactic agreement across an object relative clause (RC) is challenging. To inspect whether this
is due to the architectural limitation, we train another LM on a dataset, on which we unnaturally augment sentences involving object RCs. Since it is known that object RCs are relatively rare compared to subject RCs (Hale, 2001), frequency may be the main reason for the lower performance. Interestingly, even when increasing the number of sentences with an object RC by eight times (more than twice of sentences with a subject RC), the accuracy does not reach the same level as agreement across a subject RC. This result suggests an inherent difficulty in tracking a syntactic state across an object RC for sequential neural architectures.
We finally provide an ablation study to understand the encoded linguistic knowledge in the models learned with the help of our method. We experiment under reduced supervision at two different levels: (1) at a lexical level, by not giving negative examples on verbs that appear in the test set; (2) at a construction level, by not giving negative examples about a particular construction, e.g., verbs after a subject RC. We observe no huge score drops by both. This suggests that our learning signals at a lexical level (negative words) strengthen the abstract syntactic knowledge about the target constructions, and also that the models can generalize the knowledge acquired by negative examples to similar constructions for which negative examples are not explicitly given. The result also implies that negative examples do not have to be complete and can be noisy, which will be appealing from an engineering perspective.
2 Target Task and Setup
The most common evaluation metric of an LM is perplexity. Although neural LMs achieve impressive perplexity (Merit et al., 2018), it is an average score across all tokens and does not inform the models' behaviors on linguistically challenging structures, which are rare in the corpus. This is the primary motivation to separately evaluate the models' syntactic robustness by a different task.
2.1 Syntactic evaluation task
As introduced in Section 1, the task for a model is to assign a higher probability to the grammatical sentence over the ungrammatical one, given a pair of minimally different sentences at a critical position affecting the grammaticality. For example, (1a) and (1b) only differ at a final verb form, and to assign a higher probability to (1a), models need
to be aware of the agreement dependency between author and laughs over an RC.
Marvin and Linzen (2018) test set While initial work (Linzen et al., 2016; Gulordava et al., 2018) has collected test examples from naturally occurring sentences, this approach suffers from the coverage issue, as syntactically challenging examples are relatively rare. We use the test set compiled by Marvin and Linzen (2018), which consists of synthetic examples (in English) created by a fixed vocabulary and a grammar. This approach allows us to collect varieties of sentences with complex structures.
The test set is divided by the syntactic constructions appearing in each example. Many constructions are different types of subject-verb agreement, including local agreement on different sentential positions (2), and non-local agreement across different types of phrases. Intervening phrases include prepositional phrases, subject RCs, object RCs, and coordinated verb phrases (3). (1) is an example of agreement across an object RC.
(2) The senators smile/\*smiles.
(3) The senators like to watch television shows and are/\*is twenty three years old.
Previous work has shown that non-local agreement is particularly challenging for sequential neural models (Marvin and Linzen, 2018).
The other patterns are reflexive anaphora dependencies between a noun and a reflexive pronoun (4), and on negative polarity items (NPIs), such as ever, which requires a preceding negation word (e.g., no and none) at an appropriate scope (5):
(4) The authors hurt themselves/\*himself.
(5) No/\*Most authors have ever been popular.
Note that NPI examples differ from the others in that the context determining the grammaticality of the target word (No/\*Most) does not precede it. Rather, the grammaticality is determined by the following context. As we discuss in Section 3, this property makes it difficult to apply training with negative examples for NPIs for most of the methods studied in this work.
All examples above (1-5) are actual test sentences, and we can see that since they are synthetic some may sound somewhat unnatural. The main argument behind using this dataset is that even not very natural, they are still strictly grammatical, and an LM equipped with robust syntactic abilities should be able to handle them as a human would
We use the original test set used in Marvin and Linzen (2018).<sup>1</sup> See the supplementary materials of this for the lexical items and example sentences in each construction.
2.2 Language models
Training data Following the practice, we train LMs on the dataset not directly relevant to the test set. Throughout the paper, we use an English Wikipedia corpus assembled by Gulordava et al. (2018), which has been used as training data for the present task (Marvin and Linzen, 2018; Kuncoro et al., 2019), consisting of  $80\mathrm{M} / 10\mathrm{M} / 10\mathrm{M}$  tokens for training/dev/test sets. It is tokenized and rare words are replaced by a single unknown token, amounting to the vocabulary size of 50,000.
Baseline LSTM-LM Since our focus in this paper is an additional loss exploiting negative examples (Section 3), we fix the baseline LM throughout the experiments. Our baseline is a three-layer LSTM-LM with 1,150 hidden units at internal layers trained with the standard cross-entropy loss. Word embeddings are 400-dimensional, and input and output embeddings are tied (Inan et al., 2016). Deviating from some prior work (Marvin and Linzen, 2018; van Schijndel et al., 2019), we train LMs at sentence level as in sequence-to-sequence models (Sutskever et al., 2014). This setting has been employed in some previous work (Kuncoro et al., 2018, 2019).
Parameters are optimized by SGD. For regularization, we apply dropout on word embeddings and outputs of every layer of LSTMs, with weight decay of 1.2e-6, and anneal the learning rate by 0.5 if the validation perplexity does not improve successively, checking every 5,000 mini-batches. Mini-batch size, dropout weight, and initial learning rate are tuned by perplexity on the dev set of Wikipedia dataset. Note that we tune these values for the baseline LSTM-LM and fix them across the experiments.
<sup>1</sup>We use the "EMNLP2018" templates in https://github.com/BeckyMarvin/LM_syneval.
2On the other hand, the LSTM-LM of Marvin and Linzen (2018), which is prepared by Gulordava et al. (2018), is trained at document level through truncated backpropagation through time (BPTT) (Mikolov et al., 2011). Since our training regime is more akin to the task setting of syntactic evaluation, it may provide some advantage at test time.
3Following values are found: mini-batch size: 128; initial learnin rate: 20.0; dropout weight on the word embedding layer and each output layer of LSTM: 0.1.
The size of our three-layer LM is the same as the state-of-the-art LSTM-LM at document-level (Merit et al., 2018). Marvin and Linzen (2018)'s LSTM-LM is two-layer with 650 hidden units and word embeddings. Comparing two, since the word embeddings of our models are smaller (400 vs. 650) the total model sizes are comparable (40M for ours vs. 39M for theirs). Nonetheless, we will see in the first experiment that our carefully tuned three-layer model achieves much higher syntactic performance than their model (Section 4), being a stronger baseline to our extensions, which we introduce next.
3 Learning with Negative Examples
Now we describe four additional losses for exploiting negative examples. The first two are existing ones, proposed for a similar purpose or under a different motivation. As far as we know, the latter two have not appeared in past work.<sup>4</sup>
We note that we create negative examples by modifying the original Wikipedia training sentences, not sentences in the test set. As a running example, let us consider the case where sentence (6a) exists in a mini-batch, from which we create a negative example (6b).
(6) a. An industrial park with several companies is located in the close vicinity.
b. * An industrial park with several companies are located in the close vicinity.
Notations By a target word, we mean a word for which we create a negative example (e.g., is). We distinguish two types of negative examples: a negative token and a negative sentence; the former means a single incorrect word (e.g., are), while the latter means an entire ungrammatical sentence.
3.1 Negative Example Losses
Binary-classification loss This is proposed by Enguehard et al. (2017) to complement a weak inductive bias in LSTM-LMs for learning syntax. It is multi-task learning across the cross-entropy loss  $(L_{lm})$  and an additional loss  $(L_{add})$ :
$$
L = L _ {l m} + \beta L _ {a d d}, \tag {1}
$$
where  $\beta$  is a relative weight for  $L_{add}$ . Given outputs of LSTMs, a linear and binary softmax layers
predict whether the next token is singular or plural.  $L_{add}$  is a loss for this classification, only defined for the contexts preceding a target token  $x_{i}$ :
$$
L _ {a d d} = \sum_ {x _ {1: i} \in \mathbf {h} ^ {*}} - \log p (\operatorname {n u m} (x _ {i}) | x _ {1: i - 1}),
$$
where  $x_{1:i} = x_1 \cdots x_i$  is a prefix sequence and  $\mathbf{h}^*$  is a set of all prefixes ending with a target word (e.g., An industrial park with several companies is) in the training data.  $\mathrm{num}(x) \in \{\text{singular}, \text{plural}\}$  is a function returning the number of  $x$ . In practice, for each mini-batch for  $L_{lm}$ , we calculate  $L_{add}$  for the same set of sentences and add these two to obtain a total loss for updating parameters.
As we mentioned in Section 1, this loss does not exploit negative examples explicitly; essentially a model is only informed of a key position (target word) that determines the grammaticality. This is rather an indirect learning signal, and we expect that it does not outperform the other approaches.
Unlikelihood loss This is recently proposed (Welleck et al., 2020) for resolving the repetition issue, a known problem for neural text generators (Holtzman et al., 2019). Aiming at learning a model that can suppress repetition, they introduce an unlikelihood loss, which is an additional loss at a token level and explicitly penalizes choosing words previously appeared in the current context.
We customize their loss for negative tokens  $x_{i}^{*}$  (e.g., are in (6b)). Since this loss is added at token-level, instead of Eq. 1 the total loss is  $L_{lm}$ , which we modify as:
$$
\sum_ {\mathbf {x} \in D} \sum_ {x _ {i} \in \mathbf {x}} - \log p (x _ {i} | x _ {1: i - 1}) + \sum_ {x _ {i} ^ {*} \in \operatorname {n e g} _ {t} (x _ {i})} g (x _ {i} ^ {*}),
$$
$$
g (x _ {i} ^ {*}) = - \alpha \log (1 - p (x _ {i} ^ {*} | x _ {1: i - 1})),
$$
where  $\mathrm{neg}_t(\cdot)$  returns negative tokens for a target  $x_{i}$ .  $\alpha$  controls the weight.  $\mathbf{x}$  is a sentence in the training data  $D$ . The unlikely loss strengthens the signal to penalize undesirable words in a context by explicitly reducing the likelihood of negative tokens  $x_{i}^{*}$ . This is a more direct learning signal than the binary classification loss.
Sentence-level margin loss We propose a different loss, in which the likelihoods for correct and incorrect sentences are more tightly coupled. As in
4The loss for large-margin language models (Huang et al., 2018) is similar to our sentence-level margin loss. Whereas their formulation is more akin to the standard large-margin setting, aiming to learn a reranking model, our margin loss is simpler, just comparing two log-likelihoods of predefined positive and negative sentences.
${}^{5}$  Empty for non-target tokens. It may return multiple tokens sometimes, e.g., themselves  $\rightarrow \{$  himself, herself  $\}$  .
the binary classification loss, the total loss is given by Eq. 1. We consider the following loss for  $L_{add}$ :
$$
\sum_ {\mathbf {x} \in D} \sum_ {\mathbf {x} _ {j} ^ {*} \in \mathrm {n e g} _ {s} (\mathbf {x})} \max (0, \delta - (\log p (\mathbf {x}) - \log p (\mathbf {x} _ {j} ^ {*}))),
$$
where  $\delta$  is a margin value between the log-likelihood of original sentence  $\mathbf{x}$  and negative sentences  $\{\mathbf{x}_j^*\}$ .  $\mathrm{neg}_s(\cdot)$  returns a set of negative sentences by modifying the original one. Note that we change only one token for each  $\mathbf{x}_j^*$ , and thus may obtain multiple negative sentences from one  $\mathbf{x}$  when it contains multiple target tokens (e.g., she leaves there but comes back ...).
Comparing to the unlikelihood loss, not only decreasing the likelihood of a negative example, this loss tries to guarantee a certain difference between the two likelihoods. The learning signal of this loss seems stronger in this sense; however, the token-level supervision is missing, which may provide a more direct signal to learn a clear contrast between correct and incorrect words. This is an empirical problem we pursue in the experiments.
Token-level margin loss Our final loss is a combination of the previous two, by replacing  $g(x_{i})$  in the unlikelihood loss by a margin loss:
$$
\begin{array}{l} g (x _ {i} ^ {*}) = \max (0, \delta - (\log p (x _ {i} | x _ {1: i - 1}) \\ - \log p (x _ {i} ^ {*} | x _ {1: i - 1})). \\ \end{array}
$$
We will see that this loss is the most advantageous in the experiments (Section 4).
3.2 Parameters
Each method employs a few additional hyperparameters ( $\beta$  for the binary classification loss,  $\alpha$  for the unlikelihood loss, and  $\delta$  for the margin losses). We preliminary select  $\beta$  and  $\alpha$  from  $\{1, 10, 100, 1000\}$  that achieve the best average syntactic performance and find  $\beta = 1$  and  $\alpha = 1000$ . For the two margin losses, we fix  $\beta = 1.0$  and  $\alpha = 1.0$  and only see the effects of margin value  $\delta$ .
3.3 Scope of Negative Examples
Since our goal is to understand to what extent LMs can be sensitive to the target syntactic constructions by giving explicit supervision via negative examples, we only prepare negative examples on the constructions that are directly tested at evaluation. Specifically, we mark the following words in the training data, and create negative examples:
Present verb To create negative examples on subject-verb agreement, we mark all present verbs and change their numbers.7
Reflexive pronoun We also create negative examples on reflexive anaphora, by flipping between  $\{\text{themselves}\} \leftrightarrow \{\text{himself},\text{herself}\}$ .
These two are both related to the syntactic number of a target word. For binary classification we regard both as a target word, apart from the original work that only deals with subject-verb agreement (Enguehard et al., 2017). We use a single common linear layer for both constructions.
In this work, we do not create negative examples for NPIs. This is mainly for technical reasons. Among four losses, only the sentence-level margin loss can correctly handle negative examples for NPIs, essentially because other losses are token-level. For NPIs, left contexts do not have information to decide the grammaticality of the target token (a quantifier; no, most, etc.) (Section 2.1). Instead, in this work, we use NPI test cases as a proxy to see possible negative (or positive) impacts as compensation for specially targeting some constructions. We will see that in particular for our margin losses, such negative effects are very small.
4 Experiments on Additional Losses
We first see the overall performance of baseline LSTM-LMs as well as the effects of additional losses. Throughout the experiments, for each setting, we train five models from different random seeds and report the average score and standard deviation. The code is available at https://github.com/aistairc/lm Syntax_negative.
Naive LSTM-LM performs well The main accuracy comparison across target constructions for different settings is presented in Table 1. We first
In principle, one can cumulate this loss within a single mini-batch for  $L_{lm}$  as we do for the binary-classification loss. However, obtaining  $L_{add}$  needs to run an LM entirely on negative sentences as well, which demands a lot of GPU memories. We avoid this by separating mini-batches for  $L_{lm}$  and  $L_{add}$ . We precompute all possible pairs of  $(\mathbf{x},\mathbf{x}_j^*)$  and create a mini-batch by sampling from them. We make the batch size for  $L_{add}$  (the number of pairs) as the half of that for  $L_{lm}$ , to make the number of sentences contained in both kinds of batches equal. Finally, in each epoch, we only sample at most the half mini-batches of those for  $L_{lm}$  to reduce the total amount of training time.
<sup>7</sup>We use Stanford tagger (Toutanova et al., 2003) to find the present verbs. We change the number of verbs tagged by VBZ or VBP using inflect.py (https://pypi.org/project/inflect/).