{'fraction_non_alphanumeric': 0.03275675675675676, 'fraction_numerical': 0.010756756756756757, 'mean_word_length': 4.673259736277216, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Scaling Matters in Deep Structured-Prediction Models

Deep structured-prediction energy-based models combine the expressive power of learned representations and the ability of embedding knowledge about the task at hand into the system. A common way to learn parameters of such models consists in a multistage procedure where different combinations of components are trained at different stages. The joint end-to-end training of the whole system is then done as the last fine-tuning stage. This multistage approach is time-consuming and cumbersome as it requires multiple runs until convergence and multiple rounds of hyperparameter tuning. From this point of view, it is beneficial to start the joint training procedure from the beginning. However, such approaches often unexpectedly fail and deliver results worse than the multistage ones. In this paper, we hypothesize that one reason for joint training of deep energy-based models to fail is the incorrect relative normalization of different components in the energy function. We propose online and offline scaling algorithms that fix the joint training and demonstrate their efficacy on three different tasks.


Introduction
In structured prediction, the goal is to make multiple highly-correlated predictions jointly in a coordinated way (Nowozin & Lampert, 2011;Smith, 2011). As an example of a structured-prediction task consider optical character recognition (OCR) where the main goal is to recognize a word given the sequence of images of hand-written letters. One possible approach to this task is to train a classifier (can be, e.g., an MNIST-size convolutional neural network, CNN (LeCun & Bengio, 1995)) that separately predicts each letter given its image (we will refer to such classifiers as unary predictors). However, a unary predic-tor does not take into account the global word structure, i.e., which combinations of letters are likely to occur together. The information about the word structure can be either taken into account by enriching the features fed into the unary predictor with information about other letter images or by explicitly modeling dependencies between letters. We associate the models doing the latter with structured prediction (possibly together with the former). On the OCR dataset collected by Taskar et al. (2003), sole unary predictors usually give 8-12% letter recognition error and structured-prediction models can decrease the error to 1-3% (Pérez-Cruz et al., 2007;Leblond et al., 2018).
One popular approach to build structured-prediction systems is the framework of undirected probabilistic graphical models (Wainwright & Jordan, 2008) or closely related energy-based models (LeCun et al., 2006). As of today, it is common to use structured models with parts parameterized by neural networks. Such models give competitive results in many applications and are often called deep structuredprediction models (DSPM).
To train DSPMs, one typically needs to do inference of some form at the training time and combine it with backpropagation and stochastic optimization. Modern neural network libraries (e.g., PyTorch (Paszke et al., 2017) and TensorFlow (Abadi et al., 2015)) offer powerful automatic differentiation tools that allow to compute gradients of many inference schemes, but training such models is often difficult. A common simplifications consists in training different system components separately, which provides a good initialization for the joint fine-tuning. We refer to this approach as stage training to contrast it to the joint training, which amounts to a single stage that learns all the parameters. Stage training is time-consuming as the procedure requires multiple runs of stochastic optimization until convergence and separate hyperparameter tuning for each stage. The process also lacks stability due to the stage switching. In the literature, there is contradicting evidence whether the stage or joint training procedure works better (see Section 3).
Contributions. In this paper, we experimentally compare the stage and joint procedures and provide evidence (see Section 2 for the OCR case study) that the main reason for  joint procedure to fail in some cases 1 is an improper relative scaling of different model components. We propose the online and offline algorithms to choose scaling that fixes the joint training (see Section 5). To validate these methods, we apply them to the two particular types of DSPM, namely linear chain conditional random field, LCCRF (Lafferty et al., 2001), with application to OCR and text chunking, and Gaussian conditional random field (Chandra & Kokkinos, 2016) with application to the task of image segmentation (see Section 4 for a review of these models with the inference and training approaches). We present the experimental results in Section 6 and conclude in Section 7.

Motivation: OCR Case Study
To showcase the issues related to joint vs. stage training choice, we study a simple system for the task of optical character recognition (OCR). We use the linear chain CRF model where the unary potentials are provided by the LeNet5-like CNN (LeCun et al., 1998) and the pairwise potentials are parameterized by a 26 × 26 matrix. As the training objective we try the standard cross-entropy loss defined on the unary marginal distributions, structured SVM loss and log-likelihood. See Sections 4 and 6 for details.
The joint training procedure consists in minimizing the objective with a stochastic optimization algorithm where at each iteration the gradient is obtained by automatically differentiating the inference algorithm (the sum-product or max-sum message passing). The stage training procedure consists in the following three stages: train the unary predictor to classify the individual letter images independently, learn the matrix defining the pairwise potentials by minimizing the objective w.r.t. it (without back-propagating the gradients into the unary predictor), fine-tune all the components by minimizing the objective w.r.t. all the parameters jointly. Table 1 reports the comparison of the three different objectives for both stage and joint training procedures, where we observe that the stage training procedure is better for all objectives. If we tweak the model slightly and change the ReLU activation of the last linear layer of the unary network to sigmoid, then the stage and joint procedure deliver results that are identical up to noise. The motivation for our study is to find out why the models that are so close exhibit different behaviour. We have seen evidence of such differences in a few related works (see Section 3) and those could even be the reason for the joint training procedure to perform worse than the sole unary predictors.
We now illustrate our hypothesis that the main reason for the joint training to underperform is the relative scaling of the unary and pairwise potentials in the LCCRF model. We change the parameterization of the unary potentials by simply multiplying them by a the positive constant α and check how this change affects the performance of the model after training. In principle, this constant α multiplies the output of a linear layer of a neural network so the model parametrization might compensate for it. However, in the actual training runs this constant significantly affects the performance due to the fact that the training procedure optimization algorithm is not scale invariant (even if we use algorithms that try to approximate scale invariance, e.g., Adam (Kingma & Ba, 2015)). Figure 1a illustrates the dependence of the final model performance (trained with the cross-entropy loss) on the constant α. As the two baselines we show the accuracy of the unary predictors only and of the model trained by the stage procedure. Please note that when α is too large or small the training fails, and there exists a sweet spot α best = 1 at which the joint training matches the stage training.
Furthermore, Figure 1b shows the dynamics of the ratio of the unary and pairwise potentials 2 at the three training runs: the model trained with α = 1, where the joint training underperforms; same model with α = α best , where the joint training succeeds. As another point of comparison we show the ratio for the model with the last ReLU non-linearity substituted with sigmoid, for which the joint training succeeds with α = 1. We observe that when the joint training underperforms the ratio of the unary to pairwise potentials diverges, but stabilizes otherwise. As additional baseline, we show the behaviour of the ratio at the stage training procedure ( Figure 1c). We observe that at the first stage the ratio grows since only unary potentials are trained, at the second stage the ratio goes down to the "good" level and is stable at the third stage. Please also note that the stage training procedure needs significantly more iterations than the joint one.

Related Works
Deep Structured-Prediction Models. First, we review the works that combine neural networks with energy-based structured models and pay attention to whether they use joint or stage training. The idea of combining networks and energy-based models was well known in the 90s, for example, Bottou et al. (1997); LeCun et al. (1998) introduced graph transformers (a combination of hidden Markov models and neural networks) that were trained end-to-end and deployed as systems of hand-written character recognition.  Recently, the DenseCRF model (Krähenbühl & Koltun, 2011) received quite a bit of attention because it outperformed the previous state-of-the-art grid CRFs (Shotton et al., 2009) by a large margin on dense image labeling tasks, e.g., semantic image segmentation. Naturally, there were many works that combined DenseCRF with CNNbased feature extractors to boost the performance even further. In particular, Zheng et al. (2015); Schwing & Urtasun (2015) used the joint training procedure, but Chen et al. Note that in many of the aforementioned works the authors used terminology "joint end-to-end training" to actually refer to the end-to-end fine-tuning of a system, some parts of which had been trained on the same data at an earlier stage.
For the purposes of our study, we refer to such procedures as stage training. Also note that most of the aforementioned systems used some part of the networks pre-trained on different data, i.e., CNN feature extractors trained on Ima-geNet or word embeddings pre-trained on the Wikipedia corpus. We chose not to consider such pre-training as a separate stage because from a practical point of view such pre-training is usually done separately from building a system for the task at hand, i.e., we just initialize the system from some pretrained model.
Ill-conditioning. Improper relative scaling, which we claim to be the main reason for the joint training to underperform, is closely related to ill-conditioning, which is a general problem in optimization and computational linear algebra. Optimization literature offers a number of methods, mostly in the contexts of solving systems of linear and differential equations or convex optimization. The most popular approach is to use preconditioning (Axelsson, 1985) and its special cases, e.g., variable rescaling and various regularization schemes. These ideas have been successfully applied for training neural networks (Bottou, 2012) and laid the foundation for layer-wise normalization techniques, such as Batch-Normalization (Ioffe & Szegedy, 2015) and input normalization (Krizhevsky et al., 2012).
However, in the context of structured prediction, the aforementioned techniques are less efficient since the potentials are objects of different types (according to our experiments layer-wise normalization cannot improve the relative scaling of potentials provided by different models).
Signal aggregation. The problem of aggregation signals of different kinds naturally arises in multimodal learning (see, e.g., (Baltrušaitis et al., 2019)). For models of this type, the most common way of aggregation is a simple concatenation of signals (e.g., Simonyan & Zisserman (2014) constructed a state-of-the-art model for action recognition in video by concatenating the RGB and optical flow features computed by separate networks). In such settings, it is natural to rescale different signals before aggregating them to reduce the discrepancy between their contributions. However, in case of DSPMs, naive normalization of the potentials leads to the problems of joint training, which we are studying.
To our knowledge, there is no general approach how to choose scaling of potentials in structured prediction models. In this paper, we propose two approaches that can address the issue and can be readily applied to most DSPMs.

Models
In this section, we briefly review the models that we use for our study together with the corresponding learning and prediction algorithms.

Linear Chain Conditional Random Field
The linear chain conditional random field (LCCRF) (Lafferty et al., 2001) is one of the most standard models for sequence labeling tasks. Given a pair of input and output variables X, Y (the inputs and outputs consist of L elements, i.e., X = {x j } L j=1 and Y = {y j } L j=1 , output variables y j take one of the M values) the LCCRF model is defined by its score function (a.k.a. negative energy function) where the unary potential U θ (x j , y j ) measures the confidence of assigning the label y j to the input x j and the pairwise potential W θ (y j , y j+1 ) scores the assignment of the pair of consecutive output variables (y j , y j+1 ). In this model, each output variable y j is directly influenced only by the corresponding input variable x j and the neighbouring output variables y j−1 and y j+1 .
The LCCRF likelihood is defined by the normalized exponent of the score function where Z(θ) denotes the partition function which ensures proper normalization of the probability function. Consequently, we can define the marginal distribution (which we call simply marginals) on the hidden variable y j as the summation of P (Y |X, θ) over all possible states of all output variables except y j : Given the parameters θ and input variables X we can make prediction in several different ways, e.g., find the output variable assignment with the maximal score value, which coincides with the Maximum A Posteriori (MAP) estimate, or take the argmax of each marginal distribution.
To learn the parameters θ of LCCRF, we can use the maximum likelihood training, i.e., minimize the objective which depends on the computation of the partition function Z(θ). An alternative choice for the training objective is the marginal likelihood (Kakade et al., 2002) (equivalent to the standard cross-entropy loss defined on the marginals): Instead of computing the marginals exactly, we can also approximate them, e.g., with the mean-field scheme, which in the case of LCCRF consists in the following updates: where C j is the normalization constant which can be computed in the linear in the number of labels M time. For LCCRF, this approximation is not necessary since the exact computation of marginals is tractable, but for some more complicated models, such as DenseCRF (Krähenbühl & Koltun, 2011), the mean-field approximation is the only tractable scheme.
As an alternative to probabilistic training we can use the Structured Support Vector Machine, SSVM (Taskar et al., 2003;Tsochantaridis et al., 2005). The SSVM objective seeks the parameters θ that push the score F (Y | X, θ) on the correct configuration Y to be larger than the score F (Y | X, θ) on other labelings Y with some margin denoted as ∆(Y, Y ): In this work, we consider the margin ∆(Y, Y ) defined by the normalized Hamming distance between Y and Y which is natural for sequence labeling tasks.
In the case of the SSVM and maximum likelihood training, we use the MAP inference during for prediction. In the case of the cross-entropy training, we take an argmax of each unary marginal.
In general, the computation of the partition function, marginals and MAP estimate has complexity exponential in L as it involves the summation or maximization over all possible configurations of Y . However, the chain-like structure of the model allows to solve all these problems efficiently in linear in the number of entities L time by dynamic programming algorithms also known as max-sum and sum-product message-passing (Bishop, 2006).

Gaussian Conditional Random Field
In this section, we review a model for dense labeling of images, e.g., the image segmentation task, known as Gaussian Conditional Random Field, GCRF (Chandra & Kokkinos, 2016;Chandra et al., 2017). The GCRF model is defined by the score function where W θ (X) is the symmetric positive semi-definite matrix of size (LM ) × (LM ) that corresponds to the pairwise potentials between pixel-label combinations and U θ (X) ∈ R LM is the vector of unary terms. Here L stands for the number of pixels in the input image and M for the number of possible pixel labels. The vector s consists of the stacked scores for each instance and is continuous (unlike LCCRF): where s k,j is the score for pixel j to be labelled with label k. The unary potentials U θ (X) are of the structure similar to the score vector s, i.e., where the symbols u k θ (X) stand for the per-class unary potentials.
The λI term of equation (9) with λ > 0 enforces the matrix of the quadratic term to be strictly positive-definite, which allows to compute the maximum point in a closed form s * (X, θ) := (W θ (X) + λI) −1 U θ (X).
At the evaluation stage, the prediction is done by taking the instance-wise argmax of the score vector s * Hence, the inference task only involves solving a system of linear equations, which can be efficiently done for large matrices with the conjugate gradient iterative algorithm (Shewchuk et al., 1994).
Given the maximum point (12) we follow Chandra & Kokkinos (2016) and define the marginal distribution of pixel j taking different labels by feeding the scores s * :,j (X, θ) into the softmax function: Please note that the marginals (14) are distributions on the discrete domain {1, . . . , M } and do not have any direct relationship to the actual marginal distributions of the Gaussian that corresponds to (9). Using (14) we learn the parameters θ by optimizing the cross-entropy objective (5).
To optimize over W θ (X) and U θ (X) terms parameterized by an arbitrary model, we need to obtain the gradients of the loss function L(X, Y | θ) w.r.t. them. However, the direct propagation of gradients through the linear system solver is inefficient as it involves roll-out of the whole iterative procedure. Fortunately, in this case, the backward pass can be computed by solving another system of linear equations (Chandra et al., 2017): where we omit the dependence of the potentials on X, Y and θ for brevity and use ⊗ to denote the Kronecker product. On the backward pass, we are given ∂L ∂s * , hence, in order to compute both ∂L ∂U and ∂L ∂W we reuse s * from the forward pass and solve the system of linear equations (15).
We now define the potentials of the score (9). The unary potentials are the outputs of a CNN applied to the input image in the fully-convolutional way. We use the pairwise term W in the form of the class-agnostic Potts model (Chandra et al., 2017), where the pairwise potential for the connected pixels to have different labels is computed as the dot-product of the pixel embeddings A i (each pixel has the embedding computed as the output of a CNN similar to the unaries). In this setting, the matrix of pairwise potentials has the following form: Scaling Matters in Deep Structured-Prediction Models

Online Scaling
We now introduce our first method to automatically choose a good relative scaling between the unary and pairwise potentials. Consider a score function F (Y |X, θ) as the function of the potentials U θ (X) and W θ (X), which are conditioned on the input and parameters: In addition, we assume that we are given a training objective, which also can be viewed as a function of U θ (X) and W θ (X) as it depends on the score function and groundtruth output variable Y . We denote the training objective on a training pair X, Y by L(Y, U θ (X), W θ (X)).
Now we define the scaling factor α that essentially represents the trade-off between the unary and pairwise components of the score function: Consequently, the training objective is modified as L(Y, αU θ (X), W θ (X)).
We denote the modified loss averaged over a subset D of objects by L α (D): Now we introduce our online scaling algorithm. After each training epoch (i.e., a pass over the training set), we choose the scaling factor α via the grid search on the training set (subset for speed-up) D with respect to L α (D). At the evaluation stage, we perform inference according toF α (Y | X, θ). Algorithm 1 summarizes this approach. pick the best α best minimizing L α (D) on an α-grid 12: α := α best 13: end for Remark. When the unary potentials are defined as the output of a linear layer tweaking the constant α is equivalent to the special choice of initialization and learning rate for the parameters of the last linear layer when the stochastic optimization is done by the regular SGD (see Appendix C).

Offline Scaling
The online scaling technique has a computational bottleneck, which is the grid search w.r.t. the scaling factor α after each training epoch. Unfortunately, for many models described in section 5.1 it is impossible to determine a constant scaling factor α that works well for the whole training procedure. We will now parameterize the potentials to approximately disentangle the potential individual norm and relative scaling between unary and pairwise terms. We parameterize the potentials as follows: for some fixed scaling factor α, which can be tuned via validation. Here, for a matrix M ∈ R k × R l , we denote the averaged absolute value of its elements by M .
Consequently, the score function and the training objective are modified in the following way: In addition to the direct modification of the score function, we can also enforce proper scaling implicitly via the regularization term added to the training objective: The hyperparameters λ and α may be tuned on the validation set. The key difference of this approach from the previous one is that we do not modify the potentials directly.
Remarks. We found that the score function parameterization that rescales both the unary and pairwise potentials with a constant factor α, i.e., changes the temperature, did not affect the model performance (see results in Appendix A.2). In addition, the underperformance of the joint training is not related to the particular choice of the optimize. We report results for the Adam and SGD optimizers in Section 6.2 and Appendix A.1, respectively.

Experiments
In this section, we evaluate the stage and joint training procedures together with the methods proposed in Section 5 on the tree different tasks. Section 6.1 explains the tasks, models and evaluation methodology. Section 6.2 contains the experiment results and the discussion.

Tasks
Optical Character Recognition. In the optical character recognition (OCR) task posed by Taskar et al. (2003), 3 we need to recognize an English word given images of its letters. All the first letters of the words in the dataset are cut off due to possible capitalization. The OCR task uses the averaged accuracy 1 as the performance metric. Here {ŷ i j } Li j=1 is the prediction for word i and {y i j } Li j=1 is its ground-truth labeling. The OCR dataset contains approximately 7000 words and is divided into 10 folds. We take one fold for validation purposes and use it only for selecting hyperparameters. On the remaining 9 folds, we do the 9-fold cross-validation (train on 8 folds and test on 1, repeat 9 times).
For this task, we use the linear-chain CRF model. The unary potentials are obtained by applying the LeNet5-like (LeCun et al., 1998) convolutional neural network to letter images (each image is zero padded to the size of 32 × 32). This unary CNN consists of the two convolutional blocks with 10 and 20 filters, respectively, and the kernel size of 5. Each convolution is followed by the ReLU activation (Dahl et al., 2013) and the 2 × 2 max-pooling. The features obtained by the convolutional blocks are then passed through the two fully-connected layers with output sizes of 140 and 26, respectively, and the ReLU activation after the first fully-connected layer. The pairwise potentials are parameterized with a real-valued matrix W of size 26 × 26, where each matrix element represents the corresponding pairwise potential of the assignment of the neighboring variables (y i , y i+1 ).
CoNLL Chunking. Text chunking consists in dividing a text into syntactically correlated chunks of consecutive words. The CoNLL-2000 chunking dataset 4 (Sang & BuchHolz, 2000) contains 211727 tokens for training and 47377 tokens for the testing. Train and test data for this task are derived from the Wall Street Journal corpus (WSJ) and include words and part-of-speech (POS) tags as the input and chunking tags as the output (23 different chunking tags). For validation, we keep 20% of the training data. The performance on this task is measured by the chunk F 1 , which we compute with the official evaluation script.
We now review the system for which joint training works well. We closely follow the hierarchical recurrent network with CRF on top (Yang et al., 2016), but substitute the Bi-GRU cells with BiLSTM. In more details, the unary predictor has the following hierarchical structure: each word is first encoded with a character-level BiLSTM and the obtained feature vector is concatenated with the SENNA embedding of the word (Collobert et al., 2011) and the POS tag embedding. After that, each word combined feature vector is passed through the word-level BiLSTM to obtain the unary potentials. And finally, the unary potentials are passed to the linear-chain CRF model with the pairwise potentials parameterized by a matrix of size 23 × 23. The character-level LSTM has 2 layers with the state of size 50, the word-level LSTM has 2 layers with the state of size 300. The size of the letter embedding (encodes each letter for the character-level LSTM) equals 10, likewise the POStag embedding. Each SENNA embedding has the size of 50. We add a learnable embedding which corresponds to the words that did not appear in SENNA embeddings.
The We believe that the word-level BiLSTM cells in the model normalize the potentials properly so the scaling problem is not present. If we substitute the word-level BiLSTM with the two linear layers (the ReLU activation in-between) the scaling breaks and the joint training starts to underperform. We use this model for experiments in Section 6.2.
Binary Segmentation. We consider the Weizmann Horses dataset (Borenstein & Ullman, 2002) for the binary segmentation task. The task consists in classifying image pixels into foreground or background. The dataset consists of 328 side-view color images of horses that were manually segmented. We keep 50 samples from the training set for validation. We randomly divide the remaining dataset into 5 almost equal folds and do 5-fold cross validation. For the performance measure, this task uses the intersection over union scores (Jaccard index) between pixel labelings.
For the binary segmentation task, we use the GCRF model. The unary network is a UNet-like (Ronneberger et al., 2015) fully-convolutional neural network which is a typical encoder-decoder model. The encoder consists of convolutional blocks, which are basically a stack of convolutions, batch normalization and ReLU activations. After each convolutional block, we downsample with max-pooling. The decoder consist of similar convolutional blocks and upsampling is done by the bilinear interpolation. The shortcut connections between the convolutional blocks of the encoder and decoder of the identical resolution allow to use the features of different resolutions for more robust segmentation. The architecture of pairwise network for pixel embeddings is similar to the unary network, but without the regression layer at the end.  Table 2. Results of the main experiment. We report the performance (metrics are task specific, see Section 6.1) and the mean training time (in minutes) of the stage and joint training procedures together with the three proposed ways of fixing the joint training. On the three tasks (OCR, chunking and binary segmentation), we studied the systems trained with the suitable objectives. For all the performance metrics, we report the mean and standard deviation w.r.t. 8 random seeds. Table 2 reports the results of different training schemes (stage and regular joint training with α = 1; the three methods to improve the joint training described in Section 5) on the three tasks described in Section 6.1. On the OCR and chunking tasks, we also compare the four training objectives: the cross-entropy on the exact marginals, structured SVM, log-likelihood and the cross-entropy on the marginals estimated with the mean-field (MF) approximation. For binary segmentation, we use the only objective available, which is the cross-entropy on the marginals estimated by the softmax of (14). We always report the mean and standard deviation computed over 8 random seeds and the training time. The details on the hyperparameter choice and stopping criterion (consequently, the time measurements) are provided in Appendix B.

Results and Discussion
As another baseline, the table below shows the performance of the unary predictors only, which is significantly worse than the performance of the full models in all tasks.  Table 2 shows that the proposed scaling techniques perform up to noise identically to the stage training procedure (but are two times faster, and have less hyperparameters to tune, see Appendix B for the details) and are always superior to the joint training. The online scaling scheme 5.1 has the most stable training at the cost of additional grid search steps, which increases the training time.

OCR
The offline scaling approaches allow to reduce computational complexity at the cost of having more hyperparameters. The regularization approach has slightly higher variance and has one extra hyperparameter, which increases the tuning time.
To strengthen our conclusions, we run additional experiments to investigate possible confounding factors of the effects reported in Table 2. All the models of Table 2 were trained with the Adam optimizer (Kingma & Ba, 2015), but we have tried alternatives and observed similar story, except that all the methods performed worse. We report the full results for SGD with momentum in Appendix A.1. As another possible confounding factor we investigate the joint scaling of the potentials (a.k.a. the temperature), which implies multiplying both unary and pairwise potentials on the same constant α. Our experiments with temperature scaling showed that it did not solve underperformance of the joint training at all (see Appendix A.2 for the results). We would also like to explicitly mention that the problems of the joint training are not related to over-fitting, which is confirmed by the fact that the same discrepancy between joint and stage procedures appears in the training error as well as in the test error, which we report in all our experiments.

Conclusion
In this paper, we study the situations when the joint training of the deep structured-prediction energy-based models unexpectedly performs worse than the inconvenient multistage training approach. We conjecture that the source of the problem lies in the improper relative scaling of the summands of the energy (that by construction are of different nature) and propose several ways (with different engineering properties) to fix the problem. We apply the proposed techniques to the two well-established models (linear-chain CRF and Gaussian CRF) on three different tasks and demonstrate that they indeed improve performance of the joint training to the level of the stage training procedure.

Supplementary Material (Appendix) Scaling Matters in Deep Structured-Prediction Models
A. Additional Experiments

A.1. Main Experiment with Another Optimizer
To show whether the poor performance of the basic joint training procedure and applicability of our approaches are not optimizer dependent, we repeat the main experiments of Table 2 with a different optimization method -SGD with momentum. We report the results in Table 3. As it can be seen the overall behavior stays the same, but the performance of all methods with the SGD optimizer is slightly worse than with Adam (Table 2). This observation suggests that the reason of joint procedure to underperform is not related to a particular chose of optimization algorithm (we have also tried RMSprop, but did not run a larger scale experiments with it). As the performance of SGD is worse compared to Adam we have chosen Adam for the main experiment reported in Section 6.2.

A.2. Main Experiment, but with Temperature Tuned
To show that the issue of joint training is not related to the joint scaling of the potentials, we consider a model with the extra parameter α in front of both unary and pairwise potentials: U θ (X) := αU θ (X),Ŵ θ (X) := αW θ (X).
The scaling factor α is then chosen on the validation set.
In this setting, we use the Adam optimizer. Table 4 shows that the joint scaling of the potentials does not significantly affect the resulting performance of the joint training procedure. Another scheme with the "hard" global scaling parameterization performs up to noise identically to the one reported in Table 4. These results allow us to conclude that the choice of the joint scaling (the temperature) is not the main reason for the joint training to underperform.

B. Hyperparameter Selection
In this section, we discuss the hyperparameters of all used schemes. The most important hyperparameters for all procedures appeared to be the learning rate and the number of training iterations. Consequently, the number of hyperparameters for stage procedure is 3 times larger than for the joint scheme (because we need to select the learning rate and the number of training iterations for each stage separately). For the proposed scaling methods, we also have additional parameters to tune, which we describe below.
Learning Rate and Stopping Criterion. We now discuss the methodology of choosing the learning rate and the number of optimizer iterations in the cases of stage and joint procedures. For joint procedures, the scheme is straightforward and does not differ from the regular deep learning pipeline. We choose the learning rate to ensure faster initial convergence (but without optimization diverging) and additionally reduce it by a factor of 10 after a number of epochs (3 for OCR, 1 for chunking, 5 for binary segmentation) with the dataset specific metric on the validation set changing less than 10 −3 in the absolute value (we use the ReduceLROnPlateau function implemented in Py-Torch). The number of optimizer iterations is chosen in a similar way, i.e., if within enough epochs (7 for OCR, 3 for chunking, 13 for binary segmentation) the changes in the dataset specific metric on the validation set are smaller than 10 −3 . In the case of stage training, the same procedure is repeated for each stage (three times) and the overall model performance is more sensitive to the selection of both the learning rate and number of iterations. When using these schemes, the joint training converged significantly faster in comparison to the stage scheme.
We would also like to mention that for the stage training it is sometimes beneficial not to train unary network to convergence, which makes choosing the stopping criterion for that stage much harder. The joint procedure does not have this issue.
Additional hyperparameters. For the online scaling method, we need to set the grid to search for α, the size of the subset to choose α and the initial scale. We observed that the uniform in the log scale grid defined as {2 t | t = −8, . . . , 8} worked well for all tasks we considered and there was no need to tune it. For the subset size, it was sufficient to always use around a third of the training data (which was 2000, 3000 and 100 examples for OCR, chunking and binary segmentation, respectively). The initialization of α also appeared not to be a sensitive parameter and it was sufficient to simply start with α = 1.
For the offline methods, we had to set scaling α and regularization weight λ. We had to select these hyperparameters by looking at the trained model results on the validation set. In this case, the complexity of tuning these parameters is the same as, e.g., choosing the weight decay parameter.  Table 4. Results of the main experiment, but with the temperature tuned. TEMP denotes the scheme with the global parameter α described in Section A.2.