SlowGuess/NAACL_2021_OCR huggingface dataset:
Zhengxu Hou $^{1}$ , Bang Liu $^{2*}$ , Ruihui Zhao $^{1}$ , Zijing Ou $^{3}$ , Yafei Liu $^{1}$ , Xi Chen $^{1}$ , Yefeng Zheng $^{1}$
Tencent Jarvis Lab
$^{2}$  RALI & Mila, Université de Montréal  $^{3}$ Sun Yat-sen University
holmes.hzx@gmail.com bang.liu@umontreal.ca ouzj@mail2.sysu.edu.cn
{zacharyzhao,davenliu,jasonxchen,yefengzheng}@tencent.com
For task-oriented dialog systems, training a Reinforcement Learning (RL) based Dialog Management module suffers from low sample efficiency and slow convergence speed due to the sparse rewards in RL. To solve this problem, many strategies have been proposed to give proper rewards when training RL, but their rewards lack interpretability and cannot accurately estimate the distribution of state-action pairs in real dialogs. In this paper, we propose a multi-level reward modeling approach that factorizes a reward into a three-level hierarchy: domain, act, and slot. Based on inverse adversarial reinforcement learning, our designed reward model can provide more accurate and explainable reward signals for state-action pairs. Extensive evaluations show that our approach can be applied to a wide range of reinforcement learning-based dialog systems and significantly improves both the performance and the speed of convergence.
Task-oriented dialog systems have become a focal point in both academic and industrial research and have been playing a key role in conversational assistants such as Amazon Alexa and Apple's Siri. (Budzianowski et al., 2018; Wei et al., 2018; Chen et al., 2019b) Existing research on task-oriented dialog systems mainly includes pipeline and end-to-end methods (Zhang et al., 2020). For pipeline-based systems, usually could be divided into four components: Natural Language Understanding (NLU), Dialog State Tracking (DST), Dialog Management (DM), and Natural Language Generation (NLG). The modular structure makes the systems more interpretable and stable than end-to-end systems, which directly take natural language context as input and output a response.
In pipeline-based dialog systems, DM is a core component that is responsible for modeling the cur
Figure 1: An example of multi-domain task-oriented dialog about train ticket booking and hotel reservation. For each utterance, we show the fine-grained actions in the form of [domain-act-slot:value].
rent belief state (structured information about the current situation) and deciding the next action. Due to its non-differentiable nature, many researchers resort to Reinforcement Learning (RL) to learn a DM (Peng et al., 2017; Casanueva et al., 2018; Chen et al., 2019a; Vu, 2019). However, RL suffers from the problems of low data efficiency and slow convergence speed in dialog management due to reward sparsity and huge action space (Takanobu et al., 2019; Liu and Lane, 2018; Fang et al., 2019). To solve these problems, existing research designs reward models to estimate how similar a state-action pair is to an expert trajectory. Liu and Lane (2018) and Takanobu et al. (2019) combines a Generative Adversarial Network (GAN) with RL to acquire a reward model which could give rewards in turn/dialog level. However, introducing GAN will bring other problems like model instability. To solve this, Li et al. (2020) proposed to train a discriminator and directly use it as a fixed reward
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2993-3001 June 6-11, 2021. ©2021 Association for Computational Linguistics
estimator during RL training. However, there is no thorough evaluation to analyze the performance of their reward estimator. Besides, researchers ignore the huge action space of RL that has a huge impact on RL's converging speed.
In this paper, we propose to interpret a state-action pair from a multi-level and sequential perspective, instead of simply classifying them as "right" or "wrong". Fig. 1 shows an example of multi-domain ("Train" and "Hotel") task-oriented dialog to illustrate our idea. For each utterance, we infer the domain, act, and slot of it to form a three-level hierarchy, leading to more accurate and interpretable modeling of the dialog agent's actions. For example, for the utterance "Okay, your reference number is A9NH", the RL agent books a train ticket of A9NH. We infer the domain of the action "book" is "train", and the slot is "Ref" (reference number) with slot value "A9NH". An RL agent will get rewards from the action only if it belongs to an appropriate domain, and will get slot rewards only if it takes suitable action. For example, if the RL agent in Fig. 1 chooses the wrong action "Train-Book-Ref: A9NH" at the first turn (i.e., direct booking without confirmation from the user), it will only receive rewards for domain, since it should take the action "inform" instead of "book".
To construct a multi-level reward model, we propose the following designs. First, we utilize a disentangled autoencoder to factorize and encode a dialog state into three independent latent sub-states, characterizing domain, act, and slot, respectively. Correspondingly, we also design an action decomposer to decompose an action into three sub-actions, taking the first user action in Figure 1 as an example, the decomposer will decompose action "Train-Inform-Day:Weds" into "Train", "Inform" and "Day". Second, we learn a multi-level generator-discriminator framework. The generator generates sub-states and sub-actions from noises, and the discriminator learns to classify whether a sub state-action pair is real or generated. In this way, the learned discriminator can give rewards to a state-action pair in terms of domain, act, and slot. Lastly, we impose Markov property to our multi-level rewards by only rewarding an act/slot if the prior domain/act is appropriate. Such design also alleviates the problem of huge action decision space in RL, as the "domain-act-slot" hierarchy restricts the choice of act/slot when the domain/act has been decided.
We run extensive evaluations to test our multilevel sequential reward model by incorporating it into a variety of RL-based agents. The experimental results demonstrate that our reward model can significantly improve the performance of RL agents and accelerate the speed of convergence.
Dialog reward modeling aims to give a proper reward to the action made by an RL agent. Traditional hand-crafted rule-based reward modeling requires expert knowledge and cannot handle unseen actions or situations. Su et al. (2015) proposes a reward shaping method to speed up online policy learning, which models the sum of all rewards in turn level.
After that, most researchers tend to exploit GAN by considering an RL agent as a generator and a reward function as a discriminator. Liu and Lane (2018) first introduces the adversarial method for reward computation. It learns a discriminator which can give the probability of authenticity in the dialog level. Takanobu et al. (2019) further expands the adversarial method by inferring a user's goal and giving a proper reward in turn level. However, adding adversarial training to RL will bring potential drawbacks, as training RL is different from normal GAN training whose dataset is fixed, which needs training with the environment and simulated user which is changing all the time. Thus RL and discriminator are training with a moving target rather than a fixed object. It is hard to supervise the adversarial training of generator and discriminator due to no solid feedback. Besides, as claimed in (Li et al., 2020), such adversarial training is only suitable for policy gradient-based methods like Proximal Policy Optimization (PPO), but not working for value-based RL algorithm like Deep Q-Network (DQN).
Recently, Li et al. (2020) utilizes a generator to approximate the distribution of expert state-action pairs and trains a discriminator to distinguish them from expert state-action pairs. By introducing a pretraining method, this approach can be extended to both on-policy and off-policy RL methods. However, it is still confused that whether this reward model could give correct rewards. Different from the aforementioned methods, in this paper, our model generates rewards in a more accurate sequential and multi-level manner.
Figure 2: An overview of our multi-level and sequential reward modeling mechanism.
We propose a novel multi-level sequential reward estimator and learn it under an Inverse Reinforcement Learning (IRL) framework. IRL aims to learn a reward estimator based on expert data, which are state-action pairs  $(S_e, A_e)$  from expert policy. IRL could be formally defined as:
$$
\mathbb {E} _ {\pi_ {\theta} ^ {*} (\mathcal {A} _ {e} | \mathcal {S})} R ^ {*} (\mathcal {A} _ {e}, \mathcal {S}) \geq \mathbb {E} _ {\pi_ {\theta} (\hat {\mathcal {A}} | \mathcal {S})} R ^ {*} (\hat {\mathcal {A}}, \mathcal {S}) \tag {1}
$$
where the goal is to find an optimal reward function  $R^{*}$ , such that based on the same states  $S$ , expert dialog policy  $\pi_{\theta}^{*}$  will obtain equal or higher rewards than the agent's policy  $\pi_{\theta}$ . We denote expert action and agent action as  $A_{e}$  and  $\hat{A}$ , respectively.
Our objective is approximating  $R^*$  by capturing the distribution of expert dialog  $f_e$  and estimating how likely a state-action pair is from  $f_e$  as the reward. To accurately model the expert distribution  $f_e$ , we disentangle  $f_e$  into three levels: domain distribution  $f_d^e$ , action distribution  $f_a^e$ , and slot distribution  $f_s^e$ . Fig. 2 shows the framework of our multi-level reward estimator. Given a state-action pair from the input and output of a DM module in a pipeline-based system, we combine three components to estimate its quality. First, we acquire substates and sub-actions by utilizing a Disentangled Auto-Encoder (DAE) to encode states and a rule-based decomposer to decompose actions. Second, we learn different sub-generators to generate substates and sub-actions from noises. Third, we train different sub-discriminators to classify whether a state-action pair is from expert data or agent policy.
Besides, we sequentially connect the three discriminators, imposing Markov property to the multilevel rewards, as well as alleviating the problem of huge action space in RL. Finally, the discriminators can serve as reward estimators for domian, action, and slot during inference. Algorithm 1 summarizes the training process of our model components. We introduce more details in the following.
3.1 State-Action Decomposition and Representation
We first decompose an action into sub-actions and learn to decompose and encode a state into substates from domain, act, and slot level.
For action decomposition, we decompose an action  $\mathcal{A}$  by rules based on how the action vector is defined. Such a rule-based decomposer can be easily implemented by first defining an assignment matrix  $M$ , then multiply  $M$  with  $\mathcal{A}$  and select three sub-spans of  $\mathcal{A}$  to form three sub-actions  $a_{d}, a_{a}$  and  $a_{s}$ , which are all one-hot vectors.
For state decomposition and representation, we decompose a discrete state  $S$  into sub-states of domain, act, and slot, and learn a continuous representation of them by DAE. As shown in Fig. 2, the DAE contains three encoders  $\mathrm{E}_d$ ,  $\mathrm{E}_a$  and  $\mathrm{E}_s$  to extract and encode the sub-states from  $S$ :
$$
\left[ h _ {d}; h _ {a}; h _ {s} \right] = \operatorname {E n c o d e r} (\mathcal {S}). \tag {2}
$$
To enforce each encoder learn the sub-state corresponding to domain, act and slot respectively, we adopt three auxiliary classifiers  $(C_d, C_a$  and  $C_s)$  which classify each sub-state representation  $(s_d, s_a$
and  $s_{s}$ ) with the corresponding sub-action  $(a_{d}, a_{a}$  and  $a_{s}$ ) as label. To enhance model generalization, we inject data-dependent noises into latent variables  $h_{d}, h_{a}$  and  $h_{s}$ . In particular, a noise variance  $\sigma^2$  is obtained via the Multilayer Perceptron (MLP) transformation from state  $S$ :  $\log \sigma^2 = MLP(S)$ . Then we sample noise  $z$  from a Gaussian distribution  $\mathcal{N}(h, \sigma^2 I)$ . The reparameterization trick (Kingma and Welling, 2013) is further exploited to achieve end-to-end training:
$$
\left[ s _ {d}; s _ {a}; s _ {s} \right] = h + \sigma \epsilon , \quad \epsilon \sim N (0, I). \tag {3}
$$
In this way, the sub-state representations are different for every training time of input state  $S$ , and thus the model is provided with additional flexibility to explore various trade-offs between noise and environment.
Next, we reconstruct the state via a decoder:
$$
\hat {\mathcal {S}} = \operatorname {D e c o d e r} ([ s _ {d}; s _ {a}; s _ {s} ]). \tag {4}
$$
After that, since the state  $S$  is a discrete vector, we can learn DAE by minimizing a binary cross entropy loss:
$$
\mathcal {L} _ {d e c} = \sum_ {i = 1} ^ {| S |} \left[ \mathcal {S} _ {i} \log \left(\hat {\mathcal {S}} _ {i}\right) + \left(1 - \mathcal {S} _ {i}\right) \log \left(1 - \hat {\mathcal {S}} _ {i}\right) \right]. \tag {5}
$$
The loss for the auxiliary classifiers are:
$$
\mathcal {L} _ {e n c} ^ {i} = - \frac {\exp \left(s _ {i} ^ {T} W _ {i} a _ {i}\right)}{\sum_ {a _ {j} \in \mathcal {A} _ {i}} \exp \left(s _ {i} ^ {T} W _ {i} a _ {j}\right)}, i \in [ d, a, s ], \tag {6}
$$
where  $W_{i}\in \{W_{d},W_{a},W_{s}\}$  is the learnable parameters of the classifiers and  $\mathcal{A}_i$  is the action space of the corresponding action level. Therefore, the overall loss for training DAE is given by:
$$
\mathcal {L} _ {D A E} = \mathcal {L} _ {d e c} + \sum_ {i \in [ d, a, s ]} \mathcal {L} _ {e n c} ^ {i}. \tag {7}
$$
3.2 Adversarial Learning of State-Action Distribution
Different from previous adversarial training methods in which generator (policy) and discriminator (reward estimator) are trained alternatively when interacting with a simulated user, our GAN network (Goodfellow et al., 2014) is trained offline without the need of simulated users. As shown in Fig. 2, our discriminator  $\mathcal{D}$  is composed of
Algorithm 1 Reward Estimator Training
three sub-discriminators  $\{D_d, D_a, D_s\}$ , our generator  $\mathcal{G}$  consists a set of parallel sub-generators  $\{G_d, G_a, G_s, G_{act}\}$  with the same Gaussian noise  $Z$  as input to generate sub-states  $\{s_d^z, s_a^z, s_s^z\}$  and actoin  $\hat{\mathcal{A}}$ . Then  $\hat{\mathcal{A}}$  is decomposed into  $\{a_d^z, a_a^z, a_s^z\}$  by the same rule-based decomposer we described in Sec. 3.1. As a true action  $\mathcal{A}$  is discrete, we use Straight-Through Gumbel Softmax (Jang et al., 2016) to approximate the sampling process. The generators aim to approximate the distribution of expert dialog  $(S_e, \mathcal{A}_e)$  by learning distributions  $\{f_d^e, f_a^e, f_s^e\}$  of sub state-actions with  $\{G_d, G_a, G_s\}$  and  $G_{act}$ . We train the generators by the following loss:
$$
L _ {\mathcal {G}} (\theta) = \mathbb {E} _ {z \sim p (z)} \left(\log \left(1 - \mathcal {D} \left(\mathcal {G} (z)\right)\right)\right), \tag {8}
$$
where  $\theta$  represents the parameters of generator  $G$ .
For discriminator, it consists of three paralleled and independent MLP networks with a sigmoid output layer. The discriminator outputs three scores  $\{y_d,y_a,y_s\}$  that respectively denote the probability a sub state-action pair is from a true expert distribution. The training loss could be written as:
$$
\begin{array}{l} L _ {D _ {i}} = - \left[ \mathbb {E} _ {\left(s _ {i}, a _ {i}\right) \sim f _ {i} ^ {e}} \log D _ {\phi_ {i}} \left(s _ {i}, a _ {i}\right) \right. \\ + \mathbb {E} _ {z \sim p (z)} \left(1 - \log D _ {\phi_ {i}} \left(s _ {i} ^ {z}, a _ {i} ^ {z}\right)\right), i \in [ d, a, s ]. \tag {9} \\ \end{array}
$$
3.3 Reward Shaping and Combination
Reward shaping provides an RL agent with extra rewards in addition to the original sparse rewards  $r_{ori}$  in a task to alleviate the problem of reward sparsity. We follow the same assumption of (Liu and Lane, 2018; Paek and Pieraccini, 2008), in which state-action pairs similar to expert data will receive higher rewards.
The rewards from our discriminators are calculated as:
$$
R _ {d} = y _ {d},
$$
$$
R _ {a} = y _ {a} \cdot \operatorname {S i g m o i d} (\tau (R _ {d} + b)), \tag {10}
$$
$$
R _ {s} = y _ {s} \cdot \operatorname {S i g m o i d} (\tau (R _ {a} + b)),
$$
where  $\{y_d, y_a, y_s\}$  are the outputs of discriminators  $\{D_d, D_a, D_s\}$  in Fig. 2. Note that we impose Markov property into multi-level reward calculation by taking the reward of domain/act level into account when calculating the reward of act/slot level. An agent will receive a low reward when it chooses a wrong domain even if  $y_a$  or  $y_s$  is high. We accomplish this by the sigmoid functions in Eq. 10.  $\tau$  and  $b$  are two hyper-parameters controlling the shape of the sigmoid function. A smaller  $\tau$  will introduce a softer penalty given by prior-level reward.
After getting the three-level rewards, we propose two reward integration strategies. The first strategy we denote as  $R_{SeqPrd}$  is simply using  $R_{S}$  from Eq. 10 as the combined reward. This strategy will bring reward to nearly 1 or 0. The second strategy we denote as  $R_{SeqAvg}$  is computing the mean of the three rewards  $\{R_d, R_a, R_s\}$  as the final reward. Finally, we augment the original reward  $r_{ori}$  by adding  $R_{SeqPrd}$  or  $R_{SeqAvg}$  for reward shaping.
3.4 Details of Modeling and Training
For the Disentangled Auto-Encoder, the input of its encoder is binary states  $S$ . We use three paralleled MLP layers with same hidden size 64 as the subencoders to get hidden states  $\{h_d, h_a, h_s\}$ , which are the same with the architecture of the MLP network for generating noise variance  $\sigma^2$ . We train the encoder, decoder, and classifier network simultaneously.
For the generator part, we utilize four independent and parallel MLP layers. All layers share the same gaussian noise as input. The first three aim to capture the distribution in the field of  $d$ ,  $a$ ,  $s$  with output size  $= 64$ . The output size of  $G_{4}$  is 300 with an output layer of ST-Gumbel Softmax. To make
the output of generators be similar to the encoding representation of DAE and bring noise to the discriminator as well, we further add two MLP networks separately after generation layer to simulate the sampling process of mean and variance. We add weight regularization in a form of  $l2$  norm to avoid overfitting. In our experiments, the generator is weaker compared to the discriminator, therefore we set the training frequency ratio of generator and discriminator to be 5:1.
For the discriminator part, we utilize three parallel MLP layers followed by a sigmoid function as the output layer. Training a multi adversarial network is not easy. Three discriminators will be insensitive to their own field if training all  $\mathcal{G}$  and  $\mathcal{D}$  jointly. Thus, we train  $\mathcal{G}$  and  $\mathcal{D}$  in the following way.  $\mathcal{D}$  takes all outputs from  $\mathcal{G}$  as input, but only chosen sub-generator and sub-discriminator pairs have gradient backpropagation, and others are frozen. During the experiment, we found start training from one pair to two pairs than to all pairs brings good results.
Dataset We run evaluations based on the MultiWOZ dataset (Budzianowski et al., 2018). It is a multi-domain dialog dataset that constructed from human dialog records, mainly ranging from restaurant booking to hotel recommending scenarios. There are 3,406 single-domain dialogs and 7,032 multi-domain dialogs in total. The average number of turns is 8.93 and 15.39 for single and multi-domain dialogs, respectively.
Platform We implement our methods and baselines based on the Convlab platform (Lee et al., 2019) $^{2}$ . It is a multi-domain dialog system platform supporting end-to-end system evaluation, which integrates several RL algorithms.
Implementation Details For fair comparisons, we follow the same experiment settings in (Li et al., 2020). Specifically, an agenda-based user simulator (Schatzmann et al., 2007) is embedded and exploited to interact with dialog agent. We set the training environment to a "dialog-act to dialog-act (DA-to-DA)" level, where the agent interacts with a simulated user in a dialog act way rather than an utterance way. We use a rule-based dialog state
$^{1}$ https://github.com/budzianowski/multiwoz
$^{2}$ https://github.com/sherlock1987/SeqReward
tracker (DST) to track  $100\%$  of the user goals. We train on millions of frames (user-system turn pairs) with 392-dimensional state vectors as inputs and 300-dimensional action vectors as outputs. For all the RL networks, we use a hidden layer of 100 dimensions and ReLU activation function.
Evaluation metrics During the evaluation, the simulated user will generate a random goal first for each conversation and then complete the session successfully if the dialog agent has accomplished all user requirements. We exploit average turn, success rate and reward score to evaluate the efficiency of proposed reward model. In particular, the reward score metric is defined as
$$
r e w a r d s c o r e = \left\{ \begin{array}{l l} - T + 8 0, & \text {i f s u c c e s s} \\ - T - 4 0, & \text {i f f a i l} \end{array} \right. \tag {11}
$$
where  $T$  denotes the number of system-user turns in each conversation session. The performances averaged over 10 times with different random seeds are reported as the final results. Besides, we evaluate our RL models in every 1,000 frame (system-user turn) by using 1,000 dialogs interacting with a simulated user.
We evaluate the proposed reward estimator via two classical RL algorithms: i) Deep Q-Network (DQN) (Mnih et al., 2015), which is a value-based RL algorithm; ii) Proximal Policy Optimization (PPO) (Mnih et al., 2015), which is a policy-based RL algorithm.
In terms of the DQN-based methods, we compare our method  $\mathrm{DQN}_{SeqAvg}$  and  $\mathrm{DQN}_{SeqPrd}$  (corresponding to  $R_{SeqAvg}$  and  $R_{SeqPrd}$ , respectively) with  $\mathrm{DQN}_{vanilla}$ , whose reward function is defined in Eq. 11, and  $\mathrm{DQN}_{offgan}$  (Li et al., 2020), which also pretrains an reward function to achieve performance gains. Similarly, we also evaluate on Warm-up DQN (WDQN) with different reward function, named  $\mathrm{WDQN}_{vanilla}$ ,  $\mathrm{WDQN}_{offgan}$ ,  $\mathrm{WDQN}_{SeqAvg}$  and  $\mathrm{WDQN}_{SeqPrd}$ , respectively.
For the implementation details of DQN-based agents, we use  $\epsilon$ -greedy action exploration and set a linear decay from 0.1 in the beginning to 0.01 after  $500k$  frames. We train DQN on 500 batches of size 16 every 200 frames. Besides, we use a relay buffer of size 50,000 to stabilize training.
In terms of the PPO-based methods, we pick up two adversarial methods: i) Guided Dialog Policy
Learning (AIRL) (Takanobu et al., 2019); and ii) Generative Adversarial Imitation Learning (GAIL) (Ho and Ermon, 2016). AIRL works on turn level and gives reward scores based on state-action-state triple  $(s_t, a_t, s_{t+1})$ . For GAIL, it works on dialog level and gives rewards after dialog ends.
Similar to DQNs, we also compare our methods with  $\mathrm{PPO}_{\text {vanilla }}$  and  $\mathrm{PPO}_{\text {offgan }}$  (Li et al., 2020). There is one extra hyperparameter named training epoch for GAIL and AIRL, which represents the training ratio of discriminator and PPO models. Here we set it to 4. Apart from these, all the other hyperparameters stay the same. Different from the settings for DQN, the  $\epsilon$ -greedy stays 0.001 without decay. Besides, we set val-loss-coef to be 1, meaning no discount for value loss. We also set the training frequency to be 500 frames.
4.3 Results with DQN-based Agents