<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/" rel="alternate" type="text/html" /><updated>2026-02-17T13:05:39+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/feed.xml</id><title type="html">StatNLP Heidelberg</title><subtitle>Statistical NLP Group at Heidelberg University, Germany</subtitle><author><name>StatNLP Group</name><email>statnlpgroup@cl.uni-heidelberg.de</email></author><entry><title type="html">RL in NMT: The Good, the Bad and the Ugly</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/rl4nmt/" rel="alternate" type="text/html" title="RL in NMT: The Good, the Bad and the Ugly" /><published>2020-01-16T00:00:00+00:00</published><updated>2020-01-16T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/rl-nmt</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/rl4nmt/">&lt;!--# RL in NMT: the Good, the Bad and the Ugly--&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/horse_small.png&quot; alt=&quot;image-right&quot; class=&quot;align-right&quot; /&gt; Let me introduce you to three popular practices for using reinforcement learning (RL) in neural machine translation (NMT): &lt;strong&gt;the Good&lt;/strong&gt;, combining it with good old maximum likelihood estimation (MLE), &lt;strong&gt;the Ugly&lt;/strong&gt;, combining it with “hacks”, and &lt;strong&gt;the Bad&lt;/strong&gt;, applying it with ignorance of more evolved techniques. Those three are helping NMT researchers on the hunt for BLEU scores.&lt;/p&gt;

&lt;p&gt;Western movies aside, the aim of this blogpost is to take a critical look at the recent trend to include RL-inspired objectives in NMT training. We’ll start with a &lt;a href=&quot;#the-basics&quot;&gt;recap&lt;/a&gt; of RL training in NMT, dive right into an empirical study by &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt;, leading to the discussion of the three following questions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;How do &lt;a href=&quot;#nmt-as-an-rl-problem&quot;&gt;NMT and RL&lt;/a&gt; fit together?&lt;/li&gt;
  &lt;li&gt;Why do we even get any benefits from an &lt;a href=&quot;#rl-to-the-rescue&quot;&gt;RL objective in supervised learning&lt;/a&gt;?&lt;/li&gt;
  &lt;li&gt;Where can we find the &lt;a href=&quot;#beyond-supervised-learning&quot;&gt;real challenges&lt;/a&gt;?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; RL is a popular first-aid method to fix supervised NMT training, but maybe not the most suitable one. RL shines outside supervised learning; new challenges and opportunities are to be found there.&lt;/p&gt;

&lt;h2 id=&quot;the-basics&quot;&gt;The Basics&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Introducing RL to incorporate rewards.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;Maximum Likelihood Estimation&lt;/h3&gt;

&lt;p&gt;Standard auto-regressive NMT models, parametrized by a neural network with parameters &lt;script type=&quot;math/tex&quot;&gt;\theta&lt;/script&gt;, are trained with &lt;strong&gt;maximum likelihood estimation&lt;/strong&gt; on parallel data &lt;script type=&quot;math/tex&quot;&gt;(x, y) \in \mathcal{D}&lt;/script&gt; resulting in the popular cross-entropy objective:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align} \text{MLE} &amp;= \sum_{(x,y) \in D} \log p_{\theta}(y \mid x) \end{align} %]]&gt;&lt;/script&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;Expected Reward&lt;/h3&gt;

&lt;p&gt;So how does RL come into play? The idea is to introduce rewards to encourage model outputs that would obtain a high reward, not only the perfect reference translation (=MLE). In practice, rewards can be simulated with e.g., sentence-level BLEU scores, to reinforce samples that – if evaluated – would obtain a high BLEU score. You might ask yourself, why is it even necessary? We’ll discuss that in &lt;a href=&quot;#nmt-as-an-rl-problem&quot;&gt;a bit&lt;/a&gt;. Assuming the existence of such scalar rewards obtained from &lt;script type=&quot;math/tex&quot;&gt;R: \mathcal{Y} \to [0,1]&lt;/script&gt; we can formulate an objective that aims to maximize the &lt;strong&gt;expected reward&lt;/strong&gt; for all model outputs:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align} \text{RL} &amp;= \mathbb{E}_{p_{\theta}(y \mid x)} \left[ R(y) \right] \end{align} %]]&gt;&lt;/script&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;Policy Gradient&lt;/h3&gt;

&lt;p&gt;In contrast to the MLE objective, the RL objective is not differentiable with respect to &lt;script type=&quot;math/tex&quot;&gt;\theta&lt;/script&gt;, because the reward is a discrete function of the outputs of the model. Luckily, with the help of the &lt;a href=&quot;http://blog.shakirm.com/2015/11/machine-learning-trick-of-the-day-5-log-derivative-trick/&quot;&gt;&lt;strong&gt;log-derivative trick&lt;/strong&gt;&lt;/a&gt;, we can reformulate the gradient for this objective, also referred to as the &lt;strong&gt;policy gradient&lt;/strong&gt;:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align} \nabla_{\theta} \text{RL} &amp;= \mathbb{E}_{p_{\theta}(y \mid x)} \left[ R(y) \nabla_{\theta} \log p_{\theta}(y \mid x)\right] \end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;We can now empirically &lt;strong&gt;estimate&lt;/strong&gt; the gradient with e.g. Monte Carlo sampling and train our model with stochastic gradient ascent. This solution was introduced in the famous &lt;strong&gt;REINFORCE&lt;/strong&gt; algorithm by &lt;a href=&quot;http://www-anw.cs.umass.edu/~barto/courses/cs687/williams92simple.pdf&quot;&gt;J. Williams 1992&lt;/a&gt;. REINFORCE proposes to estimate the gradient with one sample for each input:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align} \tilde{\nabla}_{\theta} \text{RL} &amp;= R(\tilde{y}) \nabla_{\theta} \log p_{\theta}(\tilde{y} \mid x),&amp; \tilde{y} \sim p_{\theta}(y \mid x) \end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;How does this bring us to RL? In RL, more precisely in policy search, &lt;script type=&quot;math/tex&quot;&gt;p_{\theta}&lt;/script&gt; is a policy that predicts actions &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt;. The policy chooses one action and then receives a reward for this action from the environment. Importantly, it is not possible to go back and try other actions instead and compare their rewards. In a genuine RL setup, we are limited to &lt;strong&gt;single-sample&lt;/strong&gt; estimates.&lt;/p&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;Training&lt;/h3&gt;

&lt;p&gt;The current practice in NMT is to approximate the policy gradient with either multinomial sampling from the softmax-normalized outputs of the NMT model, or by beam search. 
The two objectives are trained either sequentially (e.g., supervised pre-training before reinforced fine-tuning, or alternating batches) or simultaneously (e.g., by linear interpolation).&lt;/p&gt;

&lt;h2 id=&quot;discussing-recent-trends-of-rl-in-nmt&quot;&gt;Discussing Recent Trends of RL in NMT&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;If we care about BLEU, RL alone won’t help.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the recent EMNLP paper “A Study of RL for NMT” &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 18&lt;/a&gt; observe that RL-inspired training objectives have been shown to improve NMT quality, but usually don’t come without tricks and rather weak baselines. Their question is now: Combining various variants of these tricks with learning from monolingual data, does RL still shine as expected?&lt;/p&gt;

&lt;p&gt;To spoil the suspense right away, the study finds that using RL leads to marginal improvements over well-tuned baselines, also in combination with MLE and monolingual data (&lt;strong&gt;the good&lt;/strong&gt;). However, the largest portions of improvement come from leveraging additional monolingual data (old news) (&lt;strong&gt;the ugly&lt;/strong&gt;). But the RL-inspired approaches evaluated here lack comparisons to more evolved techniques, and assume access to reference translations (&lt;strong&gt;the bad&lt;/strong&gt;). Let’s take a closer look!&lt;/p&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;RL Tricks&lt;/h3&gt;

&lt;h4 class=&quot;no_toc&quot;&gt;Variance Reduction&lt;/h4&gt;

&lt;p&gt;The variance of the &lt;a href=&quot;#policy-gradient&quot;&gt;gradient estimator&lt;/a&gt; &lt;strong&gt;can&lt;/strong&gt; be a problem for optimization, i.e. slow down or hinder convergence. The paper investigates the following solutions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Average reward baseline: Instead of using the reward directly, subtract its empirical average from the reward obtained.&lt;/li&gt;
  &lt;li&gt;Learned baseline: Subtract a learned reward instead of the empirical average. The learned reward is the output of a regression model, e.g. another neural network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The baseline was actually already proposed in the original REINFORCE paper and can be interpreted as an additive control variate (&lt;a href=&quot;https://www.elsevier.com/books/simulation/ross/978-0-12-415825-2&quot;&gt;Ross 2013&lt;/a&gt;).
Actor-critic (AC) approaches go a step further and replace the reward obtained by the environment by a reward given by a critic that is trained to imitate the original reward (applied to NMT by e.g. &lt;a href=&quot;https://arxiv.org/abs/1607.07086&quot;&gt;Bahdanau et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1707.07402&quot;&gt;Ngyuen et al. 2017&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Despite the reported effectiveness in practice, &lt;a href=&quot;http://jmlr.csail.mit.edu/papers/volume5/greensmith04a/greensmith04a.pdf&quot;&gt;Greensmith et al. 2004&lt;/a&gt; showed that both above solutions are suboptimal and that one can actually &lt;strong&gt;learn&lt;/strong&gt; an optimal baseline with minimal variance.&lt;/p&gt;

&lt;p&gt;One important aspect that has been completely neglected in the present study is that the number of samples used for the Monte Carlo gradient estimate has an essential influence of the variance of the gradient. If rewards are simulated anyway, e.g., from references using sentence-level BLEU, why not sample multiple times and average the gradients over this subset? This may sound familiar, since this is exactly what is done in &lt;strong&gt;minimum risk training&lt;/strong&gt; (proposed for NMT by &lt;a href=&quot;https://arxiv.org/abs/1512.02433&quot;&gt;Shen et al. 2016&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;In &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt;’s empirical study, there was no beneficial effect observed when using the learned baseline. This contradicts with the experience in e.g., &lt;a href=&quot;https://arxiv.org/abs/1607.07086&quot;&gt;Bahdanau et al. 2017&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1704.06497&quot;&gt;Kreutzer et al. 2017&lt;/a&gt;. The conclusion that reward baselines are not necessary from “the economic perspective” (&lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt;) might be a bit overhasty.&lt;/p&gt;

&lt;h4 class=&quot;no_toc&quot;&gt;Reward Shaping&lt;/h4&gt;

&lt;p&gt;If the reward is only obtained at the end of each sequence (here: translation), how does the model know where the errors are? The problem of &lt;a href=&quot;https://scholarworks.umass.edu/dissertations/AAI8410337/&quot;&gt;credit assignment&lt;/a&gt; is often addressed by introducing methods for reward shaping (&lt;a href=&quot;https://people.eecs.berkeley.edu/~pabbeel/cs287-fa09/readings/NgHaradaRussell-shaping-ICML1999.pdf&quot;&gt;Ng et al. 1999&lt;/a&gt;).
&lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt; investigate the implementation by &lt;a href=&quot;https://arxiv.org/abs/1607.07086&quot;&gt;Bahdanau et al. 2017&lt;/a&gt;: For each element of the output, the individual reward is the difference between the BLEU score for the partial output including and the BLEU score for the partial output excluding the element: &lt;script type=&quot;math/tex&quot;&gt;R(y_t) = R(y_{1:t}) - R(y_{1:t-1})&lt;/script&gt;. Note that the BLEU scores are computed with respect to the full reference output. Once again the references are exploited to &lt;strong&gt;simulate&lt;/strong&gt; the rewards.&lt;/p&gt;

&lt;p&gt;But does this even address the original problem of credit assignment? The problem arose because we had to wait for rewards from the environment until we completed a sequence of actions (in NMT: produced a complete translation). As soon as &lt;strong&gt;references&lt;/strong&gt; are used, we are in principle not restricted to delayed rewards anymore. One could for example compare each word in the translation to the words in the reference translation and then come up with a token-based reward. Simple binary rewards were for example proposed in &lt;a href=&quot;https://arxiv.org/abs/1806.07169&quot;&gt;Petrushkov et al. 2018&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As long as we simulate the rewards using references, we can cheat our way around the real problem.
When references are not available and you simply cannot compute BLEU scores for any arbitrary, partial translation – what would you do?&lt;/p&gt;

&lt;p&gt;To this end &lt;a href=&quot;https://arxiv.org/abs/1707.07402&quot;&gt;Ngyuen et al. 2017&lt;/a&gt; adopt the advantage-actor critic (A2C) framework (&lt;a href=&quot;http://proceedings.mlr.press/v48/mniha16.pdf&quot;&gt;Mnih et al. 2016&lt;/a&gt;). A critic network predicts the expected future reward for each element, although the reward from the environment (here: BLEU) is only obtained at the end of the sequence. Unfortunately, the latter study does not include a comparison to RL approaches without reward shaping.&lt;/p&gt;

&lt;p&gt;The empirical gains from reward shaping reported in &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt;’s study are diminishingly small which leaves the question of the usefulness of this method unanswered.&lt;/p&gt;

&lt;h3 class=&quot;no_toc&quot;&gt;Using Monolingual Data&lt;/h3&gt;

&lt;h4 class=&quot;no_toc&quot;&gt;Target-side&lt;/h4&gt;

&lt;p&gt;Leveraging monolingual data for improving MT systems has become increasingly popular, since simple methods have shown to be very effective for NMT. When target-side monolingual data is available, the trick-of-the-trade is to use back-translation as demonstrated in &lt;a href=&quot;https://arxiv.org/abs/1511.06709&quot;&gt;Sennrich et al. 2016&lt;/a&gt;. The only burden here is here one has to train a system in the opposite translation direction. This system can then generate &lt;strong&gt;pseudo-sources&lt;/strong&gt; for the available target data. The &lt;a href=&quot;https://arxiv.org/abs/1806.04402&quot;&gt;“hallucinated”&lt;/a&gt; parallel data can then be used for standard training, with simulated rewards or without.&lt;/p&gt;

&lt;p&gt;But isn’t it problematic to feed the NMT with fake data? Apparently not, at least as long as the targets are intact. &lt;a href=&quot;https://arxiv.org/pdf/1808.09381.pdf&quot;&gt;Edunov et al. 2018a&lt;/a&gt; investigate this question systematically and surprisingly find that models get even better when the pseudo-sources are of low quality (not for small data, though). They hypothesize that the noise introduced actually enriches the training data and helps learning as e.g., in &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1390294&quot;&gt;denoising auto-encoders&lt;/a&gt;.&lt;/p&gt;

&lt;h4 class=&quot;no_toc&quot;&gt;Source-side&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt; propose to leverage not only target-side monolingual data, but also source-side monolingual data.
Evoking techniques developed in the context of &lt;a href=&quot;http://ruder.io/semi-supervised/index.html#selftraining&quot;&gt;self-training&lt;/a&gt;, the idea is to let the model generate &lt;strong&gt;pseudo-targets&lt;/strong&gt; for its own training. We have to assume that it is able to generate targets that are “good enough”, in the sense that the model can bootstrap itself. In practice, this is addressed by using beam search decoding for generating translations that are likely to have higher quality than sampled or greedy decoded targets.&lt;/p&gt;

&lt;p&gt;Does the quality of the pseudo-targets matter? When they are part of the RL objective, they are only used to simulate rewards for sampled translations, which perhaps can absorb some of the noise. In supervised MLE training &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt; add them to the much larger original parallel data – the small amount of extra noise might be negligible. However, this has not been investigated systematically.&lt;/p&gt;

&lt;h2 id=&quot;nmt-as-an-rl-problem&quot;&gt;NMT as an RL problem&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;We only (mis-)use a subset of RL methods in NMT.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The “Study of RL in NMT” is limited to a very specific scenario where policy gradient is used for fine-tuning of well-trained models. What about other RL algorithms? RL researchers have in fact dealt with reinforced objectives as above for decades and have developed more sophisticated training algorithms (such as &lt;a href=&quot;https://arxiv.org/abs/1502.05477&quot;&gt;Trust Region Policy Optimization&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1707.06347&quot;&gt;Proximal Policy Optimization&lt;/a&gt;) than vanilla policy gradient. But that’s to be discussed in another blog post. 
Nevertheless, so far only policy gradient and actor-critic have become really popular for structured prediction tasks. So what’s wrong, are we just slow in adopting their algorithms?&lt;/p&gt;

&lt;p&gt;In fact, it is not trivial to cast NMT, or more general structured prediction, as a standard (PO)MDP problem which is the basis for most RL algorithms: What is the environment? What is the state? Where does the reward come from? Translation researchers don’t agree on it (comparing e.g. definitions in &lt;a href=&quot;https://arxiv.org/abs/1808.08866&quot;&gt;Wu et al. 2018&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1707.07402&quot;&gt;Ngyuen et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1607.07086&quot;&gt;Bahdanau et al. 2017&lt;/a&gt;). It is in fact often more suitable to cast it as a simpler contextual bandit problem, aka &lt;strong&gt;bandit structured prediction&lt;/strong&gt; (e.g., &lt;a href=&quot;http://papers.nips.cc/paper/6133-stochastic-structured-prediction-under-bandit-feedback&quot;&gt;Sokolov et al. 2016&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1704.06497&quot;&gt;Kreutzer et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://openreview.net/forum?id=HJNMYceCW&quot;&gt;Daumé III et al. 2018&lt;/a&gt;), as Hal Daumé III discussed in &lt;a href=&quot;https://nlpers.blogspot.com/2017/04/structured-prediction-is-not-rl.html&quot;&gt;his blogpost on structured prediction and RL&lt;/a&gt; – you may see it as a one-state MDP.&lt;/p&gt;

&lt;p&gt;What we can agree on is that in NMT we’re dealing with large and structured action spaces, where actions are discrete and rewards are sparse (and most of the time delayed) and potentially noisy. This calls for algorithms that are particularly suited for those methods, but neither REINFORCE nor AC address these issues in particular.&lt;/p&gt;

&lt;p&gt;In fact, training NMT from scratch with pure RL objectives, i.e. &lt;a href=&quot;https://arxiv.org/abs/1709.09346&quot;&gt;&lt;strong&gt;cold-start&lt;/strong&gt; RL&lt;/a&gt;, has so far not succeeded (despite &lt;a href=&quot;https://arxiv.org/abs/1611.00179&quot;&gt;Xia et al. 2016&lt;/a&gt;’s optimism).&lt;/p&gt;

&lt;h2 id=&quot;rl-to-the-rescue&quot;&gt;RL to the rescue?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;RL can improve NMT because it fixes problems of our standard objective.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What’s wrong with MLE training for NMT? &lt;a href=&quot;https://arxiv.org/abs/1511.06732&quot;&gt;Ranzato et al. 2016&lt;/a&gt; elaborated on this when proposing the MIXER algorithm that mixes policy gradient-style updates with MLE. They identify the following problems:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Exposure bias: During training reference targets are fed to the model (=teacher forcing), while during inference the model has to produce outputs based on its own previous outputs.&lt;/li&gt;
  &lt;li&gt;Token-level objective (aka “loss-evaluation mismatch” in &lt;a href=&quot;https://arxiv.org/pdf/1606.02960.pdf&quot;&gt;Wiseman and Rush 2016&lt;/a&gt;): In standard autoregressive NMT models, the sequence-level &lt;a href=&quot;#maximum-likelihood-estimation&quot;&gt;log-likelihood&lt;/a&gt; is decomposed as sum over token-level log-likelihoods. The training hence is optimized to finding the next perfect output token given the previous perfect token. During inference, however, we’re measuring the model’s quality with metrics like BLEU that evaluate whole sequences of outputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Algorithms like scheduled sampling (&lt;a href=&quot;https://arxiv.org/abs/1506.03099&quot;&gt;Bengio et al. 2015&lt;/a&gt;), DAgger (&lt;a href=&quot;https://arxiv.org/abs/1011.0686&quot;&gt;Ross et al. 2011&lt;/a&gt;) and DAD (&lt;a href=&quot;https://www.ri.cmu.edu/pub_files/2015/1/Venkatraman.pdf&quot;&gt;Venkatraman et al. 2015&lt;/a&gt;) have been designed to reduce the exposure bias by gradually exposing the model with its own outputs during training (&lt;strong&gt;imitation learning&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;The same effect is obtained when including some policy gradient in the training objective (e.g. in MIXER, MRT), since the gradient update is based on the log-likelihood of the model’s own output. It is directly optimized towards a sentence-level reward that is closer to the corpus BLEU we’re evaluating our models with. Furthermore, it can help with other non-differentiable objectives than the &lt;a href=&quot;#expected-reward&quot;&gt;expected reward&lt;/a&gt;, e.g., for adversarial training (&lt;a href=&quot;https://arxiv.org/pdf/1704.06933.pdf&quot;&gt;Wu et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1703.04887&quot;&gt;Yang et al. 2017&lt;/a&gt;. Or you might just use it to teach the NMT system what you actually want from it (beyond generating translations close to the reference), e.g., copying certain words of the input &lt;a href=&quot;https://arxiv.org/pdf/1809.03182.pdf&quot;&gt;Pham et al. 2018&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Large gains using RL have been reported under domain shift, i.e., gains over baseline models that are not fine-tuned on the evaluation domain (e.g., &lt;a href=&quot;https://arxiv.org/abs/1704.06497&quot;&gt;Kreutzer et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1806.07169&quot;&gt;Petrushkov et al. 2018&lt;/a&gt;) or when combined with classic objectives (e.g., &lt;a href=&quot;https://arxiv.org/abs/1609.08144&quot;&gt;Wu et al. 2016&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1511.06732&quot;&gt;Ranzato et al. 2016&lt;/a&gt;). The above discussed paper demonstrates that without these factors, expected improvements vanish.&lt;/p&gt;

&lt;p&gt;Most commonly, RL is exploited as a first aid for obvious MLE problems, in a fully-supervised setting where references are available and rewards are &lt;strong&gt;simulated&lt;/strong&gt;. 
Why not use (or at least compare against) other training strategies that may be better suited for NMT and fix the above problems equally, as proposed e.g., in &lt;a href=&quot;https://arxiv.org/abs/1711.04956&quot;&gt;Edunov et al. 2018b&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1512.02433&quot;&gt;Shen et al. 2016&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1609.00150&quot;&gt;Norouzi et al. 2016&lt;/a&gt;?&lt;/p&gt;

&lt;h2 id=&quot;beyond-supervised-learning&quot;&gt;Beyond supervised learning&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The challenges in RL for NLP lie outside supervised learning.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So what about more realistic uses of RL, e.g., where rewards cannot simply be simulated, or reward signals are not given as well-defined functions, or not available in unlimited amounts? In NLP, the following scenarios are evident:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Gold standard structures may not be available because of the &lt;strong&gt;cost or the lack of expertise&lt;/strong&gt; of human annotators. Weaker signals such as human judgments on the quality of output structures may be easier to obtain and may require less expertise. This is the case for example in semantic parsing (&lt;a href=&quot;https://arxiv.org/abs/1805.01252&quot;&gt;Lawrence at al. 2018&lt;/a&gt;) or in machine translation (&lt;a href=&quot;https://arxiv.org/abs/1805.10627&quot;&gt;Kreutzer et al. 2018b&lt;/a&gt;).&lt;/li&gt;
  &lt;li&gt;In genuinely &lt;strong&gt;interactive&lt;/strong&gt; settings where a system directly interacts with a human, the human responses can be interpreted as a weak signal how to further improve the system. A prime example is dialogue, where learning from human feedback has successfully been implemented to train systems e.g., for small-talk (&lt;a href=&quot;https://arxiv.org/abs/1709.02349&quot;&gt;Serban et al. 2017&lt;/a&gt;) and task-oriented dialogue (&lt;a href=&quot;https://arxiv.org/abs/1606.02689&quot;&gt;Su et al. 2016&lt;/a&gt;).&lt;/li&gt;
  &lt;li&gt;Systems that need to be heavily &lt;strong&gt;customized&lt;/strong&gt; towards a user or domain. User preferences or ratings (that usually come for free) can be used to specifically adapt the system. In industrial settings, large-scale collections of feedback have been utilised in personalized news recommendation (&lt;a href=&quot;https://dl.acm.org/citation.cfm?doid=1772690.1772758&quot;&gt;Li et al. 2010&lt;/a&gt;) or e-commerce translations systems (&lt;a href=&quot;https://arxiv.org/abs/1804.05958&quot;&gt;Kreutzer et al. 2018a&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These scenarios bring challenges that can only partly be addressed by simulations and arise from the interaction with humans in real-life scenarios. 
The human factor entails several differences to the popular simulation scenarios of RL. Firstly, human rewards are not well-defined functions, but complex and inconsistent signals. Secondly, humans cannot be expected to provide feedback for unlimited amounts of outputs. Exciting challenges (&lt;a href=&quot;https://www.alexirpan.com/2018/02/14/rl-hard.html&quot;&gt;“RL is hard”&lt;/a&gt;) like the collection of reliable feedback, building robustness against adversarial feedback, fair evaluation, and off-policy learning, are ahead of us!&lt;/p&gt;

&lt;p&gt;So instead of asking the question “How to get high BLEU with RL-objectives?” let’s move to “How to learn from rewards with RL when we depend on them?”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Languages: Thanks to &lt;a href=&quot;https://tobiaslee.top/&quot;&gt;Lei Li&lt;/a&gt; for translating this post into &lt;a href=&quot;https://zhuanlan.zhihu.com/p/101324828&quot;&gt;Chinese&lt;/a&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Carolin Lawrence, Stefan Riezler and Jasmijn Bastings for their valuable and much needed feedback for improving this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of her affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. We appreciate your feedback! If you want to cite this blogpost, use this &lt;a href=&quot;/statnlpgroup/bibtex/rl-nmt.bibtex&quot;&gt;bibfile&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;</content><author><name>Julia</name></author><category term="blog" /><category term="policy gradient" /><category term="expected reward" /><category term="monolingual data" /><category term="future challenges" /><category term="sampling" /><category term="BLEU" /><category term="reinforcement learning" /><category term="neural machine translation" /><category term="exposure bias" /><summary type="html">Discussing good, bad and ugly practices of reinforcement learning in neural machine translation.</summary></entry><entry><title type="html">Translating Middle Egyptian Hieroglyphs</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/egyptian/" rel="alternate" type="text/html" title="Translating Middle Egyptian Hieroglyphs" /><published>2019-10-29T00:00:00+00:00</published><updated>2019-10-29T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/egyptian</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/egyptian/">&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;I want to welcome you with a warmhearted
&lt;img src=&quot;/statnlpgroup/images/blog/2019-10-egyptian-5bcec701.png&quot; alt=&quot;&quot; class=&quot;mh-46&quot; /&gt;
which means&lt;/p&gt;

&lt;p&gt;‘Your heart my be unscathed’&lt;/p&gt;

&lt;p&gt;in Middle Egyptian around 5000 years ago and can simply be interpreted as&lt;/p&gt;

&lt;p&gt;‘Hello’ 😙&lt;/p&gt;

&lt;p&gt;I hope, you’re now also curious to read about the steps that we did to translate a lot of Middle Egyptian resources. So, enjoy and read on!&lt;/p&gt;

&lt;h2 id=&quot;once-upon-a-time-in-egypt&quot;&gt;Once upon a time in Egypt…&lt;/h2&gt;
&lt;p&gt;For this post, I decided to put the disclaimer early on: We’re actually not translating hieroglyphs into concurrent language by their visual appearance. The signs, that I’ve welcomed you with, are Middle Egyptian graphemes that developed from pictograms. They were used in Ancient Egypt from around 3200 BCE to the 500th century of our common era. So, it’s definitely one of the longest writing traditions out there. But these symbols, which you can observe on the remains of tomb walls and temples, were not used for letters, administrative or legal documents. For these occasions, instead, the forms of &lt;em&gt;cursive hieroglyphs&lt;/em&gt;, &lt;em&gt;hieratic&lt;/em&gt; and &lt;em&gt;demotic&lt;/em&gt; emerged, the latter to be considered as an independent language. Coming back to my disclaimer from above: We have our multiple writing forms of the hieroglyphs (not &lt;em&gt;demotic&lt;/em&gt; actually as it is not &lt;em&gt;Middle Egyptian&lt;/em&gt; exactly), but we have it in an &lt;em&gt;encoded&lt;/em&gt; format: This encoding is based on the monumental research work of Sir Alan Gardiner:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Source&lt;/th&gt;
      &lt;th&gt;Data&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Hieroglyph&lt;/td&gt;
      &lt;td&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-10-egyptian-b57c3f05.png&quot; alt=&quot;&quot; class=&quot;mh-46&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Encoding&lt;/td&gt;
      &lt;td&gt;H6 G43 M17 M17 X1 N5 Z1 G17 D4 G17 H6 Z7 N5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Transcription&lt;/td&gt;
      &lt;td&gt;šw,yt m jri̯ m šwi&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Part-of-speech tags&lt;/td&gt;
      &lt;td&gt;substantive verb verb preposition substantive&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Word-level translation&lt;/td&gt;
      &lt;td&gt;shadow , not be as sun&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Interpreted translation&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Shade, don't be as the blazing sun&lt;/code&gt; (by Mark-Jan Nederhof)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;So, we actually have some character/number combinations that map the hieroglyphs to a more manageable code. This originally comes from grouping the signs to semantic categories. Also, the table mirrors a further source: It’s called a &lt;code class=&quot;highlighter-rouge&quot;&gt;transliteration&lt;/code&gt; from an Egyptologist’s point of view, but we actually treated it as a source of &lt;code class=&quot;highlighter-rouge&quot;&gt;transcription&lt;/code&gt;. This circumscription of the hieroglyphs once was a method to publish Ancient Egyptian resources. But it also represents the translator’s interpretation of word/sentence boundaries and insertion of missing signs. Although, vowels are not reflected within the hieroglyphs, the consonantic transliteration alphabet is expressive enough to consider it as kind of transcription. That’s amazing, as we will then apply machine translation methods from both AST (Automated Speech Translation) and NMT (Neural Machine Translation). For our corpus, that we thankfully received in corporation with the &lt;a href=&quot;http://aaew.bbaw.de/tla/servlet/S05?d=d001&amp;amp;h=h001&quot;&gt;Thesaurus Linguae Aegyptia&lt;/a&gt; project, we also have access to the part-of-speech tagging. Sounds good, right? But the whole parallel corpus consisted only of around 30.000 pairs. So we dealt with a pretty tough low resource scenario.&lt;/p&gt;

&lt;h2 id=&quot;how-to-exploit-all-these-resources&quot;&gt;How to exploit all these resources?&lt;/h2&gt;
&lt;p&gt;We experimented with several techniques, called Backtranslation (NMT) and Pipeline models (AST) as viable opponents to our best player: Multi Task Learning. Here is short introduction of the three guys:&lt;/p&gt;

&lt;h3 id=&quot;pipeline-model&quot;&gt;Pipeline Model&lt;/h3&gt;
&lt;p&gt;This setup is really close to the human approach to translate Middle Egyptian texts: First train an Encoder/Decoder Model that learns to translates &lt;em&gt;hieroglyphs&lt;/em&gt; &lt;script type=&quot;math/tex&quot;&gt;\to&lt;/script&gt; &lt;em&gt;transcription&lt;/em&gt;. In parallel we also train a model from &lt;em&gt;transcription&lt;/em&gt; &lt;script type=&quot;math/tex&quot;&gt;\to&lt;/script&gt; &lt;em&gt;translation&lt;/em&gt;. We can then translate any Egyptian Text by first generating the transcription and afterwards using this output to generate translations - just like Egyptologists do it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-10-egyptian-386d1fc9.png&quot; alt=&quot;pipeline.png&quot; class=&quot;mw-500 align-center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;backtranslation&quot;&gt;Backtranslation&lt;/h3&gt;
&lt;p&gt;Backtranslation is a famous tool when dealing with low resources: One first trains a backward model on the available data that translates from the target language to the source language. After that, one can take any additional (best: in-domain) target language corpus and backtranslate into the source language - and voilá: There’s our additional data that we can use to train our main system! In our case, we were faced with a very special situation: The database that our corpus was extracted from is filled &lt;em&gt;reversely&lt;/em&gt;: The TLA first input the translation and other sources and have not yet finished integrating the Gardiner encoding. This means that on the one hand, we were missing an amount of 60.000 Egyptian encodings, but at least could use the available target sources to actually backtranslate them. We did that and added parts of these “synthetic” sentences bit by bit to the parallel corpus to evaluate if that helped our system to learn.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-10-egyptian-0b4b36b8.png&quot; alt=&quot;back.png&quot; class=&quot;mw-500 align-center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;multi-task-learning&quot;&gt;Multi Task Learning&lt;/h3&gt;
&lt;p&gt;Last, but not in the very least, we implemented a multi tasking schedule. This technique originates from human learning: When tackling a difficult problem, it might help to&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;first learn a simpler problem (e.g. creating word boundaries before translating)&lt;/li&gt;
  &lt;li&gt;deal with a related problem, that helps to generalize the solution of the main problem (e.g. POS tagging before translating)
And this is exactly how we could exploit our data sparsity! So, we implemented a schedule within our training that switched from translating &lt;em&gt;hieroglyphs&lt;/em&gt; &lt;script type=&quot;math/tex&quot;&gt;\to&lt;/script&gt; &lt;em&gt;transcription&lt;/em&gt; to, let’s say, &lt;em&gt;transcription&lt;/em&gt; &lt;script type=&quot;math/tex&quot;&gt;\to&lt;/script&gt; &lt;em&gt;hieroglyphs&lt;/em&gt; or &lt;em&gt;hieroglyphs&lt;/em&gt; &lt;script type=&quot;math/tex&quot;&gt;\to&lt;/script&gt; &lt;em&gt;pos-tags&lt;/em&gt;. The key is that the encoder/decoder was shared during that proccess and learned to encode to/decode from multiple resources!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-10-egyptian-a4c45423.png&quot; alt=&quot;mtl.png&quot; class=&quot;mw-500 align-center&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;and-the-winner-is&quot;&gt;And the winner is….&lt;/h3&gt;
&lt;p&gt;How did we do? Which system dealt best with the extreme data sparsity? For details, I’ll just point to the paper &lt;a class=&quot;citation&quot; href=&quot;#wiesenbach19&quot;&gt;(Wiesenbach &amp;amp; Riezler, 2019)&lt;/a&gt; 😋 But at as a spoiler the one-2-many MTL system cleared the first place by learning from additional 30% transcription and POS tags. The Pipeline and Backtranslaton models both fell short as they just couldn’t leverage the little amount of data. I hope you had a good read and learned some facts about dealing with ancient languages and some techniques for low resource usecases.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Stefan Riezler for his valuable and much needed feedback for improving this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of his affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. We appreciate your feedback! If you want to cite this blogpost, cite the paper instead:&lt;/strong&gt;&lt;/p&gt;

&lt;ol class=&quot;bibliography&quot;&gt;&lt;li&gt;&lt;div id=&quot;wiesenbach19&quot;&gt;&lt;div class=&quot;bib__author&quot;&gt;Philipp Wiesenbach and Stefan Riezler&lt;/div&gt;
  &lt;div class=&quot;bib__title&quot;&gt;Multi-Task Modeling of Phonographic Languages: Translating Middle Egyptian Hieroglyphs&lt;/div&gt;
  &lt;div&gt;
    &lt;span class=&quot;bib__journal&quot;&gt;Proceedings of the International Workshop on Spoken Language Translation&lt;/span&gt; &lt;span class=&quot;bib__journal-abbrev&quot;&gt;(IWSLT)&lt;/span&gt;, &lt;span class=&quot;bib__year&quot;&gt;2019&lt;/span&gt;&lt;/div&gt;
  &lt;div class=&quot;bib__link&quot;&gt;
    &lt;a href=&quot;https://www.cl.uni-heidelberg.de/statnlpgroup/publications/IWSLT2019_v2.pdf&quot;&gt;pdf&lt;/a&gt;
     | &lt;a href=&quot;&quot; data-target=&quot;collapse_wiesenbach19&quot; onclick=&quot;toggleBib(this);return false;&quot;&gt;
      bib&lt;span class=&quot;bib__close&quot;&gt;&lt;i class=&quot;fas fa-chevron-up&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;bib__open&quot;&gt;&lt;i class=&quot;fas fa-chevron-down&quot;&gt;&lt;/i&gt;&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;

  &lt;div class=&quot;bib__raw-bibtex bib__hide&quot; id=&quot;collapse_wiesenbach19&quot;&gt;&lt;pre&gt;@article{wiesenbach19,
  title = {Multi-Task Modeling of Phonographic Languages: Translating Middle Egyptian Hieroglyphs},
  author = {Wiesenbach, Philipp and Riezler, Stefan},
  journal = {Proceedings of the International Workshop on Spoken Language Translation},
  journal-abbrev = {IWSLT},
  year = {2019},
  url = {https://www.cl.uni-heidelberg.de/statnlpgroup/publications/IWSLT2019_v2.pdf}
}
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;

&lt;style&gt;
img.mh-46 {
  max-height: 46px;
}
img.mw-500 {
  max-width: 500px;
}
&lt;/style&gt;</content><author><name>Philipp</name></author><category term="blog" /><category term="multi-task modeling" /><category term="neural machine translation" /><category term="low resource scenario" /><summary type="html">This blog post gives an overview of the paper &quot;Multi-Task Modeling of Phonographic Languages: Translating Middle Egyptian Hieroglyphs&quot;.</summary></entry><entry><title type="html">Joey NMT - A Minimalist NMT Toolkit for Novices</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/joey/" rel="alternate" type="text/html" title="Joey NMT - A Minimalist NMT Toolkit for Novices" /><published>2019-10-23T00:00:00+00:00</published><updated>2019-10-23T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/joey</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/joey/">&lt;figure class=&quot;align-center&quot; style=&quot;max-width: 15cm;&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/joey_meme.jpg&quot; alt=&quot;Meme: proposing a simple and understandable NMT implementation.&quot; /&gt;
  &lt;figcaption&gt;Proposing Joey NMT.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Another neural machine translation (NMT) toolkit like all the others? No, this one is &lt;strong&gt;for you - students, novices, beginners, newbies, and for the lovers of quick prototyping and minimalism&lt;/strong&gt;. Joey NMT matches the quality of standard toolkits such as Sockeye and OpenNMT with only one fifth of the code!&lt;/p&gt;

&lt;p&gt;NMT toolkits have been &lt;a href=&quot;https://github.com/jonsafari/nmt-list&quot;&gt;popping up constantly&lt;/a&gt; over the last five years, just as &lt;a href=&quot;https://thegradient.pub/state-of-ml-frameworks-2019-pytorch-dominates-research-tensorflow-dominates-industry/&quot;&gt;deep learning frameworks keep evolving&lt;/a&gt;. As a newcomer it is difficult to find the best path through the NMT toolkit jungle. Guiding features are often 1) popularity, 2) the deep learning framework that the toolkit builds on, 3) the machine translation quality, 4) documentation, 5) speed, and 6) commmunity support. Our goal is to make the start easier with a clean code base, solid documentation and a focus on the important implementation details.&lt;/p&gt;

&lt;figure style=&quot;width: 100px&quot; class=&quot;align-right&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/joey-small.png&quot; alt=&quot;Joey NMT logo&quot; /&gt;
  &lt;figcaption&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Please find the code on &lt;a href=&quot;https://github.com/joeynmt/joeynmt&quot;&gt;GitHub: joeynmt&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;why-joey-nmt&quot;&gt;Why Joey NMT?&lt;/h2&gt;
&lt;p&gt;If you’re working on a thesis on NMT, or an internship project, or you quickly want to implement a research idea, you don’t want to get frustrated by spending days of reading through huge code bases, trying to follow inheritance hierarchies and fill the gaps in the (outdated?) documentation, and updating your fork every day to try to keep up with the most recent changes. So let’s look at what Joey NMT has to offer - I’ll give you five reasons to give Joey NMT a try.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Joey NMT builds on &lt;a href=&quot;https://pytorch.org/&quot;&gt;&lt;strong&gt;Pytorch&lt;/strong&gt;&lt;/a&gt;, a beginner-friendly Deep Learning library in Python that has lots of &lt;a href=&quot;https://pytorch.org/tutorials/&quot;&gt;open-source tutorials&lt;/a&gt; and &lt;a href=&quot;https://github.com/pytorch/examples&quot;&gt;examples&lt;/a&gt; online.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;It matches &lt;strong&gt;benchmark performance&lt;/strong&gt; of large-scale industry-led projects like &lt;a href=&quot;https://github.com/awslabs/sockeye&quot;&gt;Sockeye&lt;/a&gt; for RNN-based and Transformer models. That means you can rely on good baselines and quickly evaluate your new ideas. Find the detailed results &lt;a href=&quot;https://github.com/joeynmt/joeynmt/blob/master/benchmarks.md&quot;&gt;here&lt;/a&gt; or in the &lt;a href=&quot;https://arxiv.org/pdf/1907.12484.pdf&quot;&gt;paper&lt;/a&gt;.&lt;/p&gt;

    &lt;figure class=&quot;align-center&quot; style=&quot;max-width: 12cm;&quot;&gt;
   &lt;img src=&quot;/statnlpgroup/images/blog/benchmarks.png&quot; alt=&quot;WMT 17 benchmark results.&quot; /&gt;
   &lt;figcaption&gt;WMT 17 benchmark results.&lt;/figcaption&gt;
 &lt;/figure&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Its &lt;strong&gt;readability&lt;/strong&gt; was empirically evaluated in a user study with expert and novice NMT users. Novices were able to quickly understand the code base without teacher, just a little slower than the experts (see “User Study” in our &lt;a href=&quot;https://arxiv.org/pdf/1907.12484.pdf&quot;&gt;EMNLP paper&lt;/a&gt;). The cleanliness of the code base is ensured with the help of Pylint checks. We build a flat hierarchy with maximum one level of inheritance, slightly preferring sequential over hierarchical code solutions.&lt;/p&gt;

    &lt;figure class=&quot;align-center&quot; style=&quot;max-width: 20cm;&quot;&gt;
   &lt;img src=&quot;/statnlpgroup/images/blog/freetext.png&quot; alt=&quot;Freetext question from Joey NMT quiz.&quot; /&gt;
   &lt;figcaption&gt;Example question from the quiz that participants of the study used to explore Joey NMT code.&lt;/figcaption&gt;
 &lt;/figure&gt;
  &lt;/li&gt;
  &lt;li&gt;It has an extensive &lt;a href=&quot;https://joeynmt.readthedocs.io/en/latest/&quot;&gt;&lt;strong&gt;documentation&lt;/strong&gt;&lt;/a&gt;: docstrings, in-line comments (including tensor shapes!), &lt;a href=&quot;https://github.com/joeynmt/joeynmt/blob/master&quot;&gt;FAQs&lt;/a&gt; and a &lt;a href=&quot;https://joeynmt.readthedocs.io/en/latest/tutorial.html&quot;&gt;tutorial&lt;/a&gt;, ranging from simple use cases to instructions on how to extend the model, tune and visualize the progress. In fact, the comment-to-code ratio is almost twice as high as in other frameworks. So you’ll actually be able to read natural language, not just code.&lt;/li&gt;
  &lt;li&gt;Its purpose is to be &lt;strong&gt;stable and minimalist&lt;/strong&gt; rather than implementing the latest hottest feature. No surprises with API changes over night.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And if that’s not enough, here are two more &lt;em&gt;bonus&lt;/em&gt; points:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;We released &lt;a href=&quot;https://github.com/joeynmt/joeynmt#pre-trained-models&quot;&gt;&lt;strong&gt;pre-trained benchmark models&lt;/strong&gt;&lt;/a&gt; for large-scale tasks (&lt;a href=&quot;http://www.statmt.org/wmt17/translation-task.html&quot;&gt;WMT17&lt;/a&gt; en-de/lv) but also on low-resource South-African languages (&lt;a href=&quot;http://autshumato.sourceforge.net/&quot;&gt;Autshumato corpus&lt;/a&gt; as prepared in the &lt;a href=&quot;https://github.com/LauraMartinus/ukuxhumana&quot;&gt;Uxhumana project&lt;/a&gt;, en-af/nso/tn/ts/zu). No need for you to re-train these models. You can use them off-the-shelf for translations, distillations, and fine-tuning.&lt;/li&gt;
  &lt;li&gt;There’s a growing &lt;strong&gt;community&lt;/strong&gt; of people (and accordingly github forks) who use and extend it in different directions, e.g. for learning with &lt;a href=&quot;https://github.com/juliakreutzer/joeynmt/tree/acl19&quot;&gt;various levels of feedback&lt;/a&gt; or &lt;a href=&quot;https://www.cl.uni-heidelberg.de/statnlpgroup/publications/IWSLT2019.pdf&quot;&gt;hieroglyph translation&lt;/a&gt;. That means you can take inspiration from other people’s integration solutions. Most prominently, Joey NMT is also used to train NMT models for African languages in the &lt;a href=&quot;https://www.masakhane.io/&quot;&gt;Masakhane project&lt;/a&gt; with the goal to put Africa on the NMT map.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;whats-in-it&quot;&gt;What’s in it?&lt;/h2&gt;

&lt;p&gt;When developing Joey NMT we set the minimalist goal to achieve at least 80% quality compared to SOTA, with 20% of the code. As a result, Joey NMT now provides the following features (aka the &lt;em&gt;bare necessities&lt;/em&gt; of NMT):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Recurrent Encoder-Decoder with GRUs or LSTMs&lt;/li&gt;
  &lt;li&gt;Transformer Encoder-Decoder&lt;/li&gt;
  &lt;li&gt;Attention Types: MLP, Dot, Multi-Head, Bilinear&lt;/li&gt;
  &lt;li&gt;Word-, BPE- and character-based input handling&lt;/li&gt;
  &lt;li&gt;BLEU, ChrF evaluation&lt;/li&gt;
  &lt;li&gt;Beam search with length penalty and greedy decoding&lt;/li&gt;
  &lt;li&gt;Customizable initialization&lt;/li&gt;
  &lt;li&gt;Attention visualization&lt;/li&gt;
  &lt;li&gt;Learning curve plotting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&quot;https://arxiv.org/pdf/1907.12484.pdf&quot;&gt;EMNLP paper&lt;/a&gt; &lt;a class=&quot;citation&quot; href=&quot;#joey2019&quot;&gt;(Kreutzer et al., 2019)&lt;/a&gt; describes the details of the RNN and Transformer implementations, and also provides a comparison of features across toolkits (very last page of the Appendix).&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s next?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;How to get started?&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;Check out the &lt;a href=&quot;https://joeynmt.readthedocs.io/en/latest/tutorial.html&quot;&gt;tutorial&lt;/a&gt; (&lt;a href=&quot;https://www.youtube.com/watch?v=PzWRWSIwSYc&quot;&gt;YouTube screencast&lt;/a&gt;) for a quick walk-through for synthetic data or the &lt;a href=&quot;https://github.com/jaderabbit/masakhane/blob/master/starter_notebook.ipynb&quot;&gt;Masakhane notebook&lt;/a&gt; that describes every step from data preprocessing to model evaluation.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Missing something?&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;Talk to us on &lt;a href=&quot;https://gitter.im/joeynmt/community?utm_source=badge&amp;amp;utm_medium=badge&amp;amp;utm_campaign=pr-badge&quot;&gt;Gitter&lt;/a&gt; or raise an &lt;a href=&quot;https://github.com/joeynmt/joeynmt/issues&quot;&gt;issue on GitHub&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;How to get involved in development?&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;If you’d like to contribute, make a &lt;a href=&quot;https://github.com/joeynmt/joeynmt/pulls&quot;&gt;pull request&lt;/a&gt; for your Joey NMT extensions or look at &lt;a href=&quot;https://github.com/joeynmt/joeynmt/issues&quot;&gt;open issues&lt;/a&gt; to see where your help would be welcome.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to all students and colleagues from ICL Heidelberg and the Masakhane project who helped to improve the code quality. And thanks to Stefan Riezler, Mayumi Ohta and Jasmijn Bastings for their feedback on this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of her affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. We appreciate your feedback! If you want to cite this blogpost, cite the Joey NMT paper instead:&lt;/strong&gt;&lt;/p&gt;
&lt;ol class=&quot;bibliography&quot;&gt;&lt;li&gt;&lt;div id=&quot;joey2019&quot;&gt;&lt;div class=&quot;bib__author&quot;&gt;Julia Kreutzer, Jasmijn Bastings and Stefan Riezler&lt;/div&gt;
  &lt;div class=&quot;bib__title&quot;&gt;Joey NMT: A Minimalist NMT Toolkit for Novices&lt;/div&gt;
  &lt;div&gt;
    &lt;span class=&quot;bib__journal&quot;&gt;Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP): System Demonstrations&lt;/span&gt;, &lt;span class=&quot;bib__city&quot;&gt;Hong Kong, China&lt;/span&gt;, &lt;span class=&quot;bib__year&quot;&gt;2019&lt;/span&gt;&lt;/div&gt;
  &lt;div class=&quot;bib__link&quot;&gt;
    &lt;a href=&quot;https://www.aclweb.org/anthology/D19-3019&quot;&gt;pdf&lt;/a&gt; | &lt;a href=&quot;https://github.com/joeynmt/joeynmt&quot;&gt;code&lt;/a&gt;
     | &lt;a href=&quot;&quot; data-target=&quot;collapse_joey2019&quot; onclick=&quot;toggleBib(this);return false;&quot;&gt;
      bib&lt;span class=&quot;bib__close&quot;&gt;&lt;i class=&quot;fas fa-chevron-up&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;bib__open&quot;&gt;&lt;i class=&quot;fas fa-chevron-down&quot;&gt;&lt;/i&gt;&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;

  &lt;div class=&quot;bib__raw-bibtex bib__hide&quot; id=&quot;collapse_joey2019&quot;&gt;&lt;pre&gt;@inproceedings{joey2019,
  author = {Kreutzer, Julia and Bastings, Jasmijn and Riezler, Stefan},
  title = {Joey {NMT}: A Minimalist {NMT} Toolkit for Novices},
  journal = {Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing {(EMNLP-IJCNLP)}: System Demonstrations},
  year = {2019},
  city = {Hong Kong, China},
  url = {https://www.aclweb.org/anthology/D19-3019}
}
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;</content><author><name>Julia</name></author><category term="blog" /><category term="beginners" /><category term="neural machine translation" /><summary type="html">Introducing Joey NMT, a minimalist neural machine translation framework for novices built on Pytorch.</summary></entry><entry><title type="html">Response-Based and Counterfactual Learning for Sequence-to-Sequence Tasks in NLP: An Overview</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/lff/" rel="alternate" type="text/html" title="Response-Based and Counterfactual Learning for Sequence-to-Sequence Tasks in NLP: An Overview" /><published>2019-08-15T00:00:00+00:00</published><updated>2019-08-15T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/learn_from_feedback</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/lff/">&lt;!--#  Response-Based and Counterfactual Learning for Sequence-to-Sequence Tasks in NLP--&gt;

&lt;p&gt;“We all need people who will give us feedback. That’s how we improve.” - Bill Gates, TED Talks Education, May 2013&lt;/p&gt;

&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;We all know that &lt;strong&gt;supervised data is expensive&lt;/strong&gt; to obtain. So let’s ask the following question: What if we learn from feedback given to model outputs instead?&lt;/p&gt;

&lt;p&gt;Next to reducing the requirement for supervised data, learning from feedback also has several other advantages:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Even if supervised data is given, we want to also discover &lt;strong&gt;alternative good outputs&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;With feedback given to model outputs, we can &lt;strong&gt;improve over time&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;It is possible to &lt;strong&gt;personalise a system&lt;/strong&gt; to a specific use case or user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For these reasons, I explored how to learn from feedback for sequence-to-sequence tasks in NLP in my PhD thesis.&lt;/p&gt;

&lt;p&gt;The scenario I assume in my thesis can be summarized with the following picture:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_problem_overview.png&quot; alt=&quot;problem_overview&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A pre-trained model receives an input for which it produces one or several outputs. An output is grounded in a given external world which assigns some feedback to it. The feedback is then used to update the pre-trained model.&lt;/p&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;While exploring how to learn from feedback, there are three different aspects we consider in the thesis.
First, we have a final application in mind: we want to build a natural language interface to the geographical database &lt;a href=&quot;http://www.openstreetmap.org&quot;&gt;OpenStreetMap (OSM)&lt;/a&gt;. Second, we consider two different approaches to learn from feedback, response-based on-policy learning and counterfactual off-policy learning. Third, both approaches are applied to two different tasks, semantic parsing for question answering and machine translation.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_roadmap.jpg&quot; alt=&quot;roadmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Overall, the thesis has three parts, which we now look at in turn.&lt;/p&gt;

&lt;p&gt;In Part 1 we set up the application of building a natural language interface to OSM. Part 2 and 3 each look at one approach of learning from feedback. In both cases, the approach is applied to both tasks, semantic parsing for question-answering and machine translation. Finally, we conclude by drawing a direct comparison between both approaches.&lt;/p&gt;

&lt;p&gt;Read on for the details or &lt;a href=&quot;#conclusion&quot;&gt;jump to the conclusion&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;part-1-a-natural-language-interface-to-osm&quot;&gt;Part 1: A Natural Language Interface to &lt;a href=&quot;http://www.openstreetmap.org&quot;&gt;OSM&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;question-answering-task&quot;&gt;Question-Answering Task&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://www.openstreetmap.org&quot;&gt;OpenStreetMap (OSM)&lt;/a&gt; is a geographical database populated by volunteers about points of interest (POI) in the world. Currently, it can only be queried with straight-forward string matching methods. But to find POIs with more complex relationships, such as “where is the hotel closest to the main station?”, it is necessary to issue a complicated database query. Because everyday users do not know how to issue such complex queries, we build a natural language interface to OSM. Here, users can ask natural language questions that are then automatically mapped to database queries. The execution of a query against the OSM database yields the corresponding answer. To achieve the automatic mapping, we built a semantic parser that learns to transform a natural language question to a database query, in this context also called a (semantic) parse.&lt;/p&gt;

&lt;p&gt;We first collected a manually annotated corpus, &lt;a href=&quot;https://www.cl.uni-heidelberg.de/statnlpgroup/nlmaps/&quot;&gt;NLmaps&lt;/a&gt;, of 2,380 question-parse pairs. This corpus was later automatically extended and &lt;strong&gt;&lt;a href=&quot;https://www.cl.uni-heidelberg.de/statnlpgroup/nlmaps/&quot;&gt;NLmaps v2&lt;/a&gt; contains 28,609 question-parse pairs&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;semantic-parsers&quot;&gt;Semantic Parsers&lt;/h3&gt;

&lt;p&gt;Using either corpus, allows us to train a semantic parser. For NLmaps v2, we found the best parser to be an encoder-decoder neural network with attention (based on &lt;a href=&quot;https://github.com/EdinburghNLP/nematus&quot;&gt;Nematus&lt;/a&gt;). Additionally, named entities are handled separately. Prior to the semantic parsing step, another neural network first identifies named entities. Second, these named entities are replaced with placeholder for the semantic parsing step. Finally, the original named entity is added back into the placeholders of the parse. This led to a parser with an answer-level F1 score of about 90%.&lt;/p&gt;

&lt;p&gt;With a semantic parser now available, we built &lt;strong&gt;a &lt;a href=&quot;https://nlmaps.cl.uni-heidelberg.de/&quot;&gt;graphical interface&lt;/a&gt; for users to access the natural language interface to OSM&lt;/strong&gt;. After entering a question, it is sent to the semantic parser, which produces a database query. The parse is then executed against the database and both a textual and a graphical answer are displayed for the user. For example, in the picture below a user asked about cuisines in Heidelberg. A list of the various cuisines is displayed and clicking on a cuisine opens pop-up information boxes on relevant markers on the map below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_interface.jpg&quot; alt=&quot;interface&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If you want, &lt;a href=&quot;https://nlmaps.cl.uni-heidelberg.de/&quot;&gt;try out your own questions&lt;/a&gt;!&lt;/p&gt;

&lt;h2 id=&quot;part-2-response-based-on-policy-learning&quot;&gt;Part 2: Response-Based On-Policy Learning&lt;/h2&gt;
&lt;p&gt;We now turn to the first approach to learn from feedback, response-based on-policy learning. The idea of response-based on-policy learning is to &lt;strong&gt;ground a model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt; in a downstream task for which gold targets are available&lt;/strong&gt;. A great advantage of this approach is that feedback can be obtained for arbitrarily many outputs.&lt;/p&gt;

&lt;p&gt;Concretely, we employ a ramp loss:&lt;/p&gt;

&lt;p&gt;&lt;script type=&quot;math/tex&quot;&gt;\mathcal{L}_{\mathrm{RAMP}} = - \left( \frac{1}{m} \sum_{t=1}^{m} \pi_w(y_t^+ \vert x_t) - \frac{1}{m} \sum_{t=1}^{m} \pi_w(y_t^- \vert x_t)\right)&lt;/script&gt;.&lt;/p&gt;

&lt;p&gt;In a ramp loss, a hope sequence &lt;script type=&quot;math/tex&quot;&gt;y^+&lt;/script&gt; is encouraged, while a fear sequence &lt;script type=&quot;math/tex&quot;&gt;y^-&lt;/script&gt; is discouraged. The specific instantiations are deferred to concrete tasks. But in general, a hope sequence has a high probability under the current model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt; while receiving a high feedback score &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt;. In contrast, a fear sequence also obtains a high probability under the current model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt; but receives a low feedback score &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt;.&lt;/p&gt;

&lt;h3 id=&quot;multilingual-semantic-parsing-nlmaps&quot;&gt;Multilingual Semantic Parsing: NLmaps&lt;/h3&gt;
&lt;p&gt;For this task, we assume a semantic parser can transform English questions into OSM queries, but a user wants to ask questions in German. Thus, we first employ a machine translation system to translate the question from German into English. The goal is to adjust the machine translation system to work well in conjunction with the semantic parser. We use the ramp loss defined above and instantiate &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; to be 1 if a machine-translated question ultimately leads to the correct answer and 0 otherwise. For an overview of the setup, see the picture below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_multilingual_ramp.png&quot; alt=&quot;multilingual_ramp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;By using the feedback signal of the downstream semantic parsing task, we can improve a linear-model machine translation system to work better in conjunction with the semantic parser. The adjusted system achieves a higher answer-level F1 score by about 8 percentage points compared to the baseline system. This is the first example that demonstrates the effectiveness of grounding a model in a downstream task.&lt;/p&gt;

&lt;h3 id=&quot;question-answering-nlmaps-v2&quot;&gt;Question-Answering: NLmaps v2&lt;/h3&gt;
&lt;p&gt;For many question-answering tasks, it is easier to obtain gold answers rather than gold parses. Thus, it is possible to ground semantic parsers in gold answers and treat the parses as hidden. In this scenario, we can again employ the above defined ramp loss, where a semantic parse receives a feedback of &lt;script type=&quot;math/tex&quot;&gt;\delta=1&lt;/script&gt; if the parse leads to a correct answer and &lt;script type=&quot;math/tex&quot;&gt;\delta=0&lt;/script&gt; otherwise.&lt;/p&gt;

&lt;p&gt;On this task, we employ a neural model. Because neural models produce their output token by token, we can assign feedback at the token level. This leads to a new loss function, called Ramp+T, that performs better (for more information, see Chapter 6 of the &lt;a href=&quot;https://www.cl.uni-heidelberg.de/~lawrence/Lawrence18.pdf&quot;&gt;thesis&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For our experiment, we assume an initial model has been trained on 2k supervised question-parse pairs. For the remainder of the training data, only gold answers, but not gold parses are available. With our new loss function, Ramp+T, grounding the semantic parser in the gold answer, allows us to outperform the baseline model by over 12 percentage points in answer-level F1 score.&lt;/p&gt;

&lt;p&gt;We have now &lt;strong&gt;successfully applied response-based on-policy learning for two tasks&lt;/strong&gt;. However, this approach ultimately &lt;strong&gt;requires gold targets of a downstream task&lt;/strong&gt;. This can still be too expensive to obtain. It is for example the case in the OSM domain, e.g. for the question “How many hotels are there in Paris?”, we cannot expect a person to count all 951 hotels in a reasonable amount of time or without error. Consequently, we next look at an approach that requires no gold targets at all.&lt;/p&gt;

&lt;h2 id=&quot;part-3-counterfactual-off-policy-learning&quot;&gt;Part 3: Counterfactual Off-Policy Learning&lt;/h2&gt;
&lt;p&gt;In the second approach to learn from feedback, counterfactual off-policy learning, we assume that a model is deployed. Users interact with the model and corresponding feedback is logged, hence the deployed model is also called the logging model. Once enough feedback is collected, the collected log can be used to improve either the logging model or any other model. With this setup, we can learn from feedback and &lt;strong&gt;do not require any direct or indirect gold targets&lt;/strong&gt;. For a graphical overview see the picture below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_loglearn_schema.png&quot; alt=&quot;loglearn_schema&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We update the model offline for several reasons:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Safety: a deployed model that is updated could degenerate without notice, leading to a bad user experience.&lt;/li&gt;
  &lt;li&gt;Hyperparameters: offline it is possible to do hyperparameter testing.&lt;/li&gt;
  &lt;li&gt;Validation: the new model can be validated on a test set before it is deployed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While offline learning provides us with several crucial benefits, it is more challenging, because:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Bandit setup: feedback is only given to one output.&lt;/li&gt;
  &lt;li&gt;Bias: the logged output is biased towards the choice made by the logging policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We refer to the approach as &lt;em&gt;counterfactual&lt;/em&gt; because we can ask the following counterfactual question: &lt;em&gt;How would another model have performed if it had been in control during logging?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To employ this approach to learn from feedback, we need to collect a log &lt;script type=&quot;math/tex&quot;&gt;D=\{(x_t,y_t,\delta_t)\}_{t=1}^n&lt;/script&gt; with&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;x_t&lt;/script&gt;: input&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;y_t&lt;/script&gt;: output from logging model &lt;script type=&quot;math/tex&quot;&gt;\mu&lt;/script&gt;&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;\delta_t&lt;/script&gt;: feedback received from user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Based on the log, counterfactual estimators can be defined to estimate the performance of another model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt;. The model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt; can then be updated via stochastic gradient descent (SGD), i.e. &lt;script type=&quot;math/tex&quot;&gt;w = w + \eta \nabla_w \mathcal{V}(\pi_w)&lt;/script&gt;, where &lt;script type=&quot;math/tex&quot;&gt;\eta&lt;/script&gt; is a suitably set learning rate.&lt;/p&gt;

&lt;p&gt;In previous literature, it is assumed that outputs are sampled stochastically from the logging model. This leads to the Inverse Propensity Scoring (IPS) estimator, which can correct the bias introduced by the logging model via important sampling:&lt;/p&gt;

&lt;p&gt;&lt;script type=&quot;math/tex&quot;&gt;\mathcal{V}_{\mathrm{IPS}}(\pi_w) = \frac{1}{n} \sum_{t=1}^n \delta_t \frac{\pi_w(y_t \vert x_t)}{\mu(y_t \vert x_t)}&lt;/script&gt;.&lt;/p&gt;

&lt;p&gt;However, &lt;strong&gt;sampling is dangerous because we are at risk of showing inferior outputs to a user&lt;/strong&gt;, which would lead to a bad user experience. Imagine in the context of machine translation, if one samples from the model output, there is a high risk that the sampled output is not actually a correct translation. For this reason, we want to always select the most likeliest output. &lt;strong&gt;This leads to deterministic logging&lt;/strong&gt; where &lt;script type=&quot;math/tex&quot;&gt;\mu(y_t \vert x_t)=1&lt;/script&gt; for all instances. Consequently, the importance sampling is disabled. We refer to this estimator as Deterministic Propensity Matching (DPM):&lt;/p&gt;

&lt;p&gt;&lt;script type=&quot;math/tex&quot;&gt;\mathcal{V}_{\mathrm{DPM}}(\pi_w) = \frac{1}{n} \sum_{t=1}^n \delta_t \pi_w(y_t \vert x_t)&lt;/script&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We would now like to find out if the deterministic DPM estimator can be used instead of the stochastic IPS estimator for sequence-to-sequence tasks in NLP.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;machine-translation&quot;&gt;Machine Translation&lt;/h3&gt;
&lt;p&gt;To investigate whether DPM is feasible in comparison to IPS, we set up a machine translation experiment with simulated feedback. Given an out-of-domain MT system, the system translates in-domain data. To simulate feedback, we use available gold reference. This allows us to create stochastic and deterministic logs where both logs have the same feedback signal.&lt;/p&gt;

&lt;p&gt;Both IPS and DPM suffer from high variance and can exhibit degenerative behaviour (see Chapter 7.2 in the &lt;a href=&quot;https://www.cl.uni-heidelberg.de/~lawrence/Lawrence18.pdf&quot;&gt;thesis&lt;/a&gt;). To combat this, we add 2 control variates to each estimator, a multiplicative and an additive control variate (for an overview of control variates see &lt;a href=&quot;http://cbl.eng.cam.ac.uk/pub/Intranet/MLG/ReadingGroup/VarianceReductionTechniquesForStochasticOptimization.pdf&quot;&gt;the great slides by Matthew W. Hoffman&lt;/a&gt;. This leads to the stochastic ĉDoubly Robust (ĉDR) and the deterministic ĉDoubly Controlled (ĉDC) estimator.&lt;/p&gt;

&lt;p&gt;We run experiments on two separate datasets and in both cases the deterministic estimator performs as well as the stochastic one. From this, we conclude that &lt;strong&gt;deterministic logging is viable for sequence-to-sequence NLP tasks&lt;/strong&gt; because there is enough implicit exploration at the word level (see Chapter 7.3.4 in the &lt;a href=&quot;https://www.cl.uni-heidelberg.de/~lawrence/Lawrence18.pdf&quot;&gt;thesis&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;However, we still need to show that counterfactual off-policy learning is possible for sequence-to-sequence NLP tasks when the feedback is obtained from real human users. We tackle this in the next section.&lt;/p&gt;

&lt;h3 id=&quot;question-answering-nlmaps-v2-1&quot;&gt;Question-Answering: NLmaps v2&lt;/h3&gt;
&lt;p&gt;We noted earlier that it is difficult for some question-answering domains to obtain gold answers, e.g. in the case of the OSM domain where we, for example, can’t expect a human to count 951 hotels. As the OSM query language is relatively unknown, it is also difficult to obtain gold parses. Thus, counterfactual off-policy learning, where no gold answers are required, is particularly suitable for the OSM domain.&lt;/p&gt;

&lt;p&gt;However, given for example the question “How many hotels are there in Paris?” and a corresponding answer, e.g. “951” or “1,003”, a human still cannot judge whether “951” or “1,003” are correct or not. To solve this issue, we instead propose to make the underlying parse human understandable. We do this by automatically converting the parse into a set of statements that can easily be judged as right or wrong. You can see what this looks like for our example in the following picture:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_feedback.jpg&quot; alt=&quot;feedback&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Once the form is filled out, we can map the individual statements back to the tokens in the parse the produced them. With this approach we collected feedback for 1&lt;script type=&quot;math/tex&quot;&gt;k&lt;/script&gt; question-parse pairs from 9 humans.&lt;/p&gt;

&lt;p&gt;For this task, we again employ a neural model. Because neural models produce their output token by token, we can assign feedback at the token level. That is particularly ideal for our situation because the feedback form already collects feedback at a token level. This leads to the new objective, called DPM+T.&lt;/p&gt;

&lt;p&gt;The DPM+T objective does not employ a control variate, but we would like to do so to reduce variance. The multiplicative control variate, reweighting (&lt;a href=&quot;https://papers.nips.cc/paper/5748-the-self-normalized-estimator-for-counterfactual-learning&quot;&gt;Swaminathan and Joachims, 2015&lt;/a&gt;), we used previously is not applicable to stochastic minibatch learning. To be applicable, we modify this control variate, leading to a new control variate that we refer to as One-Step-Late reweighting (OSL). Together with the previous new objective, this leads to the combined objective, DPM+T+OSL (for more information, see Chapter 8 of the &lt;a href=&quot;https://www.cl.uni-heidelberg.de/~lawrence/Lawrence18.pdf&quot;&gt;thesis&lt;/a&gt;).
&lt;strong&gt;DPM+T+OSL is the best objective for both learning from the 1&lt;script type=&quot;math/tex&quot;&gt;k&lt;/script&gt; human feedback instances as well as learning from a larger, but simulated log of 22&lt;script type=&quot;math/tex&quot;&gt;k&lt;/script&gt; feedback instances.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;comparison-of-both-learning-approaches&quot;&gt;Comparison of both learning approaches&lt;/h3&gt;

&lt;p&gt;Because we employ the same NLmaps task and the same neural network architecture for both approaches to learn from feedback, we can directly compare the two approaches.&lt;/p&gt;

&lt;p&gt;Unsurprisingly &lt;strong&gt;response-based learning outperforms counterfactual learning significantly because it has a better learning signal available&lt;/strong&gt;. Because response-based learning has a downstream gold target at hand, it can obtain feedback for arbitrarily many model outputs. Counterfactual learning instead only has access to one model output and its feedback. Furthermore, that model output is biased by the logging policy.&lt;/p&gt;

&lt;p&gt;Ultimately, the &lt;strong&gt;choice between response-based and counterfactual learning reduces to how expensive it is to obtain gold targets&lt;/strong&gt;. For example, for the OSM domain, it is impractical to obtain gold parse as well as gold answers because the parse can only be written by a handful of people and the answers are too cumbersome to derive for humans. In such a situation, obtaining feedback to model outputs from human users is a viable alternative.&lt;/p&gt;

&lt;p&gt;If the base model is good enough, this feedback can directly be collected while real users are interacting with the system. Otherwise, another option would be to recruit human workers to provide the needed feedback.&lt;/p&gt;

&lt;p&gt;So in conclusion: &lt;strong&gt;counterfactual learning should be chosen if gold targets are impossible, too time consuming or too expensive to obtain, whereas feedback for model outputs can be collected easily. Otherwise, response-based learning is the better approach because the available gold targets offer a stronger learning signal.&lt;/strong&gt; For an overview of this, also see the following diagram:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2019-08_decision.jpg&quot; alt=&quot;decision&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a name=&quot;conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It is a good idea to explore how to learn from feedback given to model outputs for several reasons, the primary one being that the &lt;strong&gt;collection of direct gold targets might be too expensive&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In my thesis, I explored &lt;strong&gt;two separate approaches to learn from feedback&lt;/strong&gt;, response-based and counterfactual learning. Response-based learning assumes that indirect gold targets are available. Counterfactual learning does not require gold targets and instead saves feedback given by humans interacting with a deployed system in a log.&lt;/p&gt;

&lt;p&gt;If (indirect) gold targets can be obtained, &lt;strong&gt;response-based learning is the more promising approach&lt;/strong&gt; because the gold targets offer a stronger learning signal. However, for &lt;strong&gt;situation where it is not possible to collect direct or indirect gold targets, counterfactual learning offers a viable alternative&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Next to exploring how to learn from feedback, it was important to me during my PhD project to keep a concrete user application in mind. To this end, I developed a &lt;a href=&quot;https://nlmaps.cl.uni-heidelberg.de/&quot;&gt;natural language interface to OpenStreetMap (OSM)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My PhD project was a long, but very rewarding journey. I learnt so much and got to join a great NLP community. Special thanks go to my supervisor, Stefan Riezler, who always encouraged my ideas and guided me to the path that led to my thesis. I also want to thank all my colleagues who were always willing to listen and offer suggestions.&lt;/p&gt;

&lt;p&gt;If you enjoyed this post and want to discuss anything further, feel free to reach out to me via &lt;a href=&quot;mailto:Carolin.Lawrence@neclab.eu&quot;&gt;e-mail&lt;/a&gt; or &lt;a href=&quot;https://twitter.com/caro__lawrence&quot; target=&quot;_blank&quot;&gt;twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More information can be found in the &lt;a href=&quot;https://www.cl.uni-heidelberg.de/~lawrence/Lawrence18.pdf&quot;&gt;thesis&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Stefan Riezler and Mayumi Ohta for their valuable feedback to improve this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of her affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you want to cite this blogpost, use this 
&lt;a href=&quot;&quot; data-target=&quot;collapse__key&quot; onclick=&quot;toggleBib(this);return false;&quot;&gt;
bib&lt;span class=&quot;bib__close&quot;&gt;&lt;i class=&quot;fas fa-chevron-up&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;bib__open&quot;&gt;&lt;i class=&quot;fas fa-chevron-down&quot;&gt;&lt;/i&gt;&lt;/span&gt;
&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;bib__raw-bibtex bib__hide&quot; id=&quot;collapse__key&quot;&gt;
&lt;pre&gt;@misc{Lawrence:19,
    author = {Lawrence, Carolin},
    title = {Response-Based and Counterfactual Learning for Sequence-to-Sequence Tasks in NLP: An Overview},
    journal = {StatNLP HD Blog},
    type = {Blog},
    number = {August},
    year = {2019},
    howpublished = {\url{https://www.cl.uni-heidelberg.de/statnlpgroup/blog/lff/}}
}
&lt;/pre&gt;
&lt;/div&gt;</content><author><name>Carolin</name></author><category term="blog" /><category term="reinforcement learning" /><category term="semantic parsing" /><category term="machine translation" /><summary type="html">This post presents a summary of my PhD thesis. I explored how to learn from feedback given to model outputs when the collection of direct supervision signals is too costly. I also built a natural language interface to the geographical database OpenStreetMap.</summary></entry><entry><title type="html">The Real Challenge of Real-World Reinforcement Learning: The Human Factor</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/hrl/" rel="alternate" type="text/html" title="The Real Challenge of Real-World Reinforcement Learning: The Human Factor" /><published>2019-07-26T00:00:00+00:00</published><updated>2019-07-26T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/HRL</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/hrl/">&lt;blockquote&gt;
  &lt;p&gt;The full potential of reinforcement learning requires reinforcement learning agents to be embedded into the flow of real-world experience, where they act, explore, and learn in our world, not just in their worlds. (Sutton &amp;amp; Barto (2018). Reinforcement Learning. An Introduction. 2nd edition)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Recent well-recognized research has shown that artificial intelligence agents  can achieve human-like or even superhuman performance in playing Atari games (&lt;a href=&quot;https://www.nature.com/articles/nature14236&quot;&gt;Mnih et al. 2015&lt;/a&gt;), or the game of Go (&lt;a href=&quot;https://www.nature.com/articles/nature16961&quot;&gt;Silver et al. 2016&lt;/a&gt;), without human supervision  (&lt;a href=&quot;https://www.nature.com/articles/nature24270&quot;&gt;Silver et al. 2017&lt;/a&gt;), but instead using reinforcement learning techniques for many rounds of self-play.
This is a huge achievement in artificial intelligence research, opening the doors for applications where supervised learning is (too) costly, and with ramifications for many other application areas beyond gaming. The question arises how to transfer the superhuman achievements of RL agents under clean room conditions like gaming (where reward signals are well-defined and abundant)  to real-world environments with all their shortcomings, first and foremost, the shortcomings of human teachers (who obviously would not pass the Turing test, as indicated in the comic below).&lt;/p&gt;

&lt;figure class=&quot;align-center&quot; style=&quot;max-width: 15cm;&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/ProfessorsTuringTest.gif&quot; /&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;the-human-factor-in-real-world-rl-for-natural-language-processing&quot;&gt;The human factor in real-world RL for natural language processing&lt;/h2&gt;

&lt;p&gt;Let us have a look at human learning scenarios, for example, natural language translation:  A human student of translation and interpretation studies has to learn how to produce correct translations  from a mix of feedback types. The human teacher will provide supervision signals in form of gold standard translations in some cases. However, in most cases the student has to learn from weaker teacher feedback that signals how well the student accomplished the task, without knowing what would have happened if the student had produced a different translation, nor what the correct translation should look like.  In addition, the best students will become like teachers in that they acquire a repertoire of strategies to self-regulate their learning process (&lt;a href=&quot;https://journals.sagepub.com/doi/full/10.3102/003465430298487&quot;&gt;Hattie and Timperley 2007&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Now, if our goal is to build an artificial intelligence agent that learns to translate like a human student, in interaction with a professional human translator acting as the teacher, we see the same pattern of a cost-effectiveness tradeoff:  The human translator will not want to provide a supervision signal in form of a correct translation as feedback to every translation produced by the agent, even if this signal is the most informative. Rather, in some cases weaker feedback signals on the quality of the system output, or on parts of it, are a more efficient way of student-teacher interaction. Another scenario is users of online translation systems: They act as consumers - sometimes they might give a feedback signal, but rarely a fully correct translation.&lt;/p&gt;

&lt;p&gt;We also see  a similar pattern in the quality of the teacher’s feedback signal when training a human and when training an agent: The human teacher of the human translation student and the professional translator acting as a human teacher of the artificial intelligence agent are both human: Their feedback signals can be ambiguous, misdirected, sparse, in short - only human (see the comic above). This is a stark difference to the scenarios in which the success stories of RL have been written - gaming . In these environments reward signals are unambiguous, accurate, and plentiful. One might say that the RL agents playing games against humans received an unfair advantage of an artificial environment that suits their capabilities. However, in order to replicate these success stories for RL in scenarios with learning from human feedback, we should not belittle these successes, but learn from them: The goal should be to give the RL agents that learn from human feedback any possible advantage to succeed in this difficult learning scenario. For this we have to better understand what the real challenges of learning from human feedback consist of.&lt;/p&gt;

&lt;h2 id=&quot;disclaimer&quot;&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;In difference to previous work on learning from human reinforcement signals (see, for example, &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1597738&quot;&gt;Knox and Stone&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1706.03741&quot;&gt;Christiano et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1811.07871&quot;&gt;Leike et al. 2018&lt;/a&gt;), our scenario is not one where human knowledge is used to reduce the sample complexity and thus to speed up the learning process of the system, but one where no other reward signals than human feedback are available for interactive learning. This scenario applies to many personalization scenarios where a system that is pre-trained in a supervised fashion is adapted and improved in an interactive learning setup from feedback of the human user. Examples are online advertising, or, machine translation, which we will focus on here.&lt;/p&gt;

&lt;p&gt;Recent work (&lt;a href=&quot;https://arxiv.org/abs/1904.12901v1&quot;&gt;Dulac-Arnold et al. 2019&lt;/a&gt;) has recognized that the poorly defined realities of real-world systems are hampering the progress of real-world reinforcement learning. They address, amongst others, issues such as off-line learning, limited exploration, high-dimensional action spaces, or unspecified reward functions.  These challenges are important in RL for control systems or robots grounded in the physical world, however, they severly underestimate the human factor in interactive learning. We will use their paper as a foil to address several recognized challenges in real-world RL.&lt;/p&gt;

&lt;h2 id=&quot;counterfactual-learning-under-deterministic-logging&quot;&gt;Counterfactual learning under deterministic logging&lt;/h2&gt;

&lt;p&gt;One of the issues addressed in &lt;a href=&quot;https://arxiv.org/abs/1904.12901v1&quot;&gt;Dulac-Arnold et al. 2019&lt;/a&gt; is the need for off-line or off-policy RL in applications where systems cannot be  updated online.  Online learning is unrealistic in commercial settings due to latency requirements and the desire for offline testing of system updates before deployment. A natural solution would be to exploit counterfactual learning that reuses logged interaction data where the predictions have been made by a historic system different from the target system.&lt;/p&gt;

&lt;figure class=&quot;align-center&quot; style=&quot;max-width: 7cm;&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/loglearn_schema_no_observation.png&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;However, both online learning and offline learning from logged data are plagued by the problem that &lt;strong&gt;exploration is prohibitive in commercial systems since it means to show inferior outputs to users&lt;/strong&gt;. This effectively results in deterministic logging policies that lack explicit exploration, making an application of standard off-policy methods questionable. For example, techniques such as inverse propensity scoring (&lt;a href=&quot;https://www.jstor.org/stable/2335942&quot;&gt;Rosenbaum and Rubin 1983&lt;/a&gt;), doubly-robust estimation (&lt;a href=&quot;https://arxiv.org/abs/1103.4601&quot;&gt;Dudik et al. 2011&lt;/a&gt;), or weighted importance sampling  (&lt;a href=&quot;https://www.semanticscholar.org/paper/Eligibility-Traces-for-Off-Policy-Policy-Evaluation-Precup-Sutton/44fe9e7f22f8986d48e3753543792d28b0494db0&quot;&gt;Precup et al. 2000&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1511.03722&quot;&gt;Jiang and Li 2016&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1604.00923&quot;&gt;Thomas and Brunskill 2016&lt;/a&gt;) all rely on sufficient exploration of the output space by the logging system as a prerequisite for counterfactual learning. In fact, &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1390223&quot;&gt;Langford et al. 2008&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1003.0120&quot;&gt;Strehl et al. 2010&lt;/a&gt; even give impossibility results for exploration-free counterfactual learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clearly, standard off-policy learning does not apply when commercial systems interact safely, i.e., deterministically with human users!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So what to do? One solution is to hope for &lt;strong&gt;implicit exploration due to input or context variability&lt;/strong&gt;. This has been observed for the case of online advertising (&lt;a href=&quot;https://papers.nips.cc/paper/4321-an-empirical-evaluation-of-thompson-sampling&quot;&gt;Chapelle and Li 2012&lt;/a&gt;) and investigated theoretically  (&lt;a href=&quot;https://arxiv.org/abs/1704.09011v5&quot;&gt;Bastani et al. 2017&lt;/a&gt;). However, natural exploration is something inherent in the data, not something machine learning can optimize for.&lt;/p&gt;

&lt;p&gt;Another solution is to consider concrete cases of degenerate behavior in estimation from deterministically logged data, and find solutions that might repeal the impossibility theorems. One such  degenerate behavior consists in the fact that the empirical reward over the data log can be maximized by setting probability of all logged data to 1. However, it is clearly undesirable to increase the probability of low reward examples (&lt;a href=&quot;https://papers.nips.cc/paper/5748-the-self-normalized-estimator-for-counterfactual-learning&quot;&gt;Swaninathan and Joachims 2015&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1711.08621&quot;&gt;Lawrence et al. 2017a&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1707.09118&quot;&gt;Lawrence et al. 2017b&lt;/a&gt;).  A solution to the problem, called &lt;strong&gt;deterministic propensity matching&lt;/strong&gt;, has been presented by &lt;a href=&quot;https://arxiv.org/abs/1811.12239&quot;&gt;Lawrence and Riezler 2018a&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1805.01252&quot;&gt;Lawrence and Riezler 2018b&lt;/a&gt; and been tested with real human feedback in a semantic parsing scenario. The central idea is as follows:
Consider logged data &lt;script type=&quot;math/tex&quot;&gt;D = \{(\mathbf{x}^{(h)}, \mathbf{y}^{(h)}, r(\mathbf{y}^{(h)}))\} ^H_{h=1}&lt;/script&gt;,  where &lt;script type=&quot;math/tex&quot;&gt;\mathbf{y}^{(h)}&lt;/script&gt; is sampled from a logging system &lt;script type=&quot;math/tex&quot;&gt;\mu(\mathbf{y}^{(h)}|\mathbf{x}^{(h)})&lt;/script&gt;, and the reward &lt;script type=&quot;math/tex&quot;&gt;r(\mathbf{y}^{(h)}) \in [0,1]&lt;/script&gt; is obtained from a human user.  One possible objective for off-line learning under deterministic logging is to maximize the expected reward of the logged data&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;L(\theta) = \frac{1}{H}\sum_{h=1}^H r(\mathbf{y}^{(h)}) \, \bar{p}_{\theta,\theta'}(\mathbf{y}^{(h)}|\mathbf{x}^{(h)}),&lt;/script&gt;

&lt;p&gt;where a multiplicative control variate (&lt;a href=&quot;https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=2ahUKEwi898Dyw8vjAhUfSBUIHUqIAAIQFjAAegQIAhAC&amp;amp;url=https%3A%2F%2Fgalton.uchicago.edu%2Ftechreports%2Ftr348.pdf&amp;amp;usg=AOvVaw3uHX3xRujlZSV05izCD-1X&quot;&gt;Kong 1992&lt;/a&gt;) is used for reweighting, evaluated one-step-late at &lt;script type=&quot;math/tex&quot;&gt;\theta'&lt;/script&gt; from some previous iteration (for efficient gradient calculation), where&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\bar{p}_{ \theta,\theta'}(\mathbf{y}^{(h)}|\mathbf{x}^{(h)}) = \frac{p_{ \theta}(\mathbf{y}^{(h)}|\mathbf{x}^{(h)})}{\sum_{b=1}^B p_{ \theta'}(\mathbf{y}^{(b)}|\mathbf{x}^{(b)})}.&lt;/script&gt;

&lt;p&gt;The effect of this self-normalization is to prevent that the probability of low reward data can be increased in learning by taking away probability mass from higher reward outputs. This introduces a bias in the estimator (that decreases as &lt;script type=&quot;math/tex&quot;&gt;B&lt;/script&gt; increases), however, it makes learning under deterministic logging feasible, thus giving the RL agent an edge in learning in an environment that has been deemed impossible in the literature. See also &lt;a href=&quot;/statnlpgroup/blog/parsing_when_gold_answers_unattainable/&quot;&gt;Carolin’s blog&lt;/a&gt; describing the semantic parsing scenario.&lt;/p&gt;

&lt;h2 id=&quot;learning-reward-estimators-from-human-bandit-feedback&quot;&gt;Learning reward estimators from human bandit feedback&lt;/h2&gt;
&lt;p&gt;Other issues addressed prominently in  &lt;a href=&quot;https://arxiv.org/abs/1904.12901v1&quot;&gt;Dulac-Arnold et al. 2019&lt;/a&gt; are the problems of learning from limited samples, in high dimensional action spaces, with unspecified reward functions. This is a concise description of the learning scenario in interactive machine translation: Firstly, it is &lt;strong&gt;unrealistic to expect anything else than bandit feedback from a human user using a commercial machine translation system&lt;/strong&gt;. That is, a user of an machine translation system will only provide a reward signal to one deterministically produced best system output, and cannot be expected to rate a multitude of translations for the same input. Providers of commercial machine translation systems realize this and provide non-intrusive interfaces for user feedback that allow to post-edit translations (negative signal), or to copy and/or share the translation without changes (positive signal).  Furthermore, human judgements on the quality of full translations need to cover an &lt;strong&gt;exponential output space&lt;/strong&gt;, while the &lt;strong&gt;notion of translation quality is not a well-defined function&lt;/strong&gt; to start with: In general every input sentence has a multitude of correct translations, each of which humans may judge differently, depending on many contextual and personal factors.&lt;/p&gt;

&lt;p&gt;Surprisingly, the question of how  to give the RL agent an advantage in learning from real-world human feedback has been scarcely researched.  The suggestions in  &lt;a href=&quot;https://arxiv.org/abs/1904.12901v1&quot;&gt;Dulac-Arnold et al. 2019&lt;/a&gt; may seem straightforward - warm-starting agents to decrease sample complexity or using inverse reinforcement learning to recover reward functions from demonstrations - but they require additional supervision signals that RL was supposed  to alleviate. Furthermore, when it comes to the question which type of human feedback is most beneficial for training an RL agent, one finds a lot of blanket statements referring to the advantages of pairwise comparisons to produce a scale (&lt;a href=&quot;https://psycnet.apa.org/record/1928-00527-001&quot;&gt;Thurstone 1927&lt;/a&gt;), however, without providing any empirical evidence.&lt;/p&gt;

&lt;p&gt;An exception is the work of &lt;a href=&quot;https://arxiv.org/abs/1805.10627&quot;&gt;Kreutzer et al. 2018&lt;/a&gt;. This work is one of the first to investigate the question which type of human feedback - pairwise judgements or cardinal feedback on a 5-point scale - can be given most reliably by human teachers, and which type of feedback allows to learn reward estimators that best approximate human rewards and can be best integrated into an end-to-end RL task. Let’s look at example interfaces for 5-point feedback and pairwise judgements:&lt;/p&gt;

&lt;figure class=&quot;align-center&quot; style=&quot;max-width: 12cm;&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/interface-highlight.png&quot; /&gt;
	&lt;img src=&quot;/statnlpgroup/images/blog/interface-pw2-highlight.png&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;Contrary to common belief, &lt;strong&gt;inter-rater reliability was higher for 5-point ratings&lt;/strong&gt; (Krippendorff’s &lt;script type=&quot;math/tex&quot;&gt;\alpha =0.51&lt;/script&gt;) than for pairwise judgements (&lt;script type=&quot;math/tex&quot;&gt;\alpha=0.39&lt;/script&gt;) in the study of &lt;a href=&quot;https://arxiv.org/abs/1805.10627&quot;&gt;Kreutzer et al. 2018&lt;/a&gt; . They explain this by the possibility to standardize cardinal judgements for each rater to get rid of individual biases, and due to filtering out raters with low intra-rater reliability. The main problem for pairwise judgements were distinctions between similarly good or bad translations, which could be filtered out to improve intra-rater reliability, yielding the final inter-rater reliability given above.&lt;/p&gt;

&lt;p&gt;Furthermore,  when training  reward estimators on judgments collected for 800  translations, they measured learnability by the correlation between estimated rewards and translation edit rate to human reference translations. They found that &lt;strong&gt;learnablity was better for a regression model trained on 5-point feedback than for a Bradley-Terry model trained on pairwise rankings&lt;/strong&gt; (as recently used for RL from human preferences by &lt;a href=&quot;https://arxiv.org/abs/1706.03741&quot;&gt;Christiano et al. 2017&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Finally, and most importantly, when &lt;strong&gt;integrating reward estimators into an end-to-end RL task, they found that one can improve a neural machine translation system by more than 1 BLEU point by a reward estimator trained on only 800 cardinal user judgements&lt;/strong&gt;. This is not only a promising result pointing in the direction in which future research for real-world RL could happen, but it also solves all three of the above mentioned challenges of &lt;a href=&quot;https://arxiv.org/abs/1904.12901v1&quot;&gt;Dulac-Arnold et al. 2019&lt;/a&gt; (limited samples, high dimensional action spaces, unspecified reward functions) in one approach: Reward estimators can be trained on very small datasets, and then be integrated as reward functions over high dimensional action spaces. The idea is to tackle the arguably simpler problem of learning a reward estimator from human feedback first, then provide unlimited learned feedback to generalize to unseen outputs in off-policy RL.&lt;/p&gt;

&lt;h2 id=&quot;further-avenues-self-regulated-interactive-learning&quot;&gt;Further avenues: Self-regulated interactive learning&lt;/h2&gt;

&lt;p&gt;As mentioned earlier, human students have to be able learn in situations where  the most informative learning signals are the sparsest. This is because teacher feedback comes at a cost so that the most precious feedback of gold standard outputs has to be requested economically. Furthermore, students have to learn how to self-regulate their learning process and learn when to seek help and which kind of help to seek. This is different to  classic RL games where the cost of feedback is negligible (we can simulate games forever), but this is not realistic in the real world, where especially exploration can get very costly (and dangerous).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning to self-regulate&lt;/strong&gt; is a new research direction that tries to &lt;strong&gt;equip an artificial intelligence agent with a decision-making ability that is traditionally hard for humans - balancing cost and effect of learning from different types of feedback,&lt;/strong&gt;  including full supervision by teacher demonstration or correction, weak supervision in the form of positive or negative rewards for student predictions, or a self-supervision signal generated by the student.&lt;/p&gt;

&lt;figure class=&quot;align-center&quot; style=&quot;max-width: 11cm;&quot;&gt;
  &lt;img src=&quot;/statnlpgroup/images/blog/Active_RL.png&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1907.05190&quot;&gt;Kreutzer and Riezler 2019&lt;/a&gt; have shown how to cast self-regulation as a learning-to-learn problem that solves the above problem by making the agent aware of  and manage the cost-reward trade-off. They find in simulation experiments on interactive neural machine translation that the self-regulator is a powerful alternative to uncertainty-based active learning (&lt;a href=&quot;https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=2ahUKEwi3546ZrtDjAhWRr6QKHTJ7AgMQFjAAegQIBRAC&amp;amp;url=https%3A%2F%2Fwww.biostat.wisc.edu%2F~craven%2Fpapers%2Fsettles.emnlp08.pdf&amp;amp;usg=AOvVaw2hhRs69DCAsD2fv79JuL6b&quot;&gt;Settles and Craven 2008&lt;/a&gt;), and discovers an &lt;script type=&quot;math/tex&quot;&gt;\epsilon&lt;/script&gt;-greedy strategy for the optimal cost-quality trade-off by mixing
different feedback types including corrections, error markups, and self-supervision. Their simulation scenario of course abstracts away from certain confounding variables to be expected in real-life interactive machine learning, however, all of these are interesting directions for new research on real-life RL with human teachers.&lt;/p&gt;

&lt;h2 id=&quot;the-appeal-of-rl-from-human-feedback&quot;&gt;The appeal of RL from human feedback&lt;/h2&gt;
&lt;p&gt;I tried to show that some of the challenges in real-world RL originate from the human teachers who have been considered a help in previous work (&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1597738&quot;&gt;Knox and Stone&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1706.03741&quot;&gt;Christiano et al. 2017&lt;/a&gt;, &lt;a href=&quot;https://arxiv.org/abs/1811.07871&quot;&gt;Leike et al. 2018&lt;/a&gt;): In situations where only the feedback of a human user is available to personalize and adapt an artificial intelligence agent, the standard tricks of memorizing large amounts of labels in supervised learning, or training in unlimited rounds of self-play with cost-free and accurate rewards in RL, won’t do the job. If we want move RL into the uncharted territories of training artificial intelligence agents from feedback of  cost-aware, unfathomable human teachers, we need to make sure the agent does not depend on massive exploration, and we have to learn great models of human feedback. It will be interesting to see how and what artificial intelligence agents learn in the same information-deprived situations that human students have to deal with, and hopefully, it will lead to artificial intelligence agents that can support humans by smoothly adapting to their needs.g&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Julia Kreutzer and Carolin Lawrence for our joint work and their valuable feedback on this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of his affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. We appreciate your feedback! If you want to cite this blogpost, use this 
&lt;a href=&quot;&quot; data-target=&quot;collapse__key&quot; onclick=&quot;toggleBib(this);return false;&quot;&gt;
bib&lt;span class=&quot;bib__close&quot;&gt;&lt;i class=&quot;fas fa-chevron-up&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;bib__open&quot;&gt;&lt;i class=&quot;fas fa-chevron-down&quot;&gt;&lt;/i&gt;&lt;/span&gt;
&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;bib__raw-bibtex bib__hide&quot; id=&quot;collapse__key&quot;&gt;
&lt;pre&gt;@misc{riezler:hrl:19,
    author = {Riezler, Stefan},
    title = {The Real Challenges of Real-World Reinforcement Learning: The Human Factor},
    journal = {StatNLP HD Blog},
    type = {Blog},
    number = {July},
    year = {2019},
    howpublished = {\url{https://www.cl.uni-heidelberg.de/statnlpgroup/blog/hrl/}}
}
&lt;/pre&gt;
&lt;/div&gt;</content><author><name>Stefan</name></author><category term="blog" /><category term="human factor" /><category term="reinforcement learning" /><category term="neural machine translation" /><summary type="html">How can we give RL agents that learn from human feedback a possible advantage to succeed in this difficult learning scenario?</summary></entry><entry><title type="html">Counterfactual Learning of Semantic Parsers When Even Gold Answers Are Unattainable</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/parsing_when_gold_answers_unattainable/" rel="alternate" type="text/html" title="Counterfactual Learning of Semantic Parsers When Even Gold Answers Are Unattainable" /><published>2019-01-14T00:00:00+00:00</published><updated>2019-01-14T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/parsing-overview</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/parsing_when_gold_answers_unattainable/">&lt;!--#  Counterfactual Learning of Semantic Parsers When Even Gold Answers Are Unattainable--&gt;

&lt;p&gt;In semantic parsing, natural language questions are mapped to semantic parses. A semantic parse can be executed against a database to obtain an answer. This answer can then be presented to a user.&lt;/p&gt;

&lt;p&gt;Semantic parsers for question-answering can be employed in virtual personal assistants which are increasingly on the rise in recent years. Because such assistants are desired to help on an increasing number of tasks, we need to explore the best possible options to efficiently and effectively set up a parser for a new domain, to adapt them for specific user needs and to generally ensure that they improve.&lt;/p&gt;

&lt;p&gt;However, obtaining labelled data can be challenging. In this post, we first consider the different possible supervision signals that can be used to train a semantic parser. This influences which objectives can be used for training, which we explore in the second part.&lt;/p&gt;

&lt;h2 id=&quot;supervision-signal&quot;&gt;Supervision Signal&lt;/h2&gt;

&lt;h3 id=&quot;question-parse-pairs&quot;&gt;Question-Parse Pairs&lt;/h3&gt;

&lt;p&gt;To train a semantic parser, direct supervision means the collection of question-parse pairs. This can be difficult if the parse language is only understood by expert users. One option is to ensure that the parse language is as broad as possible, e.g. by choosing SQL (&lt;a href=&quot;http://aclweb.org/anthology/P17-1089&quot;&gt;Iyer et al., 2017&lt;/a&gt;). However, even in the case of SQL, experts are required for the annotation, which can get quickly very expensive.&lt;/p&gt;

&lt;h3 id=&quot;question-answer-pairs&quot;&gt;Question-Answer Pairs&lt;/h3&gt;

&lt;p&gt;An alternative option is to employ a weaker supervision signal. Collecting question-answer pairs is easier for many domains (&lt;a href=&quot;www.aclweb.org/anthology/D/D13/D13-1160.pdf&quot;&gt;Berant et al., 2013&lt;/a&gt;; &lt;a href=&quot;http://www.aclweb.org/anthology/D14-1070&quot;&gt;Iyyer et al., 2014&lt;/a&gt;; &lt;a href=&quot;http://www.aclweb.org/anthology/D15-1237&quot;&gt;Yang et al., 2015&lt;/a&gt;; &lt;em&gt;inter alia&lt;/em&gt;) and can typically be done by non-experts.&lt;/p&gt;

&lt;p&gt;However, the weaker supervision signal from question-answer presents a harder learning task. While the gold answer is known, it remains unclear which parse will lead to the gold answer. During training, the parser has to explore the output space to find a parse that executes to the correct gold answer. This search can be difficult as the output space is large. Furthermore, instead of finding a parse that represents the correct meaning of the question, one might find a &lt;strong&gt;spurious&lt;/strong&gt; parse instead. Such a parse happens to execute to the gold answer, but conveys the wrong meaning. This hampers generalisation.&lt;/p&gt;

&lt;p&gt;For example, assume we have the question “Are there any bars?” and instead of mapping “bar” to the logical form for “&lt;bar&gt;&quot;, the parser maps it to the logical form of &quot;restaurant&quot; instead. If the answer for both &quot;Are there any bars?&quot; and &quot;Are there any restaurants?&quot; is &quot;Yes&quot;, then the wrong logical form &quot;restaurant&quot; for the question &quot;Are there any bars?&quot;, will lead to the correct answer. The parser has now wrongly learnt to map &quot;bar&quot; to the logical form &quot;restaurant&quot; and for other questions, such as &quot;Where is the closest bar?&quot; it will now return the closest restaurant instead.&lt;/bar&gt;&lt;/p&gt;

&lt;h3 id=&quot;comparison-question-parse-vs-question-answer-pairs&quot;&gt;Comparison: Question-Parse vs. Question-Answer Pairs&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://www.aclweb.org/anthology/P16-2033&quot;&gt;Yih et al., 2016&lt;/a&gt; investigated the cost and benefit of obtaining question-parse pairs compared to collecting question-answer pairs. For this, they use the WebQuestion corpus &lt;a href=&quot;www.aclweb.org/anthology/D/D13/D13-1160.pdf&quot;&gt;Berant et al., 2013&lt;/a&gt; which is based on the &lt;a href=&quot;https://developers.google.com/freebase/&quot;&gt;Freebase Database&lt;/a&gt;. The corpus was originally collected with the help of non-expert crowd-source workers in the form of question-answer pairs. &lt;a href=&quot;http://www.aclweb.org/anthology/P16-2033&quot;&gt;Yih et al., 2016&lt;/a&gt; annotate each question in the corpus with corresponding gold parses. To ease the annotation, they designed a simple user interface and hired experts familiar with Freebase.&lt;/p&gt;

&lt;p&gt;Next, they compared a system trained on question-parse pairs to a system trained on question-answer pairs. In their experiments, they were able to show three, in part surprising, results:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;The model trained on question-parse pairs outperforms the model on question-answer pairs by over 5 percentage points in answer accuracy.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Answer annotation by crowd-source workers is often incorrect, in their evaluation it was incorrect 34\% of the time.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;With an easy to use interface, experts can write the correct semantic parse faster than they can retrieve the correct answer.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Observation 1. does not come as a surprise as question-parse pairs offer a stronger learning signal. But both 2. and 3. are surprising. However, as noted previously, hiring experts to annotate gold parses can be expensive.&lt;/p&gt;

&lt;p&gt;A further problem arises for domains where it is not easy to collect gold answers. For example, when answers are open-ended lists, fuzzily defined or very large.&lt;/p&gt;

&lt;p&gt;This is for example the case on the domain of geographical question-answering using the OpenStreetMap database. Here, the underlying parse language is only known to a few expert users, which makes the collection of gold parses particularly difficult. Furthermore, it is often impossible to collect gold answers because in many cases the gold answer set is too large or fuzzily defined (e.g. when searching for objects “near” another one) to be obtained in a reasonable amount of time or without error.&lt;/p&gt;

&lt;h3 id=&quot;question-feedback-pairs&quot;&gt;Question-Feedback Pairs&lt;/h3&gt;

&lt;p&gt;In cases were both the collection of gold parses and gold answers is infeasible, we need to obtain a learning signal from other sources. One option is to obtain feedback from users while they are interacting with the system (&lt;a href=&quot;http://aclweb.org/anthology/P18-1169&quot;&gt;Lawrence&amp;amp;Riezler 2018&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For this, a baseline semantic parser is trained on a small amount of question-parse pairs. This parser can be used to parse further questions for which neither gold parses nor gold answers exist. The parse suggested by the baseline, can then be automatically transformed into a set of human understandable statements. Given to human users, they can easily judge each statement as correct or incorrect. This feedback can be used to further improve the parser.&lt;/p&gt;

&lt;p&gt;For example, below is a question and the statements automatically generated from the corresponding parse.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2018-11-14_parsing_overview.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;With the filled in form, we know which parts of the parse are wrong.&lt;/p&gt;

&lt;p&gt;This allows us to go further than just promoting correct parses. For each statement, we are able to map it back to the tokens in the parse that produced it. This allows us to learn from partially correct parses, where we only promote the tokens associated with correct statements.&lt;/p&gt;

&lt;h2 id=&quot;objectives&quot;&gt;Objectives&lt;/h2&gt;

&lt;p&gt;The collected data decides which objectives can be applied during training. Below we give an overview of various objectives, which data they require and what their advantages and disadvantages are.&lt;/p&gt;

&lt;p&gt;First off, here is some general notation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt;: neural network with parameters &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt;&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;x = x_1, x_2, \dots x_{\mid x\mid }&lt;/script&gt;: input question&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;y = y_1, y_2, \dots y_{\mid y\mid }&lt;/script&gt;: output parse&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;\bar{y} = \bar{y}_1, \bar{y}_2, \dots \bar{y}_{\mid \bar{y}\mid }&lt;/script&gt;: gold parse&lt;/li&gt;
  &lt;li&gt;&lt;script type=&quot;math/tex&quot;&gt;\bar{a}&lt;/script&gt;: gold answer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We define an objective in terms of a loss function &lt;script type=&quot;math/tex&quot;&gt;\mathcal{L}&lt;/script&gt;. For training, we derive it with regards to the model’s parameters &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; to make (stochastic) gradient descent updates, &lt;script type=&quot;math/tex&quot;&gt;w = w - \eta \nabla_w \mathcal{L}&lt;/script&gt;, where &lt;script type=&quot;math/tex&quot;&gt;\eta&lt;/script&gt; is a suitable learning rate.&lt;/p&gt;

&lt;h3 id=&quot;question-parse-pairs-maximum-likelihood-estimation-mle&quot;&gt;Question-Parse Pairs: Maximum Likelihood Estimation (MLE)&lt;/h3&gt;

&lt;p&gt;Neural networks are typically trained using MLE, where the probability of a gold parse &lt;script type=&quot;math/tex&quot;&gt;\bar{y}&lt;/script&gt; is raised for given a question &lt;script type=&quot;math/tex&quot;&gt;x&lt;/script&gt; (e.g. &lt;a href=&quot;http://www.aclweb.org/anthology/P/P16/P16-1004.pdf&quot;&gt;Dong &amp;amp; Lapata, 2016&lt;/a&gt; or &lt;a href=&quot;http://www.aclweb.org/anthology/P16-1002&quot;&gt;Jia &amp;amp; Liang, 2016&lt;/a&gt;). The objective is defined as follows:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\mathcal{L}_{MLE} = - \sum_{j=1}^{\mid \bar{y}\mid } \log \pi_w(\bar{y}_{j} \mid  \bar{y}_{&lt;j}, x), %]]&gt;&lt;/script&gt;

&lt;p&gt;where &lt;script type=&quot;math/tex&quot;&gt;% &lt;![CDATA[
\bar{y}_{&lt;j} = y_{1}, y_{2}, \dots y_{j-1}. %]]&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;However, this approach is only possible if gold targets &lt;script type=&quot;math/tex&quot;&gt;\bar{y}&lt;/script&gt; are available. As mentioned in the first section, obtaining these might be too expensive in praxis and weaker supervision signals are the practical alternative.&lt;/p&gt;

&lt;p&gt;There is a further reason for a different objective, even when question-parse pairs are available:&lt;/p&gt;

&lt;p&gt;There might be other parses, not just the annotated gold parse, that lead to the correct answer. But these can never be discovered if the MLE objective is used. Discovering further valid parses could stabilise learning and help generalisation. Further, this allows the parser to find suitable parses in its own output space.&lt;/p&gt;

&lt;p&gt;Next, we turn to objectives which assume the existence of gold answers. Either from executing gold parses to obtain gold answers or because gold answers where annotated. For these objectives, a parser produces model outputs which are executed to obtain a corresponding answers. The answers can be compared to the available gold answer and a reward can be assigned to the various model outputs.&lt;/p&gt;

&lt;h3 id=&quot;question-answer-pairs-reinforce-and-minimum-risk-training-mrt&quot;&gt;Question-Answer Pairs: REINFORCE and Minimum Risk Training (MRT)&lt;/h3&gt;

&lt;p&gt;Recently, there has been a popular surge of applying reinforcement learning approaches, in particular the REINFORCE algorithm (&lt;a href=&quot;http://www-anw.cs.umass.edu/~barto/courses/cs687/williams92simple.pdf&quot;&gt;Williams 1992&lt;/a&gt;), to (weakly) supervised NLP tasks. The inherent issues that arise in this context, are also explored with regards to neural machine translation in &lt;a href=&quot;https://statnlp.github.io/rl4nmt&quot;&gt;another blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will first introduce the REINFORCE algorithm, then discuss potential issues.&lt;/p&gt;

&lt;p&gt;In REINFORCE, given an input question &lt;script type=&quot;math/tex&quot;&gt;x&lt;/script&gt;, &lt;strong&gt;one&lt;/strong&gt; output &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt; is sampled from the current model distribution (see Section 13.3 of &lt;a href=&quot;https://drive.google.com/file/d/1opPSz5AZ_kVa1uWOdOiveNiBFiEOHjkG/view&quot;&gt;Sutton &amp;amp; Barto, 2018&lt;/a&gt;). Executing this sampled parse to obtain an answer &lt;script type=&quot;math/tex&quot;&gt;a&lt;/script&gt;, the comparison with the gold answer &lt;script type=&quot;math/tex&quot;&gt;\bar{a}&lt;/script&gt; provides us with a reward &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt;. On the basis of this single reward, the model’s parameters are updated, i.e. we can define the following objective:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{REINFORCE} = - \delta \pi_w(y\mid  x).&lt;/script&gt;

&lt;p&gt;However, with just one sample, this objective can suffer from high variance. This can be combated by introducing control variates, which lower variance. The most popular choice is using a baseline, where we keep track of the average reward, which is subtracted from &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt;.&lt;/p&gt;

&lt;p&gt;But why only sample one output?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We have the luxury of having gold answers available.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This allows us to sample several outputs and obtain rewards for all of them. With this, an average can be computed and on the basis of this average updates to &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; are performed. First, this lowers the variance. Second, it allows us to try out several model outputs, which helps us to explore the output space and in turn increases our chance of finding a parse that leads to the correct answer.&lt;/p&gt;

&lt;p&gt;Building an average based on several outputs obtained for one input, is exactly the characteristic idea of Minimum Risk Training (MRT).&lt;/p&gt;

&lt;p&gt;MRT was introduced in the context of log-linear models for dependency parsing and machine translation (&lt;a href=&quot;https://people.cs.umass.edu/~dasmith/dtrain_acl_2006.pdf&quot;&gt;Smith &amp;amp; Eisner, 2006&lt;/a&gt;). It has also been tested for neural models in the context of machine translation (&lt;a href=&quot;http://anthology.aclweb.org/P/P16/P16-1159.pdf&quot;&gt;Shen et al., 2016&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Sampling &lt;script type=&quot;math/tex&quot;&gt;S&lt;/script&gt; outputs per input, we can define the following MRT objective:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{MRT} = - \frac{1}{S} \sum_{s=1}^{S} \delta \pi_w(y_s\mid  x).&lt;/script&gt;

&lt;p&gt;This objective is for example employed in &lt;a href=&quot;http://www.aclweb.org/anthology/P17-1003&quot;&gt;Liang et al., 2017&lt;/a&gt;. Although they use the term REINFORCE (“We apply REINFORCE”), their later objective is based upon &lt;script type=&quot;math/tex&quot;&gt;S&lt;/script&gt; outputs (“Thus, in contrast with common practice of approximating the gradient by sampling from the
model, we use the top-&lt;script type=&quot;math/tex&quot;&gt;k&lt;/script&gt; action sequences”), which is reminiscent of MRT. Similarly, &lt;a href=&quot;http://aclweb.org/anthology/P17-1097&quot;&gt;Guu et al., 2017&lt;/a&gt; also calculate an average over several output samples for one input (see their Equation 9). &lt;a href=&quot;http://proceedings.mlr.press/v70/mou17a/mou17a.pdf&quot;&gt;Mou et al., 2017&lt;/a&gt; also take advantage of the gold answers to sample and evaluate several parses for one input (“We adjust the reward by subtracting the mean reward, averaged over sampled actions for a certain data point.”).&lt;/p&gt;

&lt;p&gt;MRT is superior because by sampling several outputs per input, it exhibits lower variance than REINFORCE. But it can only be applied if question-answer pairs are available. Additionally, it is more expensive to compute.&lt;/p&gt;

&lt;p&gt;For our final scenario from the previous section, where neither gold answers nor gold parses are available and we only have feedback collected for one model output, we are limited to only one sample and MRT cannot be applied.&lt;/p&gt;

&lt;p&gt;Let’s see which objectives we can apply in such scenarios.&lt;/p&gt;

&lt;h3 id=&quot;question-feedback-pairs-reinforce-and-counterfactual-learning&quot;&gt;Question-Feedback Pairs: REINFORCE and Counterfactual Learning&lt;/h3&gt;

&lt;p&gt;A setup, where only one outputs and its corresponding feedback is available, is also called a bandit learning scenario. The name is inspired from choosing one among several slot machines (colloquially referred to as “one-armed bandit”), where we only observe the reward for the chosen machine (i.e. output) and it remains unknown what reward the other machines (or outputs) would have obtained.&lt;/p&gt;

&lt;p&gt;This is a crucial contrast to learning from question-answer pairs. We illustrate this graphically in the figure below. The left side shows the scenario where question-answer pairs are available, whereas the right assumes question-feedback pairs where no gold answers are available.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/2018-11-14_QA.png&quot; alt=&quot;qa&quot; class=&quot;align-left&quot; /&gt;&lt;/p&gt;

&lt;p&gt;REINFORCE is still applicable in bandit learning scenarios. But if we collect feedback as users are using the system, it can be dangerous to update the parser’s parameters online.&lt;/p&gt;

&lt;p&gt;The parser’s performance could deteriorate without notice which can lead to user dissatisfaction and monetary loss. It also makes it impossible to explore different hyperparameter setting.&lt;/p&gt;

&lt;p&gt;Instead, it is safer to first collect the feedback in a log of triples &lt;script type=&quot;math/tex&quot;&gt;\mathcal{D}_{log}=\{(x_m,y_m,\delta_m)\}_{m=1}^M&lt;/script&gt;. Once enough feedback has been collected, the log can be used to further improve the parser offline. The resulting model can then be validated against additional test sets before it is deployed.&lt;/p&gt;

&lt;p&gt;However, once we start learning, the outputs produced in log might no longer be the outputs the updated parser would choose; i.e. the log we collected is biased towards the parser that was deployed at the time. Learning from such a log leads to a counterfactual, or off-policy, learning setup.&lt;/p&gt;

&lt;p&gt;The bias in the log can be corrected using &lt;a href=&quot;https://en.wikipedia.org/wiki/Importance_sampling&quot;&gt;importance sampling&lt;/a&gt;, where we divide the probability that the new model &lt;script type=&quot;math/tex&quot;&gt;\pi_w&lt;/script&gt; prescribes to the logged output, by the probability that the deployed parser &lt;script type=&quot;math/tex&quot;&gt;\mu&lt;/script&gt; assigned to that output. This leads to the following Inverse Propensity Score (IPS) objective:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{IPS} = - \frac{1}{M} \sum_{m=1}^{M} \delta \frac{\pi_w(y_m\mid  x_m)}{\mu(y_m\mid  x_m)}.&lt;/script&gt;

&lt;p&gt;However, because we ideally want to present only correct parses and answers to our users, we want to always show the most likely output under the currently deployed model. This results in a deterministic log because the probability of choosing the most likely output is always one. Consequently, we can no longer correct the data bias.&lt;/p&gt;

&lt;p&gt;This leads to the Deterministic Propensity Matching (DPM) objective:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{DPM} = - \frac{1}{M} \sum_{m=1}^{M} \delta \pi_w(y_m\mid  x_m).&lt;/script&gt;

&lt;p&gt;Just like REINFORCE, both IPS and DPM suffer from high variance because only one output received a reward for each input. It is thus advisable to employ control variates, e.g. one-step-late reweighting (&lt;a href=&quot;http://aclweb.org/anthology/P18-1169&quot;&gt;Lawrence &amp;amp; Riezler, 2018&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;With these objectives it is possible to learn from question-feedback pairs where feedback was collected from users for one system output. This approach is useful for scenarios where neither the collection of gold parses nor the collection of gold answers is feasible.&lt;/p&gt;

&lt;p&gt;Furthermore, this approach can also be applied to other tasks, such as machine translation (&lt;a href=&quot;http://www.aclweb.org/anthology/D/D17/D17-1272.pdf&quot;&gt;Lawrence et al., 2017&lt;/a&gt; ; &lt;a href=&quot;https://arxiv.org/pdf/1804.05958.pdf&quot;&gt;Kreutzer et al., 2018a&lt;/a&gt; ; &lt;a href=&quot;https://arxiv.org/pdf/1805.10627.pdf&quot;&gt;Kreutzer et al., 2018b&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Semantic parsers are important modules in virtual personal assistants and with an increasing number of domains in which these assistants are used, we need to find efficient and effective methods to train parsers on new domains.&lt;/li&gt;
  &lt;li&gt;In general, the stronger the learning signal, the better the result. For each new domain, we should estimate the time and cost of the different approaches, while keeping in mind that:
&lt;strong&gt;question-parse pairs &amp;gt; question-answer pairs &amp;gt; question-feedback pairs.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;If it is too expensive to obtain gold parses or gold answers, then using counterfactual learning from question-feedback pairs is a viable alternative.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Julia Kreutzer and Stefan Riezler for their valuable and much needed feedback for improving this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of her affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. In particular, feel free to let us know if you think there is an important paper that we should add to this overview! We appreciate your feedback! If you want to cite this blogpost, use this &lt;a href=&quot;/statnlpgroup/bibtex/2019-01-14_parsing_overview.bibtex&quot;&gt;bibfile&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;</content><author><name>Carolin</name></author><category term="blog" /><category term="semantic parsing" /><category term="reinforcement learning" /><category term="MRT" /><category term="REINFORCE" /><summary type="html">How can we train semantic parsers if neither question-parse nor question-answer pairs can be collected?</summary></entry><entry><title type="html">Taming Wild Reward Functions: The Score Function Gradient Estimator Trick</title><link href="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/sfge/" rel="alternate" type="text/html" title="Taming Wild Reward Functions: The Score Function Gradient Estimator Trick" /><published>2018-11-12T00:00:00+00:00</published><updated>2018-11-12T00:00:00+00:00</updated><id>https://www.cl.uni-heidelberg.de/statnlpgroup/blog/score-function</id><content type="html" xml:base="https://www.cl.uni-heidelberg.de/statnlpgroup/blog/sfge/">&lt;!--# Taming Wild Reward Functions: The Score Function Gradient Estimator Trick--&gt;

&lt;p&gt;MLE is often not enough to train sequence-to-sequence neural networks in NLP. Instead we employ an external metric, which is a reward function that can help us judge model outputs. The parameters of the network are then updated on the basis of the model outputs and corresponding rewards.&lt;/p&gt;

&lt;p&gt;For this update, it is necessary to obtain a derivative.&lt;/p&gt;

&lt;p&gt;But how can we do this, if the external function is unknown or cannot be derived?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter:&lt;/strong&gt; The score function gradient estimator trick.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/statnlpgroup/images/blog/luke.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;why-mle-is-not-enough&quot;&gt;Why MLE is not Enough&lt;/h2&gt;

&lt;p&gt;Traditionally, neural networks are trained using Maximum Likelihood Estimation (MLE): given an input sequence &lt;script type=&quot;math/tex&quot;&gt;x = x_1, x_2, \dots x_{ \mid x \mid }&lt;/script&gt; and a corresponding gold target sequence &lt;script type=&quot;math/tex&quot;&gt;\bar{y} = \bar{y}_1, \bar{y}_2, \dots \bar{y}_{ \mid \bar{y} \mid }&lt;/script&gt; , we want to increase the probability that the current model &lt;script type=&quot;math/tex&quot;&gt;\pi&lt;/script&gt; with parameters &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; assigns for the pair &lt;script type=&quot;math/tex&quot;&gt;(x,\bar{y})&lt;/script&gt; . This gives the following loss function:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\mathcal{L}_{MLE} = - \sum_{j=1}^{ \mid \bar{y} \mid } \log \pi_w(\bar{y}_{j}  \mid  \bar{y}_{&lt;j}, x), %]]&gt;&lt;/script&gt;

&lt;p&gt;where &lt;script type=&quot;math/tex&quot;&gt;% &lt;![CDATA[
\bar{y}_{&lt;j} = \bar{y}_1, \bar{y}_2, \dots \bar{y}_{j-1}. %]]&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;The parameters &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; of &lt;script type=&quot;math/tex&quot;&gt;\pi&lt;/script&gt; are then updated using stochastic gradient descent,&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;w = w - \eta \nabla_w \mathcal{L}_{MLE}.&lt;/script&gt;

&lt;p&gt;But there are various issues with using MLE that has led researchers to explore alternative objectives. Let’s looks at them next.&lt;/p&gt;

&lt;h3 id=&quot;1-gold-targets-bary-are-not-available&quot;&gt;1. Gold targets &lt;script type=&quot;math/tex&quot;&gt;\bar{y}&lt;/script&gt; are not Available&lt;/h3&gt;

&lt;p&gt;This is most prominently the case in many domains of semantic parsing for question-answering, where questions &lt;script type=&quot;math/tex&quot;&gt;x&lt;/script&gt; are mapped to a semantic parse &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt;, which can be executed to obtain an answer &lt;script type=&quot;math/tex&quot;&gt;a&lt;/script&gt; . For many domains, it is easier to collect question-answer pairs, rather than question-parse pairs (e.g. see &lt;a href=&quot;http://www.aclweb.org/anthology/D/D13/D13-1160.pdf&quot;&gt;Berant et al. 2013&lt;/a&gt;). But with no gold parses available, MLE cannot be applied.&lt;/p&gt;

&lt;p&gt;What can we do instead?&lt;/p&gt;

&lt;p&gt;The current model produces a set of likely parses (e.g. by sampling from the model distribution or by employing beam search). Each parse is then executed to obtain an answer. Next, we compare the answer to the gold answer to get a reward &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; . Generally, we have &lt;script type=&quot;math/tex&quot;&gt;\delta=0&lt;/script&gt; if there is no overlap between answer and gold answer and &lt;script type=&quot;math/tex&quot;&gt;\delta=1&lt;/script&gt; if they match exactly. With this, we can update the model’s parameters.&lt;/p&gt;

&lt;h3 id=&quot;2-exposure-bias-ranzato-et-al-2016&quot;&gt;2. Exposure Bias: &lt;a href=&quot;https://arxiv.org/pdf/1511.06732.pdf&quot;&gt;Ranzato et al. 2016&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;During traditional MLE training the model is fed the perfect tokens from the available gold target &lt;script type=&quot;math/tex&quot;&gt;\bar{y}&lt;/script&gt; , but at test time the output sequence is produced on the basis of the model distribution. This causes a distribution mismatch and inferior performance.&lt;/p&gt;

&lt;p&gt;How can we reduce this mismatch?&lt;/p&gt;

&lt;p&gt;Instead, we can feed model output sequences already at training time. Typically, once an entire output sequence has been produced, this sequence is judged by an external metric and the resulting reward &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; can be used as feedback to update the model’s parameters.&lt;/p&gt;

&lt;h3 id=&quot;3-loss-evaluation-mismatch-wiseman--rush-2016&quot;&gt;3. Loss-Evaluation Mismatch: &lt;a href=&quot;http://www.aclweb.org/anthology/D16-1137&quot;&gt;Wiseman &amp;amp; Rush 2016&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;MLE is agnostic to the final evaluation metric. Ideally we would like to have the final evaluation metric in the objective used at training time, so that the parameters of the model are specifically tuned to perform well on the intended task.&lt;/p&gt;

&lt;p&gt;How can we do that?&lt;/p&gt;

&lt;p&gt;Similar to problem (2.), we can feed model output sequences at training time. In this case the external metric is the final evaluation metric. For example, in the case of machine translation, typically a per-sentence approximation of the BLEU score is used.&lt;/p&gt;

&lt;h2 id=&quot;maximise-the-expected-reward-obtained-for-model-outputs&quot;&gt;Maximise the Expected Reward Obtained for Model Outputs&lt;/h2&gt;
&lt;p&gt;To solve all three problems, we can instead maximise the expected reward &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; or, equivalently, minimise the expected risk &lt;script type=&quot;math/tex&quot;&gt;-\delta&lt;/script&gt; . This can be formulated as the following expectation:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_\delta = \mathbb{E}_{p(x)} \mathbb{E}_{\pi_w(y \mid x)} [-\delta],&lt;/script&gt;

&lt;p&gt;where &lt;script type=&quot;math/tex&quot;&gt;p(x)&lt;/script&gt; is the probability distribution over inputs &lt;script type=&quot;math/tex&quot;&gt;x&lt;/script&gt; and &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)&lt;/script&gt; is the probability distribution over outputs &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt; given &lt;script type=&quot;math/tex&quot;&gt;x&lt;/script&gt; .&lt;/p&gt;

&lt;p&gt;In praxis, this expectation has to be approximated. For example, using Monte-Carlo sampling leads to the REINFORCE algorithm (&lt;a href=&quot;http://www-anw.cs.umass.edu/~barto/courses/cs687/williams92simple.pdf&quot;&gt;Williams 1992&lt;/a&gt;): we sample one output &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt; from the model distribution &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)&lt;/script&gt; (see also Chapter 13 of &lt;a href=&quot;https://drive.google.com/file/d/1opPSz5AZ_kVa1uWOdOiveNiBFiEOHjkG/view&quot;&gt;Sutton &amp;amp; Barto 2018&lt;/a&gt;).
Approximating the expectation over &lt;script type=&quot;math/tex&quot;&gt;y&lt;/script&gt;, the actual training objective becomes:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{REINFORCE} = - \delta \pi_w(y \mid x) \approx \mathbb{E}_{p(x)} \mathbb{E}_{\pi_w(y \mid x)} [-\delta].&lt;/script&gt;

&lt;p&gt;The goal of this objective is to increase the probability of an output proportionally to its reward. The gradient of the REINFORCE objective is an unbiased estimate of the gradient of the &lt;script type=&quot;math/tex&quot;&gt;\mathcal{L}_\delta&lt;/script&gt; objective.&lt;/p&gt;

&lt;p&gt;Alternatively, we can use Minimum Risk Training (MRT) (&lt;a href=&quot;http://aclweb.org/anthology/P06-2101&quot;&gt;Smith &amp;amp; Eisner ‘06&lt;/a&gt;, &lt;a href=&quot;anthology.aclweb.org/P/P16/P16-1159.pdf&quot;&gt;Shen et al. 2016&lt;/a&gt;). Here, several outputs are sampled from the model distribution. This stabilises learning, but requires that more outputs are evaluated to get corresponding rewards. Assuming &lt;script type=&quot;math/tex&quot;&gt;S&lt;/script&gt; sampled outputs, the objective then takes the following form:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\mathcal{L}_{MRT} = - \frac{1}{S} \sum_{s=1}^{S} \delta_s \pi_w(y_s \mid x) \approx \mathbb{E}_{p(x)} \mathbb{E}_{\pi_w(y \mid x)} [-\delta].&lt;/script&gt;

&lt;p&gt;Due to sampling, both approaches can suffer from high variance, which can be combatted using control variates (see for example Chapter 9 of &lt;a href=&quot;https://www.elsevier.com/books/simulation/ross/978-0-12-415825-2&quot;&gt;Ross 2013&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;the-problem-the-reward-function-cannot-be-derived&quot;&gt;The Problem: The Reward Function cannot be Derived&lt;/h2&gt;

&lt;p&gt;To minimize &lt;script type=&quot;math/tex&quot;&gt;\mathcal{L}_{\delta}&lt;/script&gt; with stochastic gradient descent, it is necessary to calculate &lt;script type=&quot;math/tex&quot;&gt;\nabla_w \mathcal{L}_{\delta}&lt;/script&gt; , also called the policy gradient in Reinforcement Learning (RL) terms.&lt;/p&gt;

&lt;p&gt;But in praxis, the rewards &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; are typically either from an unknown function (e.g. if rewards are collected from human users) or the underlying function cannot be derived (e.g. in the case of BLEU).&lt;/p&gt;

&lt;p&gt;As such, it is not immediately clear how to derive &lt;script type=&quot;math/tex&quot;&gt;\mathcal{L}_{\delta}&lt;/script&gt; , i.e. how to calculate
 &lt;script type=&quot;math/tex&quot;&gt;\nabla_w\mathcal{L}_{\delta}.&lt;/script&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-solution-score-function-gradient-estimator&quot;&gt;The Solution: Score Function Gradient Estimator&lt;/h2&gt;

&lt;p&gt;To be able to calculate &lt;script type=&quot;math/tex&quot;&gt;\nabla_w\mathcal{L}_{\delta}&lt;/script&gt; , we use two tricks:&lt;/p&gt;

&lt;h3 id=&quot;1-the-log-derivative-trick&quot;&gt;1. The &lt;script type=&quot;math/tex&quot;&gt;\log&lt;/script&gt; Derivative Trick&lt;/h3&gt;
&lt;p&gt;The derivative of the logarithm is:&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\nabla_w \log f = \frac{\nabla_w f}{f}.&lt;/script&gt;

&lt;h3 id=&quot;2-the-identity-trick&quot;&gt;2. The Identity Trick&lt;/h3&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;f = \frac{g}{g} f&lt;/script&gt;

&lt;p&gt;Now we can formulate what is known as the score function gradient estimator (&lt;a href=&quot;https://www.sciencedirect.com/science/article/abs/pii/S0927050706130194&quot;&gt;Fu ‘06&lt;/a&gt;):&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align} \nabla_w \mathcal{L}_\delta &amp;= \nabla_w \mathbb{E}_{p(x)} \mathbb{E}_{\pi_w(y \mid x)} [- \delta] &amp; (1) \\
&amp;= \nabla_w \int_{x} \int_{y} -\delta \, \cdot \, p(x)\textrm{d}x \, \cdot \, \pi_w(y \mid x)\textrm{d}y &amp; (2) \\
&amp;= \int_{x} \int_{y} -\delta \, \cdot \, p(x)\textrm{d}x \, \cdot \, \nabla_w\pi_w(y \mid x)\textrm{d}y &amp; (3) \\
&amp;= \int_{x} \int_{y} -\delta \, \cdot \, p(x)\textrm{d}x \, \cdot \, \nabla_w \frac{\pi_w(y \mid x)}{\pi_w(y \mid x)} \, \cdot \, \pi_w(y \mid x)\textrm{d}y &amp; (4) \\
&amp;= \int_{x} \int_{y} -\delta \, \cdot \, p(x)\textrm{d}x \, \cdot \, \nabla_w \log \pi_w(y \mid x) \, \cdot \, \pi_w(y \mid x)\textrm{d}y &amp; (5) \\
&amp;= \mathbb{E}_{p(x)} \mathbb{E}_{\pi_w(y \mid x)} [-\delta \nabla_w \log \pi_w(y \mid x)]. &amp; (6) \end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;Let’s investigate for each line what happened:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;(2): The expectation is expanded into two integrals. &lt;script type=&quot;math/tex&quot;&gt;\mathbb{E}_{p(x)}&lt;/script&gt; becomes &lt;script type=&quot;math/tex&quot;&gt;\int_{x} \dots p(x)\textrm{d}x&lt;/script&gt; and &lt;script type=&quot;math/tex&quot;&gt;\mathbb{E}_{\pi_w(y \mid x)}&lt;/script&gt; turns into &lt;script type=&quot;math/tex&quot;&gt;\int_{y} \dots \pi_w(y \mid x)\textrm{d}y&lt;/script&gt; .&lt;/li&gt;
  &lt;li&gt;(3): Integral and differentiation can be switched, so we move &lt;script type=&quot;math/tex&quot;&gt;\nabla_w&lt;/script&gt; in front of &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)&lt;/script&gt; because &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)&lt;/script&gt; is the only term dependent on &lt;script type=&quot;math/tex&quot;&gt;w&lt;/script&gt; .&lt;/li&gt;
  &lt;li&gt;(4): We use the identity trick with &lt;script type=&quot;math/tex&quot;&gt;g = \pi_w(y \mid x)&lt;/script&gt; .&lt;/li&gt;
  &lt;li&gt;(5): We use the &lt;script type=&quot;math/tex&quot;&gt;\log&lt;/script&gt; derivative trick.&lt;/li&gt;
  &lt;li&gt;(6): We still have &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)\textrm{d}y&lt;/script&gt; available. With this, we can transform the expression back into an expectation. But in contrast to before, we now have &lt;script type=&quot;math/tex&quot;&gt;\nabla_w \log \pi_w(y \mid x)&lt;/script&gt; and this derivative is simply scaled by &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;script type=&quot;math/tex&quot;&gt;\rightarrow&lt;/script&gt; We no longer need to know what the function that produces &lt;script type=&quot;math/tex&quot;&gt;\delta&lt;/script&gt; looks like or derive it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For an alternative view on the subject, also see &lt;a href=&quot;http://blog.shakirm.com/2015/11/machine-learning-trick-of-the-day-5-log-derivative-trick/&quot;&gt;this great blog post&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;when-can-it-be-applied&quot;&gt;When can it be applied?&lt;/h2&gt;
&lt;p&gt;The score function gradient estimator can be applied independent of the underlying model, as long as it has a derivative.&lt;/p&gt;

&lt;p&gt;E.g. if &lt;script type=&quot;math/tex&quot;&gt;\pi_w(y \mid x)&lt;/script&gt; is a log-linear model with feature vectors &lt;script type=&quot;math/tex&quot;&gt;\phi(x,y)&lt;/script&gt; ,&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\pi_w(y  \mid  x) = \frac{e^{ w \phi(x,y)}}{\sum_{y\in \mathbf{Y}(x)} e^{ w \phi(x, y)}},&lt;/script&gt;

&lt;p&gt;then the derivative would be&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;\nabla \log \pi_w(y  \mid  x) = \phi(x,y) - \sum_{y\in \mathbf{Y}(x)} \phi(x, y)\pi_w(y  \mid  x).&lt;/script&gt;

&lt;p&gt;In the case of neural networks, backpropogation is applied to derive &lt;script type=&quot;math/tex&quot;&gt;\nabla_w \pi_w(y \mid x)&lt;/script&gt; (see for example Chapter 3 of &lt;a href=&quot;https://arxiv.org/abs/1511.07916&quot;&gt;Cho 2015&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;lessons-learnt&quot;&gt;Lessons Learnt&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;MLE can sometimes not be applied or cause inferior performance.&lt;/li&gt;
  &lt;li&gt;Instead, we leverage rewards from an external metric that evaluates the quality of our model ouputs.&lt;/li&gt;
  &lt;li&gt;The metric might be unknown or cannot be derived: (stochastic) gradient descent cannot be applied directly.&lt;/li&gt;
  &lt;li&gt;The score function gradient estimator helps us side-step this problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Acknowledgment: Thanks to Julia Kreutzer for her valuable and much needed feedback for improving this post.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This blogpost reflects solely the opinion of the author, not any of her affiliated organizations and makes no claim or warranties as to completeness, accuracy and up-to-dateness.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments, ideas and critical views are very welcome. We appreciate your feedback! If you want to cite this blogpost, use this &lt;a href=&quot;/statnlpgroup/bibtex/2018-11-12_score_function.bibtex&quot;&gt;bibfile&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;</content><author><name>Carolin</name></author><category term="blog" /><category term="score function gradient estimator" /><category term="policy gradient" /><category term="expected reward" /><category term="sampling" /><category term="MRT" /><category term="REINFORCE" /><category term="neural machine translation" /><category term="semantic parsing" /><category term="exposure bias" /><summary type="html">This post explains the need for the score function gradient estimator trick and how it works.</summary></entry></feed>